blender/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
Benoit Bolsee 3ea1c1b4b6 BGE: new sensor object to generalize Near and Radar sensor, static-static collision capbility.
A new type of "Sensor" physics object is available in the GE for advanced
collision management. It's called Sensor for its similarities with the
physics objects that underlie the Near and Radar sensors.
Like the Near and Radar object it is:
- static and ghost
- invisible by default
- always active to ensure correct collision detection
- capable of detecting both static and dynamic objects
- ignoring collision with their parent
- capable of broadphase filtering based on:
  * Actor option: the collisioning object must have the Actor flag set to be detected
  * property/material: as specified in the collision sensors attached to it
  Broadphase filtering is important for performance reason: the collision points
  will be computed only for the objects that pass the broahphase filter.
- automatically removed from the simulation when no collision sensor is active on it

Unlike the Near and Radar object it can:
- take any shape, including triangle mesh
- be made visible for debugging (just use the Visible actuator)
- have multiple collision sensors using it

Other than that, the sensor objects are ordinary objects. You can move them
freely or parent them. When parented to a dynamic object, they can provide
advanced collision control to this object.

The type of collision capability depends on the shape:
- box, sphere, cylinder, cone, convex hull provide volume detection.
- triangle mesh provides surface detection but you can give some volume
  to the suface by increasing the margin in the Advanced Settings panel.
  The margin applies on both sides of the surface.

Performance tip:
- Sensor objects perform better than Near and Radar: they do less synchronizations
  because of the Scenegraph optimizations and they can have multiple collision sensors
  on them (with different property filtering for example).
- Always prefer simple shape (box, sphere) to complex shape whenever possible.
- Always use broadphase filtering (avoid collision sensor with empty propery/material)
- Use collision sensor only when you need them. When no collision sensor is active
  on the sensor object, it is removed from the simulation and consume no CPU.

Known limitations:
- When running Blender in debug mode, you will see one warning line of the console:
  "warning btCollisionDispatcher::needsCollision: static-static collision!"
  In release mode this message is not printed.
- Collision margin has no effect on sphere, cone and cylinder shape.

Other performance improvements:
- Remove unnecessary interpolation for Near and Radar objects and by extension
  sensor objects.
- Use direct matrix copy instead of quaternion to synchronize orientation.

Other bug fix:
- Fix Near/Radar position error on newly activated objects. This was causing
  several detection problems in YoFrankie
- Fix margin not passed correctly to gImpact shape.
- Disable force/velocity actions on static objects
2009-05-17 12:51:51 +00:00

200 lines
5.6 KiB
C++

