2019-12-12 17:32:41 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
2021-08-27 17:55:04 +02:00
|
|
|
#ifndef IRR_C_SCENE_NODE_ANIMATOR_COLLISION_RESPONSE_H_INCLUDED
|
|
|
|
#define IRR_C_SCENE_NODE_ANIMATOR_COLLISION_RESPONSE_H_INCLUDED
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
#include "ISceneNodeAnimatorCollisionResponse.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace scene
|
|
|
|
{
|
|
|
|
|
|
|
|
//! Special scene node animator for doing automatic collision detection and response.
|
|
|
|
/** This scene node animator can be attached to any scene node modifying it in that
|
|
|
|
way, that it cannot move through walls of the world, is influenced by gravity and
|
|
|
|
acceleration. This animator is useful for example for first person shooter
|
|
|
|
games. Attach it for example to a first person shooter camera, and the camera will
|
|
|
|
behave as the player control in a first person shooter game: The camera stops and
|
|
|
|
slides at walls, walks up stairs, falls down if there is no floor under it, and so on.
|
|
|
|
*/
|
|
|
|
class CSceneNodeAnimatorCollisionResponse : public ISceneNodeAnimatorCollisionResponse
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CSceneNodeAnimatorCollisionResponse(ISceneManager* scenemanager,
|
|
|
|
ITriangleSelector* world, ISceneNode* object,
|
|
|
|
const core::vector3df& ellipsoidRadius = core::vector3df(30,60,30),
|
|
|
|
const core::vector3df& gravityPerSecond = core::vector3df(0,-100.0f,0),
|
|
|
|
const core::vector3df& ellipsoidTranslation = core::vector3df(0,0,0),
|
|
|
|
f32 slidingSpeed = 0.0005f);
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~CSceneNodeAnimatorCollisionResponse();
|
|
|
|
|
|
|
|
//! Returns if the attached scene node is falling, which means that
|
|
|
|
//! there is no blocking wall from the scene node in the direction of
|
|
|
|
//! the gravity.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isFalling() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets the radius of the ellipsoid with which collision detection and
|
|
|
|
//! response is done.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setEllipsoidRadius(const core::vector3df& radius) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns the radius of the ellipsoid with which the collision detection and
|
|
|
|
//! response is done.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual core::vector3df getEllipsoidRadius() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets the gravity of the environment.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setGravity(const core::vector3df& gravity) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! 'Jump' the animator, by adding a jump speed opposite to its gravity
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void jump(f32 jumpSpeed) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Should the Target react on collision ( default = true )
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setAnimateTarget ( bool enable ) IRR_OVERRIDE;
|
|
|
|
virtual bool getAnimateTarget () const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns current vector of gravity.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual core::vector3df getGravity() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets the translation of the ellipsoid for collision detection.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setEllipsoidTranslation(const core::vector3df &translation) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns the translation of the ellipsoid for collision detection.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual core::vector3df getEllipsoidTranslation() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Sets a triangle selector holding all triangles of the world with which
|
|
|
|
//! the scene node may collide.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setWorld(ITriangleSelector* newWorld) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns the current triangle selector containing all triangles for
|
|
|
|
//! collision detection.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual ITriangleSelector* getWorld() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! animates a scene node
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void animateNode(ISceneNode* node, u32 timeMs) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Writes attributes of the scene node animator.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Reads attributes of the scene node animator.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns type of the scene node animator
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual ESCENE_NODE_ANIMATOR_TYPE getType() const IRR_OVERRIDE { return ESNAT_COLLISION_RESPONSE; }
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Creates a clone of this animator.
|
|
|
|
/** Please note that you will have to drop
|
|
|
|
(IReferenceCounted::drop()) the returned pointer after calling
|
|
|
|
this. */
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Set the single node that this animator will act on.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setTargetNode(ISceneNode * node) IRR_OVERRIDE { setNode(node); }
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Gets the single node that this animator is acting on.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual ISceneNode* getTargetNode(void) const IRR_OVERRIDE { return Object; }
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns true if a collision occurred during the last animateNode()
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool collisionOccurred() const IRR_OVERRIDE { return CollisionOccurred; }
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns the last point of collision.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual const core::vector3df & getCollisionPoint() const IRR_OVERRIDE { return CollisionPoint; }
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns the last triangle that caused a collision.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual const core::triangle3df & getCollisionTriangle() const IRR_OVERRIDE { return CollisionTriangle; }
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual const core::vector3df & getCollisionResultPosition(void) const IRR_OVERRIDE { return CollisionResultPosition; }
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual ISceneNode* getCollisionNode(void) const IRR_OVERRIDE { return CollisionNode; }
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
//! Sets a callback interface which will be called if a collision occurs.
|
|
|
|
/** \param callback: collision callback handler that will be called when a collision
|
|
|
|
occurs. Set this to 0 to disable the callback.
|
|
|
|
*/
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setCollisionCallback(ICollisionCallback* callback) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void setNode(ISceneNode* node);
|
|
|
|
|
|
|
|
core::vector3df Radius;
|
|
|
|
core::vector3df Gravity;
|
|
|
|
core::vector3df Translation;
|
|
|
|
core::vector3df FallingVelocity; // In the direction of Gravity.
|
|
|
|
|
|
|
|
core::vector3df LastPosition;
|
|
|
|
core::triangle3df RefTriangle;
|
|
|
|
|
|
|
|
ITriangleSelector* World;
|
|
|
|
ISceneNode* Object;
|
|
|
|
ISceneManager* SceneManager;
|
|
|
|
u32 LastTime;
|
|
|
|
f32 SlidingSpeed;
|
|
|
|
|
|
|
|
core::vector3df CollisionPoint;
|
|
|
|
core::triangle3df CollisionTriangle;
|
|
|
|
core::vector3df CollisionResultPosition;
|
|
|
|
ISceneNode * CollisionNode;
|
|
|
|
ICollisionCallback* CollisionCallback;
|
|
|
|
|
|
|
|
bool Falling;
|
|
|
|
bool IsCamera;
|
|
|
|
bool AnimateCameraTarget;
|
|
|
|
bool CollisionOccurred;
|
|
|
|
bool FirstUpdate;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace scene
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif
|