#ifndef __C_SCENE_COLLISION_MANAGER_H_INCLUDED__
#define __C_SCENE_COLLISION_MANAGER_H_INCLUDED__
#include "ISceneCollisionManager.h"
#include "ISceneManager.h"
#include "IVideoDriver.h"
namespace irr
{
namespace scene
{
class CSceneCollisionManager : public ISceneCollisionManager
{
public:
CSceneCollisionManager(ISceneManager* smanager, video::IVideoDriver* driver);
virtual ~CSceneCollisionManager();
virtual ISceneNode* getSceneNodeFromScreenCoordinatesBB(const core::position2d<s32>& pos,
s32 idBitMask=0, bool bNoDebugObjects=false, ISceneNode* root=0);
virtual ISceneNode* getSceneNodeFromRayBB(const core::line3d<f32>& ray,
s32 idBitMask=0, bool bNoDebugObjects=false,
ISceneNode* root=0);
virtual ISceneNode* getSceneNodeFromCameraBB(ICameraSceneNode* camera,
s32 idBitMask=0, bool bNoDebugObjects = false);
virtual bool getCollisionPoint(const core::line3d<f32>& ray,
ITriangleSelector* selector, core::vector3df& outCollisionPoint,
core::triangle3df& outTriangle,
ISceneNode* & outNode);
virtual core::vector3df getCollisionResultPosition(
ITriangleSelector* selector,
const core::vector3df &ellipsoidPosition,
const core::vector3df& ellipsoidRadius,
const core::vector3df& ellipsoidDirectionAndSpeed,
core::triangle3df& triout,
core::vector3df& hitPosition,
bool& outFalling,
ISceneNode*& outNode,
f32 slidingSpeed,
const core::vector3df& gravityDirectionAndSpeed);
virtual core::line3d<f32> getRayFromScreenCoordinates(
const core::position2d<s32> & pos, ICameraSceneNode* camera = 0);
virtual core::position2d<s32> getScreenCoordinatesFrom3DPosition(
const core::vector3df & pos, ICameraSceneNode* camera=0, bool useViewPort=false);
virtual ISceneNode* getSceneNodeAndCollisionPointFromRay(
core::line3df ray,
core::vector3df & outCollisionPoint,
core::triangle3df & outTriangle,
s32 idBitMask = 0,
ISceneNode * collisionRootNode = 0,
bool noDebugObjects = false);
private:
void getPickedNodeBB(ISceneNode* root, core::line3df& ray, s32 bits,
bool bNoDebugObjects,
f32& outbestdistance, ISceneNode*& outbestnode);
void getPickedNodeFromBBAndSelector(ISceneNode * root,
core::line3df & ray,
s32 bits,
bool noDebugObjects,
f32 & outBestDistanceSquared,
ISceneNode * & outBestNode,
core::vector3df & outBestCollisionPoint,
core::triangle3df & outBestTriangle);
struct SCollisionData
{
core::vector3df eRadius;
core::vector3df R3Velocity;
core::vector3df R3Position;
core::vector3df velocity;
core::vector3df normalizedVelocity;
core::vector3df basePoint;
bool foundCollision;
f32 nearestDistance;
core::vector3df intersectionPoint;
core::triangle3df intersectionTriangle;
s32 triangleIndex;
s32 triangleHits;
f32 slidingSpeed;
ITriangleSelector* selector;
};
bool testTriangleIntersection(SCollisionData* colData,
const core::triangle3df& triangle);
core::vector3df collideEllipsoidWithWorld(ITriangleSelector* selector,
const core::vector3df &position,
const core::vector3df& radius, const core::vector3df& velocity,
f32 slidingSpeed,
const core::vector3df& gravity, core::triangle3df& triout,
core::vector3df& hitPosition,
bool& outFalling,
ISceneNode*& outNode);
core::vector3df collideWithWorld(s32 recursionDepth, SCollisionData &colData,
core::vector3df pos, core::vector3df vel);
inline bool getLowestRoot(f32 a, f32 b, f32 c, f32 maxR, f32* root);
ISceneManager* SceneManager;
video::IVideoDriver* Driver;
core::array<core::triangle3df> Triangles;
};
}
}
#endif