diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CSceneCollisionManager.h')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CSceneCollisionManager.h | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CSceneCollisionManager.h b/libraries/irrlicht-1.8/source/Irrlicht/CSceneCollisionManager.h new file mode 100644 index 0000000..c581a47 --- /dev/null +++ b/libraries/irrlicht-1.8/source/Irrlicht/CSceneCollisionManager.h | |||
@@ -0,0 +1,158 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | ||
2 | // This file is part of the "Irrlicht Engine". | ||
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | ||
4 | |||
5 | #ifndef __C_SCENE_COLLISION_MANAGER_H_INCLUDED__ | ||
6 | #define __C_SCENE_COLLISION_MANAGER_H_INCLUDED__ | ||
7 | |||
8 | #include "ISceneCollisionManager.h" | ||
9 | #include "ISceneManager.h" | ||
10 | #include "IVideoDriver.h" | ||
11 | |||
12 | namespace irr | ||
13 | { | ||
14 | namespace scene | ||
15 | { | ||
16 | |||
17 | //! The Scene Collision Manager provides methods for performing collision tests and picking on scene nodes. | ||
18 | class CSceneCollisionManager : public ISceneCollisionManager | ||
19 | { | ||
20 | public: | ||
21 | |||
22 | //! constructor | ||
23 | CSceneCollisionManager(ISceneManager* smanager, video::IVideoDriver* driver); | ||
24 | |||
25 | //! destructor | ||
26 | virtual ~CSceneCollisionManager(); | ||
27 | |||
28 | //! Returns the scene node, which is currently visible at the given | ||
29 | //! screen coordinates, viewed from the currently active camera. | ||
30 | virtual ISceneNode* getSceneNodeFromScreenCoordinatesBB(const core::position2d<s32>& pos, | ||
31 | s32 idBitMask=0, bool bNoDebugObjects=false, ISceneNode* root=0); | ||
32 | |||
33 | //! Returns the nearest scene node which collides with a 3d ray and | ||
34 | //! whose id matches a bitmask. | ||
35 | virtual ISceneNode* getSceneNodeFromRayBB(const core::line3d<f32>& ray, | ||
36 | s32 idBitMask=0, bool bNoDebugObjects=false, | ||
37 | ISceneNode* root=0); | ||
38 | |||
39 | //! Returns the scene node, at which the overgiven camera is looking at and | ||
40 | //! which id matches the bitmask. | ||
41 | virtual ISceneNode* getSceneNodeFromCameraBB(ICameraSceneNode* camera, | ||
42 | s32 idBitMask=0, bool bNoDebugObjects = false); | ||
43 | |||
44 | //! Finds the collision point of a line and lots of triangles, if there is one. | ||
45 | virtual bool getCollisionPoint(const core::line3d<f32>& ray, | ||
46 | ITriangleSelector* selector, core::vector3df& outCollisionPoint, | ||
47 | core::triangle3df& outTriangle, | ||
48 | ISceneNode* & outNode); | ||
49 | |||
50 | //! Collides a moving ellipsoid with a 3d world with gravity and returns | ||
51 | //! the resulting new position of the ellipsoid. | ||
52 | virtual core::vector3df getCollisionResultPosition( | ||
53 | ITriangleSelector* selector, | ||
54 | const core::vector3df &ellipsoidPosition, | ||
55 | const core::vector3df& ellipsoidRadius, | ||
56 | const core::vector3df& ellipsoidDirectionAndSpeed, | ||
57 | core::triangle3df& triout, | ||
58 | core::vector3df& hitPosition, | ||
59 | bool& outFalling, | ||
60 | ISceneNode*& outNode, | ||
61 | f32 slidingSpeed, | ||
62 | const core::vector3df& gravityDirectionAndSpeed); | ||
63 | |||
64 | //! Returns a 3d ray which would go through the 2d screen coodinates. | ||
65 | virtual core::line3d<f32> getRayFromScreenCoordinates( | ||
66 | const core::position2d<s32> & pos, ICameraSceneNode* camera = 0); | ||
67 | |||
68 | //! Calculates 2d screen position from a 3d position. | ||
69 | virtual core::position2d<s32> getScreenCoordinatesFrom3DPosition( | ||
70 | const core::vector3df & pos, ICameraSceneNode* camera=0, bool useViewPort=false); | ||
71 | |||
72 | //! Gets the scene node and nearest collision point for a ray based on | ||
73 | //! the nodes' id bitmasks, bounding boxes and triangle selectors. | ||
74 | virtual ISceneNode* getSceneNodeAndCollisionPointFromRay( | ||
75 | core::line3df ray, | ||
76 | core::vector3df & outCollisionPoint, | ||
77 | core::triangle3df & outTriangle, | ||
78 | s32 idBitMask = 0, | ||
79 | ISceneNode * collisionRootNode = 0, | ||
80 | bool noDebugObjects = false); | ||
81 | |||
82 | |||
83 | private: | ||
84 | |||
85 | //! recursive method for going through all scene nodes | ||
86 | void getPickedNodeBB(ISceneNode* root, core::line3df& ray, s32 bits, | ||
87 | bool bNoDebugObjects, | ||
88 | f32& outbestdistance, ISceneNode*& outbestnode); | ||
89 | |||
90 | //! recursive method for going through all scene nodes | ||
91 | void getPickedNodeFromBBAndSelector(ISceneNode * root, | ||
92 | core::line3df & ray, | ||
93 | s32 bits, | ||
94 | bool noDebugObjects, | ||
95 | f32 & outBestDistanceSquared, | ||
96 | ISceneNode * & outBestNode, | ||
97 | core::vector3df & outBestCollisionPoint, | ||
98 | core::triangle3df & outBestTriangle); | ||
99 | |||
100 | |||
101 | struct SCollisionData | ||
102 | { | ||
103 | core::vector3df eRadius; | ||
104 | |||
105 | core::vector3df R3Velocity; | ||
106 | core::vector3df R3Position; | ||
107 | |||
108 | core::vector3df velocity; | ||
109 | core::vector3df normalizedVelocity; | ||
110 | core::vector3df basePoint; | ||
111 | |||
112 | bool foundCollision; | ||
113 | f32 nearestDistance; | ||
114 | core::vector3df intersectionPoint; | ||
115 | |||
116 | core::triangle3df intersectionTriangle; | ||
117 | s32 triangleIndex; | ||
118 | s32 triangleHits; | ||
119 | |||
120 | f32 slidingSpeed; | ||
121 | |||
122 | ITriangleSelector* selector; | ||
123 | }; | ||
124 | |||
125 | //! Tests the current collision data against an individual triangle. | ||
126 | /** | ||
127 | \param colData: the collision data. | ||
128 | \param triangle: the triangle to test against. | ||
129 | \return true if the triangle is hit (and is the closest hit), false otherwise */ | ||
130 | bool testTriangleIntersection(SCollisionData* colData, | ||
131 | const core::triangle3df& triangle); | ||
132 | |||
133 | //! recursive method for doing collision response | ||
134 | core::vector3df collideEllipsoidWithWorld(ITriangleSelector* selector, | ||
135 | const core::vector3df &position, | ||
136 | const core::vector3df& radius, const core::vector3df& velocity, | ||
137 | f32 slidingSpeed, | ||
138 | const core::vector3df& gravity, core::triangle3df& triout, | ||
139 | core::vector3df& hitPosition, | ||
140 | bool& outFalling, | ||
141 | ISceneNode*& outNode); | ||
142 | |||
143 | core::vector3df collideWithWorld(s32 recursionDepth, SCollisionData &colData, | ||
144 | core::vector3df pos, core::vector3df vel); | ||
145 | |||
146 | inline bool getLowestRoot(f32 a, f32 b, f32 c, f32 maxR, f32* root); | ||
147 | |||
148 | ISceneManager* SceneManager; | ||
149 | video::IVideoDriver* Driver; | ||
150 | core::array<core::triangle3df> Triangles; // triangle buffer | ||
151 | }; | ||
152 | |||
153 | |||
154 | } // end namespace scene | ||
155 | } // end namespace irr | ||
156 | |||
157 | #endif | ||
158 | |||