Where can i find some help in order to make au Click'n Run System (like DiabloII, for au RPG).
I can't convert Mouse Position to 3D Vector....
Click'n Run System ?
I'm currently working on the same issue, my current approach is:
- getting a triangle selector on my terrain node
- building a line using the camera position and cursor position (there a method allowing to do that, though I still had no time to try it)
- getting the intersection of this line and the terrain
If I eventually manage to do it, I'll post it here. But unfortunately, I could not find a way to do it directly within the engine
- getting a triangle selector on my terrain node
- building a line using the camera position and cursor position (there a method allowing to do that, though I still had no time to try it)
- getting the intersection of this line and the terrain
If I eventually manage to do it, I'll post it here. But unfortunately, I could not find a way to do it directly within the engine
Currently working on a C# MMORPG using Irrlicht.NET
Strong99, you are wrong. First you need to convert the screen coordinate (where the mouse cursor is) to a ray (starting from the screen and going out of the screen) using ISceneCollisionManager::GetRayFromScreenCoordinates. Then, getting the triangle selector from your terrain (using ISceneManager::createTerrainTriangleSelector) and then getting the collision point between the two by using IColisionManager::getColisionPoint.
HantaCore was right because the 2D mouse coordinates are not equal to a 2D position on your terrain (they correspond only if your camera is above your terrain and is looking perfectly vertically at it, and the orientaion of the camera must be zero also).
HantaCore was right because the 2D mouse coordinates are not equal to a 2D position on your terrain (they correspond only if your camera is above your terrain and is looking perfectly vertically at it, and the orientaion of the camera must be zero also).
You are entirely right, there's just a little problem : we are working with Irrlicht .NET. and it's not that easy. I suppose you are working with C# if not, it's exactly the same way (if you are working with C++, switch to native Irrlicht ).Ced666 wrote:Strong99, you are wrong. First you need to convert the screen coordinate (where the mouse cursor is) to a ray (starting from the screen and going out of the screen) using ISceneCollisionManager::GetRayFromScreenCoordinates. Then, getting the triangle selector from your terrain (using ISceneManager::createTerrainTriangleSelector) and then getting the collision point between the two by using IColisionManager::getColisionPoint.
HantaCore was right because the 2D mouse coordinates are not equal to a 2D position on your terrain (they correspond only if your camera is above your terrain and is looking perfectly vertically at it, and the orientaion of the camera must be zero also).
First, in C# .NET, bool GetCollisionPoint(Core::Line3D ray,
Scene::ITriangleSelector* selector,
[PARAMFLAG::Out] Core::Vector3D& outCollisionPoint,
[PARAMFLAG::Out] Core::Triangle3D& outTriangle);
does not work... Don't know why, probably the Out param wich fails, I'm not familiar enough with C++.NET... Thus you can add a very simple function in "public __gc class ISceneCollisionManager" :
Code: Select all
Core::Vector3D GetCollisionPoint(Core::Line3D ray,
Scene::ITriangleSelector* selector)
{
Core::Vector3D vector;
irr::core::vector3df outCP;
irr::core::triangle3df outTr;
bool ret = SCM->getCollisionPoint(
irr::NativeConverter::getNativeLine(ray),
selector ? selector->get_NativeTriangleSelector() : 0,
outCP,
outTr);
vector = (irr::NativeConverter::getNETVector(outCP));
return vector;
};
Then you create the terrain selector :
Code: Select all
ITriangleSelector sel = SceneManager.CreateTerrainTriangleSelector(node, 0); //With a huge terrain, 0 can be very slow (depending on patch size).
Code: Select all
Line3D line = SceneManager.SceneCollisionManager.GetRayFromScreenCoordinates(Device.CursorControl.Position, null);
Vector3D y = SceneManager.SceneCollisionManager.GetCollisionPoint(line, sel);
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning