Game Development Community

3d cords to 2d or versa

by Dimitris Matsouliadis · in Torque 3D Professional · 08/15/2010 (12:37 pm) · 4 replies

hi :)
What is the best way to detect an object in world space with the mouse;
I know the mouse position in canvas also includes the location of the object in world space. How can I compare these two data more easily;

Is there an easy way to convert the position of the 3d object into 2d canvas based on the player camera or the mouse 2d in world 3d cords?

in T3D getMouse3DPos and getMouse3Dvec don't working i think.

Thanks for yours time

#1
08/15/2010 (1:09 pm)
Take a look at the function project, and unproject to translate 3D coordinates into 2D, and 2D coordinates into 3D. They're in the GuiTSCtrl, which PlayGUI inherits from.

As for figuring out what's under the mouse, the way to do that is to unproject the mouse's coordinates to get it in 3D space, then you take the vector from the camera's position, to the mouse's 3D position, and this is your vector you cast a ray along until you hit something. Whatever you hit, is what's 'under' your mouse. There are object selection resources out there which use this method. Most of the code you need is also in GuiCrosshairHud.
#2
08/15/2010 (1:53 pm)
thanks Tim :)
Something go wrong in the code ... be a little complicated. is a game breaker by fps to rpg style. All AI is loaded from database and i can't select them (quest and traders mobs). Thank you for your time, you will see everything from the beginning and perhaps solve the problem.
#3
08/15/2010 (3:01 pm)
ok now :)
i have insert this

if( isMethod( "onMouseMove" ) )
makeScriptCall( "onMouseMove", evt );

in gameTSCtrl.cpp and working properly
#4
08/16/2010 (8:08 pm)
know any why 'onMouseMove' working and 'onMouseDown' don't working.
I can not understand why it happens, torturing me for 4 hours.

Also know any where can I find Shortly thereafter the commands for T3D?