GL - camera follows player
This commit is contained in:
parent
07e8624807
commit
d54cffee8e
|
@ -43,7 +43,7 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
|
||||||
privData->state = gameStateState_loading;
|
privData->state = gameStateState_loading;
|
||||||
privData->nwClient = nwClient;
|
privData->nwClient = nwClient;
|
||||||
privData->state = LoadGame();
|
privData->state = LoadGame();
|
||||||
|
pitch = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
GameState::gameStateState GameState::LoadGame()
|
GameState::gameStateState GameState::LoadGame()
|
||||||
|
@ -309,7 +309,8 @@ void GameState::readKeyInput(InputClass* KeyInput)
|
||||||
if (KeyInput->IsMousePressed())
|
if (KeyInput->IsMousePressed())
|
||||||
{
|
{
|
||||||
camera->Yaw(-KeyInput->GetYaw());
|
camera->Yaw(-KeyInput->GetYaw());
|
||||||
camera->Pitch(KeyInput->GetPitch());
|
//camera->Pitch(KeyInput->GetPitch());
|
||||||
|
//pitch = KeyInput->GetPitch();
|
||||||
camera->UpdateViewMatrix();
|
camera->UpdateViewMatrix();
|
||||||
GameLogic::Protocol_PlayerLook playerLookDir;
|
GameLogic::Protocol_PlayerLook playerLookDir;
|
||||||
Oyster::Math::Float4 look = camera->GetLook();
|
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->setRight((Oyster::Math::Float3(world[0], world[1], world[2])));
|
||||||
camera->setUp(Oyster::Math::Float3(world[4], world[5], world[6]));
|
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 cameraLook = camera->GetLook();
|
||||||
Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13]+2, world[14]+2);
|
Oyster::Math::Float3 objForward = (Oyster::Math::Float3(world[8], world[9], world[10]));
|
||||||
//Oyster::Math::Float3 cameraPos = up + pos;
|
|
||||||
camera->SetPosition(pos);
|
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();
|
camera->UpdateViewMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ private:
|
||||||
Camera* camera;
|
Camera* camera;
|
||||||
|
|
||||||
int myId;
|
int myId;
|
||||||
|
float pitch;
|
||||||
struct myData;
|
struct myData;
|
||||||
myData* privData;
|
myData* privData;
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -118,24 +118,9 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody()
|
||||||
|
|
||||||
void Object::BeginFrame()
|
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);
|
this->rigidBody->SetState(this->newPhysicsState);
|
||||||
|
@ -144,6 +129,21 @@ void Object::BeginFrame()
|
||||||
void Object::EndFrame()
|
void Object::EndFrame()
|
||||||
{
|
{
|
||||||
this->currPhysicsState = this->rigidBody->GetState();
|
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;
|
this->newPhysicsState = this->currPhysicsState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,21 +98,21 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
|
||||||
|
|
||||||
void Player::MoveForward()
|
void Player::MoveForward()
|
||||||
{
|
{
|
||||||
//Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
||||||
Oyster::Math::Float3 forward = lookDir;
|
//Oyster::Math::Float3 forward = lookDir;
|
||||||
newPhysicsState.ApplyLinearImpulse(forward * (30000 * this->gameInstance->GetFrameTime()));
|
newPhysicsState.ApplyLinearImpulse(forward * (30000 * this->gameInstance->GetFrameTime()));
|
||||||
}
|
}
|
||||||
void Player::MoveBackwards()
|
void Player::MoveBackwards()
|
||||||
{
|
{
|
||||||
//Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
||||||
Oyster::Math::Float3 forward = lookDir;
|
//Oyster::Math::Float3 forward = lookDir;
|
||||||
newPhysicsState.ApplyLinearImpulse(-forward * 30000 * this->gameInstance->GetFrameTime());
|
newPhysicsState.ApplyLinearImpulse(-forward * 30000 * this->gameInstance->GetFrameTime());
|
||||||
}
|
}
|
||||||
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 = currPhysicsState.GetOrientation().v[2];
|
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
||||||
Oyster::Math::Float3 forward = lookDir;
|
//Oyster::Math::Float3 forward = lookDir;
|
||||||
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward);
|
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward);
|
||||||
newPhysicsState.ApplyLinearImpulse(-r * 30000 * this->gameInstance->GetFrameTime());
|
newPhysicsState.ApplyLinearImpulse(-r * 30000 * this->gameInstance->GetFrameTime());
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ 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
|
||||||
//Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
||||||
Oyster::Math::Float3 forward = lookDir;
|
//Oyster::Math::Float3 forward = lookDir;
|
||||||
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); //Still get zero
|
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); //Still get zero
|
||||||
newPhysicsState.ApplyLinearImpulse(r * 30000 * this->gameInstance->GetFrameTime());
|
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)
|
void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
|
||||||
{
|
{
|
||||||
Oyster::Math::Float dx = lookDir.w;
|
Oyster::Math::Float dx = lookDir.w;
|
||||||
|
if(dx > 0.0f)
|
||||||
|
{
|
||||||
|
int i =0 ;
|
||||||
|
}
|
||||||
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
|
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();
|
Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation();
|
||||||
|
|
||||||
//newPhysicsState.SetRotation(oldOrt + deltaAxis);
|
newPhysicsState.SetRotation(oldOrt + deltaAxis);
|
||||||
|
|
||||||
this->lookDir = lookDir.xyz;
|
this->lookDir = lookDir.xyz;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue