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:
@@ -13,15 +13,12 @@ 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 "BMF_Api.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
@@ -61,10 +58,7 @@ void ConstraintDemo::initPhysics()
|
||||
btOverlappingPairCache* broadphase = new btSimpleBroadphase();
|
||||
|
||||
|
||||
m_physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
|
||||
m_physicsEnvironmentPtr->setDeactivationTime(0.f);
|
||||
m_physicsEnvironmentPtr->setGravity(0,-10,0);
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
||||
|
||||
btCollisionShape* shape = new btBoxShape(btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS));
|
||||
btTransform trans;
|
||||
@@ -74,10 +68,12 @@ void ConstraintDemo::initPhysics()
|
||||
bool isDynamic = false;
|
||||
float mass = 1.f;
|
||||
|
||||
CcdPhysicsController* ctrl0 = localCreatePhysicsObject( isDynamic,mass,trans,shape);
|
||||
btRigidBody* body0 = localCreateRigidBody( isDynamic,mass,trans,shape);
|
||||
getDynamicsWorld()->addCollisionObject(body0);
|
||||
trans.setOrigin(btVector3(2*CUBE_HALF_EXTENTS,20,0));
|
||||
isDynamic = true;
|
||||
CcdPhysicsController* ctrl1 = localCreatePhysicsObject( isDynamic,mass,trans,shape);
|
||||
btRigidBody* body1 = localCreateRigidBody( isDynamic,mass,trans,shape);
|
||||
getDynamicsWorld()->addCollisionObject(body1);
|
||||
|
||||
|
||||
clientResetScene();
|
||||
@@ -85,21 +81,17 @@ void ConstraintDemo::initPhysics()
|
||||
{
|
||||
int constraintId;
|
||||
|
||||
float pivotX=CUBE_HALF_EXTENTS,
|
||||
pivotY=-CUBE_HALF_EXTENTS,
|
||||
pivotZ=-CUBE_HALF_EXTENTS;
|
||||
float axisX=0,axisY=0,axisZ=1;
|
||||
btVector3 pivotInA(CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS);
|
||||
btVector3 axisInA(0,0,1);
|
||||
|
||||
btVector3 pivotInB = body1 ? body1->getCenterOfMassTransform().inverse()(body0->getCenterOfMassTransform()(pivotInA)) : pivotInA;
|
||||
btVector3 axisInB = body1?
|
||||
(body1->getCenterOfMassTransform().getBasis().inverse()*(body1->getCenterOfMassTransform().getBasis() * axisInA)) :
|
||||
body0->getCenterOfMassTransform().getBasis() * axisInA;
|
||||
|
||||
constraintId =m_physicsEnvironmentPtr->createConstraint(
|
||||
ctrl0,
|
||||
ctrl1,
|
||||
PHY_POINT2POINT_CONSTRAINT,
|
||||
//PHY_GENERIC_6DOF_CONSTRAINT,//can leave any of the 6 degree of freedom 'free' or 'locked'
|
||||
//PHY_LINEHINGE_CONSTRAINT,
|
||||
pivotX,pivotY,pivotZ,
|
||||
axisX,axisY,axisZ
|
||||
);
|
||||
btTypedConstraint* p2p = new btPoint2PointConstraint(*body0,*body1,pivotInA,pivotInB);
|
||||
|
||||
m_dynamicsWorld->addConstraint(p2p);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -112,8 +104,7 @@ void ConstraintDemo::clientMoveAndDisplay()
|
||||
|
||||
float deltaTime = 1.f/60.f;
|
||||
|
||||
m_physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
|
||||
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
renderme();
|
||||
|
||||
glFlush();
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user