GL - camera follows player

This commit is contained in:
lindaandersson 2014-02-04 11:50:15 +01:00
parent 07e8624807
commit d54cffee8e
4 changed files with 50 additions and 33 deletions

View File

@ -43,7 +43,7 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
privData->state = gameStateState_loading;
privData->nwClient = nwClient;
privData->state = LoadGame();
pitch = 0;
return true;
}
GameState::gameStateState GameState::LoadGame()
@ -309,7 +309,8 @@ void GameState::readKeyInput(InputClass* KeyInput)
if (KeyInput->IsMousePressed())
{
camera->Yaw(-KeyInput->GetYaw());
camera->Pitch(KeyInput->GetPitch());
//camera->Pitch(KeyInput->GetPitch());
//pitch = KeyInput->GetPitch();
camera->UpdateViewMatrix();
GameLogic::Protocol_PlayerLook playerLookDir;
Oyster::Math::Float4 look = camera->GetLook();
@ -391,10 +392,21 @@ void GameState::Protocol( ObjPos* pos )
{
camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2])));
camera->setUp(Oyster::Math::Float3(world[4], world[5], world[6]));
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13]+2, world[14]+2);
//Oyster::Math::Float3 cameraPos = up + pos;
camera->SetPosition(pos);
Oyster::Math::Float3 cameraLook = camera->GetLook();
Oyster::Math::Float3 objForward = (Oyster::Math::Float3(world[8], world[9], world[10]));
camera->setLook(objForward);
camera->UpdateViewMatrix();
Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13], world[14]);
Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]);
up *= 2;
objForward *= -3;
Oyster::Math::Float3 cameraPos = up + pos + objForward;
//camera->Pitch(pitch);
camera->SetPosition(cameraPos);
//camera->LookAt(pos, dir, up);
//Oyster::Math::Float3 newLook = objForward;
camera->UpdateViewMatrix();
}
}

View File

@ -27,6 +27,7 @@ private:
Camera* camera;
int myId;
float pitch;
struct myData;
myData* privData;
public:

View File

@ -118,24 +118,9 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody()
void Object::BeginFrame()
{
//newPhysicsState.SetAngularMomentum(Float3::null);
//this->rigidBody->SetState(this->newPhysicsState);
//this->rigidBody->GetState(this->newPhysicsState);
Oyster::Math::Float4 axis;
if(newPhysicsState.GetGravityNormal()!= Float3::null)
{
Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(newPhysicsState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, -Oyster::Math::Float4(newPhysicsState.GetGravityNormal()), axis);
if(axis !=axis)
{
//error
int i =0 ;
}
//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();
}
this->rigidBody->SetState(this->newPhysicsState);
@ -144,6 +129,21 @@ void Object::BeginFrame()
void Object::EndFrame()
{
this->currPhysicsState = this->rigidBody->GetState();
if(currPhysicsState.GetGravityNormal()!= Float3::null)
{
Oyster::Math::Float4 axis;
Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(currPhysicsState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, -Oyster::Math::Float4(currPhysicsState.GetGravityNormal()), axis);
if(axis !=axis)
{
//error
int i =0 ;
}
currPhysicsState.SetRotation(axis.xyz);
currPhysicsState.SetAngularMomentum(Float3::null);
Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y);
debug += currPhysicsState.GetGravityNormal();
}
this->newPhysicsState = this->currPhysicsState;
}

View File

@ -98,21 +98,21 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
void Player::MoveForward()
{
//Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
Oyster::Math::Float3 forward = lookDir;
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];
Oyster::Math::Float3 forward = lookDir;
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 = lookDir;
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir;
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward);
newPhysicsState.ApplyLinearImpulse(-r * 30000 * this->gameInstance->GetFrameTime());
@ -120,8 +120,8 @@ void Player::MoveRight()
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 = lookDir;
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 * 30000 * this->gameInstance->GetFrameTime());
}
@ -141,11 +141,15 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint)
void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
{
Oyster::Math::Float dx = lookDir.w;
if(dx > 0.0f)
{
int i =0 ;
}
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
Oyster::Math::Float3 deltaAxis = up * (-dx * 0.2) ;
Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ;
Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation();
//newPhysicsState.SetRotation(oldOrt + deltaAxis);
newPhysicsState.SetRotation(oldOrt + deltaAxis);
this->lookDir = lookDir.xyz;
}