diff --git a/src/camera.cpp b/src/camera.cpp index 7395ac2d..d661eae5 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -72,6 +72,10 @@ vec3 Camera::GetTarget() { return m_target; } +vec3 Camera::GetPosition() +{ + return m_position; +} mat4 const &Camera::GetViewMatrix() { diff --git a/src/camera.h b/src/camera.h index e3628b3e..e56f56d9 100644 --- a/src/camera.h +++ b/src/camera.h @@ -36,6 +36,7 @@ public: float near, float far); void SetTarget(vec3 const &pos); vec3 GetTarget(); + vec3 GetPosition(); mat4 const &GetViewMatrix(); mat4 const &GetProjMatrix(); diff --git a/test/BtPhysTest.cpp b/test/BtPhysTest.cpp index a439dcce..dbacec05 100644 --- a/test/BtPhysTest.cpp +++ b/test/BtPhysTest.cpp @@ -51,8 +51,8 @@ int gNumObjects = 64; #define USE_WALL 1 #define USE_PLATFORM 1 -#define USE_ROPE 0 -#define USE_BODIES 0 +#define USE_ROPE 1 +#define USE_BODIES 1 #define USE_ROTATION 0 #define USE_CHARACTER 1 @@ -70,6 +70,7 @@ BtPhysTest::BtPhysTest(bool editor) m_ready = false; m_simulation = new Simulation(); + m_simulation->SetWorldLimit(vec3(-1000.0f, -1000.0f, -1000.0f), vec3(1000.0f, 1000.0f, 1000.0f)); m_simulation->Init(); vec3 NewGravity = vec3(.0f, -10.0f, .0f); m_simulation->SetGravity(NewGravity); @@ -109,7 +110,7 @@ BtPhysTest::BtPhysTest(bool editor) if (USE_PLATFORM) { quat NewRotation = quat::fromeuler_xyz(5.f, 0.f, 0.f); - vec3 NewPosition = pos_offset + vec3(5.0f, -20.0f, -15.0f); + vec3 NewPosition = pos_offset + vec3(5.0f, -25.0f, -15.0f); PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); @@ -127,7 +128,7 @@ BtPhysTest::BtPhysTest(bool editor) if (USE_CHARACTER) { quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f); - vec3 NewPosition = pos_offset + vec3(.0f, 40.0f, .0f); + vec3 NewPosition = pos_offset + vec3(.0f, 20.0f, .0f); PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2); @@ -406,6 +407,23 @@ void BtPhysTest::TickGame(float seconds) if (USE_CHARACTER) { + for (int i = 0; i < m_character_list.Count(); i++) + { + PhysicsObject* PhysObj = m_character_list[i]; + EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter(); + + int HMovement = Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/); + int VMovement = Input::GetButtonState(273 /*SDLK_UP*/) - Input::GetButtonState(274 /*SDLK_DOWN*/); + + Character->SetMovementForFrame(vec3((float)VMovement * seconds * 4.f, .0f, (float)HMovement * seconds * 4.f)); + } + } + + if (USE_CHARACTER) + { + PhysObjBarycenter = vec3(.0f); + factor = .0f; + for (int i = 0; i < m_character_list.Count(); i++) { PhysicsObject* PhysObj = m_character_list[i]; @@ -417,8 +435,9 @@ void BtPhysTest::TickGame(float seconds) PhysObjBarycenter /= factor; - m_camera->SetTarget(PhysObjBarycenter); - m_camera->SetPosition(PhysObjBarycenter + vec3(-80.0f, 80.0f, .0f)); + m_camera->SetTarget(m_camera->GetTarget() + (seconds / (seconds + 0.18f)) * (PhysObjBarycenter - m_camera->GetTarget())); + vec3 CamPosCenter = m_camera->GetTarget() + vec3(.0f, 20.0f, .0f); + m_camera->SetPosition(CamPosCenter + normalize(m_camera->GetPosition() - CamPosCenter) * 5.0f); } else { diff --git a/test/PhysicObject.h b/test/PhysicObject.h index 8119de3c..cdc84e03 100644 --- a/test/PhysicObject.h +++ b/test/PhysicObject.h @@ -40,8 +40,6 @@ public: if (dummy == 1) //for Rope purpose { m_mesh.Compile("[sc#ddd afcb20 1 20 -.1]"); - //m_mesh.Compile("[sc#f00 afcb10 10 10 -.1]"); - vec3 BoxSize = vec3(20.f, 1.f, 20.f); m_physics.SetCollisionChannel(0, 0xFF); m_physics.SetShapeToBox(BoxSize); @@ -53,9 +51,30 @@ public: else if (dummy == 2) //for character purpose { m_is_character = true; - m_mesh.Compile("[sc#f00 afcb10 10 10 -.1]"); - //m_mesh.Compile("[sc#fff scb#fff ac1 2 2 2 0 0]"); - vec3 BoxSize = vec3(2.f, 2.f, 2.f); + //m_mesh.Compile("[sc#f00 afcb10 10 10 -.1]"); + m_mesh.Compile( + "[sc#000 scb#000" + //"[sc#aaa scb#aaa" + "[ad8 2 0 rx180 ty-1]" + "[asph8 .5 .5 .5 ty1]" + "[ac32 2 .5 .5 0 0]" + "[asph6 .1 .1 .1 ty.9 tx.5 tz.15]" + "[asph6 .1 .1 .1 ty.9 tx.5 tz-.15]" + "[asph8 .05 .5 .05 ty.6 tz.5]" + "[asph8 .05 .5 .05 ty.6 tz-.5]" + "]" + "[sc#fd0 scb#fd0" + "[ac8 .4 .1 0 0 0 ty.25 rz-90 ty.7 tx.5]" + "]" + "[" + "[sc#fff scb#fff" + "[ad8 2 0 rx180 ty-1]" + "[asph8 .5 .5 .5 ty1]" + "[ac32 1.9 .5 .5 0 0]" + "]" + " ty-.1 tx.05]" + ); + vec3 BoxSize = vec3(.5f, 2.f, .5f); m_character.SetCollisionChannel(0, 0xFF); m_character.SetShapeToCapsule(BoxSize.x, BoxSize.y); m_character.SetMass(.0f); @@ -88,21 +107,21 @@ public: int ConeLimit = MeshRand.Count(); - MeshRand << "[sc#add scb#add ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; - MeshRand << "[sc#dad scb#dad ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; - MeshRand << "[sc#dda scb#dda ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; - MeshRand << "[sc#daa scb#daa ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; - MeshRand << "[sc#ada scb#ada ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; - MeshRand << "[sc#aad scb#aad ad1 2 0 rx180 ty-1 ac1 2 2 0 0 0]"; + MeshRand << "[sc#add scb#add ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]"; + MeshRand << "[sc#dad scb#dad ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]"; + MeshRand << "[sc#dda scb#dda ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]"; + MeshRand << "[sc#daa scb#daa ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]"; + MeshRand << "[sc#ada scb#ada ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]"; + MeshRand << "[sc#aad scb#aad ad1 2 0 rx180 ty-1 ac4 2 2 0 0 0]"; int CylLimit = MeshRand.Count(); - MeshRand << "[sc#add scb#add ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; - MeshRand << "[sc#dad scb#dad ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; - MeshRand << "[sc#dda scb#dda ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; - MeshRand << "[sc#daa scb#daa ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; - MeshRand << "[sc#ada scb#ada ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; - MeshRand << "[sc#aad scb#aad ad1 2 0 rx180 ty-1 my ac1 2 2 2 0 0]"; + MeshRand << "[sc#add scb#add ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]"; + MeshRand << "[sc#dad scb#dad ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]"; + MeshRand << "[sc#dda scb#dda ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]"; + MeshRand << "[sc#daa scb#daa ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]"; + MeshRand << "[sc#ada scb#ada ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]"; + MeshRand << "[sc#aad scb#aad ad1 2 0 rx180 ty-1 my ac4 2 2 2 0 0]"; int CapsLimit = MeshRand.Count(); diff --git a/test/Physics/EasyPhysics.cpp b/test/Physics/EasyPhysics.cpp index 35a3c7bd..337d2908 100644 --- a/test/Physics/EasyPhysics.cpp +++ b/test/Physics/EasyPhysics.cpp @@ -307,6 +307,13 @@ void EasyCharacterController::RemoveFromSimulation(class Simulation* current_sim } } +//Set movement for this frame +void EasyCharacterController::SetMovementForFrame(vec3 &MoveQuantity) +{ + m_character->setWalkDirection(LOL2BT_VEC3(MoveQuantity)); +} + + //------------------------------------------------------------------------- //EASY_CONSTRAINT //-- diff --git a/test/Physics/EasyPhysics.h b/test/Physics/EasyPhysics.h index 66870de1..81b182a1 100644 --- a/test/Physics/EasyPhysics.h +++ b/test/Physics/EasyPhysics.h @@ -142,6 +142,7 @@ public: virtual void InitBodyToGhost(); virtual void AddToSimulation(class Simulation* current_simulation); virtual void RemoveFromSimulation(class Simulation* current_simulation); + virtual void SetMovementForFrame(vec3 &MoveQuantity); protected: diff --git a/test/Physics/LolPhysics.h b/test/Physics/LolPhysics.h index 7cd17123..11c6f1e7 100644 --- a/test/Physics/LolPhysics.h +++ b/test/Physics/LolPhysics.h @@ -45,7 +45,14 @@ public: void Init() { // Build the broadphase - m_broadphase = new btDbvtBroadphase(); + if (1) + { + m_Sweep_broadphase = new btAxisSweep3(LOL2BT_VEC3(m_world_min), LOL2BT_VEC3(m_world_max)); + m_Sweep_broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback()); + m_broadphase = m_Sweep_broadphase; + } + else + m_broadphase = new btDbvtBroadphase(); // Set up the collision configuration and dispatcher m_collision_configuration = new btDefaultCollisionConfiguration(); @@ -98,10 +105,15 @@ private: m_dynamics_world->setGravity(LOL2BT_VEC3(NewGravity * LOL2BT_UNIT)); } + void CustomSetWorldLimit(vec3 &NewWorldMin, vec3 &NewWorldMax) + { + } + void CustomSetTimestep(float NewTimestep) { } //broadphase btBroadphaseInterface* m_broadphase; + btAxisSweep3* m_Sweep_broadphase; // Set up the collision configuration and dispatc btDefaultCollisionConfiguration* m_collision_configuration; btCollisionDispatcher* m_dispatcher; @@ -119,6 +131,7 @@ public: private: void CustomSetContinuousDetection(bool ShouldUseCCD) { } void CustomSetGravity(vec3 &NewGravity) { } + void CustomSetWorldLimit(vec3 &NewWorldMin, vec3 &NewWorldMax) { } void CustomSetTimestep(float NewTimestep) { } #endif // PHYSIC IMPLEMENTATION @@ -142,6 +155,14 @@ public: CustomSetGravity(NewGravity); } + //Sets the simulation gravity. + void SetWorldLimit(vec3 &NewWorldMin, vec3 &NewWorldMax) + { + m_world_min = NewWorldMin; + m_world_max = NewWorldMax; + CustomSetWorldLimit(NewWorldMin, NewWorldMax); + } + //Sets the simulation fixed timestep. void SetTimestep(float NewTimestep) { @@ -172,6 +193,8 @@ private: float m_timestep; bool m_using_CCD; vec3 m_gravity; + vec3 m_world_min; + vec3 m_world_max; }; } /* namespace phys */