#include "core.h"
#include "inputmanager.h"
#include "log.h"
#include "debugrender.h"
#include "game_object.h"
#include <SDL3/SDL.h>

REGISTER_ENTITY(Entity);

Entity::Entity() : 
	m_model(nullptr),
	m_skeleton(nullptr),
	m_shape(nullptr),
	m_rigidBody(nullptr),
	m_bodyDirty(false)
{
}

Entity::~Entity()
{
	if (m_onShutdownFunction.IsFunction())
	{
		LuaPlus::LuaFunctionVoid function = m_onShutdownFunction;
		function(m_luaObject);
	}

	if (m_luaObject.IsTable())
	{
		LuaPlus::LuaObject name = m_luaObject["m_name"];
		if (name.IsString())
		{
			LuaPlus::LuaObject factory = GetLuaState().GetGlobal("g_factory");
			factory.SetNil(name.GetString());
		}

		LuaPlus::LuaObject lookup = GetLuaState().GetGlobal("g_entities");
		lookup.SetNil(GetID());

		m_luaObject.AssignNil();
	}

	if (m_rigidBody) {
		g_PhysicsWorld->GetWorld()->removeRigidBody(m_rigidBody);

		delete m_rigidBody;
		m_rigidBody = nullptr;

		m_ph_motion_state.setBody(nullptr);
	}

	if (m_shape) {
		delete m_shape;
		m_shape = nullptr;
	}
}

void Entity::Update(float dt)
{
	if (m_skeleton)
		UpdateSkeleton(dt);

	if (m_rigidBody)
		UpdateBody();

	if ( m_onUpdateFunction.IsFunction())
	{
		LuaPlus::LuaFunctionVoid function = m_onUpdateFunction;
		function(m_luaObject, static_cast<lua_Number>(dt));
	}
}

bool g_debugEntityDraw = false;

void Entity::Render()
{
	if (m_model)
		m_model->Draw(GetWorldTransform(), m_skeleton);


	if (g_debugEntityDraw)
	{
		BoundingBox bbox = m_boundingBox;
		bbox.TransformAABB(GetWorldTransform());

		g_debugRender->DrawBoundingBox(bbox, glm::vec3(1.0f, 1.0f, 1.0f));
	}
}

void Entity::OnCollide(IEntityBase* other)
{
	if (!m_onCollideFunction.IsFunction())
		return;

	// find entity
	LuaPlus::LuaObject lookup = GetLuaState().GetGlobal("g_entities");
	LuaPlus::LuaObject otherTable = lookup.GetByIndex(other->GetID());
	if (!otherTable.IsNil())
	{
		LuaPlus::LuaFunctionVoid function = m_onCollideFunction;
		function(m_luaObject, otherTable);
	}
}

const std::string& Entity::GetName()
{
	return m_name;
}

void Entity::SetName(const std::string& name)
{
	m_name = name;
}

void Entity::LoadModel(const char* filename)
{
	if (m_skeleton) {
		delete m_skeleton;
		m_skeleton = nullptr;
	}

	m_model = g_modelSystem->LoadModel(filename);
	if (m_model)
		m_boundingBox = m_model->GetBoundingBox();

	if (m_model && m_model->GetNumAnimations())
		m_skeleton = m_model->CreateSkeletonInstance();
}

void Entity::SetVisible(bool visible)
{
}

bool Entity::GetVisible()
{
	return true;
}

SkeletonInstance* Entity::GetSkeletonInstance()
{
	return m_skeleton;
}

void Entity::UpdateSkeleton(float dt)
{
	if (m_model && m_skeleton)
	{
		m_model->UpdateSkeletonInstance(m_skeleton, dt);
	
		m_boundingBox = m_model->GetBoundingBox();

		for (int i = 0; i < m_skeleton->m_jointMatrices.size(); i++)
		{
			m_boundingBox.m_min = glm::min(m_boundingBox.m_min, glm::vec3(m_skeleton->m_jointMatrices[i][3]));
			m_boundingBox.m_max = glm::max(m_boundingBox.m_max, glm::vec3(m_skeleton->m_jointMatrices[i][3]));

		}
	}
}

void Entity::Init()
{
	// call init
	if (m_onInitFunction.IsFunction())
	{
		LuaPlus::LuaFunctionVoid onInitFunction = m_onInitFunction;
		onInitFunction(m_luaObject);
	}
}

