Merged with Physics
This commit is contained in:
commit
b1f82c8ef2
|
@ -55,15 +55,13 @@ namespace DanBias
|
||||||
this->sharedStateContent.network = nullptr;
|
this->sharedStateContent.network = nullptr;
|
||||||
this->sharedStateContent.mouseDevice = nullptr;
|
this->sharedStateContent.mouseDevice = nullptr;
|
||||||
this->sharedStateContent.keyboardDevice = nullptr;
|
this->sharedStateContent.keyboardDevice = nullptr;
|
||||||
this->sharedStateContent.mouseSensitivity = Utility::Value::Radian( 0.1f );
|
this->sharedStateContent.mouseSensitivity = Utility::Value::Radian( 0.6f );
|
||||||
this->serverOwner = false;
|
this->serverOwner = false;
|
||||||
this->capFrame = 0;
|
this->capFrame = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
~DanBiasGamePrivateData()
|
~DanBiasGamePrivateData()
|
||||||
{
|
{
|
||||||
//SafeDeleteInstance( this->sharedStateContent.mouseDevice );
|
|
||||||
//SafeDeleteInstance( this->sharedStateContent.keyboardDevice );
|
|
||||||
}
|
}
|
||||||
} data;
|
} data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
#include "C_StaticObj.h"
|
#include "C_StaticObj.h"
|
||||||
#include "DllInterfaces/GFXAPI.h"
|
#include "DllInterfaces/GFXAPI.h"
|
||||||
|
|
||||||
using namespace DanBias::Client;
|
using namespace DanBias::Client;
|
||||||
|
|
||||||
C_StaticObj::C_StaticObj(void)
|
C_StaticObj::C_StaticObj( GameLogic::ObjectSpecialType t )
|
||||||
:C_Object()
|
:C_Object()
|
||||||
|
,gameObjectType(t)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef DANBIAS_CLIENT_CSTATICOBJECT_H
|
#ifndef DANBIAS_CLIENT_CSTATICOBJECT_H
|
||||||
#define DANBIAS_CLIENT_CSTATICOBJECT_H
|
#define DANBIAS_CLIENT_CSTATICOBJECT_H
|
||||||
#include "../C_Object.h"
|
#include "../C_Object.h"
|
||||||
|
#include "ObjectDefines.h"
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
namespace Client
|
namespace Client
|
||||||
|
@ -8,10 +9,12 @@ namespace DanBias
|
||||||
class C_StaticObj : public C_Object
|
class C_StaticObj : public C_Object
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
const GameLogic::ObjectSpecialType gameObjectType;
|
||||||
public:
|
public:
|
||||||
C_StaticObj(void);
|
C_StaticObj(GameLogic::ObjectSpecialType type = GameLogic::ObjectSpecialType_Unknown);
|
||||||
virtual ~C_StaticObj(void);
|
virtual ~C_StaticObj(void);
|
||||||
bool Init(ModelInitData modelInit);
|
bool Init(ModelInitData modelInit);
|
||||||
|
inline GameLogic::ObjectSpecialType GetGameObjectType() const { return this->gameObjectType; }
|
||||||
|
|
||||||
};};};
|
};};};
|
||||||
#endif
|
#endif
|
|
@ -89,6 +89,7 @@ bool GameState::Init( SharedStateContent &shared )
|
||||||
// !DEGUG KEYS
|
// !DEGUG KEYS
|
||||||
|
|
||||||
shared.keyboardDevice->ReleaseTextTarget();
|
shared.keyboardDevice->ReleaseTextTarget();
|
||||||
|
//shared.mouseDevice->AddMouseEvent(this);
|
||||||
|
|
||||||
auto light = this->privData->lights->begin();
|
auto light = this->privData->lights->begin();
|
||||||
for( ; light != this->privData->lights->end(); ++light )
|
for( ; light != this->privData->lights->end(); ++light )
|
||||||
|
@ -144,10 +145,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa
|
||||||
this->privData->myId = id;
|
this->privData->myId = id;
|
||||||
this->privData->camera.SetPosition( p->getPos() );
|
this->privData->camera.SetPosition( p->getPos() );
|
||||||
Float3 offset = Float3( 0.0f );
|
Float3 offset = Float3( 0.0f );
|
||||||
// DEBUG position of camera so we can see the player model
|
|
||||||
offset.y = p->getScale().y * 5.0f;
|
|
||||||
offset.z = p->getScale().z * -5.0f;
|
|
||||||
// !DEBUG
|
|
||||||
this->privData->camera.SetHeadOffset( offset );
|
this->privData->camera.SetHeadOffset( offset );
|
||||||
this->privData->camera.UpdateOrientation();
|
this->privData->camera.UpdateOrientation();
|
||||||
}
|
}
|
||||||
|
@ -407,6 +405,7 @@ void GameState::ReadKeyInput()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message )
|
const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message )
|
||||||
{
|
{
|
||||||
if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend )
|
if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend )
|
||||||
|
@ -631,3 +630,104 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* :HACK! */
|
||||||
|
// TODO: Fix camera movement on client
|
||||||
|
/*
|
||||||
|
void GameState::SetUp( DanBias::Client::C_Player* p)
|
||||||
|
{
|
||||||
|
Float3 up;
|
||||||
|
auto it = this->privData->staticObjects->begin();
|
||||||
|
for (it; it != this->privData->staticObjects->end(); it++)
|
||||||
|
{
|
||||||
|
if(it->second->GetGameObjectType() == GameLogic::ObjectSpecialType_World)
|
||||||
|
{
|
||||||
|
up = - (p->getPos() - it->second->getPos());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Quaternion newRotation;
|
||||||
|
|
||||||
|
Float3 v1 = this->privData->camera.GetUp();
|
||||||
|
Float3 v2(up.x, up.y, up.z);
|
||||||
|
|
||||||
|
Quaternion q;
|
||||||
|
Float3 a = v1.Cross(v2);
|
||||||
|
|
||||||
|
if (v1.Dot(v2) < -0.999999)
|
||||||
|
{
|
||||||
|
Float3 xCrossPre = Float3(1, 0 ,0).Cross(v1);
|
||||||
|
if(xCrossPre.GetLength() < 0.000001)
|
||||||
|
xCrossPre = Float3(0, 1 ,0).Cross(v1);
|
||||||
|
xCrossPre.Normalize();
|
||||||
|
|
||||||
|
//q.setRotation(xCrossPre, 3.1415);
|
||||||
|
}
|
||||||
|
else if (v1.Dot(v2) > 0.999999)
|
||||||
|
{
|
||||||
|
q = Quaternion(Float3(0.0f), 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
q.imaginary.x = a.x;
|
||||||
|
q.imaginary.y = a.y;
|
||||||
|
q.imaginary.z = a.z;
|
||||||
|
|
||||||
|
q.real = (1 + v1.Dot(v2));
|
||||||
|
|
||||||
|
q.Normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get Rotation from matrix
|
||||||
|
//float trace = this->privData->camera..v[0].x + trans.v[1].y + trans.v[2].z;
|
||||||
|
float trace = trans.v[0].x + trans.v[1].y + trans.v[2].z;
|
||||||
|
|
||||||
|
float temp[4];
|
||||||
|
|
||||||
|
if (trace > float(0.0))
|
||||||
|
{
|
||||||
|
float s = sqrt(trace + float(1.0));
|
||||||
|
temp[3]=(s * float(0.5));
|
||||||
|
s = float(0.5) / s;
|
||||||
|
|
||||||
|
temp[0]=((trans.v[2].y - trans.v[1].z) * s);
|
||||||
|
temp[1]=((trans.v[0].z - trans.v[2].x) * s);
|
||||||
|
temp[2]=((trans.v[1].x - trans.v[0].y) * s);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int i = trans.v[0].x < trans.v[1].y ?
|
||||||
|
(trans.v[1].y < trans.v[2].z ? 2 : 1) :
|
||||||
|
(trans.v[0].x < trans.v[2].z ? 2 : 0);
|
||||||
|
int j = (i + 1) % 3;
|
||||||
|
int k = (i + 2) % 3;
|
||||||
|
|
||||||
|
float s = sqrt(trans.v[i][i] - trans.v[j][j] - trans.v[k][k] + float(1.0));
|
||||||
|
temp[i] = s * float(0.5);
|
||||||
|
s = float(0.5) / s;
|
||||||
|
|
||||||
|
temp[3] = (trans.v[k][j] - trans.v[j][k]) * s;
|
||||||
|
temp[j] = (trans.v[j][i] + trans.v[i][j]) * s;
|
||||||
|
temp[k] = (trans.v[k][i] + trans.v[i][k]) * s;
|
||||||
|
}
|
||||||
|
Quaternion n = Quaternion(Float3(temp[0],temp[1],temp[2]),temp[3]);
|
||||||
|
|
||||||
|
newRotation = q * n;
|
||||||
|
this->privData->camera.SetRotation(newRotation);
|
||||||
|
}
|
||||||
|
void GameState::OnMouseMoveVelocity ( Input::Struct::SAIPointInt2D coordinate, Input::Mouse* sender )
|
||||||
|
{
|
||||||
|
auto it = this->privData->players.begin();
|
||||||
|
for (it; it != this->privData->players.end(); it++)
|
||||||
|
{
|
||||||
|
if(it->second->GetId() == this->privData->myId)
|
||||||
|
{
|
||||||
|
this->SetUp(it->second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,12 @@
|
||||||
#include "OysterMath.h"
|
#include "OysterMath.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "GameStateUI.h"
|
#include "GameStateUI.h"
|
||||||
|
#include "C_obj\C_Player.h"
|
||||||
|
|
||||||
|
|
||||||
namespace DanBias { namespace Client
|
namespace DanBias { namespace Client
|
||||||
{
|
{
|
||||||
class GameState : public GameClientState
|
class GameState : public GameClientState//, Input::Mouse::MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum gameStateState
|
enum gameStateState
|
||||||
|
@ -42,6 +44,10 @@ namespace DanBias { namespace Client
|
||||||
bool renderStats;
|
bool renderStats;
|
||||||
// !DEGUG KEYS
|
// !DEGUG KEYS
|
||||||
|
|
||||||
|
//:HACK!
|
||||||
|
//void OnMouseMoveVelocity ( Input::Struct::SAIPointInt2D coordinate, Input::Mouse* sender ) override;
|
||||||
|
//void SetUp( DanBias::Client::C_Player* p);
|
||||||
|
|
||||||
};
|
};
|
||||||
} }
|
} }
|
||||||
#endif
|
#endif
|
|
@ -175,10 +175,13 @@ void GamingUI::OnMouseMoveVelocity ( Input::Struct::SAIPointInt2D coordinate, In
|
||||||
{
|
{
|
||||||
//send delta mouse movement
|
//send delta mouse movement
|
||||||
{
|
{
|
||||||
this->camera->PitchDown( (-coordinate.y) * this->sharedData->mouseSensitivity );;
|
this->camera->PitchDown( (-coordinate.y) * this->sharedData->mouseSensitivity );
|
||||||
|
//this->camera->YawLeft( (-coordinate.x) * this->sharedData->mouseSensitivity );
|
||||||
//if( deltaPos.x != 0.0f ) //This made the camera reset to a specific rotation. Why?
|
//if( deltaPos.x != 0.0f ) //This made the camera reset to a specific rotation. Why?
|
||||||
{
|
{
|
||||||
this->sharedData->network->Send( Protocol_PlayerLeftTurn((coordinate.x) * this->sharedData->mouseSensitivity, this->camera->GetLook()) );
|
this->sharedData->network->Send( Protocol_PlayerLeftTurn((coordinate.x) * this->sharedData->mouseSensitivity, this->camera->GetLook()) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName )
|
||||||
desc.scale = oh->scale;
|
desc.scale = oh->scale;
|
||||||
desc.visible = true;
|
desc.visible = true;
|
||||||
|
|
||||||
C_StaticObj *staticObject = new C_StaticObj();
|
C_StaticObj *staticObject = new C_StaticObj(oh->specialTypeID);
|
||||||
if( staticObject->Init( desc ) )
|
if( staticObject->Init( desc ) )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -84,13 +84,9 @@ void Player::BeginFrame()
|
||||||
Oyster::Math::Float maxSpeed = 30;
|
Oyster::Math::Float maxSpeed = 30;
|
||||||
|
|
||||||
// Rotate player accordingly
|
// Rotate player accordingly
|
||||||
|
this->rigidBody->AddRotationAroundY(this->rotationUp);
|
||||||
this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized());
|
this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized());
|
||||||
Oyster::Math::Quaternion firstUp = this->rigidBody->GetState().quaternion;
|
this->rotationUp = 0.0f;
|
||||||
this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp));
|
|
||||||
Oyster::Math::Quaternion secondTurn = this->rigidBody->GetState().quaternion;
|
|
||||||
|
|
||||||
this->rigidBody->SetRotation(secondTurn*firstUp);
|
|
||||||
|
|
||||||
// Direction data
|
// Direction data
|
||||||
Oyster::Math::Float4x4 xform;
|
Oyster::Math::Float4x4 xform;
|
||||||
xform = this->rigidBody->GetState().GetOrientation();
|
xform = this->rigidBody->GetState().GetOrientation();
|
||||||
|
@ -137,7 +133,7 @@ void Player::BeginFrame()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dampen velocity if certain keys are not pressed
|
// Dampen velocity if certain keys are not pressed
|
||||||
if(key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.9f)
|
if(key_jump <= 0.001 && IsWalking())
|
||||||
{
|
{
|
||||||
if(key_forward <= 0.001 && key_backward <= 0.001)
|
if(key_forward <= 0.001 && key_backward <= 0.001)
|
||||||
{
|
{
|
||||||
|
@ -155,7 +151,7 @@ void Player::BeginFrame()
|
||||||
walkDirection.Normalize();
|
walkDirection.Normalize();
|
||||||
|
|
||||||
// If on the ground, accelerate normally
|
// If on the ground, accelerate normally
|
||||||
if(this->rigidBody->GetLambda() < 0.9f)
|
if(IsWalking())
|
||||||
{
|
{
|
||||||
if(forwardSpeed < maxSpeed)
|
if(forwardSpeed < maxSpeed)
|
||||||
{
|
{
|
||||||
|
@ -167,7 +163,7 @@ void Player::BeginFrame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If in the air, accelerate slower
|
// If in the air, accelerate slower
|
||||||
if(this->rigidBody->GetLambda() >= 0.9f)
|
if(IsJumping())
|
||||||
{
|
{
|
||||||
if(forwardSpeed < maxSpeed)
|
if(forwardSpeed < maxSpeed)
|
||||||
{
|
{
|
||||||
|
@ -191,7 +187,7 @@ void Player::BeginFrame()
|
||||||
if(key_jump > 0.001)
|
if(key_jump > 0.001)
|
||||||
{
|
{
|
||||||
this->key_jump -= this->gameInstance->GetFrameTime();
|
this->key_jump -= this->gameInstance->GetFrameTime();
|
||||||
if(this->rigidBody->GetLambda() < 0.9f)
|
if(IsWalking())
|
||||||
{
|
{
|
||||||
Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized();
|
Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized();
|
||||||
this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass*20);
|
this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass*20);
|
||||||
|
@ -285,7 +281,7 @@ void Player::SetLookDir(const Oyster::Math3D::Float3& lookDir)
|
||||||
}
|
}
|
||||||
void Player::TurnLeft(Oyster::Math3D::Float deltaRadians)
|
void Player::TurnLeft(Oyster::Math3D::Float deltaRadians)
|
||||||
{
|
{
|
||||||
this->rotationUp += deltaRadians;
|
this->rotationUp = deltaRadians;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Jump()
|
void Player::Jump()
|
||||||
|
@ -295,15 +291,15 @@ void Player::Jump()
|
||||||
|
|
||||||
bool Player::IsWalking()
|
bool Player::IsWalking()
|
||||||
{
|
{
|
||||||
return (this->playerState == PLAYER_STATE::PLAYER_STATE_WALKING);
|
return (this->rigidBody->GetLambda() < 0.99f);
|
||||||
}
|
}
|
||||||
bool Player::IsJumping()
|
bool Player::IsJumping()
|
||||||
{
|
{
|
||||||
return (this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING);
|
return (this->rigidBody->GetLambda() < 1.0f);
|
||||||
}
|
}
|
||||||
bool Player::IsIdle()
|
bool Player::IsIdle()
|
||||||
{
|
{
|
||||||
return (this->playerState == PLAYER_STATE::PLAYER_STATE_IDLE);
|
return (this->rigidBody->GetLambda() < 1.0f && this->rigidBody->GetLinearVelocity().GetMagnitude() < 0.0001f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Inactivate()
|
void Player::Inactivate()
|
||||||
|
|
|
@ -28,6 +28,8 @@ GameClient::~GameClient()
|
||||||
if(this->player)
|
if(this->player)
|
||||||
this->player->Inactivate();
|
this->player->Inactivate();
|
||||||
|
|
||||||
|
delete this->player;
|
||||||
|
|
||||||
this->isReady = false;
|
this->isReady = false;
|
||||||
this->character = L"char_orca.dan";
|
this->character = L"char_orca.dan";
|
||||||
this->alias = L"Unknown";
|
this->alias = L"Unknown";
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace Input
|
||||||
|
|
||||||
void ProccessMouseData (RAWMOUSE mouse);
|
void ProccessMouseData (RAWMOUSE mouse);
|
||||||
bool Create( );
|
bool Create( );
|
||||||
|
void ToggleDefault( bool toggler );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Buttons
|
struct Buttons
|
||||||
|
|
|
@ -83,44 +83,47 @@ LRESULT Win32Input::RawInputParser(HWND h, LPARAM l)
|
||||||
LRESULT CALLBACK Win32Input::RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l)
|
LRESULT CALLBACK Win32Input::RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l)
|
||||||
{
|
{
|
||||||
LRESULT val = 0;
|
LRESULT val = 0;
|
||||||
|
UINT te = 0;
|
||||||
|
if(m != WM_INPUT)
|
||||||
|
te = m;
|
||||||
|
|
||||||
switch (m)
|
switch (m)
|
||||||
{
|
{
|
||||||
case WM_INPUT:
|
case WM_INPUT:
|
||||||
return Win32Input::instance->RawInputParser(h, l);
|
return Win32Input::instance->RawInputParser(h, l);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WM_NCACTIVATE:
|
||||||
|
case WM_ACTIVATEAPP:
|
||||||
case WM_ACTIVATE:
|
case WM_ACTIVATE:
|
||||||
Win32Input::instance->WindowActivate((w == TRUE));
|
Win32Input::instance->WindowActivate((w == TRUE));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
Win32Input::instance->WindowActivate(true);
|
Win32Input::instance->WindowActivate(true);
|
||||||
//tme.cbSize=sizeof(tme);
|
|
||||||
//tme.dwFlags=TME_HOVER;
|
|
||||||
//tme.hwndTrack=h;//hanlde of window you want the mouse over message for.
|
|
||||||
//tme.dwHoverTime=HOVER_DEFAULT;
|
|
||||||
//if(TrackMouseEvent(&tme) == FALSE)
|
|
||||||
//{ }
|
|
||||||
break;
|
|
||||||
case WM_MOUSEHOVER:
|
|
||||||
//val = 0;
|
|
||||||
break;
|
|
||||||
case WM_MOUSELEAVE:
|
|
||||||
//val = 0;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return DefWindowProc(h, m, w, l);
|
return DefWindowProc(h, m, w, l);
|
||||||
}
|
}
|
||||||
void Win32Input::WindowActivate(bool activate)
|
void Win32Input::WindowActivate(bool activate)
|
||||||
{
|
{
|
||||||
//if(activate)
|
if(activate)
|
||||||
//{
|
{
|
||||||
// ShowCursor(0);
|
SetCursor(0);
|
||||||
//}
|
for (unsigned int i = 0; i < Win32Input::instance->mouse.size(); i++)
|
||||||
//else
|
{
|
||||||
//{
|
Win32Input::instance->mouse[i]->ToggleDefault(false);
|
||||||
// ShowCursor(1);
|
}
|
||||||
//}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < Win32Input::instance->mouse.size(); i++)
|
||||||
|
{
|
||||||
|
Win32Input::instance->mouse[i]->ToggleDefault(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -279,5 +279,21 @@ bool Win32Mouse::Create()
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
void Win32Mouse::ToggleDefault( bool toggler )
|
||||||
|
{
|
||||||
|
if( toggler )
|
||||||
|
{
|
||||||
|
SetCursorPos(this->winCursPos.x, this->winCursPos.y);
|
||||||
|
ShowCursor(TRUE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
POINT p;
|
||||||
|
GetCursorPos(&p);
|
||||||
|
this->winCursPos.x = p.x;
|
||||||
|
this->winCursPos.y = p.y;
|
||||||
|
ShowCursor(FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -163,25 +163,15 @@ void SimpleRigidBody::SetRotation(::Oyster::Math::Float4x4 rotation)
|
||||||
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleRigidBody::SetRotationAsAngularAxis(::Oyster::Math::Float4 angularAxis)
|
void SimpleRigidBody::AddRotationAroundY(::Oyster::Math::Float angle)
|
||||||
{
|
{
|
||||||
if(angularAxis.xyz.GetMagnitude() == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float s = sin(angularAxis.w/2);
|
|
||||||
float x = angularAxis.x * s;
|
|
||||||
float y = angularAxis.y * s;
|
|
||||||
float z = angularAxis.z * s;
|
|
||||||
float w = cos(angularAxis.w/2);
|
|
||||||
|
|
||||||
btTransform trans;
|
btTransform trans;
|
||||||
btVector3 vector(angularAxis.x, angularAxis.y, angularAxis.z);
|
btQuaternion quaternion;
|
||||||
btQuaternion quaternion(x,y,z,w);
|
|
||||||
|
|
||||||
trans = this->rigidBody->getWorldTransform();
|
trans = this->rigidBody->getWorldTransform();
|
||||||
trans.setRotation(quaternion);
|
|
||||||
|
quaternion = btQuaternion(trans.getBasis().getColumn(1), angle);
|
||||||
|
trans.setRotation(quaternion*trans.getRotation());
|
||||||
this->rigidBody->setWorldTransform(trans);
|
this->rigidBody->setWorldTransform(trans);
|
||||||
|
|
||||||
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
||||||
|
@ -245,23 +235,45 @@ void SimpleRigidBody::SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math:
|
||||||
|
|
||||||
void SimpleRigidBody::SetUp(::Oyster::Math::Float3 up)
|
void SimpleRigidBody::SetUp(::Oyster::Math::Float3 up)
|
||||||
{
|
{
|
||||||
Float3 vector = Float3(0, 1, 0).Cross(up);
|
btQuaternion newRotation;
|
||||||
|
|
||||||
if(vector == Float3::null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Float sine = vector.GetLength();
|
|
||||||
Float cosine = acos(Float3(0, 1, 0).Dot(up));
|
|
||||||
|
|
||||||
btQuaternion quaternion(btVector3(vector.x, vector.y, vector.z),cosine);
|
|
||||||
|
|
||||||
btTransform trans;
|
btTransform trans;
|
||||||
trans = this->rigidBody->getWorldTransform();
|
trans = this->rigidBody->getWorldTransform();
|
||||||
trans.setRotation(quaternion);
|
|
||||||
|
btVector3 v1 = trans.getBasis().getColumn(1);
|
||||||
|
btVector3 v2(up.x, up.y, up.z);
|
||||||
|
|
||||||
|
btQuaternion q;
|
||||||
|
btVector3 a = v1.cross(v2);
|
||||||
|
|
||||||
|
if (v1.dot(v2) < -0.999999)
|
||||||
|
{
|
||||||
|
btVector3 xCrossPre = btVector3(1, 0 ,0).cross(v1);
|
||||||
|
if(xCrossPre.length() < 0.000001)
|
||||||
|
xCrossPre = btVector3(0, 1 ,0).cross(v1);
|
||||||
|
xCrossPre.normalize();
|
||||||
|
q.setRotation(xCrossPre, 3.1415);
|
||||||
|
}
|
||||||
|
else if (v1.dot(v2) > 0.999999)
|
||||||
|
{
|
||||||
|
q = btQuaternion(0, 0, 0, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
q.setX(a.x());
|
||||||
|
q.setY(a.y());
|
||||||
|
q.setZ(a.z());
|
||||||
|
|
||||||
|
q.setW(1 + v1.dot(v2));
|
||||||
|
|
||||||
|
q.normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
newRotation = q*trans.getRotation();
|
||||||
|
|
||||||
|
trans.setRotation(newRotation);
|
||||||
this->rigidBody->setWorldTransform(trans);
|
this->rigidBody->setWorldTransform(trans);
|
||||||
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
|
||||||
|
this->state.quaternion = Quaternion(Float3(newRotation.x(), newRotation.y(), newRotation.z()), newRotation.w());
|
||||||
}
|
}
|
||||||
|
|
||||||
Float4x4 SimpleRigidBody::GetRotation() const
|
Float4x4 SimpleRigidBody::GetRotation() const
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace Oyster
|
||||||
void SetRotation(Math::Quaternion quaternion);
|
void SetRotation(Math::Quaternion quaternion);
|
||||||
void SetRotation(Math::Float3 eulerAngles);
|
void SetRotation(Math::Float3 eulerAngles);
|
||||||
void SetRotation(::Oyster::Math::Float4x4 rotation);
|
void SetRotation(::Oyster::Math::Float4x4 rotation);
|
||||||
void SetRotationAsAngularAxis(Math::Float4 angularAxis);
|
void AddRotationAroundY(Math::Float angle);
|
||||||
void SetAngularFactor(Math::Float factor);
|
void SetAngularFactor(Math::Float factor);
|
||||||
void SetMass(Math::Float mass);
|
void SetMass(Math::Float mass);
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ namespace Oyster
|
||||||
virtual void SetRotation(::Oyster::Math::Quaternion quaternion) = 0;
|
virtual void SetRotation(::Oyster::Math::Quaternion quaternion) = 0;
|
||||||
virtual void SetRotation(::Oyster::Math::Float3 eulerAngles) = 0;
|
virtual void SetRotation(::Oyster::Math::Float3 eulerAngles) = 0;
|
||||||
virtual void SetRotation(::Oyster::Math::Float4x4 rotation) = 0;
|
virtual void SetRotation(::Oyster::Math::Float4x4 rotation) = 0;
|
||||||
virtual void SetRotationAsAngularAxis(::Oyster::Math::Float4 angularAxis) = 0;
|
virtual void AddRotationAroundY(::Oyster::Math::Float angle) = 0;
|
||||||
virtual void SetAngularFactor(::Oyster::Math::Float factor) = 0;
|
virtual void SetAngularFactor(::Oyster::Math::Float factor) = 0;
|
||||||
virtual void SetMass(::Oyster::Math::Float mass) = 0;
|
virtual void SetMass(::Oyster::Math::Float mass) = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue