Browse Source

Lazy WE :

Small tweaks in the BtPhysTest demo.
Added Ghost Object skeleton (not tested)
legacy
Benjamin ‘Touky’ Huet touky 12 years ago
parent
commit
f514756a2d
6 changed files with 99 additions and 6 deletions
  1. +46
    -1
      test/BtPhysTest.cpp
  2. +1
    -0
      test/BtPhysTest.h
  3. +13
    -0
      test/PhysicObject.h
  4. +32
    -5
      test/Physics/EasyPhysics.cpp
  5. +5
    -0
      test/Physics/EasyPhysics.h
  6. +2
    -0
      test/Physics/LolPhysics.h

+ 46
- 1
test/BtPhysTest.cpp View File

@@ -96,6 +96,23 @@ BtPhysTest::BtPhysTest(bool editor)
m_ground_list << NewPhyobj;
}

{
quat NewRotation = quat(1.f);
vec3 NewPosition = pos_offset + vec3(5.0f, -20.0f, -15.0f);

PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 0);

m_platform_list << NewPhyobj;
Ticker::Ref(NewPhyobj);

NewPosition = pos_offset + vec3(-20.0f, -25.0f, 5.0f);

NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 0);

m_platform_list << NewPhyobj;
Ticker::Ref(NewPhyobj);
}

if (1)
{
for (int x=0; x < 6; x++)
@@ -324,7 +341,7 @@ void BtPhysTest::TickGame(float seconds)
PhysObj->SetRender(true);
}

if (1)
if (0)
{
for (int i = 0; i < m_ground_list.Count(); i++)
{
@@ -340,6 +357,27 @@ void BtPhysTest::TickGame(float seconds)
}
}

{
for (int i = 0; i < m_platform_list.Count(); i++)
{
PhysicsObject* PhysObj = m_platform_list[i];

mat4 GroundMat = PhysObj->GetTransform();
if (i == 0)
{
GroundMat = GroundMat * mat4(quat::fromeuler_xyz(vec3(20.f, .0f, .0f) * seconds));
PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
}
else
{
GroundMat = GroundMat * mat4::translate(vec3(.0f, .0f, 10.0f) * seconds);
if (GroundMat.v3.z > 40.0f)
GroundMat = GroundMat * mat4::translate(vec3(.0f, .0f, -80.0f));
PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
}
}
}

PhysObjBarycenter = vec3(.0f);
for (int i = 0; i < m_physobj_list.Count(); i++)
{
@@ -447,6 +485,13 @@ BtPhysTest::~BtPhysTest()
CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
Ticker::Unref(CurPop);
}
while (m_platform_list.Count())
{
PhysicsObject* CurPop = m_platform_list.Last();
m_platform_list.Pop();
CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
Ticker::Unref(CurPop);
}
while (m_physobj_list.Count())
{
PhysicsObject* CurPop = m_physobj_list.Last();


+ 1
- 0
test/BtPhysTest.h View File

@@ -28,6 +28,7 @@ private:
Array<EasyConstraint*> m_constraint_list;
Array<PhysicsObject*> m_physobj_list;
Array<PhysicsObject*> m_ground_list;
Array<PhysicsObject*> m_platform_list;

#if 0
EasyMesh m_ground_mesh;


+ 13
- 0
test/PhysicObject.h View File

@@ -34,6 +34,19 @@ public:
m_physics.AddToSimulation(new_sim);
}

PhysicsObject(Simulation* new_sim, const vec3 &base_location, const quat &base_rotation, int dummy)
: m_ready(false), m_should_render(true)
{
m_mesh.Compile("[sc#ddd afcb20 1 20 -.1]");
vec3 BoxSize = vec3(20.f, 1.f, 20.f);
m_physics.SetCollisionChannel(0, 0xFF);
m_physics.SetShapeToBox(BoxSize);
m_physics.SetMass(.0f);
m_physics.SetTransform(base_location, base_rotation);
m_physics.InitBodyToRigid(true);
m_physics.AddToSimulation(new_sim);
}

