Browse Source

Added Cylinder primitives.

Added several delete/destructor, speeds up exit & saves memory.
legacy
Benjamin ‘Touky’ Huet touky 12 years ago
parent
commit
cd46cef099
5 changed files with 47 additions and 8 deletions
  1. +7
    -0
      test/BtPhysTest.cpp
  2. +15
    -3
      test/PhysicObject.h
  3. +14
    -0
      test/Physics/EasyPhysics.cpp
  4. +3
    -0
      test/Physics/EasyPhysics.h
  5. +8
    -5
      test/Physics/LolPhysics.h

+ 7
- 0
test/BtPhysTest.cpp View File

@@ -322,6 +322,13 @@ void BtPhysTest::TickDraw(float seconds)
BtPhysTest::~BtPhysTest()
{
Ticker::Unref(m_camera);
Ticker::Unref(m_ground_object);
while (m_physobj_list.Count())
{
PhysicsObject* CurPop = m_physobj_list.Last();
m_physobj_list.Pop();
Ticker::Unref(CurPop);
}

#if 0
//Exit Physics


+ 15
- 3
test/PhysicObject.h View File

@@ -62,16 +62,28 @@ public:
MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";

int CylLimit = MeshRand.Count();

MeshRand << "[sc#add scb#add ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
MeshRand << "[sc#dad scb#dad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
MeshRand << "[sc#dda scb#dda ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
MeshRand << "[sc#daa scb#daa ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";

int RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1));

m_mesh.Compile(MeshRand[RandValue]);
vec3 BoxSize = vec3(2.0f);
if (RandValue >= SphereLimit && RandValue < ConeLimit)
if (RandValue < SphereLimit)
m_physics.SetShapeToBox(BoxSize);
else if (RandValue < ConeLimit)
m_physics.SetShapeToSphere(BoxSize.x);
else if (RandValue >= ConeLimit)
else if (RandValue < CylLimit)
m_physics.SetShapeToCone(BoxSize.x, BoxSize.y);
else
m_physics.SetShapeToBox(BoxSize);
m_physics.SetShapeToCylinder(BoxSize);

m_physics.SetMass(base_mass);
m_physics.SetBaseTransform(base_location);
m_physics.InitBodyToRigid();


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

@@ -40,6 +40,13 @@ EasyPhysics::EasyPhysics() :
{
}

EasyPhysics::~EasyPhysics()
{
delete m_collision_object;
delete m_collision_shape;
delete m_motion_state;
}

//-------------------------------------------------------------------------
//Set Shape functions
//--
@@ -79,6 +86,13 @@ void EasyPhysics::SetShapeToCone(float radius, float height)
height * LOL2BT_UNIT));
}

void EasyPhysics::SetShapeToCylinder(lol::vec3& cyl_size)
{
vec3 new_cyl_size = cyl_size * LOL2BT_UNIT;
new_cyl_size.y *= LOL2BT_SIZE;
SetShapeTo(new btCylinderShape(LOL2BT_VEC3(new_cyl_size)));
}

//-------------------------------------------------------------------------
//Base Location/Rotation setup
//--


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

@@ -34,10 +34,13 @@ class EasyPhysics
#ifdef HAVE_PHYS_USE_BULLET
public:
EasyPhysics();
~EasyPhysics();

void SetShapeToBox(lol::vec3& box_size);
void SetShapeToSphere(float radius);
void SetShapeToCone(float radius, float height);
void SetShapeToCylinder(lol::vec3& cyl_size);

void SetBaseTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f)));
void SetMass(float mass);
void InitBodyToRigid();


+ 8
- 5
test/Physics/LolPhysics.h View File

@@ -32,7 +32,10 @@ public:
m_dynamics_world(NULL)
{
}
~Simulation() { }
~Simulation()
{
ExitContext();
}

char const *GetName() { return "<Simulation>"; }

@@ -72,11 +75,11 @@ public:

void ExitContext()
{
delete m_broadphase;
delete m_collision_configuration;
delete m_dispatcher;
delete m_solver;
delete m_dynamics_world;
delete m_solver;
delete m_dispatcher;
delete m_collision_configuration;
delete m_broadphase;
}

btDiscreteDynamicsWorld* GetWorld()


Loading…
Cancel
Save