GL - rotation and gravity fixed

This commit is contained in:
lindaandersson 2014-02-11 13:41:38 +01:00
parent 398be8361b
commit d771a5181d
7 changed files with 17 additions and 97 deletions

View File

@ -565,8 +565,6 @@ void GameState::Protocol( ObjPos* pos )
{ {
if(dynamicObjects[i]->GetId() == pos->object_ID) if(dynamicObjects[i]->GetId() == pos->object_ID)
{ {
//dynamicObjects[i]->setPos(Float3(world[12], world[13], world[14])); //dynamicObjects[i]->setPos(Float3(world[12], world[13], world[14]));
dynamicObjects[i]->setWorld(world); dynamicObjects[i]->setWorld(world);
@ -592,10 +590,10 @@ void GameState::Protocol( ObjPos* pos )
//camera->setUp(up); //camera->setUp(up);
//camera->setLook(objForward); //camera->setLook(objForward);
up *= 1; up *= 2;
objForward *= -2; objForward *= -2;
Oyster::Math::Float3 cameraPos = pos + up + objForward; Oyster::Math::Float3 cameraPos = pos + up + objForward;
//camera->SetPosition(cameraPos); camera->SetPosition(cameraPos);
//camera->UpdateViewMatrix(); //camera->UpdateViewMatrix();
} }

View File

@ -16,7 +16,7 @@ Game::PlayerData::PlayerData()
//create rigid body //create rigid body
Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f );
//rigidBody->SetAngularFactor(0.0f); rigidBody->SetAngularFactor(0.0f);
//create player with this rigid body //create player with this rigid body
this->player = new Player(rigidBody,Level::LevelCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); this->player = new Player(rigidBody,Level::LevelCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER);
this->player->GetRigidBody()->SetCustomTag(this); this->player->GetRigidBody()->SetCustomTag(this);

View File

@ -112,36 +112,8 @@ void Level::InitiateLevel(std::string levelPath)
} }
void Level::InitiateLevel(float radius) void Level::InitiateLevel(float radius)
{ {
float heading = Utility::Value::Radian(180.0f); API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
float attitude = Utility::Value::Radian(0.0f); API::Instance().SetGravity(50);
float bank = Utility::Value::Radian(0);
double c1 = cos(heading/2);
double s1 = sin(heading/2);
double c2 = cos(attitude/2);
double s2 = sin(attitude/2);
double c3 = cos(bank/2);
double s3 = sin(bank/2);
double c1c2 = c1*c2;
double s1s2 = s1*s2;
double w =c1c2*c3 - s1s2*s3;
double x =c1c2*s3 + s1s2*c3;
double y =s1*c2*c3 + c1*s2*s3;
double z =c1*s2*c3 - s1*c2*s3;
double angle = 2 * acos(w);
double norm = x*x+y*y+z*z;
if (norm < 0.001) { // when all euler angles are zero angle =0 so
// we can set axis to anything to avoid divide by zero
x=1;
y=z=0;
} else {
norm = sqrt(norm);
x /= norm;
y /= norm;
z /= norm;
}
int idCount = 100; int idCount = 100;
// add level sphere // add level sphere
ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f);

View File

@ -88,7 +88,7 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody()
void Object::BeginFrame() void Object::BeginFrame()
{ {
} }
// update physic // update physic
void Object::EndFrame() void Object::EndFrame()

View File

@ -6,7 +6,7 @@
using namespace GameLogic; using namespace GameLogic;
using namespace Oyster::Physics; using namespace Oyster::Physics;
const int MOVE_FORCE = 500; const int MOVE_FORCE = 30;
Player::Player() Player::Player()
:DynamicObject() :DynamicObject()
{ {
@ -61,6 +61,8 @@ void Player::BeginFrame()
{ {
//weapon->Update(0.002f); //weapon->Update(0.002f);
Object::BeginFrame(); Object::BeginFrame();
} }
void Player::EndFrame() void Player::EndFrame()
@ -98,31 +100,26 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
void Player::MoveForward() void Player::MoveForward()
{ {
Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2]; Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir; rigidBody->SetLinearVelocity( MOVE_FORCE * forward.GetNormalized() );
rigidBody->SetLinearVelocity( 10 * forward.GetNormalized() );
} }
void Player::MoveBackwards() void Player::MoveBackwards()
{ {
Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2]; Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir; rigidBody->SetLinearVelocity( MOVE_FORCE * -forward.GetNormalized() );
rigidBody->SetLinearVelocity( 10 * -forward.GetNormalized() );
} }
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::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2]; Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir;
Oyster::Math::Float3 r = (-this->rigidBody->GetState().centerPos.Normalize()).Cross(forward); Oyster::Math::Float3 r = (-this->rigidBody->GetState().centerPos.Normalize()).Cross(forward);
rigidBody->SetLinearVelocity(r * 10); rigidBody->SetLinearVelocity(r * MOVE_FORCE);
} }
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::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2]; Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir;
Oyster::Math::Float3 r = (-this->rigidBody->GetState().centerPos.Normalize()).Cross(forward); Oyster::Math::Float3 r = (-this->rigidBody->GetState().centerPos.Normalize()).Cross(forward);
rigidBody->SetLinearVelocity(-r * 10); rigidBody->SetLinearVelocity(-r * MOVE_FORCE);
} }
void Player::UseWeapon(const WEAPON_FIRE &usage) void Player::UseWeapon(const WEAPON_FIRE &usage)
@ -153,6 +150,8 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1]; Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1];
this->rigidBody->SetUpAndRight(up, lookDir.xyz); this->rigidBody->SetUpAndRight(up, lookDir.xyz);
this->rigidBody->SetUpAndRight(this->rigidBody->GetState().centerPos.GetNormalized(), this->rigidBody->GetState().GetOrientation().v[0].xyz.GetNormalized());
} }
void Player::Jump() void Player::Jump()

