more refactoring, removed PhysicsInterface, cleaned up demos to make use of btDynamicsWorld derived classes.

removed two cached optimizations, type in btTransform and cached inverse transform (todo: test performance impact)
committed fixes that make the code adhere to 'who creates it, also destroys it'
This commit is contained in:
ejcoumans
2006-09-30 01:36:39 +00:00
parent 14397a2f72
commit d38549aa54
37 changed files with 317 additions and 995 deletions

View File

@@ -13,13 +13,9 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#include "CcdPhysicsEnvironment.h"
#include "CcdPhysicsController.h"
#include "MyMotionState.h"
#include "btBulletDynamicsCommon.h"
#include "LinearMath/btIDebugDraw.h"
#include "GLDebugDrawer.h"
#include "PHY_Pro.h"
#include "ConcaveDemo.h"
#include "GL_ShapeDrawer.h"
#include "GlutStuff.h"
@@ -159,30 +155,31 @@ void ConcaveDemo::initPhysics()
btOverlappingPairCache* broadphase = new btSimpleBroadphase();
m_physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
m_dynamicsWorld = new btDiscreteDynamicsWorld();
bool isDynamic = false;
bool isDynamic = false;
float mass = 0.f;
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,-2,0));
startTransform.setOrigin(btVector3(0,0,0));
CcdPhysicsController* staticTrimesh = localCreatePhysicsObject(isDynamic, mass, startTransform,trimeshShape);
btRigidBody* staticBody = localCreateRigidBody(isDynamic, mass, startTransform,trimeshShape);
staticBody->m_collisionFlags |=btCollisionObject::isStatic;
getDynamicsWorld()->addCollisionObject(staticBody);
//enable custom material callback
staticTrimesh->getRigidBody()->m_collisionFlags |= btCollisionObject::customMaterialCallback;
staticBody->m_collisionFlags |= btCollisionObject::customMaterialCallback;
{
for (int i=0;i<10;i++)
{
btCollisionShape* boxShape = new btBoxShape(btVector3(1,1,1));
startTransform.setOrigin(btVector3(2*i,1,1));
localCreatePhysicsObject(true, 1, startTransform,boxShape);
getDynamicsWorld()->addCollisionObject(localCreateRigidBody(true, 1, startTransform,boxShape));
}
}
m_physicsEnvironmentPtr->setGravity(-1,-10,1);
m_physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
}
void ConcaveDemo::clientMoveAndDisplay()
@@ -191,7 +188,7 @@ void ConcaveDemo::clientMoveAndDisplay()
float deltaTime = 1.f/60.f;
m_physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
m_dynamicsWorld->stepSimulation(deltaTime);
renderme();
@@ -202,7 +199,7 @@ void ConcaveDemo::clientMoveAndDisplay()
void ConcaveDemo::clientResetScene()
{
int numObj = m_physicsEnvironmentPtr->GetNumControllers();
/*int numObj = m_physicsEnvironmentPtr->GetNumControllers();
//skip ground
for (int i=1;i<numObj;i++)
@@ -213,6 +210,8 @@ void ConcaveDemo::clientResetScene()
ctrl->SetLinearVelocity(0,0,0,0);
ctrl->SetAngularVelocity(0,0,0,0);
}
*/
}

View File

@@ -1,67 +0,0 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "MyMotionState.h"
#include "LinearMath/btPoint3.h"
MyMotionState::MyMotionState()
{
m_worldTransform.setIdentity();
}
MyMotionState::~MyMotionState()
{
}
void MyMotionState::getWorldPosition(float& posX,float& posY,float& posZ)
{
posX = m_worldTransform.getOrigin().x();
posY = m_worldTransform.getOrigin().y();
posZ = m_worldTransform.getOrigin().z();
}
void MyMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
{
scaleX = 1.;
scaleY = 1.;
scaleZ = 1.;
}
void MyMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
{
quatIma0 = m_worldTransform.getRotation().x();
quatIma1 = m_worldTransform.getRotation().y();
quatIma2 = m_worldTransform.getRotation().z();
quatReal = m_worldTransform.getRotation()[3];
}
void MyMotionState::setWorldPosition(float posX,float posY,float posZ)
{
btPoint3 pos(posX,posY,posZ);
m_worldTransform.setOrigin( pos );
}
void MyMotionState::setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
{
btQuaternion orn(quatIma0,quatIma1,quatIma2,quatReal);
m_worldTransform.setRotation( orn );
}
void MyMotionState::calculateWorldTransformations()
{
}

View File

@@ -1,44 +0,0 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef MY_MOTIONSTATE_H
#define MY_MOTIONSTATE_H
#include "PHY_IMotionState.h"
#include <LinearMath/btTransform.h>
class MyMotionState : public PHY_IMotionState
{
public:
MyMotionState();
virtual ~MyMotionState();
virtual void getWorldPosition(float& posX,float& posY,float& posZ);
virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
virtual void setWorldPosition(float posX,float posY,float posZ);
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
virtual void calculateWorldTransformations();
btTransform m_worldTransform;
};
#endif //MY_MOTIONSTATE_H