diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 9a14fa25..9e52e218 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -76,11 +76,107 @@ GameState::gameStateState GameState::LoadGame() plight.Bright = 2; Oyster::Graphics::API::AddLight(plight); - LoadModels("3bana.bias"); + // use level loader + //LoadModels("3bana.bias"); + // hardcoded objects + LoadModels(); Float3 startPos = Float3(0,0,20.0f); InitCamera(startPos); return gameStateState_playing; } +bool GameState::LoadModels() +{ + // open file + // read file + // init models + int nrOfBoxex = 5; + int id = 100; + + // add world model + ModelInitData modelData; + + modelData.position = Oyster::Math::Float3(0,0,0); + modelData.rotation = Oyster::Math::Quaternion::identity; + modelData.scale = Oyster::Math::Float3(2,2,2); + + modelData.modelPath = L"world_earth.dan"; + modelData.id = id++; + + this->staticObjects.Push(new C_StaticObj()); + this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + + + // add box model + modelData.position = Oyster::Math::Float3(0,0,0); + modelData.rotation = Oyster::Math::Quaternion::identity; + modelData.scale = Oyster::Math::Float3(1,1,1); + modelData.modelPath = L"crate_colonists.dan"; + + + for(int i =0; i< nrOfBoxex; i ++) + { + modelData.position = Oyster::Math::Float3(4,320,0); + modelData.id = id++; + + this->dynamicObjects.Push(new C_DynamicObj()); + this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + } + + + // add crystal model + modelData.position = Oyster::Math::Float3(10, 301, 0); + modelData.modelPath = L"crystalformation_b.dan"; + modelData.id = id++; + // load models + this->dynamicObjects.Push(new C_DynamicObj()); + this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + + // add house model + modelData.position = Oyster::Math::Float3(-50, 290, 0); + //Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0)); + + modelData.visible = true; + modelData.modelPath = L"building_corporation.dan"; + modelData.id = id++; + // load models + this->dynamicObjects.Push(new C_DynamicObj()); + this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + + + // add player model + modelData.position = Oyster::Math::Float3(0, 320, 0); + modelData.modelPath = L"char_still_sizeref.dan"; + modelData.id = id++; + // load models + this->dynamicObjects.Push(new C_DynamicObj()); + this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + + // add player model 2 + modelData.position = Oyster::Math::Float3(50, 320, 0); + modelData.modelPath = L"char_still_sizeref.dan"; + modelData.id = id++; + // load models + this->dynamicObjects.Push(new C_DynamicObj()); + this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + + // add jumppad + modelData.position = Oyster::Math::Float3(4, 300.3, 0); + modelData.modelPath = L"jumppad_round.dan"; + modelData.id = id++; + // load models + this->dynamicObjects.Push(new C_DynamicObj()); + this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + + // add sky sphere + modelData.position = Oyster::Math::Float3(0,0,0); + modelData.scale = Oyster::Math::Float3(800,800,800); + modelData.modelPath = L"skysphere.dan"; + modelData.id = id++; + // load models + this->dynamicObjects.Push(new C_DynamicObj()); + this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + return true; +} bool GameState::LoadModels(std::string mapFile) { GameLogic::LevelLoader levelLoader; @@ -166,130 +262,7 @@ bool GameState::LoadModels(std::string mapFile) privData->object[privData->object.size() -1 ]->Init(modelData); */ return true; - /*// open file - // read file - // init models - int nrOfBoxex = 5; - int id = 100; -// add world model - ModelInitData modelData; - Oyster::Math3D::Float4x4 translate; - C_Object* obj; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0)); - modelData.world = translate ;//modelData.world * translate - modelData.world.v[0].x = 2; - modelData.world.v[1].y = 2; - modelData.world.v[2].z = 2; - modelData.modelPath = L"world_earth.dan"; - modelData.id = id++; - - obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - - -// add box model - modelData.world = Oyster::Math3D::Float4x4::identity; - modelData.modelPath = L"crate_colonists.dan"; - - - for(int i =0; i< nrOfBoxex; i ++) - { - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0)); - modelData.world = modelData.world * translate; - modelData.id = id++; - - obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - modelData.world = Oyster::Math3D::Float4x4::identity; - } - - - // add crystal model - modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 301, 0)); - - modelData.world = modelData.world * translate; - modelData.visible = true; - modelData.modelPath = L"crystalformation_b.dan"; - modelData.id = id++; - // load models - obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - - // add house model - modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-50, 290, 0)); - Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0)); - - modelData.world = modelData.world * translate * rot; - modelData.visible = true; - modelData.modelPath = L"building_corporation.dan"; - modelData.id = id++; - // load models - obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - - - // add player model - modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 320, 0)); - - modelData.world = modelData.world * translate; - modelData.visible = true; - modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = id++; - // load models - obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - - // add player model 2 - modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 320, 0)); - - modelData.world = modelData.world * translate; - modelData.visible = true; - modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = id++; - // load models - obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - - // add jumppad - modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4, 300.3, 0)); - //Oyster::Math3D::RotationMatrix_AxisZ() - modelData.world = modelData.world * translate; - modelData.visible = true; - modelData.modelPath = L"jumppad_round.dan"; - modelData.id = id++; - // load models - obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - - // add sky sphere - modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 0, 0)); - //Oyster::Math3D::RotationMatrix_AxisZ() - modelData.world = modelData.world * translate; - modelData.world.v[0].x = 800; - modelData.world.v[1].y = 800; - modelData.world.v[2].z = 800; - modelData.visible = true; - modelData.modelPath = L"skysphere.dan"; - modelData.id = id++; - // load models - obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); */ - } bool GameState::InitCamera(Float3 startPos) { diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index 0539527e..3f182b2a 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -43,7 +43,8 @@ public: ~GameState(void); bool Init(Oyster::Network::NetworkClient* nwClient); GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override; - bool LoadModels(std::string mapFile) ; + bool LoadModels(std::string mapFile); + bool LoadModels(); bool InitCamera(Oyster::Math::Float3 startPos) ; void InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Float4x4 world); gameStateState LoadGame(); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 0e96be28..ec571b9f 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -40,7 +40,7 @@ void Level::parseObjectType(ObjectTypeHeader* obj) break; }*/ } -void Level::parsePhysicsObj(LevelLoaderInternal::PhysicsObject* obj) +void Level::parsePhysicsObj(LevelLoaderInternal::BoundingVolumeBase* obj) { // offset physObj med modelObj } @@ -68,7 +68,7 @@ void Level::InitiateLevel(std::string levelPath) { ObjectHeader* staticObjData = ((ObjectHeader*)obj); - LevelLoaderInternal::PhysicsObject* staticObjPhysicData = ((ObjectHeader*)obj); + //LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj); staticObjData->ModelFile; ICustomBody* rigidBody_Static; @@ -132,7 +132,7 @@ void Level::InitiateLevel(std::string levelPath) case ObjectType::ObjectType_Dynamic: { ObjectHeader* staticObjData = ((ObjectHeader*)obj); - LevelLoaderInternal::PhysicsObject* staticObjPhysicData = ((ObjectHeader*)obj); + //LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj); staticObjData->ModelFile; ICustomBody* rigidBody_Dynamic; diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 269c8cd8..581d1ee0 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -33,7 +33,7 @@ namespace GameLogic void InitiateLevel(float radius); void parseObjectType(ObjectTypeHeader* obj); - void parsePhysicsObj(LevelLoaderInternal::PhysicsObject* obj); + void parsePhysicsObj(LevelLoaderInternal::BoundingVolumeBase* obj); /******************************************************** * Creates a team in the level * @param teamSize: The size of the team you want to create diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 7f3a53a7..9026a60f 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -50,6 +50,7 @@ API_Impl::~API_Impl() ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) { SimpleRigidBody* body = new SimpleRigidBody; + SimpleRigidBody::State state; // Add collision shape btCollisionShape* collisionShape = new btSphereShape(radius); @@ -73,12 +74,22 @@ ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 r this->dynamicsWorld->addRigidBody(rigidBody); this->customBodies.push_back(body); + state.centerPos = position; + state.reach = Float3(radius, radius, radius); + state.dynamicFrictionCoeff = 0.5f; + state.staticFrictionCoeff = 0.5f; + state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); + state.mass = mass; + + body->SetState(state); + return body; } ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) { SimpleRigidBody* body = new SimpleRigidBody; + SimpleRigidBody::State state; // Add collision shape btCollisionShape* collisionShape = new btBoxShape(btVector3(halfSize.x, halfSize.y, halfSize.z)); @@ -102,12 +113,22 @@ ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 r this->dynamicsWorld->addRigidBody(rigidBody); this->customBodies.push_back(body); + state.centerPos = position; + state.reach = halfSize; + state.dynamicFrictionCoeff = 0.5f; + state.staticFrictionCoeff = 0.5f; + state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); + state.mass = mass; + + body->SetState(state); + return body; } ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) { SimpleRigidBody* body = new SimpleRigidBody; + SimpleRigidBody::State state; // Add collision shape btCollisionShape* collisionShape = new btCylinderShape(btVector3(halfSize.x, halfSize.y, halfSize.z)); @@ -131,6 +152,15 @@ ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::O this->dynamicsWorld->addRigidBody(rigidBody); this->customBodies.push_back(body); + state.centerPos = position; + state.reach = halfSize; + state.dynamicFrictionCoeff = 0.5f; + state.staticFrictionCoeff = 0.5f; + state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); + state.mass = mass; + + body->SetState(state); + return body; } diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index ab8925a8..879ff8bc 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -52,9 +52,11 @@ SimpleRigidBody::State& SimpleRigidBody::GetState( SimpleRigidBody::State &targe void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) { btTransform trans; + btVector3 position(state.centerPos.x, state.centerPos.y, state.centerPos.z); + btQuaternion quaternion(state.quaternion.imaginary.x, state.quaternion.imaginary.y, state.quaternion.imaginary.z, state.quaternion.real); this->motionState->getWorldTransform(trans); - trans.setRotation(btQuaternion(state.quaternion.imaginary.x, state.quaternion.imaginary.y, state.quaternion.imaginary.z, state.quaternion.real)); - trans.setOrigin(btVector3(state.centerPos.x, state.centerPos.y, state.centerPos.z)); + trans.setRotation(quaternion); + trans.setOrigin(position); this->motionState->setWorldTransform(trans); this->rigidBody->setFriction(state.staticFrictionCoeff); this->rigidBody->setRestitution(state.restitutionCoeff); @@ -154,7 +156,7 @@ Float4x4 SimpleRigidBody::GetView( const ::Oyster::Math::Float3 &offset ) const void SimpleRigidBody::CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Oyster::Math::Float kineticEnergyLoss) { - if(this->onMovement) + if(this->afterCollision) this->afterCollision(bodyA, bodyB, kineticEnergyLoss); } diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h index 4c4ae797..fa6c023c 100644 --- a/Code/GamePhysics/PhysicsStructs.h +++ b/Code/GamePhysics/PhysicsStructs.h @@ -16,7 +16,7 @@ namespace Oyster public: // Default constructor CustomBodyState( ::Oyster::Math::Float mass = 1.0f, - ::Oyster::Math::Float restitutionCoeff = 1.0f, + ::Oyster::Math::Float restitutionCoeff = 0.5f, ::Oyster::Math::Float staticFrictionCoeff = 1.0f, ::Oyster::Math::Float dynamicFrictionCoeff = 1.0f, const ::Oyster::Math::Float3 ¢erPos = ::Oyster::Math::Float3::null,