From 8e783088208b93a4a47384fa26b2b301f1adf6d7 Mon Sep 17 00:00:00 2001 From: lanariel Date: Fri, 14 Feb 2014 10:08:39 +0100 Subject: [PATCH 1/8] New Vertex format NOT STABLE UNTIL NEW MODELS --- .../Definitions/GraphicalDefinition.h | 2 -- Code/OysterGraphics/FileLoader/DanLoader.cpp | 5 ++--- Code/OysterGraphics/Render/GuiRenderer.cpp | 2 +- Code/OysterGraphics/Render/Resources.cpp | 4 +--- .../Shader/Passes/Gather/Header.hlsli | 2 -- Code/Tester/MainTest.cpp | 14 +++++++++----- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index 958904a8..ffd2869a 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -27,8 +27,6 @@ namespace Oyster Oyster::Math::Float3 pos; Oyster::Math::Float2 uv; Oyster::Math::Float3 normal; - Oyster::Math::Float3 tangent; - Oyster::Math::Float3 biTangent; Oyster::Math::Float4 boneIndex; Oyster::Math::Float4 boneWeights; }; diff --git a/Code/OysterGraphics/FileLoader/DanLoader.cpp b/Code/OysterGraphics/FileLoader/DanLoader.cpp index 99302266..69af2158 100644 --- a/Code/OysterGraphics/FileLoader/DanLoader.cpp +++ b/Code/OysterGraphics/FileLoader/DanLoader.cpp @@ -5,12 +5,11 @@ #include #include -#define DANFILEVERSIONMAJOR 1 +#define DANFILEVERSIONMAJOR 2 #define DANFILEVERSIONMINOR 1 #define FILEHEADERSIZE 8 #define VERTEXHEADERSIZE 4 -#define VERTEXSIZE 88 @@ -220,7 +219,7 @@ void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[]) delete[] buffer; // ( note: may crash here.) // Fetch all vertices - unsigned int bufferSize = VERTEXSIZE * vertexHeader.numVertices; + unsigned int bufferSize = sizeof(Vertex) * vertexHeader.numVertices; buffer = new char[bufferSize]; danFile.read(buffer, bufferSize); diff --git a/Code/OysterGraphics/Render/GuiRenderer.cpp b/Code/OysterGraphics/Render/GuiRenderer.cpp index 78b2f771..86f6fe0e 100644 --- a/Code/OysterGraphics/Render/GuiRenderer.cpp +++ b/Code/OysterGraphics/Render/GuiRenderer.cpp @@ -91,7 +91,7 @@ namespace Oyster { tmpInst.coff=(1.0f/TEXT_NR_LETTERS); tmpInst.offset=text[i]-32; - tmpInst.pos=i*(FontSize * 0.8f * TEXT_SPACING); + tmpInst.pos=i*(FontSize * 0.7f * TEXT_SPACING); if(tmpInst.pos > size.x) { text = text.substr(0,i-1); diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp index 450a075b..696ee6f1 100644 --- a/Code/OysterGraphics/Render/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources.cpp @@ -340,13 +340,11 @@ namespace Oyster { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "BITANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 44, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "BONEINDEX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 56, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "BONEWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 72, D3D11_INPUT_PER_VERTEX_DATA, 0 } }; - Shader::CreateInputLayout(indesc,7,GetShader::Vertex(L"Gather"),Gather::Pass.IAStage.Layout); + Shader::CreateInputLayout(indesc,5,GetShader::Vertex(L"Gather"),Gather::Pass.IAStage.Layout); Gather::Pass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; Gather::Pass.CBuffers.Vertex.push_back(Gather::AnimationData); Gather::Pass.CBuffers.Vertex.push_back(Gather::ModelData); diff --git a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli index ea144417..8747e46d 100644 --- a/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli @@ -3,8 +3,6 @@ struct VertexIn float3 pos : POSITION; float2 UV : TEXCOORD; float3 normal : NORMAL; - float3 tangent : TANGENT; - float3 biTangent : BITANGENT; float4 boneIndex : BONEINDEX; float4 boneWeight : BONEWEIGHT; }; diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index ad71dabb..c6956971 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -170,10 +170,10 @@ HRESULT InitDirect3D() return E_FAIL; } - m = Oyster::Graphics::API::CreateModel(L"crate_colonists.dan"); - //m->WorldMatrix.m[0][0] = 50; - //m->WorldMatrix.m[1][1] = 50; - //m->WorldMatrix.m[2][2] = 0.00000005f; + m = Oyster::Graphics::API::CreateModel(L"building_corporation.dan"); + m->WorldMatrix.m[0][0] = 0.0002f; + m->WorldMatrix.m[1][1] = 0.0002f; + m->WorldMatrix.m[2][2] = 0.0002f; m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan"); m2->Tint = Oyster::Math::Float3(0.1f,0.1f,1); m3 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan"); @@ -223,7 +223,11 @@ HRESULT Update(float deltaTime) m->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0) * angle,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * angle,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null); m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * -angle,Oyster::Math::Float3(-4,0,0),Oyster::Math::Float3::null); - //Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity; + Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity; + ma.m[0][0] = 0.2f; + ma.m[1][1] = 0.2f; + ma.m[2][2] = 0.2f; + m->WorldMatrix = m->WorldMatrix * ma; Oyster::Graphics::API::Update(deltaTime); //m2->Animation.data.AnimationTime += deltaTime;// * 0.5f; return S_OK; From a42dfe96f15c235941775d60eb8924cd8106565a Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Fri, 14 Feb 2014 11:52:44 +0100 Subject: [PATCH 2/8] Jump implemented --- Code/Game/GameLogic/Game_PlayerData.cpp | 2 +- Code/Game/GameLogic/Player.cpp | 44 +++++++++++--- Code/Game/GameLogic/Player.h | 1 + .../Implementation/PhysicsAPI_Impl.cpp | 6 +- .../Implementation/SimpleRigidBody.cpp | 57 +++++++++++++++++++ .../Implementation/SimpleRigidBody.h | 12 +++- Code/GamePhysics/PhysicsAPI.h | 2 + Code/GamePhysics/PhysicsStructs-Impl.h | 4 +- Code/GamePhysics/PhysicsStructs.h | 1 + 9 files changed, 116 insertions(+), 13 deletions(-) diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 56df13c4..1719da4a 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -15,7 +15,7 @@ Game::PlayerData::PlayerData() //sbDesc.quaternion = Oyster::Math::Float3(0, Oyster::Math::pi, 0); //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().AddCharacter(1.5f, 0.5f, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); rigidBody->SetAngularFactor(0.0f); //create player with this rigid body this->player = new Player(rigidBody, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 19a0bb9c..9a780d76 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -52,6 +52,7 @@ void Player::InitPlayer() key_strafeRight = 0; key_strafeLeft = 0; + this->previousPosition = Oyster::Math::Float3(0,0,0); this->moveDir = Oyster::Math::Float3(0,0,0); this->moveSpeed = 100; this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); @@ -72,12 +73,34 @@ void Player::BeginFrame() //weapon->Update(0.002f); Object::BeginFrame(); - if(this->moveDir != Oyster::Math::Float3::null) + //Oyster::Math::Float3 previousFall = this->previousMoveSpeed*-this->rigidBody->GetState().centerPos.GetNormalized(); + //Oyster::Math::Float3 currentFall = this->rigidBody->GetLinearVelocity()*-this->rigidBody->GetState().centerPos.GetNormalized(); + + if(this->moveDir != Oyster::Math::Float3::null && this->playerState != PLAYER_STATE_JUMPING) { Oyster::Math::Float3 velocity = this->rigidBody->GetLinearVelocity(); Oyster::Math::Float3 lostVelocity = (this->previousMoveSpeed - velocity).GetMagnitude()*this->moveDir; this->rigidBody->SetLinearVelocity(velocity + lostVelocity - this->moveDir*this->moveSpeed ); } + else + { + + if(this->rigidBody->GetLamda() == 1.0f) + { + this->playerState = PLAYER_STATE_WALKING; + } + + if(this->moveDir != Oyster::Math::Float3::null) + { + Oyster::Math::Float3 velocity = this->rigidBody->GetLinearVelocity(); + this->rigidBody->SetLinearVelocity(velocity - this->moveDir*this->moveSpeed ); + } + } + + if(this->rigidBody->GetLamda() == 1.0f) + { + this->playerState = PLAYER_STATE_WALKING; + } this->moveDir = Oyster::Math::Float3::null; @@ -109,10 +132,12 @@ void Player::BeginFrame() if(this->moveDir != Oyster::Math::Float3::null) { this->moveDir.Normalize(); - this->rigidBody->SetLinearVelocity(this->moveDir*this->moveSpeed + this->rigidBody->GetLinearVelocity()); - this->previousMoveSpeed = this->rigidBody->GetLinearVelocity(); + this->rigidBody->SetLinearVelocity(this->moveDir*this->moveSpeed + this->rigidBody->GetLinearVelocity()); } + this->previousMoveSpeed = this->rigidBody->GetLinearVelocity(); + this->previousPosition = this->rigidBody->GetState().centerPos; + this->weapon->Update(0.01f); } @@ -190,15 +215,18 @@ void Player::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D:: // this is the camera right vector this->lookDir = lookDir; - Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1]; - this->rigidBody->SetUpAndRight(up, right); + //Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1]; + //this->rigidBody->SetUpAndRight(up, right); } void Player::Jump() { - Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1].GetNormalized(); - this->rigidBody->ApplyImpulse(up *1500); - this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING; + if(this->rigidBody->GetLamda() < 1.0f) + { + Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1].GetNormalized(); + this->rigidBody->ApplyImpulse(up *1500); + this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; + } } bool Player::IsWalking() diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index bdd83f41..b9ba7c05 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -91,6 +91,7 @@ namespace GameLogic float key_jump; + Oyster::Math::Float3 previousPosition; Oyster::Math::Float3 moveDir; Oyster::Math::Float moveSpeed; Oyster::Math::Float3 previousMoveSpeed; diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index b3ad6777..9cd87d1d 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -210,7 +210,7 @@ ICustomBody* API_Impl::AddCharacter(::Oyster::Math::Float height, ::Oyster::Math this->customBodies.push_back(body); state.centerPos = position; - state.reach = Float3(radius, height*0.5f, radius); + state.reach = Float3(radius, height, radius); state.dynamicFrictionCoeff = 0.5f; state.staticFrictionCoeff = 0.5f; state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); @@ -230,7 +230,9 @@ void API_Impl::UpdateWorld() { for(unsigned int i = 0; i < this->customBodies.size(); i++ ) { - this->customBodies[i]->SetGravity(-(this->customBodies[i]->GetState().centerPos - this->gravityPoint).GetNormalized()*this->gravity); + SimpleRigidBody* simpleBody = dynamic_cast(this->customBodies[i]); + this->customBodies[i]->SetGravity(-(this->customBodies[i]->GetState().centerPos - this->gravityPoint).GetNormalized()*this->gravity); + simpleBody->PreStep(this->dynamicsWorld); } this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep); diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index 3d9fbc4f..cd0c1962 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -344,4 +344,61 @@ void * SimpleRigidBody::GetCustomTag() const void SimpleRigidBody::SetCustomTag( void *ref ) { this->customTag = ref; +} + + +void SimpleRigidBody::PreStep (const btCollisionWorld* collisionWorld) +{ + btTransform xform; + this->rigidBody->getMotionState()->getWorldTransform (xform); + btVector3 down = -xform.getBasis()[1]; + btVector3 forward = xform.getBasis()[2]; + down.normalize (); + forward.normalize(); + + this->raySource[0] = xform.getOrigin(); + this->raySource[1] = xform.getOrigin(); + + this->rayTarget[0] = this->raySource[0] + down * this->state.reach.y * btScalar(1.1); + this->rayTarget[1] = this->raySource[1] + forward * this->state.reach.y * btScalar(1.1); + + class ClosestNotMe : public btCollisionWorld::ClosestRayResultCallback + { + public: + ClosestNotMe (btRigidBody* me) : btCollisionWorld::ClosestRayResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0)) + { + m_me = me; + } + + virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace) + { + if (rayResult.m_collisionObject == m_me) + return 1.0; + + return ClosestRayResultCallback::addSingleResult (rayResult, normalInWorldSpace); + } + protected: + btRigidBody* m_me; + }; + + ClosestNotMe rayCallback(this->rigidBody); + + int i = 0; + for (i = 0; i < 2; i++) + { + rayCallback.m_closestHitFraction = 1.0; + if((this->raySource[i] - this->rayTarget[i]).length() != 0) + collisionWorld->rayTest (this->raySource[i], this->rayTarget[i], rayCallback); + if (rayCallback.hasHit()) + { + this->rayLambda[i] = rayCallback.m_closestHitFraction; + } else { + this->rayLambda[i] = 1.0; + } + } +} + +float SimpleRigidBody::GetLamda() const +{ + return this->rayLambda[0]; } \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.h b/Code/GamePhysics/Implementation/SimpleRigidBody.h index d08fd886..d67393d1 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.h @@ -58,11 +58,17 @@ namespace Oyster void SetCustomTag( void *ref ); void* GetCustomTag() const; + + // Class specific void SetCollisionShape(btCollisionShape* shape); void SetMotionState(btDefaultMotionState* motionState); void SetRigidBody(btRigidBody* rigidBody); + void PreStep(const btCollisionWorld* collisionWorld); + + float GetLamda() const; + private: btCollisionShape* collisionShape; @@ -76,7 +82,11 @@ namespace Oyster void *customTag; - ::Oyster::Math::Float3 gravity; + Math::Float3 gravity; + + btVector3 raySource[2]; + btVector3 rayTarget[2]; + btScalar rayLambda[2]; }; } } diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 1c220d3e..e83f1d99 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -179,6 +179,8 @@ namespace Oyster * @param ref: Anything castable to a void pointer, the engine won't care. ********************************************************/ virtual void SetCustomTag( void *ref ) = 0; + + virtual float GetLamda() const = 0; }; } } diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index 07ba0bb2..87cfcb17 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -10,9 +10,10 @@ namespace Oyster { namespace Struct { - inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float dynamicFrictionCoeff, const ::Oyster::Math::Float3 ¢erPos, const ::Oyster::Math::Quaternion& quaternion) + inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float3 reach, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float dynamicFrictionCoeff, const ::Oyster::Math::Float3 ¢erPos, const ::Oyster::Math::Quaternion& quaternion) { this->mass = mass; + this->reach = reach; this->restitutionCoeff = restitutionCoeff; this->staticFrictionCoeff = staticFrictionCoeff; this->dynamicFrictionCoeff = dynamicFrictionCoeff; @@ -24,6 +25,7 @@ namespace Oyster { this->mass = state.mass; this->restitutionCoeff = state.restitutionCoeff; + this->reach = state.reach; this->staticFrictionCoeff = state.staticFrictionCoeff; this->dynamicFrictionCoeff = state.dynamicFrictionCoeff; this->centerPos = state.centerPos; diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h index fa6c023c..2f369b90 100644 --- a/Code/GamePhysics/PhysicsStructs.h +++ b/Code/GamePhysics/PhysicsStructs.h @@ -16,6 +16,7 @@ namespace Oyster public: // Default constructor CustomBodyState( ::Oyster::Math::Float mass = 1.0f, + ::Oyster::Math::Float3 reach = ::Oyster::Math::Float3(0,0,0), ::Oyster::Math::Float restitutionCoeff = 0.5f, ::Oyster::Math::Float staticFrictionCoeff = 1.0f, ::Oyster::Math::Float dynamicFrictionCoeff = 1.0f, From 9fc8a8840f3c6d2310f20168a2a878ac0cf85aa9 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Fri, 14 Feb 2014 12:03:29 +0100 Subject: [PATCH 3/8] GL - fixed movement(pretty unstable but its working) --- Code/Game/GameLogic/Player.cpp | 21 +++++++++++++++++++-- Code/Game/GameLogic/StaticObject.cpp | 8 ++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 0fb93995..54841b39 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -17,17 +17,34 @@ Player::Player() Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) :DynamicObject(rigidBody, EventOnCollision, type, objectID) { + this->rigidBody = rigidBody; + + Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,400,0); + + Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f); + Oyster::Math::Float mass = 60; + Oyster::Math::Float restitutionCoeff = 0.5; + Oyster::Math::Float frictionCoeff_Static = 0.4; + Oyster::Math::Float frictionCoeff_Dynamic = 0.3; + + + this->rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); + this->rigidBody->SetAngularFactor(0.0f); + weapon = new Weapon(2,this); this->life = 100; - this->teamID = -1; + this->teamID = teamID; this->playerState = PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float3(0,0,-1); - this->moveDir = Oyster::Math::Float3(0,0,0); key_forward = 0; key_backward = 0; key_strafeRight = 0; key_strafeLeft = 0; + + this->moveDir = Oyster::Math::Float3(0,0,0); + this->moveSpeed = 100; + this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); } Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp index 158ee87e..7124b14a 100644 --- a/Code/Game/GameLogic/StaticObject.cpp +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -14,25 +14,25 @@ StaticObject::StaticObject() StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) :Object(rigidBody, EventOnCollision, type, objectID) { - //use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static + rigidBody->SetMass(0); } StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) :Object(rigidBody, EventOnCollision, type, objectID) { - //use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static + rigidBody->SetMass(0); } StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) { this->extraDamageOnCollision = extraDamageOnCollision; - //use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static + rigidBody->SetMass(0); } StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision) { this->extraDamageOnCollision = extraDamageOnCollision; - //use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static + rigidBody->SetMass(0); } StaticObject::~StaticObject(void) { From f8e68b95b2011f7e3b43f5275a2a29f93743493f Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Fri, 14 Feb 2014 12:07:49 +0100 Subject: [PATCH 4/8] Temporary jump --- Code/Game/GameLogic/Game_PlayerData.cpp | 2 +- Code/Game/GameLogic/Player.cpp | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 72251c5a..275866b9 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -17,7 +17,7 @@ Game::PlayerData::PlayerData() //sbDesc.quaternion = Oyster::Math::Float3(0, Oyster::Math::pi, 0); //create rigid body - Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCharacter(1.5f, 0.5f, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); + Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCharacter(2.0f, 0.5f, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); rigidBody->SetAngularFactor(0.0f); //create player with this rigid body this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player,0,0); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 66ae7288..508857b9 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -28,6 +28,11 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) key_backward = 0; key_strafeRight = 0; key_strafeLeft = 0; + + this->previousPosition = Oyster::Math::Float3(0,0,0); + this->moveDir = Oyster::Math::Float3(0,0,0); + this->moveSpeed = 100; + this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); } Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) @@ -103,11 +108,6 @@ void Player::BeginFrame() } } - if(this->rigidBody->GetLamda() == 1.0f) - { - this->playerState = PLAYER_STATE_WALKING; - } - this->moveDir = Oyster::Math::Float3::null; if (key_forward > 0.001) @@ -226,18 +226,12 @@ void Player::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D:: void Player::Jump() { -<<<<<<< HEAD if(this->rigidBody->GetLamda() < 1.0f) { Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1].GetNormalized(); this->rigidBody->ApplyImpulse(up *1500); this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; } -======= - Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1].GetNormalized(); - this->rigidBody->ApplyImpulse(up *1500); - this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; ->>>>>>> origin/GameLogic } bool Player::IsWalking() From 8110b677ff2704bc72607d1d2e61abef6e5fae12 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Fri, 14 Feb 2014 13:09:55 +0100 Subject: [PATCH 5/8] GL - added spawnpoint array --- .../DanBiasGame/GameClientState/GameState.cpp | 5 ++- Code/Game/GameLogic/Level.cpp | 37 +------------------ Code/Game/GameLogic/Level.h | 1 + 3 files changed, 7 insertions(+), 36 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 9e42c87b..c4da14bb 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -183,7 +183,10 @@ bool GameState::LoadModels(std::string mapFile) case GameLogic::ObjectType::ObjectType_Static: { GameLogic::ObjectHeader* staticObjData = ((GameLogic::ObjectHeader*)obj); - + if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_Sky) + { + int i = 0; + } modelData.modelPath.assign(staticObjData->ModelFile.begin(), staticObjData->ModelFile.end()); modelData.visible = true; modelData.position = staticObjData->position; diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 6d3de52c..a828f30b 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -33,7 +33,7 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) case ObjectSpecialType_Sky: { float skySize = ((SkyAttributes*)obj)->skySize; - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + //gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_World: @@ -111,13 +111,12 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) case ObjectSpecialType_SpawnPoint: { // save - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + } break; case ObjectSpecialType_Player: { // should not be read from the lvl format - //gameObj = new Player(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++); } break; case ObjectSpecialType_Generic: @@ -206,12 +205,10 @@ void Level::InitiateLevel(std::string levelPath) API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); API::Instance().SetGravity(200); int objCount = objects.size(); - int modelCount = 100; for (int i = 0; i < objCount; i++) { ObjectTypeHeader* obj = objects.at(i); - int id = obj->typeID; switch (obj->typeID) { case ObjectType::ObjectType_LevelMetaData: @@ -223,7 +220,6 @@ void Level::InitiateLevel(std::string levelPath) break; case ObjectType::ObjectType_Static: { - ObjectHeader* staticObjData = ((ObjectHeader*)obj); staticObjData->ModelFile; @@ -237,7 +233,6 @@ void Level::InitiateLevel(std::string levelPath) else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Box) { - rigidBody_Static = InitRigidBodyCube(staticObjData); } @@ -248,22 +243,13 @@ void Level::InitiateLevel(std::string levelPath) if(rigidBody_Static != NULL) { - // create game object Object* staticGameObj = createGameObj(staticObjData, rigidBody_Static); - //Object* staticGameObj = new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID); if(staticGameObj != NULL) { this->staticObjects.Push((StaticObject*)staticGameObj); - //this->staticObjects[this->staticObjects.Size()-1]->objectID = modelCount++; - //rigidBody_Static->SetCustomTag(this->staticObjects[this->staticObjects.Size()-1]); } - - //this->staticObjects.Push(new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID, 0)); - //this->staticObjects[staticObjCount]->objectID = modelCount++; - } - } break; case ObjectType::ObjectType_Dynamic: @@ -293,12 +279,9 @@ void Level::InitiateLevel(std::string levelPath) { // create game object Object* dynamicGameObj = createGameObj(dynamicObjData, rigidBody_Dynamic); - //Object* dynamicGameObj =new DynamicObject(rigidBody_Dynamic, Object::DefaultCollisionAfter, (ObjectSpecialType)dynamicObjData->specialTypeID); if (dynamicGameObj != NULL) { this->dynamicObjects.Push((DynamicObject*)dynamicGameObj); - //this->dynamicObjects[this->dynamicObjects.Size()-1]->objectID = modelCount++; - //rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[this->dynamicObjects.Size()-1]); } } } @@ -334,9 +317,6 @@ void Level::InitiateLevel(float radius) rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++)); - - //this->dynamicObjects[i]->objectID = idCount++; - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); } /*offset += nrOfBoxex; for(int i =0; i< nrOfBoxex; i ++) @@ -365,31 +345,18 @@ void Level::InitiateLevel(float radius) }*/ - - - - // add crystal ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++)); - rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]); - //this->dynamicObjects[nrOfBoxex]->objectID = idCount++; - - // add house ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f); this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic, idCount++)); - rigidBody_House->SetCustomTag(this->staticObjects[0]); - //this->staticObjects[0]->objectID = idCount++; // add jumppad ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0))); rigidBody_Jumppad->SetCustomTag(this->staticObjects[1]); - //this->staticObjects[1]->objectID = idCount++; } void Level::AddPlayerToTeam(Player *player, int teamID) diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 0b6c2a31..623d04b2 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -77,6 +77,7 @@ namespace GameLogic Utility::DynamicMemory::SmartPointer rigidBodyLevel; StaticObject *levelObj; int objID; + Utility::DynamicMemory::DynamicArray spawnPoints; }; From 25b0162b59c51f0422323e367c4994df6e4be29c Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Fri, 14 Feb 2014 13:54:50 +0100 Subject: [PATCH 6/8] GL - explosive crate testing --- Code/Game/GameLogic/CollisionManager.cpp | 24 ++++++++++++++++++-- Code/Game/GameLogic/Game_PlayerData.cpp | 4 ++-- Code/Game/GameLogic/Level.cpp | 6 +---- Code/Game/GameLogic/Player.cpp | 29 ------------------------ 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 80562b2c..0b817975 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -95,9 +95,16 @@ using namespace GameLogic; { int forceThreashHold = 200000; //how much force for the box to explode of the impact + Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed? - if(kineticEnergyLoss > forceThreashHold) + switch (realObj->GetObjectType()) { + case ObjectSpecialType::ObjectSpecialType_Generic: + break; + case ObjectSpecialType::ObjectSpecialType_StandardBox: + + break; + case ObjectSpecialType::ObjectSpecialType_Player: ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag()); @@ -107,7 +114,20 @@ using namespace GameLogic; Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode); delete hitSphere; + break; } + /*if(kineticEnergyLoss > forceThreashHold) + { + ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag()); + + + Oyster::Math::Float3 pos = rigidBodyCrate->GetState().centerPos; + Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,crate->ExplosionRadius); + + Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode); + + delete hitSphere; + }*/ } void ExplosiveCrate::Explode(Oyster::Physics::ICustomBody *obj, void* args) @@ -123,7 +143,7 @@ using namespace GameLogic; { Player *hitPlayer = (Player*)realObj; - hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision()); + //hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision()); //do shredding damage } diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 275866b9..1b725b02 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -17,12 +17,12 @@ Game::PlayerData::PlayerData() //sbDesc.quaternion = Oyster::Math::Float3(0, Oyster::Math::pi, 0); //create rigid body - Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCharacter(2.0f, 0.5f, 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); //create player with this rigid body this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player,0,0); - this->player->GetRigidBody()->SetCustomTag(this); + //this->player->GetRigidBody()->SetCustomTag(this); player->EndFrame(); } Game::PlayerData::PlayerData(int playerID,int teamID) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 11c8324e..1b1692d9 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -57,11 +57,7 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_StandardBox: { - int dmg = 50; - Oyster::Math::Float force = 50; - int radie = 10; - gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); - //gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_RedExplosiveBox: diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index b6888bf2..625a0663 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -17,20 +17,6 @@ Player::Player() Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) :DynamicObject(rigidBody, EventOnCollision, type, objectID) { - this->rigidBody = rigidBody; - - Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,400,0); - - Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f); - Oyster::Math::Float mass = 60; - Oyster::Math::Float restitutionCoeff = 0.5; - Oyster::Math::Float frictionCoeff_Static = 0.4; - Oyster::Math::Float frictionCoeff_Dynamic = 0.3; - - - this->rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); - this->rigidBody->SetAngularFactor(0.0f); - weapon = new Weapon(2,this); this->life = 100; @@ -52,20 +38,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) :DynamicObject(rigidBody, EventOnCollision, type, objectID) { - this->rigidBody = rigidBody; - - Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,400,0); - - Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f); - Oyster::Math::Float mass = 60; - Oyster::Math::Float restitutionCoeff = 0.5; - Oyster::Math::Float frictionCoeff_Static = 0.4; - Oyster::Math::Float frictionCoeff_Dynamic = 0.3; - - - this->rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); - this->rigidBody->SetAngularFactor(0.0f); - weapon = new Weapon(2,this); this->life = 100; @@ -81,7 +53,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom this->moveDir = Oyster::Math::Float3(0,0,0); this->moveSpeed = 100; this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); - } Player::~Player(void) From bfb9864be99e3de6b09eca4af806cec8d19fbd84 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Fri, 14 Feb 2014 15:07:55 +0100 Subject: [PATCH 7/8] GL - handle if the model dose not exist --- .../DanBiasGame/GameClientState/C_Object.cpp | 19 ++++- .../DanBiasGame/GameClientState/C_Object.h | 5 +- .../GameClientState/C_obj/C_DynamicObj.cpp | 4 +- .../GameClientState/C_obj/C_DynamicObj.h | 2 +- .../GameClientState/C_obj/C_Player.cpp | 11 ++- .../GameClientState/C_obj/C_Player.h | 3 +- .../GameClientState/C_obj/C_StaticObj.cpp | 4 +- .../GameClientState/C_obj/C_StaticObj.h | 2 +- .../GameClientState/C_obj/C_UIobject.cpp | 4 +- .../GameClientState/C_obj/C_UIobject.h | 2 +- .../DanBiasGame/GameClientState/GameState.cpp | 81 +++++++++++-------- Code/Misc/DynamicArray.h | 2 +- 12 files changed, 89 insertions(+), 50 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/C_Object.cpp b/Code/Game/DanBiasGame/GameClientState/C_Object.cpp index 3f9e08c1..d44d9201 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_Object.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_Object.cpp @@ -1,14 +1,31 @@ #include "C_Object.h" using namespace DanBias::Client; -void C_Object::Init(ModelInitData modelInit) +C_Object::C_Object() +{ + world = Oyster::Math::Float4x4::identity; + position = Oyster::Math::Float3::null; + rotation = Oyster::Math::Quaternion::identity; + scale = Oyster::Math::Float3::null; + + id = 0; + model = NULL; +} +C_Object::~C_Object() +{ + +} +bool C_Object::Init(ModelInitData modelInit) { position = modelInit.position; rotation = modelInit.rotation; scale = modelInit.scale; id = modelInit.id; model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); + if(model == NULL) + return false; model->Visible = modelInit.visible; updateWorld(); + return true; } void C_Object::updateWorld() { diff --git a/Code/Game/DanBiasGame/GameClientState/C_Object.h b/Code/Game/DanBiasGame/GameClientState/C_Object.h index f926a08a..ae9dc3a5 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_Object.h +++ b/Code/Game/DanBiasGame/GameClientState/C_Object.h @@ -29,8 +29,9 @@ private: protected: Oyster::Graphics::Model::Model *model; public: - - virtual void Init(ModelInitData modelInit); + C_Object(); + virtual ~C_Object(); + virtual bool Init(ModelInitData modelInit); void setWorld(Oyster::Math::Float4x4 world); Oyster::Math::Float4x4 getWorld() const; diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp index e654348f..73dd20b5 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp @@ -11,7 +11,7 @@ C_DynamicObj::~C_DynamicObj(void) { } -void C_DynamicObj::Init(ModelInitData modelInit) +bool C_DynamicObj::Init(ModelInitData modelInit) { - C_Object::Init(modelInit); + return C_Object::Init(modelInit); } diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h index ecb874d1..3f5a9dd1 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h @@ -11,7 +11,7 @@ private: public: C_DynamicObj(void); virtual ~C_DynamicObj(void); - void Init(ModelInitData modelInit); + bool Init(ModelInitData modelInit); };};}; #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp index a75785a6..b6420f53 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp @@ -13,9 +13,12 @@ C_Player::~C_Player(void) } -void C_Player::Init(ModelInitData modelInit) +bool C_Player::Init(ModelInitData modelInit) { - C_Object::Init(modelInit); - Oyster::Graphics::API::PlayAnimation(model, L"movement"); - //Oyster::Graphics::API::Update(0.002f); + return C_Object::Init(modelInit); } +void C_Player::playAnimation(std::wstring animation, bool loop) +{ + if(model) + Oyster::Graphics::API::PlayAnimation(model, L"movement", loop); +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h index 9d7c3de0..3ef96702 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h @@ -11,7 +11,8 @@ private: public: C_Player(void); virtual ~C_Player(void); - void Init(ModelInitData modelInit); + bool Init(ModelInitData modelInit); + void playAnimation(std::wstring animation, bool loop); };};}; #endif diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp index a61768e4..42a12acd 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp @@ -10,7 +10,7 @@ C_StaticObj::~C_StaticObj(void) { } -void C_StaticObj::Init(ModelInitData modelInit) +bool C_StaticObj::Init(ModelInitData modelInit) { - C_Object::Init(modelInit); + return C_Object::Init(modelInit); } diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h index d2bcb2a9..60b09046 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h @@ -11,7 +11,7 @@ private: public: C_StaticObj(void); virtual ~C_StaticObj(void); - void Init(ModelInitData modelInit); + bool Init(ModelInitData modelInit); };};}; #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp index 570fa22f..4cc57a98 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp @@ -10,7 +10,7 @@ C_UIobject::C_UIobject(void) C_UIobject::~C_UIobject(void) { } -void C_UIobject::Init(ModelInitData modelInit) +bool C_UIobject::Init(ModelInitData modelInit) { - C_Object::Init(modelInit); + return C_Object::Init(modelInit); } diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h index f002fcb2..fe4b68d0 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h @@ -12,7 +12,7 @@ namespace DanBias public: C_UIobject(void); virtual ~C_UIobject(void); - void Init(ModelInitData modelInit); + bool Init(ModelInitData modelInit); void setPos(Oyster::Math::Float4x4 world); };};}; #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index c4da14bb..c86d599d 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -195,7 +195,12 @@ bool GameState::LoadModels(std::string mapFile) modelData.id = modelId++; this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + if(!this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData)) + { + // the model don't exist + this->staticObjects.Remove(this->staticObjects.Size() -1 ); + modelId--; + } } break; case GameLogic::ObjectType::ObjectType_Dynamic: @@ -209,7 +214,12 @@ bool GameState::LoadModels(std::string mapFile) modelData.id = modelId++; this->dynamicObjects.Push(new C_DynamicObj()); - this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + if(!this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData)) + { + // the model don't exist + this->dynamicObjects.Remove(this->dynamicObjects.Size() -1 ); + modelId--; + } } break; case GameLogic::ObjectType::ObjectType_Light: @@ -241,40 +251,44 @@ bool GameState::LoadModels(std::string mapFile) modelData.rotation = first; modelData.scale = Oyster::Math::Float3(1,1,1); modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = myId; + modelData.id = modelId; this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + if(!this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData)) + { + // the model don't exist + this->staticObjects.Remove(this->staticObjects.Size() -1 ); + modelId--; + } + //modelData.visible = true; + //modelData.position = Oyster::Math::Float3(22, 127,0); + //modelData.rotation = second; + //modelData.scale = Oyster::Math::Float3(1,1,1); + //modelData.modelPath = L"char_still_sizeref.dan"; + //modelData.id = myId; - modelData.visible = true; - modelData.position = Oyster::Math::Float3(22, 127,0); - modelData.rotation = second; - modelData.scale = Oyster::Math::Float3(1,1,1); - modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = myId; + //this->staticObjects.Push(new C_StaticObj()); + //this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); - this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + //modelData.visible = true; + //modelData.position = Oyster::Math::Float3(24, 127,0); + //modelData.rotation = result; + //modelData.scale = Oyster::Math::Float3(1,1,1); + //modelData.modelPath = L"char_still_sizeref.dan"; + //modelData.id = myId; - modelData.visible = true; - modelData.position = Oyster::Math::Float3(24, 127,0); - modelData.rotation = result; - modelData.scale = Oyster::Math::Float3(1,1,1); - modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = myId; + //this->staticObjects.Push(new C_StaticObj()); + //this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); - this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + //modelData.visible = true; + //modelData.position = Oyster::Math::Float3(26, 127,0); + //modelData.rotation = total; + //modelData.scale = Oyster::Math::Float3(1,1,1); + //modelData.modelPath = L"char_still_sizeref.dan"; + //modelData.id = myId; - modelData.visible = true; - modelData.position = Oyster::Math::Float3(26, 127,0); - modelData.rotation = total; - modelData.scale = Oyster::Math::Float3(1,1,1); - modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = myId; - - this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + //this->staticObjects.Push(new C_StaticObj()); + //this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); return true; @@ -302,13 +316,16 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Flo modelData.position = Oyster::Math::Float3(world[12], world[13], world[14]); modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(0,0,0), 1); modelData.scale = Oyster::Math::Float3(1,1,1); - modelData.modelPath = modelName; + modelData.modelPath = L"crate_generic.dan"; // modelName; modelData.id = myId; obj = new C_Player(); this->dynamicObjects.Push(obj); - this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); - + if(!this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData)) + { + // the model don't exist + this->dynamicObjects.Remove(this->dynamicObjects.Size() -1 ); + } Oyster::Math::Float3 right = Oyster::Math::Float3(world[0], world[1], world[2]); Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]); diff --git a/Code/Misc/DynamicArray.h b/Code/Misc/DynamicArray.h index 8b4c98da..9d7bbc30 100644 --- a/Code/Misc/DynamicArray.h +++ b/Code/Misc/DynamicArray.h @@ -170,7 +170,7 @@ namespace Utility template void DynamicArray::Remove(unsigned int index) { - assert(index > (unsigned int) this->size); + assert(index < (unsigned int) this->size); T* temp = new T[this->capacity - 1]; From 3051621f30fe8730b8c2ccd21af25fa136405d10 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Fri, 14 Feb 2014 15:18:38 +0100 Subject: [PATCH 8/8] GL- levelLoader can now load a correct spawnpoint --- .../DanBiasGame/GameClientState/GameState.cpp | 7 +++++ .../LevelLoader/LevelParser.cpp | 30 ++++++++++++++----- .../LevelLoader/ObjectDefines.h | 11 ++++++- .../GameLogic/LevelLoader/LevelParser.cpp | 29 +++++++++++++----- .../GameLogic/LevelLoader/ObjectDefines.h | 7 ++++- 5 files changed, 67 insertions(+), 17 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index c86d599d..22194795 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -175,8 +175,15 @@ bool GameState::LoadModels(std::string mapFile) { GameLogic::ObjectTypeHeader* obj = objects.at(i); + switch (obj->typeID) { + + case GameLogic::ObjectType::ObjectType_SpawnPoint: + { + + break; + } case GameLogic::ObjectType::ObjectType_LevelMetaData: break; diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp index c5dfa8cc..39d2f625 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp @@ -59,6 +59,27 @@ std::vector> LevelParser::Parse(std::string filen break; } + case ObjectType_SpawnPoint: + { + loadCgf = false; + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + SpawnPointAttributes* spawn = new SpawnPointAttributes; + + spawn->typeID = header->typeID; + + for(int i = 0; i < 3; i++) + { + spawn->position[i] = header->position[i]; + } + + delete header; + //objects.push_back(header); + objects.push_back(spawn); + break; + } + //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. //Unless they are changed to not be the same. case ObjectType_Static: case ObjectType_Dynamic: @@ -133,13 +154,8 @@ std::vector> LevelParser::Parse(std::string filen objects.push_back(header); break; } - - case ObjectSpecialType_SpawnPoint: - { - loadCgf = false; - ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter, loadCgf); - } + //this is a hotfix, fix so you only load the relevant data when the file is updated + default: //Couldn't find specialType diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h index 09556cdc..bb2ae439 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h @@ -16,6 +16,7 @@ namespace GameLogic ObjectType_Static, ObjectType_Dynamic, ObjectType_Light, + ObjectType_SpawnPoint, //Etc ObjectType_NUM_OF_TYPES, @@ -38,7 +39,6 @@ namespace GameLogic ObjectSpecialType_CrystalShard, ObjectSpecialType_JumpPad, ObjectSpecialType_Portal, - ObjectSpecialType_SpawnPoint, ObjectSpecialType_Player, @@ -206,6 +206,13 @@ namespace GameLogic virtual ~ObjectHeader(){} }; + //inheritance from the base class because there is no use for ModelFile, Rotation and Scale + //so this is a special struct for just spawnpoints + struct SpawnPointAttributes : public ObjectTypeHeader + { + float position[3]; + }; + /************************************ Special objects *************************************/ @@ -234,6 +241,8 @@ namespace GameLogic + + /************************************ Lights *************************************/ diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 038b9a40..1e33361d 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -3,7 +3,6 @@ ///////////////////////////////////// #include "LevelParser.h" - #include "Loader.h" #include "ParseFunctions.h" @@ -59,6 +58,27 @@ std::vector> LevelParser::Parse(std::string filen break; } + case ObjectType_SpawnPoint: + { + loadCgf = false; + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + SpawnPointAttributes* spawn = new SpawnPointAttributes; + + spawn->typeID = header->typeID; + + for(int i = 0; i < 3; i++) + { + spawn->position[i] = header->position[i]; + } + + delete header; + //objects.push_back(header); + objects.push_back(spawn); + break; + } + //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. //Unless they are changed to not be the same. case ObjectType_Static: case ObjectType_Dynamic: @@ -134,13 +154,6 @@ std::vector> LevelParser::Parse(std::string filen break; } - case ObjectSpecialType_SpawnPoint: - { - loadCgf = false; - ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter, loadCgf); - } - default: //Couldn't find specialType break; diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 50c722b6..01d17c3e 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -16,6 +16,7 @@ namespace GameLogic ObjectType_Static, ObjectType_Dynamic, ObjectType_Light, + ObjectType_SpawnPoint, //Etc ObjectType_NUM_OF_TYPES, @@ -38,7 +39,6 @@ namespace GameLogic ObjectSpecialType_CrystalShard, ObjectSpecialType_JumpPad, ObjectSpecialType_Portal, - ObjectSpecialType_SpawnPoint, ObjectSpecialType_Player, ObjectSpecialType_Generic, @@ -207,6 +207,11 @@ namespace GameLogic virtual ~ObjectHeader(){} }; + struct SpawnPointAttributes : public ObjectTypeHeader + { + ObjectSpecialType specialTypeID; + float position[3]; + }; /************************************ Special objects *************************************/