00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef PHY_GEOM_H
00028 #define PHY_GEOM_H
00029
00030 #include <PVLE/Config.h>
00031 #include <PVLE/Export.h>
00032 #include <PVLE/Util/Assert.h>
00033
00034 #include <PVLE/Physics/AbstractGeom.h>
00035 #include <PVLE/Physics/Body.h>
00036 #include <PVLE/Physics/GeometryHandlers.h>
00037 #include <PVLE/Physics/Converters.h>
00038 #include <PVLE/Physics/SurfaceParams.h>
00039
00040 #include <osg/Vec3>
00041 #include <osg/Vec3d>
00042 #include <osg/Quat>
00043 #include <osg/Matrix>
00044
00045
00046
00047 inline void dGeomSetPosition(dGeomID id, const osg::Vec3 & pos) { dGeomSetPosition(id, pos.x(), pos.y(), pos.z()); }
00048 inline osg::Vec3 dGeomGetPositionV(dGeomID id) { return Physics::toGraphVec3(dGeomGetPosition(id)); }
00049 inline void dGeomSetQuaternion(dGeomID id, const osg::Quat & quat) { dQuaternion q; Physics::toPhyQuat(quat, q); dGeomSetQuaternion(id, q); }
00050 inline osg::Quat dGeomGetQuaternionV(dGeomID id) { dQuaternion res; dGeomGetQuaternion(id, res); return Physics::toGraphQuat(res);}
00051 inline void dGeomSetRotation(dGeomID id, const osg::Matrix & matrix) { dMatrix3 rot; Physics::toPhyMatRotation(matrix, rot); dGeomSetRotation(id, rot); }
00052 inline osg::Matrix dGeomGetRotationV(dGeomID id, const osg::Matrix & matrix) { return Physics::toGraphMatRotation(dGeomGetRotation(id)); }
00053
00054 inline void dGeomSetOffsetPosition(dGeomID id, const osg::Vec3 & offset) { dGeomSetOffsetPosition(id, offset.x(), offset.y(), offset.z()); }
00055 inline void dGeomSetOffsetWorldPosition(dGeomID id, const osg::Vec3 & worldPos) { dGeomSetOffsetWorldPosition(id, worldPos.x(), worldPos.y(), worldPos.z()); }
00056 inline osg::Vec3 dGeomGetOffsetPositionV(dGeomID id) { return Physics::toGraphVec3(dGeomGetOffsetPosition(id)); }
00057 inline void dGeomSetOffsetQuaternion(dGeomID id, const osg::Quat & offsetQuat) { dQuaternion q; Physics::toPhyQuat(offsetQuat, q); dGeomSetOffsetQuaternion(id, q); }
00058 inline void dGeomSetOffsetWorldQuaternion(dGeomID id, const osg::Quat & worldQuat) { dQuaternion q; Physics::toPhyQuat(worldQuat, q); dGeomSetOffsetWorldQuaternion(id, q); }
00059 inline osg::Quat dGeomGetOffsetQuaternionV(dGeomID id) { dQuaternion q; dGeomGetOffsetQuaternion(id, q); return Physics::toGraphQuat(q); }
00060 inline void dGeomSetOffsetRotation(dGeomID id, const osg::Matrix & matrix) { dMatrix3 rot; Physics::toPhyMatRotation(matrix, rot); dGeomSetOffsetRotation(id, rot); }
00061 inline void dGeomSetOffsetWorldRotation(dGeomID id, const osg::Matrix & worldMatrix) { dMatrix3 rot; Physics::toPhyMatRotation(worldMatrix, rot); dGeomSetOffsetWorldRotation(id, rot); }
00062 inline osg::Matrix dGeomGetOffsetRotationV(dGeomID id) { return Physics::toGraphMatRotation(dGeomGetOffsetRotation(id)); }
00063
00064
00065
00066 class IGeomCollisionContainer;
00067
00068 namespace Physics {
00069
00070 class Visitor;
00071 class Contact;
00072
00073 #ifdef PVLE_PHYSICS_KEEP_DEPRECATED_TRANSFORMS
00074 class Transform;
00075 #endif
00076
00087 class PVLE_EXPORT Geom : public AbstractGeom {
00088 public:
00090
00091 Geom(GeometryHandler * pGeometryHandler, const SurfaceParams & surfaceParams = Materials::DEFAULT);
00092
00093 Geom(const Geom & v, UINT opts = COPY_ALL, IGeomCollisionContainer * pContainer = NULL, TDuplicatedBodiesMap * pDuplicatedBodies = NULL);
00094
00095 virtual Geom * asGeom() { return this; }
00096 virtual const Geom * asGeom() const { return this; }
00097
00099 GeometryHandler * getHandler() { return pGeomH.get(); }
00100 const GeometryHandler * getHandler() const { return pGeomH.get(); }
00101
00114 void setBody(Body * pBody);
00115 inline Body * getBody() { return pBody.get(); }
00116 inline const Body * getBody() const { return pBody.get(); }
00117
00120 void resetAndApplyHints();
00121
00122 #ifdef PVLE_PHYSICS_KEEP_DEPRECATED_TRANSFORMS
00123 virtual Transform * asTransform() { return NULL; }
00124 #endif
00125
00130 #ifdef ENABLE_PHYSICS_BASIC_WRAPPING
00131 void setPos(const osg::Vec3 & pos) { dGeomSetPosition(id, pos.x(), pos.y(), pos.z()); }
00132 osg::Vec3 getPos() const { return toGraphVec3(dGeomGetPosition(id)); }
00133 #endif
00134 void translate(const osg::Vec3 & vec) { const dReal * v = dGeomGetPosition(id); dGeomSetPosition(id, v[0] + vec.x(), v[1] + vec.y(), v[2] + vec.z()); }
00135
00136 #ifdef ENABLE_PHYSICS_BASIC_WRAPPING
00137 void setQuaternion(const osg::Quat & quat) { dQuaternion q; toPhyQuat(quat, q); dGeomSetQuaternion(id, q); }
00138 osg::Quat getQuaternion() const { dQuaternion q; dGeomGetQuaternion(id, q); return toGraphQuat(q); }
00139 #endif
00141 void rotate(const osg::Quat & quat) { dGeomSetQuaternion(id, dGeomGetQuaternionV(id) * quat); }
00143 void rotate(const osg::Quat & quat, const osg::Vec3 & center) {
00144 setMatrix(getMatrix() * osg::Matrix::translate(-center) * osg::Matrix::rotate(quat) * osg::Matrix::translate(center));
00145 }
00146
00148 void setMatrix(const osg::Matrix & matrix) {
00149 dGeomSetPosition(id, matrix.getTrans());
00150 dGeomSetRotation(id, matrix);
00151 }
00153 #ifdef PVLE_PHYSICS_KEEP_DEPRECATED_TRANSFORMS
00154 virtual
00155 #endif
00156 osg::Matrix getMatrix() const { return toGraphMatRotationPosition(dGeomGetRotation(id), dGeomGetPosition(id)); }
00158
00163
00164 #ifdef ENABLE_PHYSICS_BASIC_WRAPPING
00166 void setOffsetPos(const osg::Vec3 & offset) { dGeomSetOffsetPosition(id, offset.x(), offset.y(), offset.z()); }
00168 void setOffsetPosWorld(const osg::Vec3 & worldPos) { dGeomSetOffsetWorldPosition(id, worldPos.x(), worldPos.y(), worldPos.z()); }
00170 osg::Vec3 getOffsetPos() const { return toGraphVec3(dGeomGetOffsetPosition(id)); }
00171 #endif
00173 void translateOffset(const osg::Vec3 & offset) { const dReal * curpos = dGeomGetOffsetPosition(id); dGeomSetOffsetPosition(id, curpos[0] + offset.x(), curpos[1] + offset.y(), curpos[2] + offset.z()); }
00174
00175 #ifdef ENABLE_PHYSICS_BASIC_WRAPPING
00177 void setOffsetQuaternion(const osg::Quat & offsetQuat) { dQuaternion q; toPhyQuat(offsetQuat, q); dGeomSetOffsetQuaternion(id, q); }
00179 void setOffsetQuaternionWorld(const osg::Quat & worldQuat) { dQuaternion q; toPhyQuat(worldQuat, q); dGeomSetOffsetWorldQuaternion(id, q); }
00181 osg::Quat getOffsetQuaternion() const { dQuaternion q; dGeomGetOffsetQuaternion(id, q); return toGraphQuat(q); }
00182 #endif
00185 void rotateOffset(const osg::Quat & offsetQuat) { dGeomSetOffsetQuaternion(id, dGeomGetOffsetQuaternionV(id) * offsetQuat); }
00186
00188 void setOffsetMatrix(const osg::Matrix & offsetMatrix) {
00189 dGeomSetOffsetPosition(id, offsetMatrix.getTrans());
00190 dGeomSetOffsetRotation(id, offsetMatrix);
00191 }
00193 void setOffsetMatrixWorld(const osg::Matrix & worldMatrix) {
00194 dGeomSetOffsetWorldPosition(id, worldMatrix.getTrans());
00195 dGeomSetOffsetWorldRotation(id, worldMatrix);
00196 }
00198 void multOffset(const osg::Matrix & offsetMatrix) { setOffsetMatrix(getOffsetMatrix() * offsetMatrix); }
00200 osg::Matrix getOffsetMatrix() const { return toGraphMatRotationPosition(dGeomGetOffsetRotation(id), dGeomGetOffsetPosition(id)); }
00201
00202 #ifdef ENABLE_PHYSICS_EXTRA_WRAPPING
00204 void clearOffset() { dGeomClearOffset(id); }
00206 bool isOffset() const { return dGeomIsOffset(id) != 0; }
00207 #endif
00209
00212
00214 SurfaceParams surface;
00215
00217 IGeomCollisionContainer * getCollisionContainer() { return pContainer; }
00219 void setCollisionContainer(IGeomCollisionContainer * pContainer) { this->pContainer = pContainer; }
00220
00223 void setGameplayDensity(float density) { gameplayDensity = density; }
00224 float getGameplayDensity() { return gameplayDensity; }
00226
00229
00231 UINT collide(Geom * pGeom, UINT nbMaxContacts, Contact * pContacts);
00232
00233 #ifdef ENABLE_PHYSICS_BASIC_WRAPPING
00237 void setCategoryBits(ULONG mask) { return dGeomSetCategoryBits(id, mask); }
00240 ULONG getCategoryBits() const { return dGeomGetCategoryBits(id); }
00241 #endif
00243 void addCategoryBits(ULONG mask) { return dGeomSetCategoryBits(id, dGeomGetCategoryBits(id) | mask); }
00245 void removeCategoryBits(ULONG mask) { return dGeomSetCategoryBits(id, dGeomGetCategoryBits(id) & ~mask); }
00246 #ifdef ENABLE_PHYSICS_BASIC_WRAPPING
00250 void setCollideBits(ULONG mask) { return dGeomSetCollideBits(id, mask); }
00253 ULONG getCollideBits() const { return dGeomGetCollideBits(id); }
00254 #endif
00256 void addCollideBits(ULONG mask) { return dGeomSetCollideBits(id, dGeomGetCollideBits(id) | mask); }
00258 void removeCollideBits(ULONG mask) { return dGeomSetCollideBits(id, dGeomGetCollideBits(id) & ~mask); }
00260
00261 virtual void accept(Visitor & v);
00262 virtual void traverse(Visitor & v);
00263
00264 operator dGeomID() { return id; }
00265 operator const dGeomID() const { return id; }
00266
00267 protected:
00268 #ifdef PVLE_PHYSICS_KEEP_DEPRECATED_TRANSFORMS
00270 Geom();
00271 #endif
00272 void applyHints();
00273
00274 osg::ref_ptr<Body> pBody;
00275 osg::ref_ptr<GeometryHandler> pGeomH;
00276
00277 IGeomCollisionContainer * pContainer;
00278 float gameplayDensity;
00279 };
00280
00281 }
00282
00283
00309 #endif // PHY_GEOM_H