void Entity::InitFromTable(LuaPlus::LuaObject& _object)
{
	SDL_assert_always(!_object.IsNil() && "Invalid object passed");

	// catch table instance
	m_luaObject = _object;

	// find functions
	InitLuaCallbacks();

	// check
	//SDL_assert_always(m_onInitFunction.IsFunction() || m_onShutdownFunction.IsFunction() || m_onUpdateFunction.IsFunction());

	// register base entity functions
	RegisterBaseFunctions();

	// register entity functions
	RegisterFunctions();

	m_luaObject.SetString("m_name", m_name.c_str());

	// assign C++ object
	m_luaObject.SetLightUserdata("__object", this);
}

void Entity::InitLuaCallbacks()
{
	m_onInitFunction = m_luaObject.GetByName("on_init");
	m_onShutdownFunction = m_luaObject.GetByName("on_shutdown");
	m_onUpdateFunction = m_luaObject.GetByName("on_update");
	m_onCollideFunction = m_luaObject.GetByName("on_collide");
}

void Entity::RegisterBaseFunctions()
{
	m_luaObject.Register("load_model", *this, &Entity::Lua_LoadModel);
	m_luaObject.Register("update_transform", *this, &Entity::Lua_UpdateTransform);
	m_luaObject.Register("translate", *this, &Entity::Lua_Translate);
	m_luaObject.Register("set_position", *this, &Entity::Lua_SetPosition);
	m_luaObject.Register("get_position", *this, &Entity::Lua_GetPosition);
	m_luaObject.Register("set_rotation", *this, &Entity::Lua_SetRotation);
	m_luaObject.Register("get_rotation", *this, &Entity::Lua_GetRotation);
	m_luaObject.Register("set_rotation_from_vectors", *this, &Entity::Lua_SetRotationFromVectors);
	m_luaObject.Register("get_classname", *this, &Entity::Lua_GetClassname);
	m_luaObject.Register("get_id", *this, &Entity::Lua_GetID);
	m_luaObject.Register("mark_for_delete", *this, &Entity::Lua_MarkForDelete);
	m_luaObject.Register("set_name", *this, &Entity::Lua_SetName);
	m_luaObject.Register("get_name", *this, &Entity::Lua_GetName);

	// physics
	m_luaObject.Register("set_velocity",  *this, &Entity::Lua_SetVelocity);
	m_luaObject.Register("get_velocity",  *this, &Entity::Lua_GetVelocity);
	m_luaObject.Register("has_rigid_body",  *this, &Entity::Lua_HasRigidBody);
	m_luaObject.Register("create_box_body",  *this, &Entity::Lua_CreateBoxBody);
	m_luaObject.Register("create_sphere_body",  *this, &Entity::Lua_CreateSphereBody);
	m_luaObject.Register("ForceBodyTransformUpdate",  *this, &Entity::Lua_ForceBodyTransformUpdate);
	m_luaObject.Register("set_body_filter_group",  *this, &Entity::Lua_SetBodyFilterGroup);
	m_luaObject.Register("set_body_filter_mask",  *this, &Entity::Lua_SetBodyFilterMask);
	m_luaObject.Register("get_body_filter_group",  *this, &Entity::Lua_GetBodyFilterGroup);
	m_luaObject.Register("get_body_filter_mask",  *this, &Entity::Lua_GetBodyFilterMask);

	// animation
	m_luaObject.Register("find_animation", *this, &Entity::Lua_FindAnimation);
	m_luaObject.Register("play_animation", *this, &Entity::Lua_PlayAnimation);
	m_luaObject.Register("stop_animation", *this, &Entity::Lua_StopAnimation);
	m_luaObject.Register("get_current_animation", *this, &Entity::Lua_GetCurrentAnimation);
	m_luaObject.Register("get_current_animation_time", *this, &Entity::Lua_GetCurrentAnimationTime);
	m_luaObject.Register("get_animation_time", *this, &Entity::Lua_GetAnimationTime);

	//int Lua_FindAnimation(LuaPlus::LuaState * state);
	//int Lua_PlayAnimation(LuaPlus::LuaState * state);
	//int Lua_GetCurrentAnimation(LuaPlus::LuaState * state);
	//int Lua_GetCurrentAnimationTime(LuaPlus::LuaState * state);
	//int Lua_GetAnimationTime(LuaPlus::LuaState * state);

//	m_luaObject.RegisterDirect("load_model", &Entity_LoadModel);
	//m_luaObject.RegisterDirect("set_visible", &Entity_SetVisible);
	//m_luaObject.RegisterDirect("get_visible", &Entity_GetVisible);
}

