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
5 #include "CSceneCollisionManager.h"
6 #include "ICameraSceneNode.h"
7 #include "SViewFrustum.h"
17 CSceneCollisionManager::CSceneCollisionManager(ISceneManager
*smanager
, video::IVideoDriver
*driver
) :
18 SceneManager(smanager
), Driver(driver
)
21 setDebugName("CSceneCollisionManager");
29 CSceneCollisionManager::~CSceneCollisionManager()
35 //! Returns a 3d ray which would go through the 2d screen coordinates.
36 core::line3d
<f32
> CSceneCollisionManager::getRayFromScreenCoordinates(
37 const core::position2d
<s32
> &pos
, const ICameraSceneNode
*camera
)
39 core::line3d
<f32
> ln(0, 0, 0, 0, 0, 0);
45 camera
= SceneManager
->getActiveCamera();
50 const scene::SViewFrustum
*f
= camera
->getViewFrustum();
52 core::vector3df farLeftUp
= f
->getFarLeftUp();
53 core::vector3df lefttoright
= f
->getFarRightUp() - farLeftUp
;
54 core::vector3df uptodown
= f
->getFarLeftDown() - farLeftUp
;
56 const core::rect
<s32
> &viewPort
= Driver
->getViewPort();
57 core::dimension2d
<u32
> screenSize(viewPort
.getWidth(), viewPort
.getHeight());
59 f32 dx
= pos
.X
/ (f32
)screenSize
.Width
;
60 f32 dy
= pos
.Y
/ (f32
)screenSize
.Height
;
62 if (camera
->isOrthogonal())
63 ln
.start
= f
->cameraPosition
+ (lefttoright
* (dx
- 0.5f
)) + (uptodown
* (dy
- 0.5f
));
65 ln
.start
= f
->cameraPosition
;
67 ln
.end
= farLeftUp
+ (lefttoright
* dx
) + (uptodown
* dy
);
72 } // end namespace scene
73 } // end namespace irr