Click'n Run System ?

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
Nezumi
Posts: 15
Joined: Fri Sep 30, 2005 9:42 pm

Click'n Run System ?

Post 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....
HantaCore
Posts: 21
Joined: Wed Mar 22, 2006 4:38 pm

Post 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
Currently working on a C# MMORPG using Irrlicht.NET
Strong99
Admin
Posts: 687
Joined: Fri Mar 31, 2006 7:06 pm
Location: Netherlands
Contact:

Post 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...
Ced666
Posts: 86
Joined: Fri Jan 13, 2006 10:29 am
Location: Belgium

Post 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).
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post 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 !
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
HantaCore
Posts: 21
Joined: Wed Mar 22, 2006 4:38 pm

Post 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...
Currently working on a C# MMORPG using Irrlicht.NET
Locked