void Entity::RegisterFunctions()
{
}

void Entity::Help_Translate(float x, float y, float z)
{
	m_position.x += x;
	m_position.y += y;
	m_position.z += z;
}

void Entity::Help_SetPosition(float x, float y, float z)
{
	m_position.x = x;
	m_position.y = y;
	m_position.z = z;
}

void Entity::Help_SetRotation(float x, float y, float z)
{
	m_rotation.x = x;
	m_rotation.y = y;
	m_rotation.z = z;
}

void Entity::Help_SetRotationFromVectors(const glm::vec3& front, const glm::vec3& right, const glm::vec3& up)
{
	glm::mat3 rot;

	rot[0] = right;
	rot[1] = up;
	rot[2] = -front;

	glm::quat q = glm::quat_cast(rot);
	
	glm::quat fix = glm::angleAxis(glm::radians(90.0f), glm::vec3(0, 1, 0));
	q = q * fix;

	m_rotation = glm::degrees(glm::eulerAngles(q));
}

void Entity::Help_SetVelocity(float x, float y, float z)
{
	if (m_rigidBody)
		m_rigidBody->setLinearVelocity(btVector3(x, y, z));
}

int Entity::Lua_LoadModel(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);
	
	if (stack.Count() > 1)
	{
		LoadModel(stack[2].GetString());
	}
	else
	{
		LoadModel(stack[1].GetString());
	}
	
	return 0;
}

int Entity::Lua_Translate(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);

	float x = stack[2].GetNumber();
	float y = stack[3].GetNumber();
	float z = stack[4].GetNumber();

	Help_Translate(x, y, z);

	return 0;
}

int Entity::Lua_SetPosition(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);

	float x = stack[2].GetNumber();
	float y = stack[3].GetNumber();
	float z = stack[4].GetNumber();

	Help_SetPosition(x, y, z);

	return 0;
}

int Entity::Lua_GetPosition(LuaPlus::LuaState* state)
{
	state->PushNumber(m_position.x);
	state->PushNumber(m_position.y);
	state->PushNumber(m_position.z);
	return 3;
}

int Entity::Lua_GetRotation(LuaPlus::LuaState* state)
{
	state->PushNumber(m_rotation.x);
	state->PushNumber(m_rotation.y);
	state->PushNumber(m_rotation.z);
	return 3;
}

int Entity::Lua_SetRotation(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);

	float x = stack[2].GetNumber();
	float y = stack[3].GetNumber();
	float z = stack[4].GetNumber();

	Help_SetRotation(x, y, z);

	return 0;
}

int Entity::Lua_SetRotationFromVectors(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);

	glm::vec3 front = glm::vec3(stack[2].GetNumber(), stack[3].GetNumber(), stack[4].GetNumber());
	glm::vec3 right = glm::vec3(stack[5].GetNumber(), stack[6].GetNumber(), stack[7].GetNumber());
	glm::vec3 up = glm::vec3(stack[8].GetNumber(), stack[9].GetNumber(), stack[10].GetNumber());

	Help_SetRotationFromVectors(front, right, up);

	return 0;
}

int Entity::Lua_GetClassname(LuaPlus::LuaState* state)
{
	state->PushString(GetClassname());
	return 1;
}

int Entity::Lua_GetID(LuaPlus::LuaState* state)
{
	state->PushInteger(GetID());
	return 1;
}

int Entity::Lua_UpdateTransform(LuaPlus::LuaState* state)
{
	UpdateTransform();

	return 0;
}

int Entity::Lua_MarkForDelete(LuaPlus::LuaState* state)
{
	MarkForDelete();

	return 0;
}

int Entity::Lua_SetName(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);
	const char* name = stack[2].GetString();

	SetName(name);

	return 0;
}

int Entity::Lua_GetName(LuaPlus::LuaState* state)
{
	state->PushString(m_name.c_str());
	return 1;
}

