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;
|
2014-01-16 12:26:14 +01:00
|
|
|
|
2014-01-29 14:33:21 +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-20 09:42:02 +01:00
|
|
|
this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN;
|
2014-01-29 14:33:21 +01:00
|
|
|
this->objectID = GID();
|
2014-02-03 15:52:00 +01:00
|
|
|
this->currPhysicsState = this->rigidBody->GetState();
|
|
|
|
this->newPhysicsState = this->currPhysicsState;
|
2013-12-12 09:36:14 +01:00
|
|
|
}
|
2013-11-19 18:35:35 +01:00
|
|
|
|
2014-01-29 14:33:21 +01:00
|
|
|
Object::Object(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
|
|
|
|
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);
|
2014-01-29 14:33:21 +01:00
|
|
|
this->type = type;
|
2013-12-18 13:01:13 +01:00
|
|
|
this->objectID = GID();
|
2014-02-03 15:52:00 +01:00
|
|
|
this->currPhysicsState = this->rigidBody->GetState();
|
|
|
|
this->newPhysicsState = this->currPhysicsState;
|
2014-01-29 14:33:21 +01:00
|
|
|
}
|
2014-01-23 09:14:04 +01:00
|
|
|
|
2014-01-29 14:33:21 +01:00
|
|
|
Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
|
|
|
|
{
|
|
|
|
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
|
|
|
this->rigidBody = rigidBody;
|
2014-01-23 09:14:04 +01:00
|
|
|
this->type = type;
|
2014-01-29 14:33:21 +01:00
|
|
|
this->objectID = GID();
|
2014-02-03 15:52:00 +01:00
|
|
|
this->currPhysicsState = this->rigidBody->GetState();
|
|
|
|
this->newPhysicsState = this->currPhysicsState;
|
2014-01-23 09:14:04 +01:00
|
|
|
}
|
|
|
|
|
2014-01-29 14:33:21 +01:00
|
|
|
Object::Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
|
2014-01-23 09:14:04 +01:00
|
|
|
{
|
2014-01-29 14:33:21 +01:00
|
|
|
API::SimpleBodyDescription sbDesc;
|
|
|
|
|
|
|
|
this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
|
2014-01-23 09:14:04 +01:00
|
|
|
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
2014-01-29 14:33:21 +01:00
|
|
|
|
|
|
|
this->type = type;
|
|
|
|
this->objectID = GID();
|
2014-02-03 15:52:00 +01:00
|
|
|
this->currPhysicsState = this->rigidBody->GetState();
|
|
|
|
this->newPhysicsState = this->currPhysicsState;
|
2014-01-29 14:33:21 +01:00
|
|
|
}
|
2014-01-23 09:14:04 +01:00
|
|
|
|
2014-01-29 14:33:21 +01:00
|
|
|
Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
|
|
|
|
{
|
|
|
|
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
2014-01-27 08:54:25 +01:00
|
|
|
|
2014-01-29 14:33:21 +01:00
|
|
|
this->rigidBody = rigidBody;
|
|
|
|
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(collisionFuncBefore));
|
|
|
|
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
|
2013-12-18 13:01:13 +01:00
|
|
|
|
2013-12-12 09:36:14 +01:00
|
|
|
this->type = type;
|
2014-01-29 14:33:21 +01:00
|
|
|
this->objectID = GID();
|
2014-02-03 15:52:00 +01:00
|
|
|
this->currPhysicsState = this->rigidBody->GetState();
|
|
|
|
this->newPhysicsState = this->currPhysicsState;
|
2013-11-21 12:05:39 +01:00
|
|
|
}
|
2013-11-28 08:33:29 +01:00
|
|
|
|
2014-01-29 14:33:21 +01:00
|
|
|
Object::Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
|
2014-01-27 08:54:25 +01:00
|
|
|
{
|
2014-01-27 13:54:57 +01:00
|
|
|
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
2014-01-28 15:04:25 +01:00
|
|
|
|
2014-01-27 13:54:57 +01:00
|
|
|
this->rigidBody = rigidBody;
|
2014-01-29 14:33:21 +01:00
|
|
|
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(collisionFuncBefore));
|
|
|
|
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
|
|
|
|
|
|
|
|
|
2014-01-27 13:54:57 +01:00
|
|
|
this->type = type;
|
|
|
|
this->objectID = GID();
|
2014-02-03 15:52:00 +01:00
|
|
|
this->currPhysicsState = this->rigidBody->GetState();
|
|
|
|
this->newPhysicsState = this->currPhysicsState;
|
2014-01-27 08:54:25 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 15:44:32 +01:00
|
|
|
void Object::ApplyLinearImpulse(Oyster::Math::Float3 force)
|
2014-01-22 14:26:45 +01:00
|
|
|
{
|
2014-02-03 15:52:00 +01:00
|
|
|
newPhysicsState.ApplyLinearImpulse(force);
|
2014-01-22 14:26:45 +01:00
|
|
|
}
|
|
|
|
|
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-30 09:40:58 +01:00
|
|
|
OBJECT_TYPE Object::GetObjectType() 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-02-03 15:52:00 +01:00
|
|
|
|
2014-02-04 11:50:15 +01:00
|
|
|
|
2014-02-04 16:08:28 +01:00
|
|
|
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
|
|
|
{
|
|
|
|
//error
|
|
|
|
int i =0 ;
|
|
|
|
}
|
|
|
|
if(currPhysicsState.GetCenterPosition() !=currPhysicsState.GetCenterPosition())
|
|
|
|
{
|
|
|
|
//error
|
|
|
|
int i =0 ;
|
|
|
|
}
|
|
|
|
if(currPhysicsState.GetAngularAxis() !=currPhysicsState.GetAngularAxis())
|
|
|
|
{
|
|
|
|
//error
|
|
|
|
int i =0 ;
|
|
|
|
}
|
2014-02-03 15:52:00 +01:00
|
|
|
this->rigidBody->SetState(this->newPhysicsState);
|
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-02-04 16:39:01 +01:00
|
|
|
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
|
|
|
{
|
|
|
|
//error
|
|
|
|
int i =0 ;
|
|
|
|
}
|
2014-02-03 15:52:00 +01:00
|
|
|
this->currPhysicsState = this->rigidBody->GetState();
|
2014-02-04 16:39:01 +01:00
|
|
|
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
|
|
|
{
|
|
|
|
//error
|
|
|
|
int i =0 ;
|
|
|
|
}
|
2014-02-04 16:08:28 +01:00
|
|
|
if(currPhysicsState.GetGravityNormal() !=currPhysicsState.GetGravityNormal())
|
|
|
|
{
|
|
|
|
//error
|
|
|
|
int i =0 ;
|
|
|
|
}
|
2014-02-05 09:06:33 +01:00
|
|
|
|
|
|
|
|
2014-02-07 11:43:18 +01:00
|
|
|
//if(currPhysicsState.GetGravityNormal()!= Float3::null)
|
2014-02-04 11:50:15 +01:00
|
|
|
{
|
|
|
|
Oyster::Math::Float4 axis;
|
2014-02-07 11:43:18 +01:00
|
|
|
Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(currPhysicsState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, Oyster::Math::Float4(currPhysicsState.GetCenterPosition().GetNormalized(), 0), axis);
|
2014-02-04 11:50:15 +01:00
|
|
|
if(axis !=axis)
|
|
|
|
{
|
|
|
|
//error
|
|
|
|
int i =0 ;
|
|
|
|
}
|
2014-02-06 21:15:28 +01:00
|
|
|
axis.Normalize();
|
2014-02-04 11:50:15 +01:00
|
|
|
currPhysicsState.SetRotation(axis.xyz);
|
|
|
|
currPhysicsState.SetAngularMomentum(Float3::null);
|
2014-02-07 11:43:18 +01:00
|
|
|
//Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y);
|
|
|
|
//debug += currPhysicsState.GetGravityNormal();
|
2014-02-04 11:50:15 +01:00
|
|
|
}
|
2014-02-07 11:43:18 +01:00
|
|
|
//Oyster::Math::Float3 pos = currPhysicsState.GetCenterPosition();
|
|
|
|
//Oyster::Math::Float3 up = -currPhysicsState.GetGravityNormal();
|
2014-02-05 09:06:33 +01:00
|
|
|
//300, 0,0,
|
|
|
|
//1,0,0
|
|
|
|
|
2014-02-07 11:43:18 +01:00
|
|
|
/*if( pos.GetLength() < 301.5f)
|
2014-02-05 09:06:33 +01:00
|
|
|
{
|
2014-02-07 11:43:18 +01:00
|
|
|
Oyster::Math::Float moveUp = 301.5 - pos.GetLength();
|
2014-02-05 09:06:33 +01:00
|
|
|
up *= moveUp;
|
|
|
|
|
2014-02-05 11:46:04 +01:00
|
|
|
currPhysicsState.SetCenterPosition(pos + up);
|
2014-02-06 21:15:28 +01:00
|
|
|
}*/
|
2014-02-04 16:08:28 +01:00
|
|
|
|
|
|
|
|
2014-02-04 16:39:01 +01:00
|
|
|
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
|
|
|
{
|
|
|
|
//error
|
|
|
|
int i =0 ;
|
|
|
|
}
|
2014-02-04 16:08:28 +01:00
|
|
|
|
2014-02-03 15:52:00 +01:00
|
|
|
this->newPhysicsState = this->currPhysicsState;
|
2014-01-28 15:04:25 +01:00
|
|
|
}
|
2014-01-29 16:01:56 +01:00
|
|
|
|
|
|
|
void Object::setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter))
|
|
|
|
{
|
|
|
|
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(collisionFuncBefore));
|
|
|
|
}
|
|
|
|
void Object::setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss))
|
|
|
|
{
|
|
|
|
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
|
|
|
|
}
|
|
|
|
|
2014-01-28 15:04:25 +01:00
|
|
|
Oyster::Math::Float3 Object::GetPosition()
|
|
|
|
{
|
|
|
|
Oyster::Physics::ICustomBody::State state;
|
|
|
|
state = this->rigidBody->GetState();
|
|
|
|
return state.GetCenterPosition();
|
|
|
|
}
|
|
|
|
Oyster::Math::Float4x4 Object::GetOrientation()
|
|
|
|
{
|
|
|
|
Oyster::Physics::ICustomBody::State state;
|
|
|
|
state = this->rigidBody->GetState();
|
|
|
|
return state.GetOrientation();
|
2014-01-20 15:47:52 +01:00
|
|
|
}
|