2013-11-19 18:35:35 +01:00
|
|
|
#include "Object.h"
|
2013-11-21 12:05:39 +01:00
|
|
|
#include "OysterMath.h"
|
2013-12-12 12:16:13 +01:00
|
|
|
#include "CollisionManager.h"
|
2013-12-18 13:01:13 +01:00
|
|
|
#include "GID.h"
|
2013-12-21 17:37:30 +01:00
|
|
|
#include "PhysicsAPI.h"
|
2014-01-20 15:47:52 +01:00
|
|
|
#include "Game.h"
|
2013-11-21 12:05:39 +01:00
|
|
|
|
2013-11-19 18:35:35 +01:00
|
|
|
|
|
|
|
using namespace GameLogic;
|
|
|
|
|
2013-11-21 12:05:39 +01:00
|
|
|
using namespace Oyster::Math;
|
2013-11-28 11:23:11 +01:00
|
|
|
using namespace Oyster::Physics;
|
2013-11-19 18:35:35 +01:00
|
|
|
|
2014-01-20 15:47:52 +01:00
|
|
|
const Game *Object::gameInstance = (Game*)(&Game::Instance());
|
|
|
|
|
2013-12-12 09:36:14 +01:00
|
|
|
Object::Object()
|
|
|
|
{
|
2013-11-29 09:23:00 +01:00
|
|
|
API::SimpleBodyDescription sbDesc;
|
|
|
|
//sbDesc.centerPosition =
|
|
|
|
|
2013-12-03 11:47:04 +01:00
|
|
|
//poi
|
2014-01-15 11:03:25 +01:00
|
|
|
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
|
2013-11-28 11:23:11 +01:00
|
|
|
|
2014-01-16 12:26:14 +01:00
|
|
|
|
|
|
|
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
|
|
|
|
2013-12-21 17:37:30 +01:00
|
|
|
//rigidBody->gameObjectRef = this;
|
2013-11-21 12:05:39 +01:00
|
|
|
|
2013-12-18 13:01:13 +01:00
|
|
|
this->objectID = GID();
|
2013-11-19 18:35:35 +01:00
|
|
|
|
2013-12-20 09:42:02 +01:00
|
|
|
this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN;
|
2013-12-12 09:36:14 +01:00
|
|
|
}
|
2013-11-19 18:35:35 +01:00
|
|
|
|
2013-12-12 09:36:14 +01:00
|
|
|
Object::Object(void* collisionFunc, OBJECT_TYPE type)
|
2013-11-19 18:35:35 +01:00
|
|
|
{
|
2013-12-12 09:36:14 +01:00
|
|
|
API::SimpleBodyDescription sbDesc;
|
2013-11-28 08:37:56 +01:00
|
|
|
|
2013-12-12 09:36:14 +01:00
|
|
|
//poi
|
2014-01-20 15:47:52 +01:00
|
|
|
this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
|
2014-01-16 12:26:14 +01:00
|
|
|
|
|
|
|
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
2013-12-12 09:36:14 +01:00
|
|
|
|
|
|
|
rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
|
|
|
|
|
2013-12-21 17:37:30 +01:00
|
|
|
//rigidBody->gameObjectRef = this;
|
2013-11-28 08:33:29 +01:00
|
|
|
|
2013-12-18 13:01:13 +01:00
|
|
|
this->objectID = GID();
|
|
|
|
|
2013-12-12 09:36:14 +01:00
|
|
|
this->type = type;
|
2013-11-21 12:05:39 +01:00
|
|
|
}
|
2013-11-28 08:33:29 +01:00
|
|
|
|
2014-01-22 14:26:45 +01:00
|
|
|
void Object::ApplyLinearImpulse(Oyster::Math::Float4 force)
|
|
|
|
{
|
|
|
|
setState.ApplyLinearImpulse(force);
|
|
|
|
}
|
|
|
|
|
2013-12-12 09:36:14 +01:00
|
|
|
|
|
|
|
Object::~Object(void)
|
2013-11-28 11:23:11 +01:00
|
|
|
{
|
2013-12-12 09:36:14 +01:00
|
|
|
|
2013-11-19 18:35:35 +01:00
|
|
|
}
|
2013-11-26 11:30:49 +01:00
|
|
|
|
2014-01-15 11:03:25 +01:00
|
|
|
OBJECT_TYPE Object::GetType() const
|
2013-11-26 11:30:49 +01:00
|
|
|
{
|
|
|
|
return this->type;
|
|
|
|
}
|
2014-01-15 11:03:25 +01:00
|
|
|
int Object::GetID() const
|
2013-12-18 13:01:13 +01:00
|
|
|
{
|
|
|
|
return this->objectID;
|
|
|
|
}
|
2013-12-12 12:16:13 +01:00
|
|
|
|
|
|
|
Oyster::Physics::ICustomBody* Object::GetRigidBody()
|
|
|
|
{
|
|
|
|
return this->rigidBody;
|
|
|
|
}
|
2014-01-20 15:47:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
void Object::BeginFrame()
|
|
|
|
{
|
2014-01-23 08:24:35 +01:00
|
|
|
|
2014-01-20 15:47:52 +01:00
|
|
|
this->rigidBody->SetState(this->setState);
|
2014-01-23 08:24:35 +01:00
|
|
|
|
2014-01-20 15:47:52 +01:00
|
|
|
}
|
2014-01-23 08:24:35 +01:00
|
|
|
// update physic
|
2014-01-20 15:47:52 +01:00
|
|
|
void Object::EndFrame()
|
|
|
|
{
|
2014-01-23 08:24:35 +01:00
|
|
|
|
|
|
|
//Oyster::Math::Float rot = (setState.GetGravityNormal().xyz).Dot(getState.GetGravityNormal().xyz);
|
|
|
|
//Oyster::Math::Float3 axis = (setState.GetGravityNormal().xyz).Cross(getState.GetGravityNormal().xyz);
|
|
|
|
Oyster::Math::Float4x4 rotMatrix = setState.GetOrientation(); //Oyster::Math3D::RotationMatrix(rot, axis);
|
|
|
|
Oyster::Math3D::SnapAxisYToNormal_UsingNlerp(rotMatrix, -setState.GetGravityNormal());
|
|
|
|
setState.SetOrientation(rotMatrix);
|
|
|
|
|
|
|
|
|
|
|
|
this->getState = this->rigidBody->GetState();
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-20 15:47:52 +01:00
|
|
|
this->setState = this->getState;
|
2014-01-23 08:24:35 +01:00
|
|
|
|
2014-01-20 15:47:52 +01:00
|
|
|
}
|