View File

@ -97,59 +97,10 @@ namespace DanBias
GameSession::gameSession->networkTimer.reset(); GameSession::gameSession->networkTimer.reset();
GameLogic::IObjectData* obj = movedObject; GameLogic::IObjectData* obj = movedObject;
if(movedObject->GetID() == testID) //TODO: TEST
{
float sec = (float)testTimer.getElapsedSeconds();
sec = 0;
}
int id = obj->GetID(); int id = obj->GetID();
Protocol_ObjectPosition p(obj->GetOrientation(), id); Protocol_ObjectPosition p(obj->GetOrientation(), id);
//if(id != 1)
GameSession::gameSession->Send(p.GetProtocol()); GameSession::gameSession->Send(p.GetProtocol());
/*
if(dynamic_cast<GameLogic::ILevelData*>(obj))
{
obj = ((GameLogic::ILevelData*)movedObject)->GetObjectAt(0);
if(obj)
{
if(obj->GetObjectType() == OBJECT_TYPE_WORLD)
{
int id = obj->GetID();
Oyster::Math::Float4x4 world =obj->GetOrientation();
Protocol_ObjectPosition p(world, id);
gameSession->Send(p.GetProtocol());
}
}
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1);
if(obj)
{
if(obj->GetObjectType() == OBJECT_TYPE_BOX)
{
int id = obj->GetID();
Oyster::Math::Float4x4 world = obj->GetOrientation();
Protocol_ObjectPosition p(world, id);
gameSession->Send(p.GetProtocol());
}
}
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(2);
if(obj)
{
if(obj->GetObjectType() == OBJECT_TYPE_BOX)
{
int id = obj->GetID();
Oyster::Math::Float4x4 world = obj->GetOrientation();
Protocol_ObjectPosition p(world, id);
GameSession::gameSession->Send(p.GetProtocol());
}
}
}
*/
} }
} }

View File

@ -136,7 +136,7 @@ namespace DanBias
} }
else else
{ {
Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_white.dan", readyList[i]->GetPlayer()->GetOrientation()); Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_temporary.dan", readyList[i]->GetPlayer()->GetOrientation());
readyList[i]->GetClient()->Send(p); readyList[i]->GetClient()->Send(p);
} }
} }
@ -156,7 +156,7 @@ namespace DanBias
{ {
if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID()) if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID())
{ {
Protocol_ObjectCreate p(this->clients[k]->GetPlayer()->GetOrientation(), this->clients[k]->GetPlayer()->GetID(), "char_white.dan"); //The model name will be custom later.. Protocol_ObjectCreate p(this->clients[k]->GetPlayer()->GetOrientation(), this->clients[k]->GetPlayer()->GetID(), "char_temporary.dan"); //The model name will be custom later..
readyList[i]->GetClient()->Send(p); readyList[i]->GetClient()->Send(p);
} }
} }