Project

General

Profile

SO3Engine
OgreNewt_RayCast.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
13#ifndef _INCLUDE_OGRENEWT_RAYCAST
14#define _INCLUDE_OGRENEWT_RAYCAST
15
16
19
20// OgreNewt namespace. all functions and classes use this namespace.
21namespace OgreNewt
22{
23
24
26
29class _OgreNewtExport Raycast
30{
31public:
32
34 Raycast();
35
37 virtual ~Raycast();
38
40
46 void go( const OgreNewt::World* world, const Ogre::Vector3& startpt, const Ogre::Vector3& endpt );
47
48
50
54 virtual bool userPreFilterCallback( OgreNewt::Body* body ) { return true; }
55
57
64 virtual bool userCallback( OgreNewt::Body* body, Ogre::Real distance, const Ogre::Vector3& normal, dLong collisionID ) = 0;
65
66 //Newton >= 2.30
67 friend dFloat CollisionPrimitives::TreeCollision::newtonRayCastCallback(const NewtonBody* const body, const NewtonCollision* const treeCollision, dFloat distance, dFloat *normal, int faceId, void *userData);
68 //friend float CollisionPrimitives::TreeCollision::newtonRayCastCallback(float distance, float *normal, int faceId, void *userData);
69protected:
72
75
76private:
77
79 static float newtonRaycastFilter(const NewtonBody* body, const NewtonCollision* const shapeHit, const dFloat* const hitContact, const dFloat* hitNormal, dLong collisionID, void* userData, dFloat intersectParam);
80
82 static unsigned newtonRaycastPreFilter( const NewtonBody* body, const NewtonCollision* collision, void* userData);
83};
84
85
86
87
89
92class _OgreNewtExport BasicRaycast : public Raycast
93{
94public:
96 class _OgreNewtExport BasicRaycastInfo
97 {
98 public:
101
102 Ogre::Real getDistance() { return mDistance; };
103 OgreNewt::Body* getBody() { return mBody; };
104 dLong getCollisionId() { return mCollisionID; };
105 Ogre::Vector3 getNormal() { return mNormal; };
106 Ogre::Quaternion getNormalOrientation() { return OgreNewt::Converters::grammSchmidt(mNormal); };
107
108 Ogre::Real mDistance;
111 Ogre::Vector3 mNormal;
112
113 bool operator<(const BasicRaycastInfo& rhs) const
114 {
115 return mDistance < rhs.mDistance;
116 }
117 };
118
119
121 BasicRaycast();
122
124
131 BasicRaycast( const OgreNewt::World* world, const Ogre::Vector3& startpt, const Ogre::Vector3& endpt, bool sorted);
132
134
141 void go( const OgreNewt::World* world, const Ogre::Vector3& startpt, const Ogre::Vector3& endpt, bool sorted);
142
145
147 bool userCallback( Body* body, Ogre::Real distance, const Ogre::Vector3& normal, dLong collisionID );
148
149 // ------------------------------------------------------
150 // the following functions can be used to retrieve information about the bodies collided by the ray.
151
153 int getHitCount() const;
154
156 BasicRaycastInfo getInfoAt( unsigned int hitnum ) const;
157
159 BasicRaycastInfo getFirstHit() const;
160
161private:
162
163
164 // container for results.
165 typedef std::vector<BasicRaycastInfo> RaycastInfoList;
166
167 RaycastInfoList mRayList;
168};
169
170
171} // end NAMESPACE OgreNewt
172
173
174
175
176
177#endif // _INCLUDE_OGRENEWT_RAYCAST
178
simple class that represents a single raycast rigid body intersection.
Ogre::Real mDistance
dist from point1 of the raycast, in range [0,1].
bool operator<(const BasicRaycastInfo &rhs) const
OgreNewt::Body * mBody
pointer to body intersected with
Ogre::Vector3 mNormal
normal of intersection.
dLong mCollisionID
collision ID of the primitive hit by the ray (for compound collision bodies)
Basic implementation of the raycast.
main class for all Rigid Bodies in the system.
general raycast
bool m_treecollisioncallback_bodyalreadyadded
save if this body was already added by RayCastCallback from TreeCollision
OgreNewt::Body * m_treecollisioncallback_lastbody
save the last OgreNewt::Body from the newtonRaycastPreFilter to use this for example the TreeCollisio...
virtual bool userCallback(OgreNewt::Body *body, Ogre::Real distance, const Ogre::Vector3 &normal, dLong collisionID)=0
user callback filter function
virtual bool userPreFilterCallback(OgreNewt::Body *body)
user callback pre-filter function.
represents a physics world.
_OgreNewtExport Ogre::Quaternion grammSchmidt(const Ogre::Vector3 &pin)