SO3Engine
OgreNewt_Collision.h
Go to the documentation of this file.
1/*
2 OgreNewt Library
3
4 Ogre implementation of Newton Game Dynamics SDK
5
6 OgreNewt basically has no license, you may use any or all of the library however you desire... I hope it can help you in any way.
7
8 by Walaber
9 some changes by melven
10
11*/
12#ifndef _INCLUDE_OGRENEWT_COLLISION
13#define _INCLUDE_OGRENEWT_COLLISION
14
15
17
18
19// OgreNewt namespace. all functions and classes use this namespace.
20namespace OgreNewt
21{
22
23
25 {
26 BoxPrimitiveType = SERIALIZE_ID_BOX,
27 ConePrimitiveType = SERIALIZE_ID_CONE,
28 EllipsoidPrimitiveType = SERIALIZE_ID_SPHERE,
29 CapsulePrimitiveType = SERIALIZE_ID_CAPSULE,
30 CylinderPrimitiveType = SERIALIZE_ID_CYLINDER,
31 CompoundCollisionPrimitiveType = SERIALIZE_ID_COMPOUND,
32 ConvexHullPrimitiveType = SERIALIZE_ID_CONVEXHULL,
33 ChamferCylinderPrimitiveType = SERIALIZE_ID_CHAMFERCYLINDER,
34 TreeCollisionPrimitiveType = SERIALIZE_ID_TREE,
35 NullPrimitiveType = SERIALIZE_ID_NULL,
36 HeighFieldPrimitiveType = SERIALIZE_ID_HEIGHTFIELD,
37 ScenePrimitiveType = SERIALIZE_ID_SCENE
38 };
39
40 /*
41 CLASS DEFINITION:
42
43 Collision
44
45 USE:
46 this class represents a NewtonCollision, which is the newton structure
47 for collision geometry.
48 */
50 class _OgreNewtExport Collision
51 {
52 public:
54 Collision(const World* world);
55
57 Collision(const Collision& shape);
58
60 Collision(const NewtonCollision* collision, const World* world);
61
62
64 virtual ~Collision();
65
67
70 NewtonCollision* const getNewtonCollision() const { return m_col; }
71
75 const World* getWorld() const { return m_world; }
76
77 // this is not possible any more (since newton 2.04), you can only set the id when creating the collision
78 // //! set a user ID for collision callback identification
79 // /*!
80 // you can set different IDs for each piece in a compound collision object, and then use these IDs in a collision callback to
81 // determine which part is currently colliding.
82 // */
83 // void setUserID( unsigned id ) const { NewtonCollisionSetUserID( m_col, id); }
84
86 unsigned getUserID() const { return NewtonCollisionGetUserID(m_col); }
87
89
92 Ogre::AxisAlignedBox getAABB(const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY, const Ogre::Vector3& pos = Ogre::Vector3::ZERO) const;
93
96
98 static CollisionPrimitiveType getCollisionPrimitiveType(const NewtonCollision *col);
99
101 NewtonCollisionInfoRecord* getInfo() { return getInfo(m_col); }
102
104 static NewtonCollisionInfoRecord* getInfo(const NewtonCollision *col);
105
108 //friend void CollisionSerializer::exportCollision(const CollisionPtr& collision, const Ogre::String& filename);
109 //friend CollisionPtr CollisionSerializer::importCollision(Ogre::DataStreamPtr& stream, OgreNewt::World* world);
110
111 protected:
112 NewtonCollision* m_col;
114
115 };
116
117
118
120 class _OgreNewtExport ConvexCollision : public Collision
121 {
122 public:
124 ConvexCollision(const World* world);
125
127 ConvexCollision(const Collision& convexShape);
128
130 ConvexCollision(const ConvexCollision& convexShape);
131
134
136 Ogre::Real calculateVolume() const { return (Ogre::Real)NewtonConvexCollisionCalculateVolume(m_col); }
137
139 void calculateInertialMatrix(Ogre::Vector3& inertia, Ogre::Vector3& offset) const
140 {
141 dVector iner;
142 dVector off;
143 NewtonConvexCollisionCalculateInertialMatrix(m_col, &iner.m_x, &off.m_x);
144
145 inertia.x = Ogre::Real(iner.m_x);
146 inertia.y = Ogre::Real(iner.m_y);
147 inertia.z = Ogre::Real(iner.m_z);
148 offset.x = Ogre::Real(off.m_x);
149 offset.y = Ogre::Real(off.m_y);
150 offset.z = Ogre::Real(off.m_z);
151 }
152 };
153
154
155#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR
158#else
159 typedef std::shared_ptr<Collision> CollisionPtr;
160 typedef std::shared_ptr<ConvexCollision> ConvexCollisionPtr;
161#endif
162
163} // end NAMESPACE OgreNewt
164
165#endif
166// _INCLUDE_OGRENEWT_COLLISION
167
represents a shape for collision detection
NewtonCollision * m_col
CollisionPrimitiveType getCollisionPrimitiveType() const
Returns the Collisiontype for this Collision.
NewtonCollisionInfoRecord * getInfo()
Returns collision info record for this collision.
const World * getWorld() const
NewtonCollision *const getNewtonCollision() const
retrieve the Newton pointer
represents a collision shape that is explicitly convex.
void calculateInertialMatrix(Ogre::Vector3 &inertia, Ogre::Vector3 &offset) const
calculate the moment of inertia for this collision primitive, along with the theoretical center-of-ma...
Ogre::Real calculateVolume() const
calculate the volume of the collision shape, useful for buoyancy calculations.
represents a physics world.
Collision * CollisionPtr
@ CompoundCollisionPrimitiveType
@ ChamferCylinderPrimitiveType
ConvexCollision * ConvexCollisionPtr