Skip to content

Commit

Permalink
base bullet wrapper for object added
Browse files Browse the repository at this point in the history
  • Loading branch information
soniccat committed Jan 17, 2010
1 parent 353bf37 commit d929854
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 73 deletions.
Binary file modified Docs/codeStyleGide.rtf
Binary file not shown.
22 changes: 13 additions & 9 deletions src/Objects/SEPhysicObject.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#include "SEPhysicObject.h"
#include "SEDefinition.h"
#include "SEPhysicWorld.h"

SEPhysicObject::SEPhysicObject(void)
{
}

SEPhysicObject::~SEPhysicObject(void)
{
//SEPhysicWorld::sharedInstance()->world()->removeRigidBody( mRigidBody.get() );
}

void SEPhysicObject::Init( SEMeshPtr mesh, const btRigidBody::btRigidBodyConstructionInfo& info )
{
mMesh = mesh;
mRigidBody = btRigidBodyPtr( SENewObject<btRigidBody>( info ) );
}

Expand All @@ -19,19 +23,19 @@ void SEPhysicObject::Draw()
mRigidBody->getMotionState()->getWorldTransform(trans);

glTranslatef( trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ() );


//FIXME: replace rotation for increase perfomance
btQuaternion quatern = trans.getRotation();
btVector3 vec = quatern.getAxis();

float radToGrad = 180.0/3.14;

//printf("world pos = %f,%f,%f\n",float(trans.getOrigin().getX()),float(trans.getOrigin().getY()),float(trans.getOrigin().getZ()));
//printf("world rot = %f,%f,%f,%f\n",quatern.getAngle(),vec.x(), vec.y(), vec.z());


glRotatef( quatern.getAngle()*radToGrad, vec.x(), vec.y(), vec.z() );
glRotatef( quatern.getAngle()*RAD_TO_DEG, vec.x(), vec.y(), vec.z() );
mMesh->Draw();
glRotatef( -quatern.getAngle()*radToGrad, vec.x(), vec.y(), vec.z() );
glRotatef( -quatern.getAngle()*RAD_TO_DEG, vec.x(), vec.y(), vec.z() );

glTranslatef(-trans.getOrigin().getX(),-trans.getOrigin().getY(),-trans.getOrigin().getZ() );
}

btRigidBodyPtr SEPhysicObject::rigidBody()
{
return mRigidBody;
}
7 changes: 6 additions & 1 deletion src/Objects/SEPhysicObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

typedef shared_ptr<btRigidBody> btRigidBodyPtr;

class SEPhysicObject;
typedef shared_ptr<SEPhysicObject> SEPhysicObjectPtr;


class SEPhysicObject: public SEObjectInterface
{
Expand All @@ -21,7 +24,9 @@ class SEPhysicObject: public SEObjectInterface

void Init( SEMeshPtr mesh, const btRigidBody::btRigidBodyConstructionInfo& info );

virtual void Draw()=0;
virtual void Draw();
btRigidBodyPtr rigidBody();
SEMeshPtr mesh();
};


Expand Down
1 change: 1 addition & 0 deletions src/Tools/SEDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
void operator=(const TypeName&)

#define BREAKPOINTPLACE {int i=0;++i;}
#define RAD_TO_DEG (180.0f/3.14f)


#define PATH_DELIMETER '/'
Expand Down
36 changes: 24 additions & 12 deletions src/Tools/SEMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,55 @@
template<typename T>
T* SENewObject()
{
void* mem = malloc(sizeof(T));
return new(mem)T;
return new T;

//void* mem = malloc(sizeof(T));
//return new(mem)T;
}

template<typename T, typename ARG1>
T* SENewObject( ARG1 arg1)
{
void* mem = malloc(sizeof(T));
return new(mem)T(arg1);
return new T(arg1);

//void* mem = malloc(sizeof(T));
//return new(mem)T(arg1);
}

template<typename T, typename ARG1, typename ARG2>
T* SENewObject( ARG1 arg1, ARG2 arg2)
{
void* mem = malloc(sizeof(T));
return new(mem)T(arg1, arg2);
return new T(arg1, arg2);

//void* mem = malloc(sizeof(T));
//return new(mem)T(arg1, arg2);
}

template<typename T, typename ARG1, typename ARG2, typename ARG3>
T* SENewObject( ARG1 arg1, ARG2 arg2, ARG3 arg3)
{
void* mem = malloc(sizeof(T));
return new(mem)T(arg1, arg2, arg3);
return new T(arg1, arg2, arg3);

//void* mem = malloc(sizeof(T));
//return new(mem)T(arg1, arg2, arg3);
}

template<typename T, typename ARG1, typename ARG2, typename ARG3, typename ARG4>
T* SENewObject( ARG1 arg1, ARG2 arg2, ARG3 arg3, ARG4 arg4)
{
void* mem = malloc(sizeof(T));
return new(mem)T(arg1, arg2, arg3, arg4);
return new T(arg1, arg2, arg3, arg4);

//void* mem = malloc(sizeof(T));
//return new(mem)T(arg1, arg2, arg3, arg4);
}

template<typename T>
T* SENewArray( size_t itemCount )
{
T* arr = (T*)calloc( itemCount, sizeof(T) );
return new(arr) T[itemCount];
return new T[itemCount];

//T* arr = (T*)calloc( itemCount, sizeof(T) );
//return new(arr) T[itemCount];
}


