Object IDs and Picking -- How do I know what I clicked
by Matthew "Ashteth" Kee · in Torque Game Builder · 03/06/2005 (11:48 am) · 1 replies
I presume that picking in Torque works someting like it does in OpenGL. Looking at the manual, if I use the function:
It should return a list of object IDs beneath a given point. My question is: How do I convert an object ID back into an object, or alternatively can I set the object ID of something myself so that I know what I got back?
fxSceneGraph2D::pickPoint()
It should return a list of object IDs beneath a given point. My question is: How do I convert an object ID back into an object, or alternatively can I set the object ID of something myself so that I know what I got back?
Associate Melv May
If you create an object like this...
...you can do this...
This is will return the objects internal ID that's used by T2D. Assuming this number is "1234", you can still do stuff like this...
... which is cool. What this means that the object-IDs that the pick-routines return (as do other functions), can be used directly so I can do this...
// Pick a point. %pickList = myScene.pickPoint("5 10"); // Get Pick Count. %pickCount = getWordCount(%pickList) // Finish if we didn't pick anything. if ( %pickCount == 0 ) return; for ( %n = 0; %n < %pickCount; %n++ ) { // Fetch Object. %obj = getWord( %pickList, %n ); // Dump where object is actually positioned. echo( "We picked object whose position is" SPC %obj.getPosition() ); }... and we can do this because "%obj" contains the ID and it can be used as the object itself!
One thing to add is that the picking routines use the collision-polygon which defaults to the same size as the bounding-box. It does this because it uses the same swept-polygon system to pick a point, area or line.
- Melv.