diff options
Diffstat (limited to 'libraries/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorCollisionResponse.h')
-rw-r--r-- | libraries/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorCollisionResponse.h | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorCollisionResponse.h b/libraries/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorCollisionResponse.h new file mode 100644 index 0000000..42ff71a --- /dev/null +++ b/libraries/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorCollisionResponse.h | |||
@@ -0,0 +1,157 @@ | |||
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_NODE_ANIMATOR_COLLISION_RESPONSE_H_INCLUDED__ | ||
6 | #define __C_SCENE_NODE_ANIMATOR_COLLISION_RESPONSE_H_INCLUDED__ | ||
7 | |||
8 | #include "ISceneNodeAnimatorCollisionResponse.h" | ||
9 | |||
10 | namespace irr | ||
11 | { | ||
12 | namespace scene | ||
13 | { | ||
14 | |||
15 | //! Special scene node animator for doing automatic collision detection and response. | ||
16 | /** This scene node animator can be attached to any scene node modifying it in that | ||
17 | way, that it cannot move through walls of the world, is influenced by gravity and | ||
18 | acceleration. This animator is useful for example for first person shooter | ||
19 | games. Attach it for example to a first person shooter camera, and the camera will | ||
20 | behave as the player control in a first person shooter game: The camera stops and | ||
21 | slides at walls, walks up stairs, falls down if there is no floor under it, and so on. | ||
22 | */ | ||
23 | class CSceneNodeAnimatorCollisionResponse : public ISceneNodeAnimatorCollisionResponse | ||
24 | { | ||
25 | public: | ||
26 | |||
27 | //! constructor | ||
28 | CSceneNodeAnimatorCollisionResponse(ISceneManager* scenemanager, | ||
29 | ITriangleSelector* world, ISceneNode* object, | ||
30 | const core::vector3df& ellipsoidRadius = core::vector3df(30,60,30), | ||
31 | const core::vector3df& gravityPerSecond = core::vector3df(0,-100.0f,0), | ||
32 | const core::vector3df& ellipsoidTranslation = core::vector3df(0,0,0), | ||
33 | f32 slidingSpeed = 0.0005f); | ||
34 | |||
35 | //! destructor | ||
36 | virtual ~CSceneNodeAnimatorCollisionResponse(); | ||
37 | |||
38 | //! Returns if the attached scene node is falling, which means that | ||
39 | //! there is no blocking wall from the scene node in the direction of | ||
40 | //! the gravity. | ||
41 | virtual bool isFalling() const; | ||
42 | |||
43 | //! Sets the radius of the ellipsoid with which collision detection and | ||
44 | //! response is done. | ||
45 | virtual void setEllipsoidRadius(const core::vector3df& radius); | ||
46 | |||
47 | //! Returns the radius of the ellipsoid with which the collision detection and | ||
48 | //! response is done. | ||
49 | virtual core::vector3df getEllipsoidRadius() const; | ||
50 | |||
51 | //! Sets the gravity of the environment. | ||
52 | virtual void setGravity(const core::vector3df& gravity); | ||
53 | |||
54 | //! 'Jump' the animator, by adding a jump speed opposite to its gravity | ||
55 | virtual void jump(f32 jumpSpeed); | ||
56 | |||
57 | //! Should the Target react on collision ( default = true ) | ||
58 | virtual void setAnimateTarget ( bool enable ); | ||
59 | virtual bool getAnimateTarget () const; | ||
60 | |||
61 | //! Returns current vector of gravity. | ||
62 | virtual core::vector3df getGravity() const; | ||
63 | |||
64 | //! Sets the translation of the ellipsoid for collision detection. | ||
65 | virtual void setEllipsoidTranslation(const core::vector3df &translation); | ||
66 | |||
67 | //! Returns the translation of the ellipsoid for collision detection. | ||
68 | virtual core::vector3df getEllipsoidTranslation() const; | ||
69 | |||
70 | //! Sets a triangle selector holding all triangles of the world with which | ||
71 | //! the scene node may collide. | ||
72 | virtual void setWorld(ITriangleSelector* newWorld); | ||
73 | |||
74 | //! Returns the current triangle selector containing all triangles for | ||
75 | //! collision detection. | ||
76 | virtual ITriangleSelector* getWorld() const; | ||
77 | |||
78 | //! animates a scene node | ||
79 | virtual void animateNode(ISceneNode* node, u32 timeMs); | ||
80 | |||
81 | //! Writes attributes of the scene node animator. | ||
82 | virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const; | ||
83 | |||
84 | //! Reads attributes of the scene node animator. | ||
85 | virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0); | ||
86 | |||
87 | //! Returns type of the scene node animator | ||
88 | virtual ESCENE_NODE_ANIMATOR_TYPE getType() const { return ESNAT_COLLISION_RESPONSE; } | ||
89 | |||
90 | //! Creates a clone of this animator. | ||
91 | /** Please note that you will have to drop | ||
92 | (IReferenceCounted::drop()) the returned pointer after calling | ||
93 | this. */ | ||
94 | virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0); | ||
95 | |||
96 | //! Set the single node that this animator will act on. | ||
97 | virtual void setTargetNode(ISceneNode * node) { setNode(node); } | ||
98 | |||
99 | //! Gets the single node that this animator is acting on. | ||
100 | virtual ISceneNode* getTargetNode(void) const { return Object; } | ||
101 | |||
102 | //! Returns true if a collision occurred during the last animateNode() | ||
103 | virtual bool collisionOccurred() const { return CollisionOccurred; } | ||
104 | |||
105 | //! Returns the last point of collision. | ||
106 | virtual const core::vector3df & getCollisionPoint() const { return CollisionPoint; } | ||
107 | |||
108 | //! Returns the last triangle that caused a collision. | ||
109 | virtual const core::triangle3df & getCollisionTriangle() const { return CollisionTriangle; } | ||
110 | |||
111 | virtual const core::vector3df & getCollisionResultPosition(void) const { return CollisionResultPosition; } | ||
112 | |||
113 | virtual ISceneNode* getCollisionNode(void) const { return CollisionNode; } | ||
114 | |||
115 | |||
116 | //! Sets a callback interface which will be called if a collision occurs. | ||
117 | /** \param callback: collision callback handler that will be called when a collision | ||
118 | occurs. Set this to 0 to disable the callback. | ||
119 | */ | ||
120 | virtual void setCollisionCallback(ICollisionCallback* callback); | ||
121 | |||
122 | private: | ||
123 | |||
124 | void setNode(ISceneNode* node); | ||
125 | |||
126 | core::vector3df Radius; | ||
127 | core::vector3df Gravity; | ||
128 | core::vector3df Translation; | ||
129 | core::vector3df FallingVelocity; // In the direction of Gravity. | ||
130 | |||
131 | core::vector3df LastPosition; | ||
132 | core::triangle3df RefTriangle; | ||
133 | |||
134 | ITriangleSelector* World; | ||
135 | ISceneNode* Object; | ||
136 | ISceneManager* SceneManager; | ||
137 | u32 LastTime; | ||
138 | f32 SlidingSpeed; | ||
139 | |||
140 | core::vector3df CollisionPoint; | ||
141 | core::triangle3df CollisionTriangle; | ||
142 | core::vector3df CollisionResultPosition; | ||
143 | ISceneNode * CollisionNode; | ||
144 | ICollisionCallback* CollisionCallback; | ||
145 | |||
146 | bool Falling; | ||
147 | bool IsCamera; | ||
148 | bool AnimateCameraTarget; | ||
149 | bool CollisionOccurred; | ||
150 | bool FirstUpdate; | ||
151 | }; | ||
152 | |||
153 | } // end namespace scene | ||
154 | } // end namespace irr | ||
155 | |||
156 | #endif | ||
157 | |||