1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __C_SCENE_NODE_ANIMATOR_COLLISION_RESPONSE_H_INCLUDED__
6
#define __C_SCENE_NODE_ANIMATOR_COLLISION_RESPONSE_H_INCLUDED__
8
#include "ISceneNodeAnimatorCollisionResponse.h"
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.
23
class CSceneNodeAnimatorCollisionResponse : public ISceneNodeAnimatorCollisionResponse
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);
36
virtual ~CSceneNodeAnimatorCollisionResponse();
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
41
virtual bool isFalling() const;
43
//! Sets the radius of the ellipsoid with which collision detection and
45
virtual void setEllipsoidRadius(const core::vector3df& radius);
47
//! Returns the radius of the ellipsoid with which the collision detection and
49
virtual core::vector3df getEllipsoidRadius() const;
51
//! Sets the gravity of the environment.
52
virtual void setGravity(const core::vector3df& gravity);
54
//! 'Jump' the animator, by adding a jump speed opposite to its gravity
55
virtual void jump(f32 jumpSpeed);
57
//! Should the Target react on collision ( default = true )
58
virtual void setAnimateTarget ( bool enable );
59
virtual bool getAnimateTarget () const;
61
//! Returns current vector of gravity.
62
virtual core::vector3df getGravity() const;
64
//! Sets the translation of the ellipsoid for collision detection.
65
virtual void setEllipsoidTranslation(const core::vector3df &translation);
67
//! Returns the translation of the ellipsoid for collision detection.
68
virtual core::vector3df getEllipsoidTranslation() const;
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);
74
//! Returns the current triangle selector containing all triangles for
75
//! collision detection.
76
virtual ITriangleSelector* getWorld() const;
78
//! animates a scene node
79
virtual void animateNode(ISceneNode* node, u32 timeMs);
81
//! Writes attributes of the scene node animator.
82
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const;
84
//! Reads attributes of the scene node animator.
85
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
87
//! Returns type of the scene node animator
88
virtual ESCENE_NODE_ANIMATOR_TYPE getType() const { return ESNAT_COLLISION_RESPONSE; }
90
//! Creates a clone of this animator.
91
/** Please note that you will have to drop
92
(IReferenceCounted::drop()) the returned pointer after calling
94
virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0);
96
//! Set the single node that this animator will act on.
97
virtual void setTargetNode(ISceneNode * node) { setNode(node); }
99
//! Gets the single node that this animator is acting on.
100
virtual ISceneNode* getTargetNode(void) const { return Object; }
102
//! Returns true if a collision occurred during the last animateNode()
103
virtual bool collisionOccurred() const { return CollisionOccurred; }
105
//! Returns the last point of collision.
106
virtual const core::vector3df & getCollisionPoint() const { return CollisionPoint; }
108
//! Returns the last triangle that caused a collision.
109
virtual const core::triangle3df & getCollisionTriangle() const { return CollisionTriangle; }
111
virtual const core::vector3df & getCollisionResultPosition(void) const { return CollisionResultPosition; }
113
virtual ISceneNode* getCollisionNode(void) const { return CollisionNode; }
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.
120
virtual void setCollisionCallback(ICollisionCallback* callback);
124
void setNode(ISceneNode* node);
126
core::vector3df Radius;
127
core::vector3df Gravity;
128
core::vector3df Translation;
129
core::vector3df FallingVelocity; // In the direction of Gravity.
131
core::vector3df LastPosition;
132
core::triangle3df RefTriangle;
134
ITriangleSelector* World;
136
ISceneManager* SceneManager;
140
core::vector3df CollisionPoint;
141
core::triangle3df CollisionTriangle;
142
core::vector3df CollisionResultPosition;
143
ISceneNode * CollisionNode;
144
ICollisionCallback* CollisionCallback;
148
bool AnimateCameraTarget;
149
bool CollisionOccurred;
153
} // end namespace scene
154
} // end namespace irr