2D to 3D coordinates

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
fakin
Posts: 14
Joined: Wed Jan 24, 2007 9:02 pm
Location: zagreb, croatia

2D to 3D coordinates

Post by fakin »

hi.

is there a build-in function in IrrLicht that converts 2D screen coordinates to 3D coordinates. or if not could anyone give me some directions on how to do it. I've google it and $%@# but no luck.

thanks.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Code: Select all

line3d<f32> testLine = smgr->getSceneCollisionManager ()->getRayFromScreenCoordinates  (core::position2d< s32>  pos,  ICameraSceneNode *  camera = 0);
in the main loop >

after smgr->drawAll();

Code: Select all

smgr->getSceneCollisionManager()->getSceneNodeFromRayBB(testLine,0, false);
That will get the scene node detected by the line afore mentioned frame-by-frame...you can modify it to fit your needs.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

PS.

Irrlicht Collision is really slow and limited, I reccomend a Physics Engine or Wrapper for Irrlicht..

IPhysics and IrrNewt are both good, check the Project Announcements forums.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

You didn't say what kind of collision you wanted, so I'll post a snippet that shows how to get the collision point with a plane. In this case, it's the XZ plane at Y=0, but you can set up and collide with any plane you like.

Code: Select all

	static plane3df const shipPlane(vector3df(0.f, 0.f, 0.f),
									vector3df(1.f, 0.f, 0.f),
									vector3df(0.f, 0.f, 1.f));

	position2d<s32> cursorPosition(gs_device->getCursorControl()->getPosition());
	line3d<f32> ray(gs_collisionManager->getRayFromScreenCoordinates(cursorPosition, gs_tacticalCamera));

	vector3df intersectWithPlane;

	if(shipPlane.getIntersectionWithLine(ray.start, ray.getVector(), intersectWithPlane))
	{
... and intersectWithPlane is your 3D point
	}
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
fakin
Posts: 14
Joined: Wed Jan 24, 2007 9:02 pm
Location: zagreb, croatia

Post by fakin »

this is very nice and helpful rogerborg. thanks.
Gladius_Coldhead
Posts: 56
Joined: Thu Oct 12, 2006 5:15 am

Post by Gladius_Coldhead »

somebody know how convert 2D screen coordinates to 3D coordinates with Newton Game Dynamics?

by the way...

IrrNewt/IPhysics is better than "pure" Newton?
Post Reply