Updated creation of objects

This commit is contained in:
Erik Persson 2014-01-27 08:54:25 +01:00
parent fb2cf714c6
commit 74ac5e2d31
12 changed files with 60 additions and 30 deletions

View File

@ -50,7 +50,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float
Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20); Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20);
Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace)); Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace));
//Oyster::Physics::API::Instance().ApplyEffect(hitFrustum,ForcePushAction); Oyster::Physics::API::Instance().ApplyEffect(hitFrustum,ForcePushAction);
} }

View File

@ -36,7 +36,7 @@ namespace GameLogic
********************************************************/ ********************************************************/
void ForceSuck(const WEAPON_FIRE &usage, float dt); void ForceSuck(const WEAPON_FIRE &usage, float dt);
void ForcePushAction(Oyster::Physics::ICustomBody *obj); static void ForcePushAction(Oyster::Physics::ICustomBody *obj);
private: private:

View File

@ -13,14 +13,14 @@ using namespace GameLogic;
void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss); void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss);
//Physics::ICustomBody::SubscriptMessage //Physics::ICustomBody::SubscriptMessage
void Player::PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) void Player::PlayerCollision(Oyster::Physics::ICustomBody *rigidBodyPlayer, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
{ {
Player *player = ((Player*)(rigidBodyPlayer->GetCustomTag())); Player *player = ((Player*)(rigidBodyPlayer->GetCustomTag()));
Object *realObj = (Object*)obj->GetCustomTag(); Object *realObj = (Object*)obj->GetCustomTag();
switch (realObj->GetType()) switch (realObj->GetType())
{ {
case OBJECT_H::OBJECT_TYPE_GENERIC: case OBJECT_TYPE::OBJECT_TYPE_GENERIC:
PlayerVObject(*player,*realObj, kineticEnergyLoss); PlayerVObject(*player,*realObj, kineticEnergyLoss);
//return Physics::ICustomBody::SubscriptMessage_none; //return Physics::ICustomBody::SubscriptMessage_none;
break; break;
@ -52,9 +52,16 @@ using namespace GameLogic;
//Collision between a player and a general static or dynamic object //Collision between a player and a general static or dynamic object
//use kinetic energyloss of the collision in order too determin how much damage to take //use kinetic energyloss of the collision in order too determin how much damage to take
//use as part of the damage algorithm //use as part of the damage algorithm
player.DamageLife(20); int damageDone = 0;
} int forceThreashHold = 200;
if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough
{
damageDone = kineticEnergyLoss * 0.10f;
player.DamageLife(damageDone);
}
}
//Oyster::Physics::ICustomBody::SubscriptMessage //Oyster::Physics::ICustomBody::SubscriptMessage
void Level::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) void Level::LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
{ {
@ -63,6 +70,6 @@ using namespace GameLogic;
void AttatchmentMassDriver::ForcePushAction(Oyster::Physics::ICustomBody *obj) void AttatchmentMassDriver::ForcePushAction(Oyster::Physics::ICustomBody *obj)
{ {
Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500); Oyster::Math::Float4 pushForce = Oyster::Math::Float4(owner->GetLookDir()) * (500);
((Object*)obj->GetCustomTag())->ApplyLinearImpulse(pushForce); ((Object*)obj->GetCustomTag())->ApplyLinearImpulse(pushForce);
} }

View File

@ -16,6 +16,12 @@ DynamicObject::DynamicObject(void* collisionFunc, OBJECT_TYPE type)
} }
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
:Object(rigidBody, collisionFunc, type)
{
}
DynamicObject::~DynamicObject(void) DynamicObject::~DynamicObject(void)
{ {

View File

@ -15,6 +15,7 @@ namespace GameLogic
public: public:
DynamicObject(); DynamicObject();
DynamicObject(void* collisionFunc, OBJECT_TYPE type); DynamicObject(void* collisionFunc, OBJECT_TYPE type);
DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
~DynamicObject(void); ~DynamicObject(void);
private: private:

View File

@ -5,7 +5,16 @@ using namespace GameLogic;
Game::PlayerData::PlayerData() Game::PlayerData::PlayerData()
{ {
this->player = new Player(); Oyster::Physics::API::SimpleBodyDescription sbDesc;
//create rigidbody
Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release();
//create player with this rigidbody
this->player = new Player(rigidBody,Player::PlayerCollision,OBJECT_TYPE::OBJECT_TYPE_PLAYER);
this->player->GetRigidBody()->SetCustomTag(this); this->player->GetRigidBody()->SetCustomTag(this);
} }
Game::PlayerData::PlayerData(int playerID,int teamID) Game::PlayerData::PlayerData(int playerID,int teamID)

View File

@ -54,12 +54,17 @@ Object::Object(ICustomBody *rigidBody ,void* collisionFunc, OBJECT_TYPE type)
Oyster::Physics::API::Instance().AddObject(rigidBody); Oyster::Physics::API::Instance().AddObject(rigidBody);
rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc)); rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
rigidBody->SetCustomTag(this);
this->objectID = GID(); this->objectID = GID();
this->type = type; this->type = type;
} }
Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
{
}
void Object::ApplyLinearImpulse(Oyster::Math::Float4 force) void Object::ApplyLinearImpulse(Oyster::Math::Float4 force)
{ {
setState.ApplyLinearImpulse(force); setState.ApplyLinearImpulse(force);
@ -98,11 +103,9 @@ void Object::EndFrame()
//Oyster::Math::Float rot = (setState.GetGravityNormal().xyz).Dot(getState.GetGravityNormal().xyz); //Oyster::Math::Float rot = (setState.GetGravityNormal().xyz).Dot(getState.GetGravityNormal().xyz);
//Oyster::Math::Float3 axis = (setState.GetGravityNormal().xyz).Cross(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);
// align with gravity normal Oyster::Math3D::SnapAxisYToNormal_UsingNlerp(rotMatrix, -setState.GetGravityNormal());
//Oyster::Math::Float4x4 rotMatrix = setState.GetOrientation(); //Oyster::Math3D::RotationMatrix(rot, axis); setState.SetOrientation(rotMatrix);
//Oyster::Math3D::SnapAxisYToNormal_UsingNlerp(rotMatrix, -setState.GetGravityNormal());
//setState.SetOrientation(rotMatrix);
this->getState = this->rigidBody->GetState(); this->getState = this->rigidBody->GetState();

View File

@ -19,6 +19,7 @@ namespace GameLogic
Object(); Object();
Object(void* collisionFunc, OBJECT_TYPE type); Object(void* collisionFunc, OBJECT_TYPE type);
Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFunc, OBJECT_TYPE type); Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFunc, OBJECT_TYPE type);
Object(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
~Object(void); ~Object(void);
OBJECT_TYPE GetType() const; OBJECT_TYPE GetType() const;

View File

@ -18,7 +18,12 @@ Player::Player()
lookDir = Oyster::Math::Float4(0,0,-1,0); lookDir = Oyster::Math::Float4(0,0,-1,0);
setState.SetCenterPosition(Oyster::Math::Float4(0,15,0,1)); setState.SetCenterPosition(Oyster::Math::Float4(0,15,0,1));
setState.SetReach(Oyster::Math::Float4(2,3.5,2,0)); setState.SetReach(Oyster::Math::Float4(2,3.5,2,0));
//setState.SetRotation(Oyster::Math::Float4(0,0,0,0).Normalize()); }
Player::Player(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
:DynamicObject(rigidBody, collisionFunc, type)
{
} }
Player::~Player(void) Player::~Player(void)
@ -65,7 +70,6 @@ void Player::MoveBackwards()
void Player::MoveRight() void Player::MoveRight()
{ {
//Do cross product with forward vector and negative gravity vector //Do cross product with forward vector and negative gravity vector
// temp up vector
Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 ); Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
//Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); //Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir);
setState.ApplyLinearImpulse(r * 20 * this->gameInstance->GetFrameTime()); setState.ApplyLinearImpulse(r * 20 * this->gameInstance->GetFrameTime());
@ -74,7 +78,6 @@ void Player::MoveRight()
void Player::MoveLeft() void Player::MoveLeft()
{ {
//Do cross product with forward vector and negative gravity vector //Do cross product with forward vector and negative gravity vector
// temp up vector
Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 ); Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
//Oyster::Math::Float4 r1 = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); //Still get zero //Oyster::Math::Float4 r1 = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); //Still get zero
setState.ApplyLinearImpulse(-r * 20 * this->gameInstance->GetFrameTime()); setState.ApplyLinearImpulse(-r * 20 * this->gameInstance->GetFrameTime());
@ -93,17 +96,10 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint)
this->lookDir = Oyster::Math::Float4(1,0,0); this->lookDir = Oyster::Math::Float4(1,0,0);
} }
void Player::Rotate(const Oyster::Math3D::Float3 lookDir) void Player::Rotate(float dx, float dy)
{ {
this->lookDir = lookDir; //this->lookDir = lookDir;
Oyster::Math::Float4 up(0,1,0,0);//-setState.GetGravityNormal();
Oyster::Math::Float4 pos = setState.GetCenterPosition();
Oyster::Math::Float4x4 world = Oyster::Math3D::OrientationMatrix_LookAtDirection(lookDir, up.xyz, pos.xyz);
// cant set rotation
//setState.SetOrientation(world);
//this->lookDir = lookDir - up.xyz;
//this->setState.AddRotation(Oyster::Math::Float4(x, y)); //this->setState.AddRotation(Oyster::Math::Float4(x, y));
//this->setState.SetRotation(); //this->setState.SetRotation();

View File

@ -16,6 +16,7 @@ namespace GameLogic
{ {
public: public:
Player(void); Player(void);
Player(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
~Player(void); ~Player(void);
/******************************************************** /********************************************************
@ -42,7 +43,7 @@ namespace GameLogic
void Respawn(Oyster::Math::Float3 spawnPoint); void Respawn(Oyster::Math::Float3 spawnPoint);
void Rotate(const Oyster::Math3D::Float3 lookDir); void Rotate(float x, float y);
/******************************************************** /********************************************************
* Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody
@ -50,7 +51,7 @@ namespace GameLogic
* @param rigidBodyPlayer: physics object of the player * @param rigidBodyPlayer: physics object of the player
* @param obj: physics object for the object that collided with the player * @param obj: physics object for the object that collided with the player
********************************************************/ ********************************************************/
static void PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); static void PlayerCollision(Oyster::Physics::ICustomBody *rigidBodyPlayer, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
bool IsWalking(); bool IsWalking();

View File

@ -24,6 +24,11 @@ StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody,void* collisi
:Object(rigidBody,collisionFunc,type) :Object(rigidBody,collisionFunc,type)
{ {
}
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
:Object(rigidBody, collisionFunc, type)
{
} }

View File

@ -18,6 +18,7 @@ namespace GameLogic
StaticObject(); StaticObject();
StaticObject(void* collisionFunc, OBJECT_TYPE type); StaticObject(void* collisionFunc, OBJECT_TYPE type);
StaticObject(Oyster::Physics::ICustomBody *rigidBody,void* collisionFunc, OBJECT_TYPE type); StaticObject(Oyster::Physics::ICustomBody *rigidBody,void* collisionFunc, OBJECT_TYPE type);
StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
StaticObject(OBJECT_TYPE type); StaticObject(OBJECT_TYPE type);
~StaticObject(void); ~StaticObject(void);