/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef KX_CONVERTPHYSICSOBJECTS
#define KX_CONVERTPHYSICSOBJECTS
/* These are defined by the build system... */
//but the build system is broken, because it doesn't allow for 2 or more defines at once.
//Please leave Sumo _AND_ Bullet enabled
//#define USE_SUMO_SOLID // scons defines this
#define USE_BULLET
//#define USE_ODE
//on visual studio 7/8, always enable BULLET for now
//you can have multiple physics engines running anyway, and
//the scons build system doesn't really support this at the moment.
//if you got troubles, just comment out USE_BULLET
#if 1300 <= _MSC_VER
#define USE_BULLET
#endif
class RAS_MeshObject;
class KX_Scene;
struct DerivedMesh;
typedef enum {
KX_BOUNDBOX,
KX_BOUNDSPHERE,
KX_BOUNDCYLINDER,
KX_BOUNDCONE,
KX_BOUNDMESH,
KX_BOUNDPOLYTOPE,
KX_BOUND_DYN_MESH
} KX_BoundBoxClass;
struct KX_BoxBounds
{
float m_center[3];
float m_extends[3];
};
/* Cone/Cylinder */
struct KX_CBounds
{
float m_radius;
float m_height;
};
struct KX_ObjectProperties
{
bool m_dyna;
bool m_softbody;
double m_radius;
bool m_angular_rigidbody;
bool m_in_active_layer;
bool m_ghost;
class KX_GameObject* m_dynamic_parent;
bool m_isactor;
bool m_sensor;
bool m_concave;
bool m_isdeformable;
bool m_disableSleeping;
bool m_hasCompoundChildren;
bool m_isCompoundChild;
/////////////////////////
int m_gamesoftFlag;
float m_soft_linStiff; /* linear stiffness 0..1 */
float m_soft_angStiff; /* angular stiffness 0..1 */
float m_soft_volume; /* volume preservation 0..1 */
int m_soft_viterations; /* Velocities solver iterations */
int m_soft_piterations; /* Positions solver iterations */
int m_soft_diterations; /* Drift solver iterations */
int m_soft_citerations; /* Cluster solver iterations */
float m_soft_kSRHR_CL; /* Soft vs rigid hardness [0,1] (cluster only) */
float m_soft_kSKHR_CL; /* Soft vs kinetic hardness [0,1] (cluster only) */
float m_soft_kSSHR_CL; /* Soft vs soft hardness [0,1] (cluster only) */
float m_soft_kSR_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
float m_soft_kSK_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
float m_soft_kSS_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
float m_soft_kVCF; /* Velocities correction factor (Baumgarte) */
float m_soft_kDP; /* Damping coefficient [0,1] */
float m_soft_kDG; /* Drag coefficient [0,+inf] */
float m_soft_kLF; /* Lift coefficient [0,+inf] */
float m_soft_kPR; /* Pressure coefficient [-inf,+inf] */
float m_soft_kVC; /* Volume conversation coefficient [0,+inf] */
float m_soft_kDF; /* Dynamic friction coefficient [0,1] */
float m_soft_kMT; /* Pose matching coefficient [0,1] */
float m_soft_kCHR; /* Rigid contacts hardness [0,1] */
float m_soft_kKHR; /* Kinetic contacts hardness [0,1] */
float m_soft_kSHR; /* Soft contacts hardness [0,1] */
float m_soft_kAHR; /* Anchors hardness [0,1] */
int m_soft_collisionflags; /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */
int m_soft_numclusteriterations; /* number of iterations to refine collision clusters*/
float m_soft_welding; /* threshold to remove duplicate/nearby vertices */
/////////////////////////
bool m_lockXaxis;
bool m_lockYaxis;
bool m_lockZaxis;
bool m_lockXRotaxis;
bool m_lockYRotaxis;
bool m_lockZRotaxis;
/////////////////////////
double m_margin;
KX_BoundBoxClass m_boundclass;
union {
KX_BoxBounds box;
KX_CBounds c;
} m_boundobject;
};
#ifdef USE_ODE
void KX_ConvertODEEngineObject(KX_GameObject* gameobj,
RAS_MeshObject* meshobj,
KX_Scene* kxscene,
struct PHY_ShapeProps* shapeprops,
struct PHY_MaterialProps* smmaterial,
struct KX_ObjectProperties* objprop);
#endif //USE_ODE
void KX_ConvertDynamoObject(KX_GameObject* gameobj,
RAS_MeshObject* meshobj,
KX_Scene* kxscene,
struct PHY_ShapeProps* shapeprops,
struct PHY_MaterialProps* smmaterial,
struct KX_ObjectProperties* objprop);
#ifdef USE_SUMO_SOLID
void KX_ConvertSumoObject( class KX_GameObject* gameobj,
class RAS_MeshObject* meshobj,
class KX_Scene* kxscene,
struct PHY_ShapeProps* shapeprops,
struct PHY_MaterialProps* smmaterial,
struct KX_ObjectProperties* objprop);
void KX_ClearSumoSharedShapes();
bool KX_ReInstanceShapeFromMesh(RAS_MeshObject* meshobj);
#endif
#ifdef USE_BULLET
void KX_ConvertBulletObject( class KX_GameObject* gameobj,
class RAS_MeshObject* meshobj,
struct DerivedMesh* dm,
class KX_Scene* kxscene,
struct PHY_ShapeProps* shapeprops,
struct PHY_MaterialProps* smmaterial,
struct KX_ObjectProperties* objprop);
void KX_ClearBulletSharedShapes();
//bool KX_ReInstanceShapeFromMesh(RAS_MeshObject* meshobj);
#endif
#endif //KX_CONVERTPHYSICSOBJECTS