int Entity::Lua_SetVelocity(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);

	float x = stack[2].GetNumber();
	float y = stack[3].GetNumber();
	float z = stack[4].GetNumber();

	Help_SetVelocity(x, y, z);

	return 0;
}

int Entity::Lua_GetVelocity(LuaPlus::LuaState* state)
{
	glm::vec3 velocity = glm::vec3(0.0f);
	if (m_rigidBody)
	{
		velocity = btVectorToGlm(m_rigidBody->getLinearVelocity());
	}

	state->PushNumber(velocity.x);
	state->PushNumber(velocity.y);
	state->PushNumber(velocity.z);

	return 3;
}

int Entity::Lua_HasRigidBody(LuaPlus::LuaState* state)
{
	state->PushBoolean(!!m_rigidBody);
	return 1;
}

int Entity::Lua_CreateBoxBody(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);

	glm::vec3 size;
	size.x = stack[2].GetNumber();
	size.y = stack[3].GetNumber();
	size.z = stack[4].GetNumber();

	float mass = stack[5].GetNumber();
	float friction = stack[6].GetNumber();
	float damping = stack[7].GetNumber();

	bool is_trigger = stack[8].GetBoolean();
	bool use_parameters = stack[9].GetBoolean();

	CreateBoxBody(size, mass, friction, damping, is_trigger, use_parameters);

	return 0;
}

int Entity::Lua_CreateSphereBody(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);

	float radius = stack[2].GetNumber();
	float mass = stack[3].GetNumber();
	float friction = stack[4].GetNumber();
	float damping = stack[5].GetNumber();

	bool is_trigger = stack[6].GetBoolean();
	bool use_parameters = stack[7].GetBoolean();

	CreateSphereBody(radius, mass, friction, damping, is_trigger, use_parameters);

	return 0;
}

int Entity::Lua_ForceBodyTransformUpdate(LuaPlus::LuaState* state)
{
	ForceUpdateBodyTranslation();

	return 0;
}

int Entity::Lua_SetBodyFilterGroup(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);
	SetBodyFilterGroup((PhysicsFilter)stack[2].GetInteger());

	return 0;
}

int Entity::Lua_SetBodyFilterMask(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);
	SetBodyFilterMask(stack[2].GetInteger());

	return 0;
}

int Entity::Lua_GetBodyFilterGroup(LuaPlus::LuaState* state)
{
	if (m_rigidBody)
		state->PushInteger(m_rigidBody->getBroadphaseHandle()->m_collisionFilterGroup);
	else
		state->PushInteger(-1);

	return 1;
}

int Entity::Lua_GetBodyFilterMask(LuaPlus::LuaState* state)
{
	if (m_rigidBody)
		state->PushInteger(m_rigidBody->getBroadphaseHandle()->m_collisionFilterMask);
	else
		state->PushInteger(-1);


	return 1;
}

int Entity::Lua_FindAnimation(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);
	const char* name = stack[2].GetString();

	if (!stack[2].IsString())
	{
		Core::Warning("find_animation: first argument is not an string");
		return 0;
	}

	if (m_model)
		state->PushInteger(m_model->FindAnimation(name));
	else
		state->PushInteger(INVALID_ANIMATION_HANDLE);

	return 1;
}

int Entity::Lua_PlayAnimation(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);

	if (!stack[2].IsNumber())
	{
		Core::Warning("play_animation: first argument is not an number");
		return 0;
	}

	AnimationId_t id = stack[2].GetInteger();
	int mode = stack[3].GetInteger();

	if (m_skeleton)
		m_skeleton->PlayAnimation(id, mode);

	return 0;
}

int Entity::Lua_StopAnimation(LuaPlus::LuaState* state)
{
	if (m_skeleton)
		m_skeleton->StopAnimation();

	return 0;
}

int Entity::Lua_GetCurrentAnimation(LuaPlus::LuaState* state)
{
	if (m_skeleton)
		state->PushInteger(m_skeleton->GetCurrentAnimation());
	else
		state->PushInteger(INVALID_ANIMATION_HANDLE);

	return 1;
}

int Entity::Lua_GetCurrentAnimationTime(LuaPlus::LuaState* state)
{
	if (m_skeleton)
		state->PushNumber(m_skeleton->GetCurrentTime());
	else
		state->PushNumber(0.0f);

	return 1;
}

