GL - testing physics

This commit is contained in:
lindaandersson 2014-02-04 10:29:02 +01:00
parent 6e9423670f
commit fcadd5b4c3
7 changed files with 34 additions and 25 deletions

View File

@ -85,6 +85,9 @@ namespace DanBias
float dt = (float)m_data->timer.getElapsedSeconds();
m_data->timer.reset();
if(m_data->recieverObj->IsConnected())
m_data->recieverObj->Update();
capFrame += dt;
if(capFrame > 0.03)
{
@ -130,8 +133,7 @@ namespace DanBias
HRESULT DanBiasGame::Update(float deltaTime)
{
if(m_data->recieverObj->IsConnected())
m_data->recieverObj->Update();
m_data->inputObj->Update();

View File

@ -378,7 +378,7 @@ void GameState::Protocol( ObjPos* pos )
{
world[i] = pos->worldPos[i];
}
//printf("pos for obj %d, ",pos->object_ID );
for (unsigned int i = 0; i < privData->object.size(); i++)
{
if(privData->object[i]->GetId() == pos->object_ID)
@ -389,10 +389,10 @@ void GameState::Protocol( ObjPos* pos )
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
if(i == myId) // playerobj
{
Oyster::Math::Float3 up = (Oyster::Math::Float3(world[4], world[5]+2, world[6]));
Oyster::Math::Float3 up = (Oyster::Math::Float3(world[4], world[5], world[6]));
Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13]+2, world[14]);
Oyster::Math::Float3 cameraPos = up + pos;
camera->SetPosition(pos);
camera->SetPosition(cameraPos);
camera->UpdateViewMatrix();
}
}

View File

@ -27,7 +27,8 @@ void Level::InitiateLevel(float radius)
sbDesc.ignoreGravity = true;
sbDesc.radius = 300;
sbDesc.mass = 10e12f;
sbDesc.frictionCoeff_Static = 0;
sbDesc.frictionCoeff_Dynamic = 0;
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
ICustomBody::State state;
@ -61,7 +62,7 @@ void Level::InitiateLevel(float radius)
// add gravitation
API::Gravity gravityWell;
gravityWell.gravityType = API::Gravity::GravityType_Well;
gravityWell.well.mass = 1e15f;
gravityWell.well.mass = 1e18f;
gravityWell.well.position = Oyster::Math::Float4(0,0,0,1);
API::Instance().AddGravity(gravityWell);
}

View File

@ -118,9 +118,9 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody()
void Object::BeginFrame()
{
this->rigidBody->SetState(this->newPhysicsState);
this->rigidBody->GetState(this->newPhysicsState);
//newPhysicsState.SetAngularMomentum(Float3::null);
//this->rigidBody->SetState(this->newPhysicsState);
//this->rigidBody->GetState(this->newPhysicsState);
Oyster::Math::Float4 axis;
if(newPhysicsState.GetGravityNormal()!= Float3::null)
@ -131,7 +131,7 @@ void Object::BeginFrame()
//error
int i =0 ;
}
newPhysicsState.SetRotation(axis.xyz);
//newPhysicsState.SetRotation(axis.xyz);
newPhysicsState.SetAngularMomentum(Float3::null);
Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y);
debug += newPhysicsState.GetGravityNormal();

View File

@ -98,28 +98,32 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
void Player::MoveForward()
{
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
newPhysicsState.ApplyLinearImpulse(forward * (2000 * this->gameInstance->GetFrameTime()));
//Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
Oyster::Math::Float3 forward = lookDir;
newPhysicsState.ApplyLinearImpulse(forward * (30000 * this->gameInstance->GetFrameTime()));
}
void Player::MoveBackwards()
{
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
newPhysicsState.ApplyLinearImpulse(-forward * 2000 * this->gameInstance->GetFrameTime());
//Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
Oyster::Math::Float3 forward = lookDir;
newPhysicsState.ApplyLinearImpulse(-forward * 30000 * this->gameInstance->GetFrameTime());
}
void Player::MoveRight()
{
//Do cross product with forward vector and negative gravity vector
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
//Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
Oyster::Math::Float3 forward = lookDir;
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward);
newPhysicsState.ApplyLinearImpulse(r * 2000 * this->gameInstance->GetFrameTime());
newPhysicsState.ApplyLinearImpulse(-r * 30000 * this->gameInstance->GetFrameTime());
}
void Player::MoveLeft()
{
//Do cross product with forward vector and negative gravity vector
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
//Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
Oyster::Math::Float3 forward = lookDir;
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); //Still get zero
newPhysicsState.ApplyLinearImpulse(-r * 2000 * this->gameInstance->GetFrameTime());
newPhysicsState.ApplyLinearImpulse(r * 30000 * this->gameInstance->GetFrameTime());
}
void Player::UseWeapon(const WEAPON_FIRE &usage)
@ -138,8 +142,10 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
{
Oyster::Math::Float dx = lookDir.w;
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ;
newPhysicsState.AddRotation(deltaAxis);
Oyster::Math::Float3 deltaAxis = up * (-dx * 0.2) ;
Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation();
//newPhysicsState.SetRotation(oldOrt + deltaAxis);
this->lookDir = lookDir.xyz;
}
@ -147,7 +153,7 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
void Player::Jump()
{
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
newPhysicsState.ApplyLinearImpulse(up * 2000 * this->gameInstance->GetFrameTime());
newPhysicsState.ApplyLinearImpulse(up * 30000 * this->gameInstance->GetFrameTime());
}
bool Player::IsWalking()

View File

@ -106,7 +106,7 @@ namespace DanBias
Oyster::Math::Float4x4 world =obj->GetOrientation();
Protocol_ObjectPosition p(world, id);
GameSession::gameSession->Send(*p.GetProtocol());
//GameSession::gameSession->Send(*p.GetProtocol());
}
}

View File

@ -51,8 +51,8 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength )
// updating the linear
//Decrease momentum with 1% as "fall-off"
//! HACK: @todo Add real solution with fluid drag
this->momentum_Linear = this->momentum_Linear*0.99f;
this->momentum_Angular = this->momentum_Angular*0.99f;
this->momentum_Linear = this->momentum_Linear*0.9999f;
this->momentum_Angular = this->momentum_Angular*0.9999f;
// ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G
this->centerPos += ( updateFrameLength / this->mass ) * AverageWithDelta( this->momentum_Linear, this->impulse_Linear );