Expand Down
124 changes: 73 additions & 51 deletions vs/GLUT_Window_Template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ void init ()
// This function is passed to glutDisplayFunc in order to display
// OpenGL contents on the window.
//-------------------------------------------------------------------------

SEPhysicObjectPtr physicObject1;
SEPhysicObjectPtr physicObject2;


void display (void)
{
SEGLAssert;
Expand All @@ -99,7 +104,7 @@ void display (void)
SEPhysicWorld::sharedInstance()->world()->stepSimulation(1.f/60.f,10);

//print positions of all objects
for (int j= SEPhysicWorld::sharedInstance()->world()->getNumCollisionObjects()-1; j>=0 ;j--)
/*for (int j= SEPhysicWorld::sharedInstance()->world()->getNumCollisionObjects()-1; j>=0 ;j--)
{
btCollisionObject* obj = SEPhysicWorld::sharedInstance()->world()->getCollisionObjectArray()[j];
btRigidBody* body = btRigidBody::upcast(obj);
Expand Down Expand Up @@ -134,10 +139,16 @@ void display (void)
glTranslatef(-trans.getOrigin().getX(),-trans.getOrigin().getY(),-trans.getOrigin().getZ() );
}
}
}
}*/
//}

// Draw object

if( physicObject1.get() )
physicObject1->Draw();

if( physicObject2.get() )
physicObject2->Draw();


glTranslatef(0,0,10);
Expand All @@ -159,7 +170,7 @@ void drawObject ()
// Draw Icosahedron
//glutWireIcosahedron ();

SEMeshPtr mesh = SEObjectStore::sharedInstance()->GetMesh( "Plane" );
//SEMeshPtr mesh = SEObjectStore::sharedInstance()->GetMesh( "Plane" );

//static GLUquadric* quadr = gluNewQuadric();

Expand All @@ -176,7 +187,7 @@ void drawObject ()
//glRotatef(angle,1,1,0);
//gluSphere( quadr,5,10,10 );

mesh->Draw();
//mesh->Draw();

//glRotatef(-angle,1,1,0);
}
Expand Down Expand Up @@ -448,10 +459,10 @@ void main (int argc, sechar **argv)
btConstraintSolverPtr solver = btConstraintSolverPtr( SENewObject<btSequentialImpulseConstraintSolver>() );

SEPhysicWorld::sharedInstance()->InitDiscreteDynamicsWorld( dispatcher ,overlappingPairCache, solver, collisionConfiguration );
SEPhysicWorld::sharedInstance()->world()->setGravity(btVector3(0,-8,0));
SEPhysicWorld::sharedInstance()->world()->setGravity(btVector3(0,-5,0));

///create a few basic rigid bodies
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(1.0),btScalar(1.0),btScalar(1.0)));
btCollisionShape* groundShape = SENewObject<btBoxShape>(btVector3(btScalar(1.0),btScalar(1.0),btScalar(1.0)));

/*
btTriangleMesh* triangleMesh = new btTriangleMesh();
Expand All @@ -460,51 +471,6 @@ void main (int argc, sechar **argv)
btCollisionShape = new btBvhTriangleMeshShape( triangleMesh, 1, 1 );
*/

btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,0,0));

{
btScalar mass(0.0);

//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);

btVector3 localInertia(0,0,0);
if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia);

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

//add the body to the dynamics world
SEPhysicWorld::sharedInstance()->world()->addRigidBody(body);
}

groundTransform.setOrigin(btVector3(0.0,5,1));

{
btScalar mass(0.1);

//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);

btVector3 localInertia(0,0,0);
if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia);

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

//add the body to the dynamics world
SEPhysicWorld::sharedInstance()->world()->addRigidBody(body);
}



//SEPath* a = (SEPath*) malloc(sizeof(SEPath));
//a = new(a) SEPath();
Expand Down Expand Up @@ -549,6 +515,60 @@ void main (int argc, sechar **argv)
loader.Load( &currentPath );


btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,0,0));

{
btScalar mass(0.0);

//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);

btVector3 localInertia(0,0,0);
if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia);

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = SENewObject<btDefaultMotionState>(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
//btRigidBody* body = new btRigidBody(rbInfo);

SEMeshPtr mesh = SEObjectStore::sharedInstance()->GetMesh( "Plane" );

physicObject1 = SEPhysicObjectPtr(SENewObject<SEPhysicObject>());
physicObject1->Init( mesh, rbInfo );

//add the body to the dynamics world
SEPhysicWorld::sharedInstance()->world()->addRigidBody( physicObject1->rigidBody().get() );
}

groundTransform.setOrigin(btVector3(0.0,5,1));

{
btScalar mass(0.1);

//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);

btVector3 localInertia(0,0,0);
if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia);

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = SENewObject<btDefaultMotionState>(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);

SEMeshPtr mesh = SEObjectStore::sharedInstance()->GetMesh( "Plane" );

physicObject2 = SEPhysicObjectPtr(SENewObject<SEPhysicObject>());
physicObject2->Init( mesh, rbInfo );

//add the body to the dynamics world
SEPhysicWorld::sharedInstance()->world()->addRigidBody( physicObject2->rigidBody().get() );
}


//SEImageLoader imageLoader;
//SEImagePtr image = imageLoader.Load( "test.jpg" );

Expand All @@ -559,5 +579,7 @@ void main (int argc, sechar **argv)

// Start GLUT event processing loop
glutMainLoop();


}

Binary file modified vs/GLUT_Window_Template.suo
Binary file not shown.

0 comments on commit d929854

Please sign in to comment.