Page 1 of 1

Click'n Run System ?

Posted: Sat Mar 25, 2006 10:10 pm
by Nezumi
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....

Posted: Mon Mar 27, 2006 3:09 pm
by HantaCore
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

Posted: Tue Apr 04, 2006 3:18 pm
by Strong99
You only have to use x and y because, you can add the height for the gravity, so when you klick on 2 x en 5 y your node of the user wel desyt how heigh it must be...

Posted: Wed Apr 05, 2006 8:53 am
by Ced666
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).

Posted: Wed Apr 05, 2006 9:54 am
by DeusXL
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).
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 :roll:).

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 need to create the terrain (we'll name it "node"...).
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).
Then when the player clicks on the ground you just have to do :

Code: Select all

Line3D line = SceneManager.SceneCollisionManager.GetRayFromScreenCoordinates(Device.CursorControl.Position, null);
Vector3D y = SceneManager.SceneCollisionManager.GetCollisionPoint(line, sel);
And y contains the place where the user clicked !

Posted: Thu Apr 06, 2006 6:32 am
by HantaCore
DeusXL you're great, I'll try that tonight :)

I couldn't get the "GetTriangles(...)" methods of ITriangleSelector to work until now, and that was really problematic...