diff options
author | sfan5 <sfan5@live.de> | 2021-08-24 23:51:48 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2021-08-26 22:17:35 +0200 |
commit | da33f80bb8afa6c18ea047ca230cf5dce90c963d (patch) | |
tree | a16bb666767f8efc50fa203e2deb26b16f20b4b9 /source/Irrlicht/CSceneCollisionManager.cpp | |
parent | f9078a6a1222e111f09fe6762ee998cbd835a8fa (diff) | |
download | irrlicht-da33f80bb8afa6c18ea047ca230cf5dce90c963d.tar.xz |
Readd CSceneCollisionManager with only the method we need
Diffstat (limited to 'source/Irrlicht/CSceneCollisionManager.cpp')
-rw-r--r-- | source/Irrlicht/CSceneCollisionManager.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/source/Irrlicht/CSceneCollisionManager.cpp b/source/Irrlicht/CSceneCollisionManager.cpp new file mode 100644 index 0000000..f975ab8 --- /dev/null +++ b/source/Irrlicht/CSceneCollisionManager.cpp @@ -0,0 +1,76 @@ +// 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
+
+#include "CSceneCollisionManager.h"
+#include "ICameraSceneNode.h"
+#include "SViewFrustum.h"
+
+#include "os.h"
+#include "irrMath.h"
+
+namespace irr
+{
+namespace scene
+{
+
+//! constructor
+CSceneCollisionManager::CSceneCollisionManager(ISceneManager* smanager, video::IVideoDriver* driver)
+: SceneManager(smanager), Driver(driver)
+{
+ #ifdef _DEBUG
+ setDebugName("CSceneCollisionManager");
+ #endif
+
+ if (Driver)
+ Driver->grab();
+}
+
+
+//! destructor
+CSceneCollisionManager::~CSceneCollisionManager()
+{
+ if (Driver)
+ Driver->drop();
+}
+
+
+//! Returns a 3d ray which would go through the 2d screen coordinates.
+core::line3d<f32> CSceneCollisionManager::getRayFromScreenCoordinates(
+ const core::position2d<s32> & pos, const ICameraSceneNode* camera)
+{
+ core::line3d<f32> ln(0,0,0,0,0,0);
+
+ if (!SceneManager)
+ return ln;
+
+ if (!camera)
+ camera = SceneManager->getActiveCamera();
+
+ if (!camera)
+ return ln;
+
+ const scene::SViewFrustum* f = camera->getViewFrustum();
+
+ core::vector3df farLeftUp = f->getFarLeftUp();
+ core::vector3df lefttoright = f->getFarRightUp() - farLeftUp;
+ core::vector3df uptodown = f->getFarLeftDown() - farLeftUp;
+
+ const core::rect<s32>& viewPort = Driver->getViewPort();
+ core::dimension2d<u32> screenSize(viewPort.getWidth(), viewPort.getHeight());
+
+ f32 dx = pos.X / (f32)screenSize.Width;
+ f32 dy = pos.Y / (f32)screenSize.Height;
+
+ if (camera->isOrthogonal())
+ ln.start = f->cameraPosition + (lefttoright * (dx-0.5f)) + (uptodown * (dy-0.5f));
+ else
+ ln.start = f->cameraPosition;
+
+ ln.end = farLeftUp + (lefttoright * dx) + (uptodown * dy);
+
+ return ln;
+}
+
+} // end namespace scene
+} // end namespace irr
|