Pull from master. Cant pick up boxes.

This commit is contained in:
Linda Andersson 2014-02-27 15:14:34 +01:00
commit 7063c6bc47
6 changed files with 38 additions and 21 deletions

View File

@ -17,12 +17,13 @@ GamingUI::GamingUI() :
this->sharedData = nullptr; this->sharedData = nullptr;
this->camera = nullptr; this->camera = nullptr;
this->plane = nullptr; this->plane = nullptr;
this->text = nullptr; this->energy = nullptr;
this->hp = nullptr;
this->key_backward = false; this->key_backward = false;
this->key_forward = false; this->key_forward = false;
this->key_strafeLeft = false; this->key_strafeLeft = false;
this->key_strafeRight = false; this->key_strafeRight = false;
this->nextState = GameStateUI::UIState_same; this->nextState = GameStateUI::UIState_same;
} }
GamingUI::GamingUI( SharedStateContent* shared, Camera_FPSV2 *camera ) : GamingUI::GamingUI( SharedStateContent* shared, Camera_FPSV2 *camera ) :
@ -31,7 +32,8 @@ GamingUI::GamingUI( SharedStateContent* shared, Camera_FPSV2 *camera ) :
this->sharedData = shared; this->sharedData = shared;
this->camera = camera; this->camera = camera;
this->plane = nullptr; this->plane = nullptr;
this->text = nullptr; this->hp = nullptr;
this->energy = nullptr;
this->key_backward = false; this->key_backward = false;
this->key_forward = false; this->key_forward = false;
this->key_strafeLeft = false; this->key_strafeLeft = false;
@ -44,11 +46,10 @@ bool GamingUI::Init()
{ {
// z value should be between 0.5 - 0.9 so that it will be behind other states // z value should be between 0.5 - 0.9 so that it will be behind other states
// add textures and text // add textures and text
this->plane = new Plane_UI(L"box_tex.png", Float3(0.5f, 0.0f, 0.5f), Float2(0.3f, 0.1f)); this->hp = new Text_UI(L"100", Float3(0.04f,0.91f,0.1f), Float2(0.1f,0.1f), Float4(1,0,0,1));
this->text = new Text_UI(L"hej", Float3(0.5f,0.0f,0.1f), Float2(0.1f,0.1f)); this->energy = new Text_UI(L"100", Float3(0.8f,0.91f,0.1f), Float2(0.4f,0.1f), Float4(1,1,0,1));
this->sharedData = sharedData; this->sharedData = sharedData;
// setting input mode to all raw // setting input mode to all raw
this->sharedData->keyboardDevice->Activate(); this->sharedData->keyboardDevice->Activate();
this->sharedData->keyboardDevice->AddKeyboardEvent(this); this->sharedData->keyboardDevice->AddKeyboardEvent(this);
@ -75,12 +76,13 @@ bool GamingUI::HaveTextRender() const
void GamingUI::RenderGUI() const void GamingUI::RenderGUI() const
{ {
this->plane->RenderTexture(); //this->plane->RenderTexture();
} }
void GamingUI::RenderText() const void GamingUI::RenderText() const
{ {
this->text->RenderText(); this->hp->RenderText();
this->energy->RenderText();
} }
bool GamingUI::Release() bool GamingUI::Release()
@ -90,16 +92,15 @@ bool GamingUI::Release()
this->sharedData->mouseDevice->RemoveMouseEvent(this); this->sharedData->mouseDevice->RemoveMouseEvent(this);
// TODO: Release UI components here. // TODO: Release UI components here.
if(this->plane) delete this->plane; if(this->plane) delete this->plane;
if(this->text) delete this->text; if(this->hp) delete this->hp;
if(this->energy) delete this->energy;
this->sharedData = 0; this->sharedData = 0;
return true; return true;
} }
void GamingUI::SetHPtext( std::wstring hp ) void GamingUI::SetHPtext( std::wstring hp )
{ {
this->text->setText(hp); this->hp->setText(hp);
} }
void GamingUI::ReadKeyInput() void GamingUI::ReadKeyInput()
{ {

View File

@ -45,7 +45,8 @@ namespace DanBias { namespace Client
Camera_FPSV2 *camera; Camera_FPSV2 *camera;
// TODO add multiple UI elements // TODO add multiple UI elements
Text_UI* text; Text_UI* hp;
Text_UI* energy;
Plane_UI* plane; Plane_UI* plane;
bool key_forward; bool key_forward;

View File

@ -27,7 +27,7 @@ bool RespawnUI::Init()
{ {
// z value should be between 0.5 - 0.9 so that it will be behind other states // z value should be between 0.5 - 0.9 so that it will be behind other states
// add textures and text // add textures and text
this->text = new Text_UI(L"DEAD", Float3(0.5f,0.0f,0.5f), Float2(0.2f,0.2f)); this->text = new Text_UI(L"DEAD", Float3(0.35f,0.35f,0.5f), Float2(0.5f,0.2f));
return true; return true;
} }
GameStateUI::UIState RespawnUI::Update( float deltaTime ) GameStateUI::UIState RespawnUI::Update( float deltaTime )

View File

@ -93,6 +93,8 @@ ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 r
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
dynamic_cast<btSphereShape*>(collisionShape)->setMargin(0.2f);
state.centerPos = position; state.centerPos = position;
state.reach = Float3(radius, radius, radius); state.reach = Float3(radius, radius, radius);
state.dynamicFrictionCoeff = dynamicFriction; state.dynamicFrictionCoeff = dynamicFriction;
@ -132,6 +134,8 @@ ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 r
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
dynamic_cast<btBoxShape*>(collisionShape)->setMargin(0.2f);
state.centerPos = position; state.centerPos = position;
state.reach = halfSize; state.reach = halfSize;
state.dynamicFrictionCoeff = dynamicFriction; state.dynamicFrictionCoeff = dynamicFriction;
@ -171,6 +175,8 @@ ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::O
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
dynamic_cast<btCylinderShape*>(collisionShape)->setMargin(0.2f);
state.centerPos = position; state.centerPos = position;
state.reach = halfSize; state.reach = halfSize;
state.dynamicFrictionCoeff = dynamicFriction; state.dynamicFrictionCoeff = dynamicFriction;
@ -212,6 +218,8 @@ ICustomBody* API_Impl::AddCharacter(::Oyster::Math::Float height, ::Oyster::Math
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
dynamic_cast<btCapsuleShape*>(collisionShape)->setMargin(0.2f);
state.centerPos = position; state.centerPos = position;
state.reach = Float3(radius, height, radius); state.reach = Float3(radius, height, radius);
state.dynamicFrictionCoeff = dynamicFriction; state.dynamicFrictionCoeff = dynamicFriction;
@ -245,9 +253,11 @@ ICustomBody* API_Impl::AddTriangleMesh(const std::wstring fileName, ::Oyster::Ma
btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w),btVector3(position.x, position.y, position.z))); btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w),btVector3(position.x, position.y, position.z)));
body->SetMotionState(motionState); body->SetMotionState(motionState);
// Add rigid body // Add rigid body
btVector3 fallInertia(0, 0, 0); btVector3 fallInertia(0, 0, 0);
//collisionShape->calculateLocalInertia(mass, fallInertia); //collisionShape->calcu%lateLocalInertia(mass, fallInertia);
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(0, motionState, collisionShape, fallInertia); btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(0, motionState, collisionShape, fallInertia);
btRigidBody* rigidBody = new btRigidBody(rigidBodyCI); btRigidBody* rigidBody = new btRigidBody(rigidBodyCI);
rigidBody->setFriction(staticFriction); rigidBody->setFriction(staticFriction);
@ -259,6 +269,8 @@ ICustomBody* API_Impl::AddTriangleMesh(const std::wstring fileName, ::Oyster::Ma
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
dynamic_cast<btBvhTriangleMeshShape*>(collisionShape)->setMargin(0.5);
state.centerPos = position; state.centerPos = position;
state.reach = Float3(0, 0, 0); state.reach = Float3(0, 0, 0);
state.dynamicFrictionCoeff = dynamicFriction; state.dynamicFrictionCoeff = dynamicFriction;
@ -284,10 +296,7 @@ void API_Impl::UpdateWorld()
this->customBodies[i]->SetGravity(-(this->customBodies[i]->GetState().centerPos - this->gravityPoint).GetNormalized()*this->gravity); this->customBodies[i]->SetGravity(-(this->customBodies[i]->GetState().centerPos - this->gravityPoint).GetNormalized()*this->gravity);
simpleBody->PreStep(this->dynamicsWorld); simpleBody->PreStep(this->dynamicsWorld);
if(simpleBody->GetRigidBody()->getActivationState() == ACTIVE_TAG)
{
this->customBodies[i]->CallSubscription_Move();
}
simpleBody->SetPreviousVelocity(simpleBody->GetLinearVelocity()); simpleBody->SetPreviousVelocity(simpleBody->GetLinearVelocity());
} }
@ -302,6 +311,11 @@ void API_Impl::UpdateWorld()
trans = simpleBody->GetRigidBody()->getWorldTransform(); trans = simpleBody->GetRigidBody()->getWorldTransform();
this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z())); this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z()));
this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w())); this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w()));
if(simpleBody->GetRigidBody()->getActivationState() == ACTIVE_TAG)
{
this->customBodies[i]->CallSubscription_Move();
}
} }
int numManifolds = this->dynamicsWorld->getDispatcher()->getNumManifolds(); int numManifolds = this->dynamicsWorld->getDispatcher()->getNumManifolds();

View File

@ -73,6 +73,7 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
void SimpleRigidBody::ApplyImpulse(Float3 impulse) void SimpleRigidBody::ApplyImpulse(Float3 impulse)
{ {
this->rigidBody->applyCentralImpulse(btVector3(impulse.x, impulse.y, impulse.z)); this->rigidBody->applyCentralImpulse(btVector3(impulse.x, impulse.y, impulse.z));
this->rigidBody->setActivationState(ACTIVE_TAG);
} }
void SimpleRigidBody::SetCollisionShape(btCollisionShape* shape) void SimpleRigidBody::SetCollisionShape(btCollisionShape* shape)