int Entity::Lua_GetAnimationTime(LuaPlus::LuaState* state)
{
	LuaPlus::LuaStack stack(state);
	AnimationId_t id = stack[2].GetInteger();

	if (m_skeleton)
		state->PushNumber(m_skeleton->GetAnimationTime(id));
	else
		state->PushNumber(0.0f);

	return 1;
}

const LuaPlus::LuaObject& Entity::GetLuaObject()
{
	return m_luaObject;
}

void Entity::CreateTestBody()
{
	m_shape = new btBoxShape(btVector3(0.2f, 0.2f, 0.2f));

	CreateBodyPrivate(80.0f, 0.0, 0.0f, false, false);

	//m_mass = 80.0f;
	//btVector3 local_inertia(0.0f, 0.0f, 0.0f);
	//if (m_mass > 0.f) {
	//	m_shape->calculateLocalInertia(m_mass, local_inertia);
	//}

	//btRigidBody::btRigidBodyConstructionInfo rigid_body_ci(m_mass, nullptr, m_shape, local_inertia);

	//m_rigidBody = new btRigidBody(rigid_body_ci);
	//m_rigidBody->setUserPointer(this);
	//m_rigidBody->setMotionState(&m_ph_motion_state);
	//m_ph_motion_state.setBody(m_rigidBody);

	//// I'm sure that position is valid
	//btTransform xform;
	//xform.setIdentity();
	//xform.setOrigin(glmVectorToBt(m_position));
	//m_rigidBody->setWorldTransform(xform);

	//// #TODO: body filter and mask
	//g_PhysicsWorld->GetWorld()->addRigidBody(m_rigidBody);

	//m_bodyDirty = true;
}

void Entity::CreateBoxBody(const glm::vec3& size, float mass, float friction, float damping, bool is_trigger, bool use_parameters)
{
	m_shape = (btCollisionShape*)new btBoxShape(glmVectorToBt(size));

	CreateBodyPrivate(mass, friction, damping, is_trigger, use_parameters);
}

void Entity::CreateSphereBody(float radius, float mass, float friction, float damping, bool is_trigger, bool use_parameters)
{
	m_shape = (btCollisionShape*)new btSphereShape(radius);

	CreateBodyPrivate(mass, friction, damping, is_trigger, use_parameters);
}

void Entity::CreateBodyPrivate(float mass, float friction, float damping, bool is_trigger, bool use_parameters)
{
	SDL_assert_always(m_shape);

	m_mass = mass;

	if (is_trigger && m_mass > 0.f)
	{
		Msg("WARNING! Entity '%s' trying to create body with mass %f and trigger flag, setting to zero.", m_name.c_str(), mass);
		m_mass = 0.0f;
	}

	btVector3 local_inertia(0.0f, 0.0f, 0.0f);
	if (m_mass > 0.f) {
		m_shape->calculateLocalInertia(m_mass, local_inertia);
	}

	btRigidBody::btRigidBodyConstructionInfo rigid_body_ci(m_mass, nullptr, m_shape, local_inertia);

	m_rigidBody = new btRigidBody(rigid_body_ci);
	m_rigidBody->setUserPointer(this);
	m_rigidBody->setMotionState(&m_ph_motion_state);
	m_ph_motion_state.setBody(m_rigidBody);

	// I'm sure that position is valid
	btTransform xform;
	xform.setIdentity();
	xform.setOrigin(glmVectorToBt(m_position));
	m_rigidBody->setWorldTransform(xform);

	// body parameters
	if (use_parameters)
	{
		m_rigidBody->setFriction(friction);
		m_rigidBody->setAnisotropicFriction(btVector3(0.0f, 0.0f, 0.0f));
		m_rigidBody->setDamping(damping, 0.0f);
	}
	
	int bodyCollisionFlags = m_rigidBody->getCollisionFlags();

	if (is_trigger)
		bodyCollisionFlags |= btRigidBody::CF_NO_CONTACT_RESPONSE;
	else
		bodyCollisionFlags &= ~btRigidBody::CF_NO_CONTACT_RESPONSE;

	m_rigidBody->setCollisionFlags(bodyCollisionFlags);

	if (is_trigger)
		m_rigidBody->setCustomDebugColor(btVector3(1.0f, 0.5f, 0.0f));

	// #TODO: body filter and mask
	g_PhysicsWorld->GetWorld()->addRigidBody(m_rigidBody);

	m_bodyDirty = true;
}

void Entity::UpdateBody()
{
	m_position = btVectorToGlm(m_ph_motion_state.m_transform.getOrigin());
	m_ph_motion_state.m_transform.getRotation().getEulerZYX(m_rotation.z, m_rotation.y, m_rotation.x);
	m_rotation = glm::degrees(m_rotation);
}

void Entity::UpdateBodyDirty()
{
	if (m_bodyDirty)
	{
		btTransform xform;
		xform.setIdentity();
		xform.setOrigin(glmVectorToBt(m_position));
		m_rigidBody->setWorldTransform(xform);

		m_bodyDirty = false;
	}
}

void Entity::ForceUpdateBodyTranslation()
{
	if (!m_rigidBody)
		return;

	// I'm sure that position is valid
	btTransform xform;
	xform.setIdentity();
	xform.setOrigin(glmVectorToBt(m_position));
	m_rigidBody->setWorldTransform(xform);
}

void Entity::SetBodyFilterGroup(PhysicsFilter group)
{
	if (!m_rigidBody)
		return;

	m_rigidBody->getBroadphaseHandle()->m_collisionFilterGroup = group;
}

void Entity::SetBodyFilterMask(int mask)
{
	if (!m_rigidBody)
		return;

	m_rigidBody->getBroadphaseHandle()->m_collisionFilterMask = mask;
}

REGISTER_ENTITY(WeaponBase);

WeaponBase::WeaponBase()
{
}

WeaponBase::~WeaponBase()
{
}

void WeaponBase::Update(float dt)
{
	Entity::Update(dt);
}

void WeaponBase::Fire(const glm::vec3& direction, float damage)
{
}

//// Lua wrappers
//void Entity_LoadModel(LuaPlus::LuaState* state)
//{
//	LuaPlus::LuaStack stack(state);
//
//	Entity* entity = (Entity*)stack[1].GetByName("__object").GetLightUserdata();
//	entity->LoadModel(stack[2].GetString());
//}
//
//void Entity_SetVisible(LuaPlus::LuaState* state)
//{
//	LuaPlus::LuaStack stack(state);
//
//	Entity* entity = (Entity*)stack[1].GetByName("__object").GetLightUserdata();
//	entity->SetVisible(stack[2].GetBoolean());
//}
//
//bool Entity_GetVisible(LuaPlus::LuaState* state)
//{
//	LuaPlus::LuaStack stack(state);
//
//	Entity* entity = (Entity*)stack[1].GetByName("__object").GetLightUserdata();
//	return entity->GetVisible();
//}
//
//void ActorBase_UpdateCameraMovement(LuaPlus::LuaState* state)
//{
//	LuaPlus::LuaStack stack(state);
//
//	ActorBase* entity = (ActorBase*)stack[1].GetByName("__object").GetLightUserdata();
//	entity->UpdateCameraMovement(stack[2].GetFloat());
//}
//
//void ActorBase_UpdateCameraLook(LuaPlus::LuaState* state)
//{
//	LuaPlus::LuaStack stack(state);
//
//	ActorBase* entity = (ActorBase*)stack[1].GetByName("__object").GetLightUserdata();
//	entity->UpdateCameraLook();
//}
//
//void ActorBase_ActivateCamera(LuaPlus::LuaState* state)
//{
//	LuaPlus::LuaStack stack(state);
//
//	ActorBase* entity = (ActorBase*)stack[1].GetByName("__object").GetLightUserdata();
//	entity->ActivateCamera();
//}

REGISTER_ENTITY(TriggerBase);

TriggerBase::TriggerBase()
{
}

TriggerBase::~TriggerBase()
{
}

void TriggerBase::Render()
{
	if (m_rigidBody && g_debugEntityDraw)
	{
		BoundingBox bbox;
		bbox.m_min = btVectorToGlm(m_rigidBody->getBroadphaseHandle()->m_aabbMin);
		bbox.m_max = btVectorToGlm(m_rigidBody->getBroadphaseHandle()->m_aabbMax);
		g_debugRender->DrawBoundingBox(bbox, glm::vec3(1.0f, 0.5f, 0.0f));
	}
}
