GL - movement with physics working!!

This commit is contained in:
lindaandersson 2014-01-16 12:26:14 +01:00
parent a070e4d459
commit a168328a44
6 changed files with 50 additions and 9 deletions

View File

@ -85,6 +85,15 @@ bool GameState::LoadModels(std::wstring mapFile)
privData->object.push_back(obj); privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData); privData->object[privData->object.size() -1 ]->Init(modelData);
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
modelData.world = modelData.world * translate;
modelData.modelPath = L"..\\Content\\worldDummy";
modelData.id ++;
obj = new C_DynamicObj();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
return true; return true;
} }
@ -260,7 +269,13 @@ void GameState::Protocol( ObjPos* pos )
for (int i = 0; i < privData->object.size(); i++) for (int i = 0; i < privData->object.size(); i++)
{ {
if(privData->object[i]->GetId() == pos->object_ID) if(privData->object[i]->GetId() == pos->object_ID)
{
privData->object[i]->setPos(world); privData->object[i]->setPos(world);
//privData->view = world;
//privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
}
} }
} }

View File

@ -61,9 +61,8 @@ namespace DanBias
//world.v[3].y = -2; //world.v[3].y = -2;
c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT); c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_LEFT);
Oyster::Math::Float4x4 world = c->GetPlayer()->GetOrientation();
Protocol_ObjectPosition p(world, 1);
Send(p.GetProtocol());
} }
break; break;
case protocol_Gameplay_PlayerMouseMovement: case protocol_Gameplay_PlayerMouseMovement:
@ -78,6 +77,8 @@ namespace DanBias
case protocol_Gameplay_ObjectPosition: case protocol_Gameplay_ObjectPosition:
break; break;
} }
this->modifiedClient.Push(e); this->modifiedClient.Push(e);

View File

@ -34,6 +34,8 @@ namespace DanBias
Sleep(100); Sleep(100);
} }
this->ParseEvents(); this->ParseEvents();
this->gameInstance.NewFrame(); this->gameInstance.NewFrame();
@ -56,6 +58,15 @@ namespace DanBias
//e.data.player->GetOrientation(); //e.data.player->GetOrientation();
break; break;
} }
}
if(clients.Size() == 1)
{
Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation();
Protocol_ObjectPosition p(world, 1);
Send(p.GetProtocol());
Sleep(100);
} }
} }

View File

@ -18,6 +18,9 @@ Object::Object()
//poi //poi
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
Oyster::Physics::API::Instance().AddObject(rigidBody);
//rigidBody->gameObjectRef = this; //rigidBody->gameObjectRef = this;
this->objectID = GID(); this->objectID = GID();
@ -32,6 +35,8 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type)
//poi //poi
ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
Oyster::Physics::API::Instance().AddObject(rigidBody);
rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc)); rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));

View File

@ -13,7 +13,12 @@ Player::Player()
life = 100; life = 100;
teamID = -1; teamID = -1;
playerState = PLAYER_STATE::PLAYER_STATE_IDLE; playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float4(1,0,0,0); lookDir = Oyster::Math::Float4(0,0,-1,0);
Oyster::Physics::ICustomBody::State state;
this->rigidBody->GetState( this->setState );
setState.SetLinearMomentum( Oyster::Math::Float4(20, 0, 0, 0) );
this->rigidBody->SetState( setState );
} }
Player::~Player(void) Player::~Player(void)
@ -61,13 +66,16 @@ 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
Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
//Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir);
setState.ApplyLinearImpulse(r * 100); setState.ApplyLinearImpulse(r * 100);
} }
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
Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 );
//Oyster::Math::Float4 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir);
setState.ApplyLinearImpulse(-r * 100); setState.ApplyLinearImpulse(-r * 100);
} }
@ -106,7 +114,7 @@ Oyster::Math::Float3 Player::GetPosition() const
{ {
return (Oyster::Math::Float3)getState.GetCenterPosition(); return (Oyster::Math::Float3)getState.GetCenterPosition();
} }
Oyster::Math::Float4x4 Player::GetOrientation() const Oyster::Math::Float4x4 Player::GetOrientation() const
{ {
return this->getState.GetOrientation(); return this->getState.GetOrientation();
} }
@ -135,4 +143,5 @@ void Player::BeginFrame()
void Player::EndFrame() void Player::EndFrame()
{ {
this->rigidBody->GetState(this->getState); this->rigidBody->GetState(this->getState);
this->setState = this->getState;
} }

View File

@ -42,7 +42,7 @@ namespace GameLogic
bTurnLeft = val[3].value.netBool; bTurnLeft = val[3].value.netBool;
bTurnRight = val[4].value.netBool; bTurnRight = val[4].value.netBool;
bStrafeRight = val[5].value.netBool; bStrafeRight = val[5].value.netBool;
bStrafeRight = val[6].value.netBool; bStrafeLeft = val[6].value.netBool;
return *this; return *this;
} }
@ -53,7 +53,7 @@ namespace GameLogic
this->protocol[3].value = bTurnLeft; this->protocol[3].value = bTurnLeft;
this->protocol[4].value = bTurnRight; this->protocol[4].value = bTurnRight;
this->protocol[5].value = bStrafeRight; this->protocol[5].value = bStrafeRight;
this->protocol[6].value = bStrafeRight; this->protocol[6].value = bStrafeLeft;
return &protocol; return &protocol;
} }