Browse Source

So Character Controller works with a lazy camera logic.

legacy
Benjamin ‘Touky’ Huet touky 12 years ago
parent
commit
e8d2d8c202
7 changed files with 98 additions and 24 deletions
  1. +4
    -0
      src/camera.cpp
  2. +1
    -0
      src/camera.h
  3. +25
    -6
      test/BtPhysTest.cpp
  4. +36
    -17
      test/PhysicObject.h
  5. +7
    -0
      test/Physics/EasyPhysics.cpp
  6. +1
    -0
      test/Physics/EasyPhysics.h
  7. +24
    -1
      test/Physics/LolPhysics.h

+ 4
- 0
src/camera.cpp View File

@@ -72,6 +72,10 @@ vec3 Camera::GetTarget()
{ {
return m_target; return m_target;
} }
vec3 Camera::GetPosition()
{
return m_position;
}


mat4 const &Camera::GetViewMatrix() mat4 const &Camera::GetViewMatrix()
{ {


+ 1
- 0
src/camera.h View File

@@ -36,6 +36,7 @@ public:
float near, float far); float near, float far);
void SetTarget(vec3 const &pos); void SetTarget(vec3 const &pos);
vec3 GetTarget(); vec3 GetTarget();
vec3 GetPosition();


mat4 const &GetViewMatrix(); mat4 const &GetViewMatrix();
mat4 const &GetProjMatrix(); mat4 const &GetProjMatrix();


+ 25
- 6
test/BtPhysTest.cpp View File

@@ -51,8 +51,8 @@ int gNumObjects = 64;


#define USE_WALL 1 #define USE_WALL 1
#define USE_PLATFORM 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_ROTATION 0
#define USE_CHARACTER 1 #define USE_CHARACTER 1


@@ -70,6 +70,7 @@ BtPhysTest::BtPhysTest(bool editor)
m_ready = false; m_ready = false;


m_simulation = new Simulation(); m_simulation = new Simulation();
m_simulation->SetWorldLimit(vec3(-1000.0f, -1000.0f, -1000.0f), vec3(1000.0f, 1000.0f, 1000.0f));
m_simulation->Init(); m_simulation->Init();
vec3 NewGravity = vec3(.0f, -10.0f, .0f); vec3 NewGravity = vec3(.0f, -10.0f, .0f);
m_simulation->SetGravity(NewGravity); m_simulation->SetGravity(NewGravity);
@@ -109,7 +110,7 @@ BtPhysTest::BtPhysTest(bool editor)
if (USE_PLATFORM) if (USE_PLATFORM)
{ {
quat NewRotation = quat::fromeuler_xyz(5.f, 0.f, 0.f); 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); PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);


@@ -127,7 +128,7 @@ BtPhysTest::BtPhysTest(bool editor)
if (USE_CHARACTER) if (USE_CHARACTER)
{ {
quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f); 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); PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2);


@@ -406,6 +407,23 @@ void BtPhysTest::TickGame(float seconds)