PhysicsObject(Simulation* new_sim, float base_mass, const vec3 &base_location, int RandValue = -1)
: m_ready(false), m_should_render(true)
{


+ 32
- 5
test/Physics/EasyPhysics.cpp View File

@@ -32,6 +32,7 @@ namespace phys
EasyPhysic::EasyPhysic() :
m_collision_object(NULL),
m_rigid_body(NULL),
m_ghost_object(NULL),
m_collision_shape(NULL),
m_motion_state(NULL),
m_mass(.0f),
@@ -106,10 +107,15 @@ void EasyPhysic::SetShapeToCapsule(float radius, float height)
//--
void EasyPhysic::SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation)
{
if (m_motion_state)
m_motion_state->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT)));
if (m_ghost_object)
m_ghost_object->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT)));
else
m_motion_state = new btDefaultMotionState(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT)));
{
if (m_motion_state)
m_motion_state->setWorldTransform(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT)));
else
m_motion_state = new btDefaultMotionState(btTransform(LOL2BT_QUAT(base_rotation), LOL2BT_VEC3(base_location * LOL2BT_UNIT)));
}
}

//-------------------------------------------------------------------------
@@ -137,7 +143,6 @@ void EasyPhysic::InitBodyToRigid(bool SetToKinematic)
if (m_collision_object)
delete m_collision_object;

SetLocalInertia(m_mass);
if (!m_motion_state)
SetTransform(vec3(.0f));

@@ -152,12 +157,34 @@ void EasyPhysic::InitBodyToRigid(bool SetToKinematic)
}
}

//Init to Ghost object, for Overlap/Sweep Test/Touching logic
void EasyPhysic::InitBodyToGhost()
{
if (m_collision_object)
delete m_collision_object;

m_ghost_object = new btGhostObject();
m_ghost_object->setCollisionShape(m_collision_shape);
m_collision_object = m_ghost_object;

SetTransform(vec3(.0f));

m_ghost_object->setCollisionFlags(m_ghost_object->getCollisionFlags());
//btCollisionObject::CF_CHARACTER_OBJECT
}

//Add Physic object to the simulation
void EasyPhysic::AddToSimulation(class Simulation* current_simulation)
{
btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld();
if (dynamics_world)
{
if (m_rigid_body)
if (m_ghost_object)
{
dynamics_world->addCollisionObject(m_ghost_object, m_collision_group, m_collision_mask);
current_simulation->AddToGhost(this);
}
else if (m_rigid_body)
{
dynamics_world->addRigidBody(m_rigid_body, m_collision_group, m_collision_mask);
if (m_mass != .0f)


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

@@ -21,6 +21,7 @@
#include "core.h"
#include <bullet/btBulletDynamicsCommon.h>
#include <bullet/btBulletCollisionCommon.h>
#include <bullet/BulletCollision/CollisionDispatch/btGhostObject.h>
#endif

namespace lol
@@ -50,6 +51,7 @@ public:
void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f)));
void SetMass(float mass);
void InitBodyToRigid(bool ZeroMassIsKinematic=false);
void InitBodyToGhost();
void AddToSimulation(class Simulation* current_simulation);
void RemoveFromSimulation(class Simulation* current_simulation);
mat4 GetTransform();
@@ -60,6 +62,8 @@ protected:

btCollisionObject* m_collision_object;

btGhostObject* m_ghost_object;

btRigidBody* m_rigid_body;
btVector3 m_local_inertia;

@@ -81,6 +85,7 @@ public:
void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) { }
void SetMass(float mass) { }
void InitBodyToRigid() { }
void InitBodyToGhost() { }
void AddToSimulation(class Simulation* current_simulation) { }
void RemoveFromSimulation(class Simulation* current_simulation) { }
mat4 GetTransform() { return mat4(1.0f); }


+ 2
- 0
test/Physics/LolPhysics.h View File

@@ -159,11 +159,13 @@ private:
//Adds the given EasyPhysic to the correct list.
void AddToDynamic(EasyPhysic* NewEPDynamic) { m_dynamic_list << NewEPDynamic; }
void AddToStatic(EasyPhysic* NewEPStatic) { m_static_list << NewEPStatic; }
void AddToGhost(EasyPhysic* NewEPGhost) { m_ghost_list << NewEPGhost; }
void AddToConstraint(EasyConstraint* NewEC) { m_constraint_list << NewEC; }

//Easy Physics body List
Array<EasyPhysic*> m_dynamic_list;
Array<EasyPhysic*> m_static_list;
Array<EasyPhysic*> m_ghost_list;
Array<EasyConstraint*> m_constraint_list;

//Easy Physics data storage


Loading…
Cancel
Save