2006-04-28 00:08:18 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
#include "CcdPhysicsEnvironment.h"
|
|
|
|
#include "CcdPhysicsController.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2006-11-21 00:53:40 +00:00
|
|
|
#include "btBulletDynamicsCommon.h"
|
|
|
|
#include "LinearMath/btIDebugDraw.h"
|
|
|
|
#include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
|
2008-09-17 01:49:47 +00:00
|
|
|
#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-04-13 05:11:34 +00:00
|
|
|
//profiling/timings
|
2006-11-21 00:53:40 +00:00
|
|
|
#include "LinearMath/btQuickprof.h"
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
#include "PHY_IMotionState.h"
|
2005-07-18 05:41:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool useIslands = true;
|
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
#ifdef NEW_BULLET_VEHICLE_SUPPORT
|
2006-11-21 00:53:40 +00:00
|
|
|
#include "BulletDynamics/Vehicle/btRaycastVehicle.h"
|
|
|
|
#include "BulletDynamics/Vehicle/btVehicleRaycaster.h"
|
|
|
|
#include "BulletDynamics/Vehicle/btWheelInfo.h"
|
2006-02-13 06:28:35 +00:00
|
|
|
#include "PHY_IVehicle.h"
|
2006-11-21 00:53:40 +00:00
|
|
|
btRaycastVehicle::btVehicleTuning gTuning;
|
2006-02-13 06:28:35 +00:00
|
|
|
|
|
|
|
#endif //NEW_BULLET_VEHICLE_SUPPORT
|
2006-11-21 00:53:40 +00:00
|
|
|
#include "LinearMath/btAabbUtil2.h"
|
2006-04-06 20:37:38 +00:00
|
|
|
|
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
void DrawRasterizerLine(const float* from,const float* to,int color);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
#include "BulletDynamics/ConstraintSolver/btContactConstraint.h"
|
2005-07-18 05:41:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-08-28 12:12:56 +00:00
|
|
|
#include <string.h> // for memset
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
#ifdef NEW_BULLET_VEHICLE_SUPPORT
|
|
|
|
class WrapperVehicle : public PHY_IVehicle
|
|
|
|
{
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btRaycastVehicle* m_vehicle;
|
2006-02-13 06:28:35 +00:00
|
|
|
PHY_IPhysicsController* m_chassis;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
public:
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
WrapperVehicle(btRaycastVehicle* vehicle,PHY_IPhysicsController* chassis)
|
2006-02-13 06:28:35 +00:00
|
|
|
:m_vehicle(vehicle),
|
|
|
|
m_chassis(chassis)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btRaycastVehicle* GetVehicle()
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
|
|
|
return m_vehicle;
|
|
|
|
}
|
|
|
|
|
|
|
|
PHY_IPhysicsController* GetChassis()
|
|
|
|
{
|
|
|
|
return m_chassis;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void AddWheel(
|
2006-04-28 00:08:18 +00:00
|
|
|
PHY_IMotionState* motionState,
|
|
|
|
PHY__Vector3 connectionPoint,
|
|
|
|
PHY__Vector3 downDirection,
|
|
|
|
PHY__Vector3 axleDirection,
|
|
|
|
float suspensionRestLength,
|
|
|
|
float wheelRadius,
|
|
|
|
bool hasSteering
|
2006-02-13 06:28:35 +00:00
|
|
|
)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btVector3 connectionPointCS0(connectionPoint[0],connectionPoint[1],connectionPoint[2]);
|
|
|
|
btVector3 wheelDirectionCS0(downDirection[0],downDirection[1],downDirection[2]);
|
|
|
|
btVector3 wheelAxle(axleDirection[0],axleDirection[1],axleDirection[2]);
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btWheelInfo& info = m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxle,
|
2006-02-13 06:28:35 +00:00
|
|
|
suspensionRestLength,wheelRadius,gTuning,hasSteering);
|
|
|
|
info.m_clientInfo = motionState;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SyncWheels()
|
|
|
|
{
|
|
|
|
int numWheels = GetNumWheels();
|
|
|
|
int i;
|
|
|
|
for (i=0;i<numWheels;i++)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btWheelInfo& info = m_vehicle->getWheelInfo(i);
|
2006-02-13 06:28:35 +00:00
|
|
|
PHY_IMotionState* motionState = (PHY_IMotionState*)info.m_clientInfo ;
|
2006-12-04 04:13:42 +00:00
|
|
|
// m_vehicle->updateWheelTransformsWS(info,false);
|
|
|
|
m_vehicle->updateWheelTransform(i,false);
|
2006-12-02 22:25:47 +00:00
|
|
|
btTransform trans = m_vehicle->getWheelInfo(i).m_worldTransform;
|
2006-11-21 00:53:40 +00:00
|
|
|
btQuaternion orn = trans.getRotation();
|
|
|
|
const btVector3& pos = trans.getOrigin();
|
2006-02-13 06:28:35 +00:00
|
|
|
motionState->setWorldOrientation(orn.x(),orn.y(),orn.z(),orn[3]);
|
|
|
|
motionState->setWorldPosition(pos.x(),pos.y(),pos.z());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int GetNumWheels() const
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
return m_vehicle->getNumWheels();
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
virtual void GetWheelPosition(int wheelIndex,float& posX,float& posY,float& posZ) const
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btTransform trans = m_vehicle->getWheelTransformWS(wheelIndex);
|
2006-02-13 06:28:35 +00:00
|
|
|
posX = trans.getOrigin().x();
|
|
|
|
posY = trans.getOrigin().y();
|
|
|
|
posZ = trans.getOrigin().z();
|
|
|
|
}
|
|
|
|
virtual void GetWheelOrientationQuaternion(int wheelIndex,float& quatX,float& quatY,float& quatZ,float& quatW) const
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btTransform trans = m_vehicle->getWheelTransformWS(wheelIndex);
|
|
|
|
btQuaternion quat = trans.getRotation();
|
|
|
|
btMatrix3x3 orn2(quat);
|
2006-02-13 06:28:35 +00:00
|
|
|
|
|
|
|
quatX = trans.getRotation().x();
|
|
|
|
quatY = trans.getRotation().y();
|
|
|
|
quatZ = trans.getRotation().z();
|
|
|
|
quatW = trans.getRotation()[3];
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
|
|
|
|
//printf("test");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual float GetWheelRotation(int wheelIndex) const
|
|
|
|
{
|
|
|
|
float rotation = 0.f;
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
|
2006-02-13 06:28:35 +00:00
|
|
|
rotation = info.m_rotation;
|
|
|
|
}
|
|
|
|
return rotation;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
virtual int GetUserConstraintId() const
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
return m_vehicle->getUserConstraintId();
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int GetUserConstraintType() const
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
return m_vehicle->getUserConstraintType();
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetSteeringValue(float steering,int wheelIndex)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
m_vehicle->setSteeringValue(steering,wheelIndex);
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ApplyEngineForce(float force,int wheelIndex)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
m_vehicle->applyEngineForce(force,wheelIndex);
|
2006-02-13 06:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ApplyBraking(float braking,int wheelIndex)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
|
2006-02-13 06:28:35 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
|
2006-02-13 06:28:35 +00:00
|
|
|
info.m_brake = braking;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-21 07:08:23 +00:00
|
|
|
virtual void SetWheelFriction(float friction,int wheelIndex)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
|
2006-02-21 07:08:23 +00:00
|
|
|
info.m_frictionSlip = friction;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-02-21 07:08:23 +00:00
|
|
|
virtual void SetSuspensionStiffness(float suspensionStiffness,int wheelIndex)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
|
2006-02-21 07:08:23 +00:00
|
|
|
info.m_suspensionStiffness = suspensionStiffness;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetSuspensionDamping(float suspensionDamping,int wheelIndex)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
|
2006-02-21 07:08:23 +00:00
|
|
|
info.m_wheelsDampingRelaxation = suspensionDamping;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetSuspensionCompression(float suspensionCompression,int wheelIndex)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
|
2006-02-21 07:08:23 +00:00
|
|
|
info.m_wheelsDampingCompression = suspensionCompression;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-02-21 07:08:23 +00:00
|
|
|
virtual void SetRollInfluence(float rollInfluence,int wheelIndex)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
|
2006-02-21 07:08:23 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
|
2006-02-21 07:08:23 +00:00
|
|
|
info.m_rollInfluence = rollInfluence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
virtual void SetCoordinateSystem(int rightIndex,int upIndex,int forwardIndex)
|
|
|
|
{
|
|
|
|
m_vehicle->setCoordinateSystem(rightIndex,upIndex,forwardIndex);
|
|
|
|
}
|
|
|
|
|
2006-02-21 07:08:23 +00:00
|
|
|
|
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
};
|
|
|
|
#endif //NEW_BULLET_VEHICLE_SUPPORT
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2008-03-01 19:17:37 +00:00
|
|
|
class CcdOverlapFilterCallBack : public btOverlapFilterCallback
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
class CcdPhysicsEnvironment* m_physEnv;
|
|
|
|
public:
|
|
|
|
CcdOverlapFilterCallBack(CcdPhysicsEnvironment* env) :
|
|
|
|
m_physEnv(env)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~CcdOverlapFilterCallBack()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// return true when pairs need collision
|
|
|
|
virtual bool needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const;
|
|
|
|
};
|
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-11-21 12:26:05 +00:00
|
|
|
void CcdPhysicsEnvironment::setDebugDrawer(btIDebugDraw* debugDrawer)
|
|
|
|
{
|
|
|
|
if (debugDrawer && m_dynamicsWorld)
|
|
|
|
m_dynamicsWorld->setDebugDrawer(debugDrawer);
|
|
|
|
m_debugDrawer = debugDrawer;
|
|
|
|
}
|
2005-07-27 09:30:53 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
static void DrawAabb(btIDebugDraw* debugDrawer,const btVector3& from,const btVector3& to,const btVector3& color)
|
2005-07-27 09:30:53 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btVector3 halfExtents = (to-from)* 0.5f;
|
|
|
|
btVector3 center = (to+from) *0.5f;
|
2005-07-27 09:30:53 +00:00
|
|
|
int i,j;
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btVector3 edgecoord(1.f,1.f,1.f),pa,pb;
|
2005-07-27 09:30:53 +00:00
|
|
|
for (i=0;i<4;i++)
|
|
|
|
{
|
|
|
|
for (j=0;j<3;j++)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
pa = btVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1],
|
2005-07-27 09:30:53 +00:00
|
|
|
edgecoord[2]*halfExtents[2]);
|
|
|
|
pa+=center;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2005-07-27 09:30:53 +00:00
|
|
|
int othercoord = j%3;
|
|
|
|
edgecoord[othercoord]*=-1.f;
|
2006-11-21 00:53:40 +00:00
|
|
|
pb = btVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1],
|
2005-07-27 09:30:53 +00:00
|
|
|
edgecoord[2]*halfExtents[2]);
|
|
|
|
pb+=center;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
debugDrawer->drawLine(pa,pb,color);
|
2005-07-27 09:30:53 +00:00
|
|
|
}
|
2006-11-21 00:53:40 +00:00
|
|
|
edgecoord = btVector3(-1.f,-1.f,-1.f);
|
2005-07-27 09:30:53 +00:00
|
|
|
if (i<3)
|
|
|
|
edgecoord[i]*=-1.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
CcdPhysicsEnvironment::CcdPhysicsEnvironment(btDispatcher* dispatcher,btOverlappingPairCache* pairCache)
|
2006-02-21 05:36:56 +00:00
|
|
|
:m_scalingPropagated(false),
|
2006-03-29 03:11:30 +00:00
|
|
|
m_numIterations(10),
|
2006-05-22 21:03:43 +00:00
|
|
|
m_numTimeSubSteps(1),
|
2005-08-04 19:07:39 +00:00
|
|
|
m_ccdMode(0),
|
2006-04-13 05:11:34 +00:00
|
|
|
m_solverType(-1),
|
|
|
|
m_profileTimings(0),
|
2008-03-01 19:17:37 +00:00
|
|
|
m_enableSatCollisionDetection(false),
|
|
|
|
m_solver(NULL),
|
|
|
|
m_ownPairCache(NULL),
|
|
|
|
m_ownDispatcher(NULL),
|
|
|
|
m_filterCallback(NULL)
|
2005-07-18 05:41:00 +00:00
|
|
|
{
|
2005-08-04 19:07:39 +00:00
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
for (int i=0;i<PHY_NUM_RESPONSE;i++)
|
|
|
|
{
|
|
|
|
m_triggerCallbacks[i] = 0;
|
|
|
|
}
|
2008-09-03 02:27:16 +00:00
|
|
|
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
if (!dispatcher)
|
2008-03-01 19:17:37 +00:00
|
|
|
{
|
2008-09-03 02:27:16 +00:00
|
|
|
dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
2008-03-01 19:17:37 +00:00
|
|
|
m_ownDispatcher = dispatcher;
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-09-03 02:27:16 +00:00
|
|
|
m_broadphase = new btDbvtBroadphase();
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-03-01 19:17:37 +00:00
|
|
|
m_filterCallback = new CcdOverlapFilterCallBack(this);
|
2008-09-03 02:27:16 +00:00
|
|
|
m_broadphase->getOverlappingPairCache()->setOverlapFilterCallback(m_filterCallback);
|
2006-04-06 20:37:38 +00:00
|
|
|
|
2006-05-09 01:15:12 +00:00
|
|
|
setSolverType(1);//issues with quickstep and memory allocations
|
2008-09-17 01:49:47 +00:00
|
|
|
// m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
|
|
|
m_dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
m_debugDrawer = 0;
|
2006-11-21 00:53:40 +00:00
|
|
|
m_gravity = btVector3(0.f,-10.f,0.f);
|
|
|
|
m_dynamicsWorld->setGravity(m_gravity);
|
2006-08-28 06:44:29 +00:00
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btRigidBody* body = ctrl->GetRigidBody();
|
2008-09-17 01:49:47 +00:00
|
|
|
btCollisionObject* obj = ctrl->GetCollisionObject();
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
//this m_userPointer is just used for triggers, see CallbackTriggers
|
2008-09-17 01:49:47 +00:00
|
|
|
obj->setUserPointer(ctrl);
|
|
|
|
if (body)
|
|
|
|
body->setGravity( m_gravity );
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2008-07-30 17:41:47 +00:00
|
|
|
m_controllers.insert(ctrl);
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-09-17 01:49:47 +00:00
|
|
|
if (body)
|
|
|
|
{
|
|
|
|
//use explicit group/filter for finer control over collision in bullet => near/radar sensor
|
|
|
|
m_dynamicsWorld->addRigidBody(body, ctrl->GetCollisionFilterGroup(), ctrl->GetCollisionFilterMask());
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (ctrl->GetSoftBody())
|
|
|
|
{
|
|
|
|
//not yet
|
|
|
|
btAssert(0);
|
|
|
|
//m_dynamicsWorld->addSo
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (obj->getCollisionShape())
|
|
|
|
{
|
|
|
|
m_dynamicsWorld->addCollisionObject(obj,ctrl->GetCollisionFilterGroup(), ctrl->GetCollisionFilterMask());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (obj->isStaticOrKinematicObject())
|
2006-11-21 12:26:05 +00:00
|
|
|
{
|
2008-09-17 01:49:47 +00:00
|
|
|
obj->setActivationState(ISLAND_SLEEPING);
|
2006-11-21 12:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
//CollisionObject(body,ctrl->GetCollisionFilterGroup(),ctrl->GetCollisionFilterMask());
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2008-09-17 01:49:47 +00:00
|
|
|
assert(obj->getBroadphaseHandle());
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btBroadphaseInterface* scene = getBroadphase();
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btCollisionShape* shapeinterface = ctrl->GetCollisionShape();
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
assert(shapeinterface);
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-09-17 01:49:47 +00:00
|
|
|
const btTransform& t = ctrl->GetCollisionObject()->getWorldTransform();
|
2006-08-28 06:44:29 +00:00
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btPoint3 minAabb,maxAabb;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
shapeinterface->getAabb(t,minAabb,maxAabb);
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
float timeStep = 0.02f;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
//extent it with the motion
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-09-17 01:49:47 +00:00
|
|
|
if (body)
|
|
|
|
{
|
|
|
|
btVector3 linMotion = body->getLinearVelocity()*timeStep;
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2008-09-17 01:49:47 +00:00
|
|
|
float maxAabbx = maxAabb.getX();
|
|
|
|
float maxAabby = maxAabb.getY();
|
|
|
|
float maxAabbz = maxAabb.getZ();
|
|
|
|
float minAabbx = minAabb.getX();
|
|
|
|
float minAabby = minAabb.getY();
|
|
|
|
float minAabbz = minAabb.getZ();
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-09-17 01:49:47 +00:00
|
|
|
if (linMotion.x() > 0.f)
|
|
|
|
maxAabbx += linMotion.x();
|
|
|
|
else
|
|
|
|
minAabbx += linMotion.x();
|
|
|
|
if (linMotion.y() > 0.f)
|
|
|
|
maxAabby += linMotion.y();
|
|
|
|
else
|
|
|
|
minAabby += linMotion.y();
|
|
|
|
if (linMotion.z() > 0.f)
|
|
|
|
maxAabbz += linMotion.z();
|
|
|
|
else
|
|
|
|
minAabbz += linMotion.z();
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-09-17 01:49:47 +00:00
|
|
|
minAabb = btVector3(minAabbx,minAabby,minAabbz);
|
|
|
|
maxAabb = btVector3(maxAabbx,maxAabby,maxAabbz);
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CcdPhysicsEnvironment::removeCcdPhysicsController(CcdPhysicsController* ctrl)
|
|
|
|
{
|
|
|
|
//also remove constraint
|
2008-09-17 01:49:47 +00:00
|
|
|
btRigidBody* body = ctrl->GetRigidBody();
|
|
|
|
if (body)
|
|
|
|
{
|
|
|
|
m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody());
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
//if a softbody
|
|
|
|
if (ctrl->GetSoftBody())
|
|
|
|
{
|
|
|
|
//not yet
|
|
|
|
btAssert(0);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
m_dynamicsWorld->removeCollisionObject(ctrl->GetCollisionObject());
|
|
|
|
}
|
|
|
|
}
|
2008-07-30 17:41:47 +00:00
|
|
|
m_controllers.erase(ctrl);
|
2006-04-17 01:33:10 +00:00
|
|
|
|
2008-08-05 16:23:33 +00:00
|
|
|
if (ctrl->m_registerCount != 0)
|
|
|
|
printf("Warning: removing controller with non-zero m_registerCount: %d\n", ctrl->m_registerCount);
|
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
//remove it from the triggers
|
2008-07-30 17:41:47 +00:00
|
|
|
m_triggerControllers.erase(ctrl);
|
2005-07-18 05:41:00 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 15:40:03 +00:00
|
|
|
void CcdPhysicsEnvironment::updateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask)
|
2008-07-19 10:27:52 +00:00
|
|
|
{
|
|
|
|
// this function is used when the collisionning group of a controller is changed
|
|
|
|
// remove and add the collistioning object
|
|
|
|
btRigidBody* body = ctrl->GetRigidBody();
|
2008-09-17 01:49:47 +00:00
|
|
|
btCollisionObject* obj = ctrl->GetCollisionObject();
|
|
|
|
if (obj)
|
|
|
|
{
|
|
|
|
btVector3 inertia(0.0,0.0,0.0);
|
|
|
|
m_dynamicsWorld->removeCollisionObject(obj);
|
|
|
|
obj->setCollisionFlags(newCollisionFlags);
|
|
|
|
if (body)
|
|
|
|
{
|
|
|
|
if (newMass)
|
|
|
|
body->getCollisionShape()->calculateLocalInertia(newMass, inertia);
|
|
|
|
body->setMassProps(newMass, inertia);
|
|
|
|
}
|
|
|
|
m_dynamicsWorld->addCollisionObject(obj, newCollisionGroup, newCollisionMask);
|
|
|
|
}
|
2008-07-20 15:40:03 +00:00
|
|
|
// to avoid nasty interaction, we must update the property of the controller as well
|
|
|
|
ctrl->m_cci.m_mass = newMass;
|
|
|
|
ctrl->m_cci.m_collisionFilterGroup = newCollisionGroup;
|
|
|
|
ctrl->m_cci.m_collisionFilterMask = newCollisionMask;
|
|
|
|
ctrl->m_cci.m_collisionFlags = newCollisionFlags;
|
2008-07-19 10:27:52 +00:00
|
|
|
}
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2008-07-20 15:40:03 +00:00
|
|
|
void CcdPhysicsEnvironment::enableCcdPhysicsController(CcdPhysicsController* ctrl)
|
|
|
|
{
|
2008-07-30 17:41:47 +00:00
|
|
|
if (m_controllers.insert(ctrl).second)
|
2008-07-20 15:40:03 +00:00
|
|
|
{
|
2008-09-17 01:49:47 +00:00
|
|
|
btCollisionObject* obj = ctrl->GetCollisionObject();
|
|
|
|
obj->setUserPointer(ctrl);
|
|
|
|
m_dynamicsWorld->addCollisionObject(obj,
|
2008-07-20 15:40:03 +00:00
|
|
|
ctrl->GetCollisionFilterGroup(), ctrl->GetCollisionFilterMask());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-05 16:23:33 +00:00
|
|
|
void CcdPhysicsEnvironment::disableCcdPhysicsController(CcdPhysicsController* ctrl)
|
|
|
|
{
|
|
|
|
if (m_controllers.erase(ctrl))
|
|
|
|
{
|
2008-09-17 01:49:47 +00:00
|
|
|
btRigidBody* body = ctrl->GetRigidBody();
|
|
|
|
if (body)
|
|
|
|
{
|
|
|
|
m_dynamicsWorld->removeRigidBody(body);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (ctrl->GetSoftBody())
|
|
|
|
{
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
m_dynamicsWorld->removeCollisionObject(body);
|
|
|
|
}
|
|
|
|
}
|
2008-08-05 16:23:33 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-20 15:40:03 +00:00
|
|
|
|
|
|
|
|
2006-01-01 00:20:50 +00:00
|
|
|
void CcdPhysicsEnvironment::beginFrame()
|
|
|
|
{
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-01-01 00:20:50 +00:00
|
|
|
}
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-04-13 05:11:34 +00:00
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
|
|
|
|
{
|
2008-07-30 17:41:47 +00:00
|
|
|
std::set<CcdPhysicsController*>::iterator it;
|
|
|
|
int i;
|
2006-01-15 11:34:55 +00:00
|
|
|
|
2008-07-30 17:41:47 +00:00
|
|
|
for (it=m_controllers.begin(); it!=m_controllers.end(); it++)
|
2006-04-13 05:11:34 +00:00
|
|
|
{
|
2008-07-30 17:41:47 +00:00
|
|
|
(*it)->SynchronizeMotionStates(timeStep);
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2006-04-13 05:11:34 +00:00
|
|
|
|
2007-05-07 17:10:44 +00:00
|
|
|
float subStep = timeStep / float(m_numTimeSubSteps);
|
|
|
|
for (i=0;i<m_numTimeSubSteps;i++)
|
|
|
|
{
|
|
|
|
m_dynamicsWorld->stepSimulation(subStep,0);//perform always a full simulation step
|
|
|
|
}
|
|
|
|
|
2008-07-30 17:41:47 +00:00
|
|
|
for (it=m_controllers.begin(); it!=m_controllers.end(); it++)
|
2006-11-21 12:26:05 +00:00
|
|
|
{
|
2008-07-30 17:41:47 +00:00
|
|
|
(*it)->SynchronizeMotionStates(timeStep);
|
2006-11-21 12:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0;i<m_wrapperVehicles.size();i++)
|
|
|
|
{
|
|
|
|
WrapperVehicle* veh = m_wrapperVehicles[i];
|
|
|
|
veh->SyncWheels();
|
|
|
|
}
|
|
|
|
|
2008-09-03 02:27:16 +00:00
|
|
|
m_dynamicsWorld->debugDrawWorld();
|
|
|
|
|
|
|
|
|
2006-11-29 07:23:01 +00:00
|
|
|
CallbackTriggers();
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2006-04-13 05:11:34 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
|
|
|
|
void CcdPhysicsEnvironment::setDebugMode(int debugMode)
|
|
|
|
{
|
|
|
|
if (m_debugDrawer){
|
|
|
|
m_debugDrawer->setDebugMode(debugMode);
|
2006-04-13 05:11:34 +00:00
|
|
|
}
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2006-04-13 05:11:34 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::setNumIterations(int numIter)
|
|
|
|
{
|
|
|
|
m_numIterations = numIter;
|
|
|
|
}
|
|
|
|
void CcdPhysicsEnvironment::setDeactivationTime(float dTime)
|
|
|
|
{
|
|
|
|
gDeactivationTime = dTime;
|
|
|
|
}
|
|
|
|
void CcdPhysicsEnvironment::setDeactivationLinearTreshold(float linTresh)
|
|
|
|
{
|
|
|
|
gLinearSleepingTreshold = linTresh;
|
|
|
|
}
|
|
|
|
void CcdPhysicsEnvironment::setDeactivationAngularTreshold(float angTresh)
|
|
|
|
{
|
|
|
|
gAngularSleepingTreshold = angTresh;
|
|
|
|
}
|
2006-04-13 05:11:34 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::setContactBreakingTreshold(float contactBreakingTreshold)
|
|
|
|
{
|
|
|
|
gContactBreakingThreshold = contactBreakingTreshold;
|
2006-04-13 05:11:34 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2006-04-06 20:37:38 +00:00
|
|
|
|
2006-04-13 05:11:34 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::setCcdMode(int ccdMode)
|
|
|
|
{
|
|
|
|
m_ccdMode = ccdMode;
|
|
|
|
}
|
2006-05-22 21:03:43 +00:00
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::setSolverSorConstant(float sor)
|
|
|
|
{
|
|
|
|
m_solverInfo.m_sor = sor;
|
|
|
|
}
|
2006-05-22 21:03:43 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::setSolverTau(float tau)
|
|
|
|
{
|
|
|
|
m_solverInfo.m_tau = tau;
|
|
|
|
}
|
|
|
|
void CcdPhysicsEnvironment::setSolverDamping(float damping)
|
|
|
|
{
|
|
|
|
m_solverInfo.m_damping = damping;
|
|
|
|
}
|
2006-05-22 21:03:43 +00:00
|
|
|
|
2006-04-13 05:11:34 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::setLinearAirDamping(float damping)
|
|
|
|
{
|
2008-09-03 02:27:16 +00:00
|
|
|
//gLinearAirDamping = damping;
|
2006-01-15 11:34:55 +00:00
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::setUseEpa(bool epa)
|
|
|
|
{
|
2006-11-29 05:25:37 +00:00
|
|
|
//gUseEpa = epa;
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::setSolverType(int solverType)
|
|
|
|
{
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
switch (solverType)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
if (m_solverType != solverType)
|
|
|
|
{
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
m_solver = new btSequentialImpulseConstraintSolver();
|
2008-09-03 02:27:16 +00:00
|
|
|
// ((btSequentialImpulseConstraintSolver*)m_solver)->setSolverMode(btSequentialImpulseConstraintSolver::SOLVER_USE_WARMSTARTING | btSequentialImpulseConstraintSolver::SOLVER_RANDMIZE_ORDER);
|
2006-11-21 00:53:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
if (m_solverType != solverType)
|
|
|
|
{
|
|
|
|
// m_solver = new OdeConstraintSolver();
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
};
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
m_solverType = solverType ;
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::setGravity(float x,float y,float z)
|
|
|
|
{
|
|
|
|
m_gravity = btVector3(x,y,z);
|
|
|
|
m_dynamicsWorld->setGravity(m_gravity);
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2005-08-13 08:05:48 +00:00
|
|
|
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2005-08-08 17:08:42 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
static int gConstraintUid = 1;
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
//Following the COLLADA physics specification for constraints
|
|
|
|
int CcdPhysicsEnvironment::createUniversalD6Constraint(
|
|
|
|
class PHY_IPhysicsController* ctrlRef,class PHY_IPhysicsController* ctrlOther,
|
|
|
|
btTransform& frameInA,
|
|
|
|
btTransform& frameInB,
|
|
|
|
const btVector3& linearMinLimits,
|
|
|
|
const btVector3& linearMaxLimits,
|
|
|
|
const btVector3& angularMinLimits,
|
|
|
|
const btVector3& angularMaxLimits
|
|
|
|
)
|
|
|
|
{
|
2006-05-11 00:13:42 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
//we could either add some logic to recognize ball-socket and hinge, or let that up to the user
|
|
|
|
//perhaps some warning or hint that hinge/ball-socket is more efficient?
|
|
|
|
|
|
|
|
btGeneric6DofConstraint* genericConstraint = 0;
|
|
|
|
CcdPhysicsController* ctrl0 = (CcdPhysicsController*) ctrlRef;
|
|
|
|
CcdPhysicsController* ctrl1 = (CcdPhysicsController*) ctrlOther;
|
|
|
|
|
|
|
|
btRigidBody* rb0 = ctrl0->GetRigidBody();
|
|
|
|
btRigidBody* rb1 = ctrl1->GetRigidBody();
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
if (rb1)
|
|
|
|
{
|
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2008-09-03 02:27:16 +00:00
|
|
|
bool useReferenceFrameA = true;
|
2006-11-21 00:53:40 +00:00
|
|
|
genericConstraint = new btGeneric6DofConstraint(
|
|
|
|
*rb0,*rb1,
|
2008-09-03 02:27:16 +00:00
|
|
|
frameInA,frameInB,useReferenceFrameA);
|
2006-11-21 00:53:40 +00:00
|
|
|
genericConstraint->setLinearLowerLimit(linearMinLimits);
|
|
|
|
genericConstraint->setLinearUpperLimit(linearMaxLimits);
|
|
|
|
genericConstraint->setAngularLowerLimit(angularMinLimits);
|
|
|
|
genericConstraint->setAngularUpperLimit(angularMaxLimits);
|
|
|
|
} else
|
2005-07-18 05:41:00 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
// TODO: Implement single body case...
|
|
|
|
//No, we can use a fixed rigidbody in above code, rather then unnecessary duplation of code
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (genericConstraint)
|
|
|
|
{
|
|
|
|
// m_constraints.push_back(genericConstraint);
|
|
|
|
m_dynamicsWorld->addConstraint(genericConstraint);
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
genericConstraint->setUserConstraintId(gConstraintUid++);
|
|
|
|
genericConstraint->setUserConstraintType(PHY_GENERIC_6DOF_CONSTRAINT);
|
|
|
|
//64 bit systems can't cast pointer to int. could use size_t instead.
|
|
|
|
return genericConstraint->getUserConstraintId();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-08-28 06:44:29 +00:00
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::removeConstraint(int constraintId)
|
|
|
|
{
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int numConstraints = m_dynamicsWorld->getNumConstraints();
|
|
|
|
for (i=0;i<numConstraints;i++)
|
|
|
|
{
|
|
|
|
btTypedConstraint* constraint = m_dynamicsWorld->getConstraint(i);
|
|
|
|
if (constraint->getUserConstraintId() == constraintId)
|
|
|
|
{
|
2006-12-25 02:02:13 +00:00
|
|
|
constraint->getRigidBodyA().activate();
|
|
|
|
constraint->getRigidBodyB().activate();
|
2006-11-21 00:53:40 +00:00
|
|
|
m_dynamicsWorld->removeConstraint(constraint);
|
|
|
|
break;
|
2005-07-18 05:41:00 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2006-04-13 05:11:34 +00:00
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
struct FilterClosestRayResultCallback : public btCollisionWorld::ClosestRayResultCallback
|
|
|
|
{
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
PHY_IRayCastFilterCallback& m_phyRayFilter;
|
|
|
|
const btCollisionShape* m_hitTriangleShape;
|
|
|
|
int m_hitTriangleIndex;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
FilterClosestRayResultCallback (PHY_IRayCastFilterCallback& phyRayFilter,const btVector3& rayFrom,const btVector3& rayTo)
|
2006-11-21 00:53:40 +00:00
|
|
|
: btCollisionWorld::ClosestRayResultCallback(rayFrom,rayTo),
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
m_phyRayFilter(phyRayFilter),
|
|
|
|
m_hitTriangleShape(NULL),
|
|
|
|
m_hitTriangleIndex(0)
|
2006-11-21 00:53:40 +00:00
|
|
|
{
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
virtual ~FilterClosestRayResultCallback()
|
|
|
|
{
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-09-04 23:07:43 +00:00
|
|
|
virtual bool needsCollision(btBroadphaseProxy* proxy0) const
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
{
|
2008-09-04 23:07:43 +00:00
|
|
|
if (!(proxy0->m_collisionFilterGroup & m_collisionFilterMask))
|
|
|
|
return false;
|
|
|
|
if (!(m_collisionFilterGroup & proxy0->m_collisionFilterMask))
|
|
|
|
return false;
|
|
|
|
btCollisionObject* object = (btCollisionObject*)proxy0->m_clientObject;
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
CcdPhysicsController* phyCtrl = static_cast<CcdPhysicsController*>(object->getUserPointer());
|
2008-09-04 23:07:43 +00:00
|
|
|
if (phyCtrl == m_phyRayFilter.m_ignoreController)
|
|
|
|
return false;
|
|
|
|
return m_phyRayFilter.needBroadphaseRayCast(phyCtrl);
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 23:07:43 +00:00
|
|
|
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
|
2006-11-21 00:53:40 +00:00
|
|
|
{
|
|
|
|
CcdPhysicsController* curHit = static_cast<CcdPhysicsController*>(rayResult.m_collisionObject->getUserPointer());
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
// save shape information as ClosestRayResultCallback::AddSingleResult() does not do it
|
|
|
|
if (rayResult.m_localShapeInfo)
|
|
|
|
{
|
2008-09-11 20:16:30 +00:00
|
|
|
m_hitTriangleShape = rayResult.m_collisionObject->getCollisionShape();
|
|
|
|
m_hitTriangleIndex = rayResult.m_localShapeInfo->m_triangleIndex;
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
m_hitTriangleShape = NULL;
|
|
|
|
m_hitTriangleIndex = 0;
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2008-09-04 23:07:43 +00:00
|
|
|
return ClosestRayResultCallback::addSingleResult(rayResult,normalInWorldSpace);
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
};
|
2006-04-13 05:11:34 +00:00
|
|
|
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
PHY_IPhysicsController* CcdPhysicsEnvironment::rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ)
|
2006-11-21 00:53:40 +00:00
|
|
|
{
|
2006-04-28 00:08:18 +00:00
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
float minFraction = 1.f;
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btVector3 rayFrom(fromX,fromY,fromZ);
|
|
|
|
btVector3 rayTo(toX,toY,toZ);
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btVector3 hitPointWorld,normalWorld;
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
//Either Ray Cast with or without filtering
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
//btCollisionWorld::ClosestRayResultCallback rayCallback(rayFrom,rayTo);
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
FilterClosestRayResultCallback rayCallback(filterCallback,rayFrom,rayTo);
|
|
|
|
|
2005-07-18 05:41:00 +00:00
|
|
|
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
PHY_RayCastResult result;
|
|
|
|
memset(&result, 0, sizeof(result));
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-04-10 20:17:12 +00:00
|
|
|
// don't collision with sensor object
|
2008-09-03 02:27:16 +00:00
|
|
|
rayCallback.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter;
|
|
|
|
//, ,filterCallback.m_faceNormal);
|
|
|
|
|
|
|
|
m_dynamicsWorld->rayTest(rayFrom,rayTo,rayCallback);
|
|
|
|
if (rayCallback.hasHit())
|
2006-06-17 13:55:59 +00:00
|
|
|
{
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
CcdPhysicsController* controller = static_cast<CcdPhysicsController*>(rayCallback.m_collisionObject->getUserPointer());
|
|
|
|
result.m_controller = controller;
|
|
|
|
result.m_hitPoint[0] = rayCallback.m_hitPointWorld.getX();
|
|
|
|
result.m_hitPoint[1] = rayCallback.m_hitPointWorld.getY();
|
|
|
|
result.m_hitPoint[2] = rayCallback.m_hitPointWorld.getZ();
|
2006-06-17 13:55:59 +00:00
|
|
|
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
if (rayCallback.m_hitTriangleShape != NULL)
|
|
|
|
{
|
|
|
|
// identify the mesh polygon
|
|
|
|
CcdShapeConstructionInfo* shapeInfo = controller->m_shapeInfo;
|
|
|
|
if (shapeInfo)
|
|
|
|
{
|
2008-09-17 01:49:47 +00:00
|
|
|
btCollisionShape* shape = controller->GetCollisionObject()->getCollisionShape();
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
if (shape->isCompound())
|
|
|
|
{
|
|
|
|
btCompoundShape* compoundShape = (btCompoundShape*)shape;
|
|
|
|
CcdShapeConstructionInfo* compoundShapeInfo = shapeInfo;
|
|
|
|
// need to search which sub-shape has been hit
|
|
|
|
for (int i=0; i<compoundShape->getNumChildShapes(); i++)
|
|
|
|
{
|
|
|
|
shapeInfo = compoundShapeInfo->GetChildShape(i);
|
|
|
|
shape=compoundShape->getChildShape(i);
|
|
|
|
if (shape == rayCallback.m_hitTriangleShape)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (shape == rayCallback.m_hitTriangleShape &&
|
|
|
|
rayCallback.m_hitTriangleIndex < shapeInfo->m_polygonIndexArray.size())
|
|
|
|
{
|
2008-09-20 21:33:54 +00:00
|
|
|
result.m_meshObject = shapeInfo->GetMesh();
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
result.m_polygon = shapeInfo->m_polygonIndexArray.at(rayCallback.m_hitTriangleIndex);
|
2008-09-11 20:16:30 +00:00
|
|
|
|
|
|
|
// Bullet returns the normal from "outside".
|
|
|
|
// If the user requests the real normal, compute it now
|
|
|
|
if (filterCallback.m_faceNormal)
|
|
|
|
{
|
2008-09-13 16:03:11 +00:00
|
|
|
// mesh shapes are shared and stored in the shapeInfo
|
|
|
|
btTriangleMeshShape* triangleShape = shapeInfo->GetMeshShape();
|
|
|
|
if (triangleShape)
|
2008-09-11 20:16:30 +00:00
|
|
|
{
|
2008-09-13 16:03:11 +00:00
|
|
|
// this code is copied from Bullet
|
|
|
|
btVector3 triangle[3];
|
|
|
|
const unsigned char *vertexbase;
|
|
|
|
int numverts;
|
|
|
|
PHY_ScalarType type;
|
|
|
|
int stride;
|
|
|
|
const unsigned char *indexbase;
|
|
|
|
int indexstride;
|
|
|
|
int numfaces;
|
|
|
|
PHY_ScalarType indicestype;
|
|
|
|
btStridingMeshInterface* meshInterface = triangleShape->getMeshInterface();
|
|
|
|
|
|
|
|
meshInterface->getLockedReadOnlyVertexIndexBase(
|
|
|
|
&vertexbase,
|
|
|
|
numverts,
|
|
|
|
type,
|
|
|
|
stride,
|
|
|
|
&indexbase,
|
|
|
|
indexstride,
|
|
|
|
numfaces,
|
|
|
|
indicestype,
|
|
|
|
0);
|
|
|
|
|
|
|
|
unsigned int* gfxbase = (unsigned int*)(indexbase+rayCallback.m_hitTriangleIndex*indexstride);
|
|
|
|
const btVector3& meshScaling = shape->getLocalScaling();
|
|
|
|
for (int j=2;j>=0;j--)
|
|
|
|
{
|
|
|
|
int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
|
|
|
|
|
|
|
|
btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
|
|
|
|
|
|
|
|
triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
|
|
|
|
}
|
|
|
|
meshInterface->unLockReadOnlyVertexBase(0);
|
|
|
|
btVector3 triangleNormal;
|
|
|
|
triangleNormal = (triangle[1]-triangle[0]).cross(triangle[2]-triangle[0]);
|
|
|
|
rayCallback.m_hitNormalWorld = rayCallback.m_collisionObject->getWorldTransform().getBasis()*triangleNormal;
|
2008-09-11 20:16:30 +00:00
|
|
|
}
|
|
|
|
}
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-11 20:16:30 +00:00
|
|
|
if (rayCallback.m_hitNormalWorld.length2() > (SIMD_EPSILON*SIMD_EPSILON))
|
|
|
|
{
|
|
|
|
rayCallback.m_hitNormalWorld.normalize();
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
rayCallback.m_hitNormalWorld.setValue(1,0,0);
|
|
|
|
}
|
|
|
|
result.m_hitNormal[0] = rayCallback.m_hitNormalWorld.getX();
|
|
|
|
result.m_hitNormal[1] = rayCallback.m_hitNormalWorld.getY();
|
|
|
|
result.m_hitNormal[2] = rayCallback.m_hitNormalWorld.getZ();
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
filterCallback.reportHit(&result);
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2006-06-17 13:55:59 +00:00
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
BGE patch: KX_GameObject::rayCast() improvements to have X-Ray option, return true face normal and hit polygon information.
rayCast(to,from,dist,prop,face,xray,poly):
The face paremeter determines the orientation of the normal:
0 or omitted => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
The prop and xray parameters interact as follow:
prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
prop off, xray on : idem.
prop on, xray off: return closest hit if it matches prop, no hit otherwise.
prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
if poly is 0 or omitted, returns a 3-tuple with object reference, hit point and hit normal or (None,None,None) if no hit.
if poly is 1, returns a 4-tuple with in addition a KX_PolyProxy as 4th element.
The KX_PolyProxy object holds information on the polygon hit by the ray: the index of the vertex forming the poylgon, material, etc.
Attributes (read-only):
matname: The name of polygon material, empty if no material.
material: The material of the polygon
texture: The texture name of the polygon.
matid: The material index of the polygon, use this to retrieve vertex proxy from mesh proxy
v1: vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v2: vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v3: vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy
v4: vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
use this to retrieve vertex proxy from mesh proxy
visible: visible state of the polygon: 1=visible, 0=invisible
collide: collide state of the polygon: 1=receives collision, 0=collision free.
Methods:
getMaterialName(): Returns the polygon material name with MA prefix
getMaterial(): Returns the polygon material
getTextureName(): Returns the polygon texture name
getMaterialIndex(): Returns the material bucket index of the polygon.
getNumVertex(): Returns the number of vertex of the polygon.
isVisible(): Returns whether the polygon is visible or not
isCollider(): Returns whether the polygon is receives collision or not
getVertexIndex(vertex): Returns the mesh vertex index of a polygon vertex
getMesh(): Returns a mesh proxy
New methods of KX_MeshProxy have been implemented to retrieve KX_PolyProxy objects:
getNumPolygons(): Returns the number of polygon in the mesh.
getPolygon(index): Gets the specified polygon from the mesh.
More details in PyDoc.
2008-08-27 19:34:19 +00:00
|
|
|
return result.m_controller;
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2005-07-18 05:41:00 +00:00
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2005-07-29 18:14:41 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
int CcdPhysicsEnvironment::getNumContactPoints()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2006-04-06 20:37:38 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
void CcdPhysicsEnvironment::getContactPoint(int i,float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ)
|
|
|
|
{
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btBroadphaseInterface* CcdPhysicsEnvironment::getBroadphase()
|
|
|
|
{
|
|
|
|
return m_dynamicsWorld->getBroadphase();
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
|
|
|
|
2006-04-13 05:11:34 +00:00
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
CcdPhysicsEnvironment::~CcdPhysicsEnvironment()
|
|
|
|
{
|
2006-04-06 20:37:38 +00:00
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
#ifdef NEW_BULLET_VEHICLE_SUPPORT
|
2006-11-21 00:53:40 +00:00
|
|
|
m_wrapperVehicles.clear();
|
2006-04-06 20:37:38 +00:00
|
|
|
#endif //NEW_BULLET_VEHICLE_SUPPORT
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
//m_broadphase->DestroyScene();
|
|
|
|
//delete broadphase ? release reference on broadphase ?
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
//first delete scene, then dispatcher, because pairs have to release manifolds on the dispatcher
|
|
|
|
//delete m_dispatcher;
|
|
|
|
delete m_dynamicsWorld;
|
|
|
|
|
2006-02-21 05:36:56 +00:00
|
|
|
|
2008-03-01 19:17:37 +00:00
|
|
|
if (NULL != m_ownPairCache)
|
|
|
|
delete m_ownPairCache;
|
|
|
|
|
|
|
|
if (NULL != m_ownDispatcher)
|
|
|
|
delete m_ownDispatcher;
|
|
|
|
|
|
|
|
if (NULL != m_solver)
|
|
|
|
delete m_solver;
|
|
|
|
|
|
|
|
if (NULL != m_debugDrawer)
|
|
|
|
delete m_debugDrawer;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-03-01 19:17:37 +00:00
|
|
|
if (NULL != m_filterCallback)
|
|
|
|
delete m_filterCallback;
|
2008-09-03 02:27:16 +00:00
|
|
|
|
|
|
|
if (NULL != m_collisionConfiguration)
|
|
|
|
delete m_collisionConfiguration;
|
|
|
|
|
|
|
|
if (NULL != m_broadphase)
|
|
|
|
delete m_broadphase;
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2005-07-18 05:41:00 +00:00
|
|
|
|
|
|
|
|
2006-12-02 03:48:36 +00:00
|
|
|
void CcdPhysicsEnvironment::setConstraintParam(int constraintId,int param,float value0,float value1)
|
|
|
|
{
|
|
|
|
btTypedConstraint* typedConstraint = getConstraintById(constraintId);
|
|
|
|
switch (typedConstraint->getUserConstraintType())
|
|
|
|
{
|
|
|
|
case PHY_GENERIC_6DOF_CONSTRAINT:
|
|
|
|
{
|
|
|
|
//param = 1..12, min0,max0,min1,max1...min6,max6
|
|
|
|
btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
|
2008-09-03 02:27:16 +00:00
|
|
|
genCons->setLimit(param,value0,value1);
|
2006-12-02 03:48:36 +00:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2006-02-13 06:28:35 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
btTypedConstraint* CcdPhysicsEnvironment::getConstraintById(int constraintId)
|
2006-04-06 20:37:38 +00:00
|
|
|
{
|
2006-12-02 03:48:36 +00:00
|
|
|
|
|
|
|
int numConstraints = m_dynamicsWorld->getNumConstraints();
|
2006-04-06 20:37:38 +00:00
|
|
|
int i;
|
2006-12-02 03:48:36 +00:00
|
|
|
for (i=0;i<numConstraints;i++)
|
2006-04-06 20:37:38 +00:00
|
|
|
{
|
2006-12-02 03:48:36 +00:00
|
|
|
btTypedConstraint* constraint = m_dynamicsWorld->getConstraint(i);
|
2006-11-21 00:53:40 +00:00
|
|
|
if (constraint->getUserConstraintId()==constraintId)
|
2006-04-06 20:37:38 +00:00
|
|
|
{
|
|
|
|
return constraint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-13 06:28:35 +00:00
|
|
|
|
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
void CcdPhysicsEnvironment::addSensor(PHY_IPhysicsController* ctrl)
|
|
|
|
{
|
2006-05-22 21:03:43 +00:00
|
|
|
|
|
|
|
CcdPhysicsController* ctrl1 = (CcdPhysicsController* )ctrl;
|
2008-07-30 17:41:47 +00:00
|
|
|
// addSensor() is a "light" function for bullet because it is used
|
|
|
|
// dynamically when the sensor is activated. Use enableCcdPhysicsController() instead
|
|
|
|
//if (m_controllers.insert(ctrl1).second)
|
|
|
|
//{
|
|
|
|
// addCcdPhysicsController(ctrl1);
|
|
|
|
//}
|
|
|
|
enableCcdPhysicsController(ctrl1);
|
|
|
|
|
2008-03-01 19:17:37 +00:00
|
|
|
//Collision filter/mask is now set at the time of the creation of the controller
|
2006-12-01 01:04:27 +00:00
|
|
|
//force collision detection with everything, including static objects (might hurt performance!)
|
2008-03-01 19:17:37 +00:00
|
|
|
//ctrl1->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterMask = btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::SensorTrigger;
|
|
|
|
//ctrl1->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterGroup = btBroadphaseProxy::SensorTrigger;
|
2006-12-04 04:13:42 +00:00
|
|
|
//todo: make this 'sensor'!
|
2006-05-22 21:03:43 +00:00
|
|
|
|
|
|
|
requestCollisionCallback(ctrl);
|
2006-04-17 06:27:57 +00:00
|
|
|
//printf("addSensor\n");
|
2006-04-17 01:33:10 +00:00
|
|
|
}
|
2006-05-22 21:03:43 +00:00
|
|
|
|
|
|
|
void CcdPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl)
|
|
|
|
{
|
2008-08-05 16:23:33 +00:00
|
|
|
CcdPhysicsController* ccdCtrl = (CcdPhysicsController*)ctrl;
|
|
|
|
if (ccdCtrl->Unregister())
|
|
|
|
m_triggerControllers.erase(ccdCtrl);
|
2006-05-22 21:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
void CcdPhysicsEnvironment::removeSensor(PHY_IPhysicsController* ctrl)
|
|
|
|
{
|
2008-08-05 16:23:33 +00:00
|
|
|
removeCollisionCallback(ctrl);
|
|
|
|
|
|
|
|
disableCcdPhysicsController((CcdPhysicsController*)ctrl);
|
2006-04-17 01:33:10 +00:00
|
|
|
}
|
2008-07-30 17:41:47 +00:00
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
void CcdPhysicsEnvironment::addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
|
|
|
|
{
|
2006-04-28 00:08:18 +00:00
|
|
|
/* printf("addTouchCallback\n(response class = %i)\n",response_class);
|
2006-04-17 01:33:10 +00:00
|
|
|
|
|
|
|
//map PHY_ convention into SM_ convention
|
|
|
|
switch (response_class)
|
|
|
|
{
|
|
|
|
case PHY_FH_RESPONSE:
|
2006-04-28 00:08:18 +00:00
|
|
|
printf("PHY_FH_RESPONSE\n");
|
|
|
|
break;
|
2006-04-17 01:33:10 +00:00
|
|
|
case PHY_SENSOR_RESPONSE:
|
2006-04-28 00:08:18 +00:00
|
|
|
printf("PHY_SENSOR_RESPONSE\n");
|
|
|
|
break;
|
2006-04-17 01:33:10 +00:00
|
|
|
case PHY_CAMERA_RESPONSE:
|
2006-04-28 00:08:18 +00:00
|
|
|
printf("PHY_CAMERA_RESPONSE\n");
|
|
|
|
break;
|
2006-04-17 01:33:10 +00:00
|
|
|
case PHY_OBJECT_RESPONSE:
|
2006-04-28 00:08:18 +00:00
|
|
|
printf("PHY_OBJECT_RESPONSE\n");
|
|
|
|
break;
|
2006-04-17 01:33:10 +00:00
|
|
|
case PHY_STATIC_RESPONSE:
|
2006-04-28 00:08:18 +00:00
|
|
|
printf("PHY_STATIC_RESPONSE\n");
|
|
|
|
break;
|
2006-04-17 01:33:10 +00:00
|
|
|
default:
|
2006-04-28 00:08:18 +00:00
|
|
|
assert(0);
|
|
|
|
return;
|
2006-04-17 01:33:10 +00:00
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
*/
|
2006-04-17 01:33:10 +00:00
|
|
|
|
|
|
|
m_triggerCallbacks[response_class] = callback;
|
|
|
|
m_triggerCallbacksUserPtrs[response_class] = user;
|
|
|
|
|
|
|
|
}
|
|
|
|
void CcdPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl)
|
|
|
|
{
|
|
|
|
CcdPhysicsController* ccdCtrl = static_cast<CcdPhysicsController*>(ctrl);
|
|
|
|
|
2008-08-05 16:23:33 +00:00
|
|
|
if (ccdCtrl->Register())
|
|
|
|
m_triggerControllers.insert(ccdCtrl);
|
2006-04-17 01:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CcdPhysicsEnvironment::CallbackTriggers()
|
|
|
|
{
|
2006-08-28 06:44:29 +00:00
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
CcdPhysicsController* ctrl0=0,*ctrl1=0;
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
if (m_triggerCallbacks[PHY_OBJECT_RESPONSE] || (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)))
|
2006-04-17 01:33:10 +00:00
|
|
|
{
|
2006-04-17 06:27:57 +00:00
|
|
|
//walk over all overlapping pairs, and if one of the involved bodies is registered for trigger callback, perform callback
|
2008-08-07 11:31:24 +00:00
|
|
|
btDispatcher* dispatcher = m_dynamicsWorld->getDispatcher();
|
|
|
|
int numManifolds = dispatcher->getNumManifolds();
|
2006-04-17 01:33:10 +00:00
|
|
|
for (int i=0;i<numManifolds;i++)
|
|
|
|
{
|
2008-08-07 11:31:24 +00:00
|
|
|
btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
|
2006-11-21 00:53:40 +00:00
|
|
|
int numContacts = manifold->getNumContacts();
|
2006-04-17 01:33:10 +00:00
|
|
|
if (numContacts)
|
|
|
|
{
|
2008-08-07 11:31:24 +00:00
|
|
|
btRigidBody* rb0 = static_cast<btRigidBody*>(manifold->getBody0());
|
|
|
|
btRigidBody* rb1 = static_cast<btRigidBody*>(manifold->getBody1());
|
2006-11-21 00:53:40 +00:00
|
|
|
if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints))
|
2006-08-28 06:44:29 +00:00
|
|
|
{
|
|
|
|
for (int j=0;j<numContacts;j++)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btVector3 color(1,0,0);
|
|
|
|
const btManifoldPoint& cp = manifold->getContactPoint(j);
|
2006-08-28 06:44:29 +00:00
|
|
|
if (m_debugDrawer)
|
2006-11-21 00:53:40 +00:00
|
|
|
m_debugDrawer->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color);
|
2006-08-28 06:44:29 +00:00
|
|
|
}
|
|
|
|
}
|
2008-08-07 11:31:24 +00:00
|
|
|
btRigidBody* obj0 = rb0;
|
|
|
|
btRigidBody* obj1 = rb1;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
//m_internalOwner is set in 'addPhysicsController'
|
|
|
|
CcdPhysicsController* ctrl0 = static_cast<CcdPhysicsController*>(obj0->getUserPointer());
|
|
|
|
CcdPhysicsController* ctrl1 = static_cast<CcdPhysicsController*>(obj1->getUserPointer());
|
2006-04-17 01:33:10 +00:00
|
|
|
|
2008-07-30 17:41:47 +00:00
|
|
|
std::set<CcdPhysicsController*>::const_iterator i = m_triggerControllers.find(ctrl0);
|
2006-04-17 01:33:10 +00:00
|
|
|
if (i == m_triggerControllers.end())
|
|
|
|
{
|
2008-07-30 17:41:47 +00:00
|
|
|
i = m_triggerControllers.find(ctrl1);
|
2006-04-17 01:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(i == m_triggerControllers.end()))
|
|
|
|
{
|
|
|
|
m_triggerCallbacks[PHY_OBJECT_RESPONSE](m_triggerCallbacksUserPtrs[PHY_OBJECT_RESPONSE],
|
|
|
|
ctrl0,ctrl1,0);
|
|
|
|
}
|
2008-08-07 17:29:06 +00:00
|
|
|
// Bullet does not refresh the manifold contact point for object without contact response
|
|
|
|
// may need to remove this when a newer Bullet version is integrated
|
|
|
|
if (!dispatcher->needsResponse(rb0, rb1))
|
|
|
|
{
|
|
|
|
// Refresh algorithm fails sometimes when there is penetration
|
|
|
|
// (usuall the case with ghost and sensor objects)
|
|
|
|
// Let's just clear the manifold, in any case, it is recomputed on each frame.
|
|
|
|
manifold->clearManifold(); //refreshContactPoints(rb0->getCenterOfMassTransform(),rb1->getCenterOfMassTransform());
|
|
|
|
}
|
2006-04-17 01:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
|
|
|
|
}
|
2006-04-17 06:27:57 +00:00
|
|
|
|
2006-08-28 06:44:29 +00:00
|
|
|
|
2006-04-17 01:33:10 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 19:17:37 +00:00
|
|
|
// This call back is called before a pair is added in the cache
|
|
|
|
// Handy to remove objects that must be ignored by sensors
|
|
|
|
bool CcdOverlapFilterCallBack::needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const
|
|
|
|
{
|
|
|
|
btCollisionObject *colObj0, *colObj1;
|
|
|
|
CcdPhysicsController *sensorCtrl, *objCtrl;
|
|
|
|
bool collides;
|
|
|
|
// first check the filters
|
|
|
|
collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
|
|
|
|
collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
|
|
|
|
if (!collides)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// additional check for sensor object
|
|
|
|
if (proxy0->m_collisionFilterGroup & btBroadphaseProxy::SensorTrigger)
|
|
|
|
{
|
|
|
|
// this is a sensor object, the other one can't be a sensor object because
|
|
|
|
// they exclude each other in the above test
|
|
|
|
assert(!(proxy1->m_collisionFilterGroup & btBroadphaseProxy::SensorTrigger));
|
|
|
|
colObj0 = (btCollisionObject*)proxy0->m_clientObject;
|
|
|
|
colObj1 = (btCollisionObject*)proxy1->m_clientObject;
|
|
|
|
}
|
|
|
|
else if (proxy1->m_collisionFilterGroup & btBroadphaseProxy::SensorTrigger)
|
|
|
|
{
|
|
|
|
colObj0 = (btCollisionObject*)proxy1->m_clientObject;
|
|
|
|
colObj1 = (btCollisionObject*)proxy0->m_clientObject;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!colObj0 || !colObj1)
|
|
|
|
return false;
|
|
|
|
sensorCtrl = static_cast<CcdPhysicsController*>(colObj0->getUserPointer());
|
|
|
|
objCtrl = static_cast<CcdPhysicsController*>(colObj1->getUserPointer());
|
|
|
|
if (m_physEnv->m_triggerCallbacks[PHY_BROADPH_RESPONSE])
|
|
|
|
{
|
|
|
|
return m_physEnv->m_triggerCallbacks[PHY_BROADPH_RESPONSE](m_physEnv->m_triggerCallbacksUserPtrs[PHY_BROADPH_RESPONSE], sensorCtrl, objCtrl, 0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2006-04-17 01:33:10 +00:00
|
|
|
|
|
|
|
|
2006-02-13 06:28:35 +00:00
|
|
|
#ifdef NEW_BULLET_VEHICLE_SUPPORT
|
|
|
|
|
|
|
|
//complex constraint for vehicles
|
|
|
|
PHY_IVehicle* CcdPhysicsEnvironment::getVehicleConstraint(int constraintId)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
int numVehicles = m_wrapperVehicles.size();
|
|
|
|
for (i=0;i<numVehicles;i++)
|
|
|
|
{
|
|
|
|
WrapperVehicle* wrapperVehicle = m_wrapperVehicles[i];
|
2006-11-21 00:53:40 +00:00
|
|
|
if (wrapperVehicle->GetVehicle()->getUserConstraintId() == constraintId)
|
2006-02-13 06:28:35 +00:00
|
|
|
return wrapperVehicle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-24 16:40:32 +00:00
|
|
|
#endif //NEW_BULLET_VEHICLE_SUPPORT
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
int currentController = 0;
|
|
|
|
int numController = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PHY_IPhysicsController* CcdPhysicsEnvironment::CreateSphereController(float radius,const PHY__Vector3& position)
|
|
|
|
{
|
|
|
|
|
|
|
|
CcdConstructionInfo cinfo;
|
2008-03-01 19:17:37 +00:00
|
|
|
// memory leak! The shape is not deleted by Bullet and we cannot add it to the KX_Scene.m_shapes list
|
2006-11-21 00:53:40 +00:00
|
|
|
cinfo.m_collisionShape = new btSphereShape(radius);
|
|
|
|
cinfo.m_MotionState = 0;
|
|
|
|
cinfo.m_physicsEnv = this;
|
2008-03-01 19:17:37 +00:00
|
|
|
// declare this object as Dyamic rather then static!!
|
|
|
|
// The reason as it is designed to detect all type of object, including static object
|
|
|
|
// It would cause static-static message to be printed on the console otherwise
|
|
|
|
cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE/* | btCollisionObject::CF_KINEMATIC_OBJECT*/;
|
2006-11-21 00:53:40 +00:00
|
|
|
DefaultMotionState* motionState = new DefaultMotionState();
|
|
|
|
cinfo.m_MotionState = motionState;
|
2008-03-01 19:17:37 +00:00
|
|
|
// we will add later the possibility to select the filter from option
|
|
|
|
cinfo.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter;
|
|
|
|
cinfo.m_collisionFilterGroup = CcdConstructionInfo::SensorFilter;
|
2006-11-21 00:53:40 +00:00
|
|
|
motionState->m_worldTransform.setIdentity();
|
|
|
|
motionState->m_worldTransform.setOrigin(btVector3(position[0],position[1],position[2]));
|
|
|
|
|
|
|
|
CcdPhysicsController* sphereController = new CcdPhysicsController(cinfo);
|
|
|
|
|
|
|
|
return sphereController;
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl0,class PHY_IPhysicsController* ctrl1,PHY_ConstraintType type,
|
|
|
|
float pivotX,float pivotY,float pivotZ,
|
2006-12-16 05:50:38 +00:00
|
|
|
float axisX,float axisY,float axisZ,
|
|
|
|
float axis1X,float axis1Y,float axis1Z,
|
|
|
|
float axis2X,float axis2Y,float axis2Z
|
|
|
|
)
|
2006-04-28 00:08:18 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
CcdPhysicsController* c0 = (CcdPhysicsController*)ctrl0;
|
|
|
|
CcdPhysicsController* c1 = (CcdPhysicsController*)ctrl1;
|
|
|
|
|
|
|
|
btRigidBody* rb0 = c0 ? c0->GetRigidBody() : 0;
|
|
|
|
btRigidBody* rb1 = c1 ? c1->GetRigidBody() : 0;
|
|
|
|
|
|
|
|
bool rb0static = rb0 ? rb0->isStaticOrKinematicObject() : true;
|
|
|
|
bool rb1static = rb1 ? rb1->isStaticOrKinematicObject() : true;
|
|
|
|
|
|
|
|
|
|
|
|
if (rb0static && rb1static)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
btVector3 pivotInA(pivotX,pivotY,pivotZ);
|
2006-12-02 03:48:36 +00:00
|
|
|
btVector3 pivotInB = rb1 ? rb1->getCenterOfMassTransform().inverse()(rb0->getCenterOfMassTransform()(pivotInA)) :
|
|
|
|
rb0->getCenterOfMassTransform() * pivotInA;
|
2006-11-21 00:53:40 +00:00
|
|
|
btVector3 axisInA(axisX,axisY,axisZ);
|
2007-01-19 03:14:51 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
|
|
|
|
bool angularOnly = false;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case PHY_POINT2POINT_CONSTRAINT:
|
|
|
|
{
|
|
|
|
|
|
|
|
btPoint2PointConstraint* p2p = 0;
|
|
|
|
|
|
|
|
if (rb1)
|
|
|
|
{
|
|
|
|
p2p = new btPoint2PointConstraint(*rb0,
|
|
|
|
*rb1,pivotInA,pivotInB);
|
|
|
|
} else
|
2006-04-28 00:08:18 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
p2p = new btPoint2PointConstraint(*rb0,
|
|
|
|
pivotInA);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dynamicsWorld->addConstraint(p2p);
|
|
|
|
// m_constraints.push_back(p2p);
|
|
|
|
|
|
|
|
p2p->setUserConstraintId(gConstraintUid++);
|
|
|
|
p2p->setUserConstraintType(type);
|
|
|
|
//64 bit systems can't cast pointer to int. could use size_t instead.
|
|
|
|
return p2p->getUserConstraintId();
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
case PHY_GENERIC_6DOF_CONSTRAINT:
|
|
|
|
{
|
|
|
|
btGeneric6DofConstraint* genericConstraint = 0;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
if (rb1)
|
|
|
|
{
|
|
|
|
btTransform frameInA;
|
|
|
|
btTransform frameInB;
|
|
|
|
|
2006-12-16 05:50:38 +00:00
|
|
|
btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z);
|
|
|
|
if (axis1.length() == 0.0)
|
|
|
|
{
|
|
|
|
btPlaneSpace1( axisInA, axis1, axis2 );
|
|
|
|
}
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
|
|
|
|
axisInA.y(), axis1.y(), axis2.y(),
|
|
|
|
axisInA.z(), axis1.z(), axis2.z() );
|
|
|
|
frameInA.setOrigin( pivotInA );
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2007-01-19 03:14:51 +00:00
|
|
|
btTransform inv = rb1->getCenterOfMassTransform().inverse();
|
|
|
|
|
|
|
|
btTransform globalFrameA = rb0->getCenterOfMassTransform() * frameInA;
|
|
|
|
|
|
|
|
frameInB = inv * globalFrameA;
|
2008-09-03 02:27:16 +00:00
|
|
|
bool useReferenceFrameA = true;
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
genericConstraint = new btGeneric6DofConstraint(
|
|
|
|
*rb0,*rb1,
|
2008-09-03 02:27:16 +00:00
|
|
|
frameInA,frameInB,useReferenceFrameA);
|
2006-04-28 00:08:18 +00:00
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
} else
|
|
|
|
{
|
2006-12-02 03:48:36 +00:00
|
|
|
static btRigidBody s_fixedObject2( 0,0,0);
|
2007-01-19 03:14:51 +00:00
|
|
|
btTransform frameInA;
|
2006-12-02 03:48:36 +00:00
|
|
|
btTransform frameInB;
|
|
|
|
|
|
|
|
btVector3 axis1, axis2;
|
|
|
|
btPlaneSpace1( axisInA, axis1, axis2 );
|
|
|
|
|
|
|
|
frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
|
|
|
|
axisInA.y(), axis1.y(), axis2.y(),
|
|
|
|
axisInA.z(), axis1.z(), axis2.z() );
|
|
|
|
|
|
|
|
frameInA.setOrigin( pivotInA );
|
|
|
|
|
2007-01-19 03:14:51 +00:00
|
|
|
///frameInB in worldspace
|
|
|
|
frameInB = rb0->getCenterOfMassTransform() * frameInA;
|
2006-04-28 00:08:18 +00:00
|
|
|
|
2008-09-03 02:27:16 +00:00
|
|
|
bool useReferenceFrameA = true;
|
2006-12-02 03:48:36 +00:00
|
|
|
genericConstraint = new btGeneric6DofConstraint(
|
|
|
|
*rb0,s_fixedObject2,
|
2008-09-03 02:27:16 +00:00
|
|
|
frameInA,frameInB,useReferenceFrameA);
|
2006-11-21 00:53:40 +00:00
|
|
|
}
|
2006-06-22 01:10:50 +00:00
|
|
|
|
2006-12-02 03:48:36 +00:00
|
|
|
if (genericConstraint)
|
|
|
|
{
|
|
|
|
//m_constraints.push_back(genericConstraint);
|
|
|
|
m_dynamicsWorld->addConstraint(genericConstraint);
|
|
|
|
genericConstraint->setUserConstraintId(gConstraintUid++);
|
|
|
|
genericConstraint->setUserConstraintType(type);
|
|
|
|
//64 bit systems can't cast pointer to int. could use size_t instead.
|
|
|
|
return genericConstraint->getUserConstraintId();
|
|
|
|
}
|
2006-11-21 00:53:40 +00:00
|
|
|
|
2007-07-16 05:56:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PHY_CONE_TWIST_CONSTRAINT:
|
|
|
|
{
|
|
|
|
btConeTwistConstraint* coneTwistContraint = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (rb1)
|
|
|
|
{
|
|
|
|
btTransform frameInA;
|
|
|
|
btTransform frameInB;
|
|
|
|
|
|
|
|
btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z);
|
|
|
|
if (axis1.length() == 0.0)
|
|
|
|
{
|
|
|
|
btPlaneSpace1( axisInA, axis1, axis2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
|
|
|
|
axisInA.y(), axis1.y(), axis2.y(),
|
|
|
|
axisInA.z(), axis1.z(), axis2.z() );
|
|
|
|
frameInA.setOrigin( pivotInA );
|
|
|
|
|
|
|
|
btTransform inv = rb1->getCenterOfMassTransform().inverse();
|
|
|
|
|
|
|
|
btTransform globalFrameA = rb0->getCenterOfMassTransform() * frameInA;
|
|
|
|
|
|
|
|
frameInB = inv * globalFrameA;
|
|
|
|
|
|
|
|
coneTwistContraint = new btConeTwistConstraint( *rb0,*rb1,
|
|
|
|
frameInA,frameInB);
|
|
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
static btRigidBody s_fixedObject2( 0,0,0);
|
|
|
|
btTransform frameInA;
|
|
|
|
btTransform frameInB;
|
|
|
|
|
|
|
|
btVector3 axis1, axis2;
|
|
|
|
btPlaneSpace1( axisInA, axis1, axis2 );
|
|
|
|
|
|
|
|
frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
|
|
|
|
axisInA.y(), axis1.y(), axis2.y(),
|
|
|
|
axisInA.z(), axis1.z(), axis2.z() );
|
|
|
|
|
|
|
|
frameInA.setOrigin( pivotInA );
|
|
|
|
|
|
|
|
///frameInB in worldspace
|
|
|
|
frameInB = rb0->getCenterOfMassTransform() * frameInA;
|
|
|
|
|
|
|
|
coneTwistContraint = new btConeTwistConstraint(
|
|
|
|
*rb0,s_fixedObject2,
|
|
|
|
frameInA,frameInB);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coneTwistContraint)
|
|
|
|
{
|
|
|
|
//m_constraints.push_back(genericConstraint);
|
|
|
|
m_dynamicsWorld->addConstraint(coneTwistContraint);
|
|
|
|
coneTwistContraint->setUserConstraintId(gConstraintUid++);
|
|
|
|
coneTwistContraint->setUserConstraintType(type);
|
|
|
|
//64 bit systems can't cast pointer to int. could use size_t instead.
|
|
|
|
return coneTwistContraint->getUserConstraintId();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PHY_ANGULAR_CONSTRAINT:
|
|
|
|
angularOnly = true;
|
|
|
|
|
|
|
|
|
|
|
|
case PHY_LINEHINGE_CONSTRAINT:
|
|
|
|
{
|
|
|
|
btHingeConstraint* hinge = 0;
|
|
|
|
|
|
|
|
if (rb1)
|
|
|
|
{
|
2007-01-19 03:14:51 +00:00
|
|
|
btVector3 axisInB = rb1 ?
|
|
|
|
(rb1->getCenterOfMassTransform().getBasis().inverse()*(rb0->getCenterOfMassTransform().getBasis() * axisInA)) :
|
|
|
|
rb0->getCenterOfMassTransform().getBasis() * axisInA;
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
hinge = new btHingeConstraint(
|
|
|
|
*rb0,
|
|
|
|
*rb1,pivotInA,pivotInB,axisInA,axisInB);
|
|
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
hinge = new btHingeConstraint(*rb0,
|
|
|
|
pivotInA,axisInA);
|
|
|
|
|
2006-04-28 00:08:18 +00:00
|
|
|
}
|
2006-11-21 00:53:40 +00:00
|
|
|
hinge->setAngularOnly(angularOnly);
|
2006-05-22 21:03:43 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
//m_constraints.push_back(hinge);
|
|
|
|
m_dynamicsWorld->addConstraint(hinge);
|
|
|
|
hinge->setUserConstraintId(gConstraintUid++);
|
|
|
|
hinge->setUserConstraintType(type);
|
|
|
|
//64 bit systems can't cast pointer to int. could use size_t instead.
|
|
|
|
return hinge->getUserConstraintId();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef NEW_BULLET_VEHICLE_SUPPORT
|
2006-05-22 21:03:43 +00:00
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
case PHY_VEHICLE_CONSTRAINT:
|
|
|
|
{
|
|
|
|
btRaycastVehicle::btVehicleTuning* tuning = new btRaycastVehicle::btVehicleTuning();
|
|
|
|
btRigidBody* chassis = rb0;
|
|
|
|
btDefaultVehicleRaycaster* raycaster = new btDefaultVehicleRaycaster(m_dynamicsWorld);
|
|
|
|
btRaycastVehicle* vehicle = new btRaycastVehicle(*tuning,chassis,raycaster);
|
|
|
|
WrapperVehicle* wrapperVehicle = new WrapperVehicle(vehicle,ctrl0);
|
|
|
|
m_wrapperVehicles.push_back(wrapperVehicle);
|
|
|
|
m_dynamicsWorld->addVehicle(vehicle);
|
|
|
|
vehicle->setUserConstraintId(gConstraintUid++);
|
|
|
|
vehicle->setUserConstraintType(type);
|
|
|
|
return vehicle->getUserConstraintId();
|
|
|
|
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
#endif //NEW_BULLET_VEHICLE_SUPPORT
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB
|
|
|
|
|
|
|
|
return 0;
|
2006-05-22 21:03:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-21 00:53:40 +00:00
|
|
|
|
2006-05-22 21:03:43 +00:00
|
|
|
PHY_IPhysicsController* CcdPhysicsEnvironment::CreateConeController(float coneradius,float coneheight)
|
|
|
|
{
|
|
|
|
CcdConstructionInfo cinfo;
|
2008-08-21 15:19:54 +00:00
|
|
|
|
|
|
|
// we don't need a CcdShapeConstructionInfo for this shape:
|
|
|
|
// it is simple enough for the standard copy constructor (see CcdPhysicsController::GetReplica)
|
2006-11-21 00:53:40 +00:00
|
|
|
cinfo.m_collisionShape = new btConeShape(coneradius,coneheight);
|
2006-05-22 21:03:43 +00:00
|
|
|
cinfo.m_MotionState = 0;
|
|
|
|
cinfo.m_physicsEnv = this;
|
2006-12-01 01:04:27 +00:00
|
|
|
cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE;
|
2006-05-22 21:03:43 +00:00
|
|
|
DefaultMotionState* motionState = new DefaultMotionState();
|
|
|
|
cinfo.m_MotionState = motionState;
|
2008-03-01 19:17:37 +00:00
|
|
|
|
|
|
|
// we will add later the possibility to select the filter from option
|
|
|
|
cinfo.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter;
|
|
|
|
cinfo.m_collisionFilterGroup = CcdConstructionInfo::SensorFilter;
|
2006-05-22 21:03:43 +00:00
|
|
|
motionState->m_worldTransform.setIdentity();
|
2006-11-21 00:53:40 +00:00
|
|
|
// motionState->m_worldTransform.setOrigin(btVector3(position[0],position[1],position[2]));
|
2006-05-22 21:03:43 +00:00
|
|
|
|
|
|
|
CcdPhysicsController* sphereController = new CcdPhysicsController(cinfo);
|
|
|
|
|
|
|
|
|
|
|
|
return sphereController;
|
|
|
|
}
|
|
|
|
|
2006-08-28 06:44:29 +00:00
|
|
|
float CcdPhysicsEnvironment::getAppliedImpulse(int constraintid)
|
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
int i;
|
|
|
|
int numConstraints = m_dynamicsWorld->getNumConstraints();
|
|
|
|
for (i=0;i<numConstraints;i++)
|
2006-08-28 06:44:29 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
btTypedConstraint* constraint = m_dynamicsWorld->getConstraint(i);
|
|
|
|
if (constraint->getUserConstraintId() == constraintid)
|
2006-08-28 06:44:29 +00:00
|
|
|
{
|
2006-11-21 00:53:40 +00:00
|
|
|
return constraint->getAppliedImpulse();
|
2006-08-28 06:44:29 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-21 00:53:40 +00:00
|
|
|
|
2006-08-28 06:44:29 +00:00
|
|
|
return 0.f;
|
|
|
|
}
|