if (USE_CHARACTER) 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++) for (int i = 0; i < m_character_list.Count(); i++)
{ {
PhysicsObject* PhysObj = m_character_list[i]; PhysicsObject* PhysObj = m_character_list[i];
@@ -417,8 +435,9 @@ void BtPhysTest::TickGame(float seconds)


PhysObjBarycenter /= factor; 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 else
{ {


+ 36
- 17
test/PhysicObject.h View File

@@ -40,8 +40,6 @@ public:
if (dummy == 1) //for Rope purpose if (dummy == 1) //for Rope purpose
{ {
m_mesh.Compile("[sc#ddd afcb20 1 20 -.1]"); 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); vec3 BoxSize = vec3(20.f, 1.f, 20.f);
m_physics.SetCollisionChannel(0, 0xFF); m_physics.SetCollisionChannel(0, 0xFF);
m_physics.SetShapeToBox(BoxSize); m_physics.SetShapeToBox(BoxSize);
@@ -53,9 +51,30 @@ public:
else if (dummy == 2) //for character purpose else if (dummy == 2) //for character purpose
{ {
m_is_character = true; 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.SetCollisionChannel(0, 0xFF);
m_character.SetShapeToCapsule(BoxSize.x, BoxSize.y); m_character.SetShapeToCapsule(BoxSize.x, BoxSize.y);
m_character.SetMass(.0f); m_character.SetMass(.0f);
@@ -88,21 +107,21 @@ public:


int ConeLimit = MeshRand.Count(); 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(); 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(); int CapsLimit = MeshRand.Count();




+ 7
- 0
test/Physics/EasyPhysics.cpp View File

@@ -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 //EASY_CONSTRAINT
//-- //--


+ 1
- 0
test/Physics/EasyPhysics.h View File

@@ -142,6 +142,7 @@ public:
virtual void InitBodyToGhost(); virtual void InitBodyToGhost();
virtual void AddToSimulation(class Simulation* current_simulation); virtual void AddToSimulation(class Simulation* current_simulation);
virtual void RemoveFromSimulation(class Simulation* current_simulation); virtual void RemoveFromSimulation(class Simulation* current_simulation);
virtual void SetMovementForFrame(vec3 &MoveQuantity);


protected: protected:




+ 24
- 1
test/Physics/LolPhysics.h View File

@@ -45,7 +45,14 @@ public:
void Init() void Init()
{ {
// Build the broadphase // 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 // Set up the collision configuration and dispatcher
m_collision_configuration = new btDefaultCollisionConfiguration(); m_collision_configuration = new btDefaultCollisionConfiguration();
@@ -98,10 +105,15 @@ private:
m_dynamics_world->setGravity(LOL2BT_VEC3(NewGravity * LOL2BT_UNIT)); m_dynamics_world->setGravity(LOL2BT_VEC3(NewGravity * LOL2BT_UNIT));
} }


void CustomSetWorldLimit(vec3 &NewWorldMin, vec3 &NewWorldMax)
{
}

void CustomSetTimestep(float NewTimestep) { } void CustomSetTimestep(float NewTimestep) { }


//broadphase //broadphase
btBroadphaseInterface* m_broadphase; btBroadphaseInterface* m_broadphase;
btAxisSweep3* m_Sweep_broadphase;
// Set up the collision configuration and dispatc // Set up the collision configuration and dispatc
btDefaultCollisionConfiguration* m_collision_configuration; btDefaultCollisionConfiguration* m_collision_configuration;
btCollisionDispatcher* m_dispatcher; btCollisionDispatcher* m_dispatcher;
@@ -119,6 +131,7 @@ public:
private: private:
void CustomSetContinuousDetection(bool ShouldUseCCD) { } void CustomSetContinuousDetection(bool ShouldUseCCD) { }
void CustomSetGravity(vec3 &NewGravity) { } void CustomSetGravity(vec3 &NewGravity) { }
void CustomSetWorldLimit(vec3 &NewWorldMin, vec3 &NewWorldMax) { }
void CustomSetTimestep(float NewTimestep) { } void CustomSetTimestep(float NewTimestep) { }


#endif // PHYSIC IMPLEMENTATION #endif // PHYSIC IMPLEMENTATION
@@ -142,6 +155,14 @@ public:
CustomSetGravity(NewGravity); 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. //Sets the simulation fixed timestep.
void SetTimestep(float NewTimestep) void SetTimestep(float NewTimestep)
{ {
@@ -172,6 +193,8 @@ private:
float m_timestep; float m_timestep;
bool m_using_CCD; bool m_using_CCD;
vec3 m_gravity; vec3 m_gravity;
vec3 m_world_min;
vec3 m_world_max;
}; };


} /* namespace phys */ } /* namespace phys */


Loading…
Cancel
Save