Advertisement

Finding screen coordinates of 3D object?

Started by October 11, 2001 09:10 AM
4 comments, last by Edge42 23 years, 4 months ago
I'm developing a strategy game like Final Fantasy Tactics and X-Com where I have characters moving around 3D terrain in an isometric viewpoint. I am currently working on having a context menu pop up when the player clicks on a character. In order to draw the menu, I think I need to know the character's location in screen coordinates. Does anyone know how to find the screen coordinates of a 3D object? Thanks! -Scott- Edited by - Edge42 on October 11, 2001 10:11:20 AM
You are looking for a thing called ''selection''.
Look for it on the web. you can find many good tutorials and demos.

enjoy
Advertisement
Sorry, my post was a little confusing because I made too many assumptions.

I'm currently using selection. But when someone clicks on a 3D item in the world, I want the context menu to be layed out relative to the object rather than the current mouse location.

In other words, I need a way to set a point in 3D and find its location in screen coordinates.

Thanks for your help - sorry my post was so confusing.

-Scott-

Edited by - Edge42 on October 11, 2001 10:29:59 AM
Hmmm... Well if they clicked something, then you know what they clicked as you''re using selection, which means you must know it''s 3D co-ords... so couldn''t you just lay out the context menu as a billboard near those coords if you really don''t want to use mouse position?

Probably do away with lots of extra work... sorry if I''m missing something

-=aSe=-
-=aSe=-
If you are using a 2D mouse cursor on top of a 3D world then the first thing you need to do is find out what 3D objects are underneath the current 2D position of the mouse. This process is sometimes called picking, and your 3D api might support this, e.g. Direct3D Retained Mode has a function Direct3DRMViewport.Pick which takes a 2D pixel coordinate and returns a list of 3D objects underneath it.

If you are using a 3D virtual reality pointer instead of 2D mouse (e.g. a hand), or you are displaying your mouse pointer as a 3D object in your 3D world, then you know what your pointer has touched via standard 3D collision detection techniques, and what you have to do is translate this 3D position into a 2D screen coordinate. Yet again, your 3D API might support this, e.g. Direct3D Retained Mode has a function Direct3DRMViewport.Transform with takes a 3D cordinate and translates it into screen pixel x,y (and z and w) cordinates.

Unfortunately, since I only know Direct3D Retained Mode, I cannot help you with other 3D APIs, but looking up terms like picking, transform, inversetransform might help.
from MSDN help.(Also there is something called gluUnProject())

-----------------------------------------------------------
The gluProject function maps object coordinates to window coordinates.

int gluProject(
GLdouble objx,
GLdouble objy,
GLdouble objz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble * winx,
GLdouble * winy,
GLdouble * winz
);

Parameters
objx, objy, objz
The object coordinates.
modelMatrix
The current modelview matrix (as from a glGetDoublev call).
projMatrix
The current projection matrix (as from a glGetDoublev call).
viewport
The current viewport (as from a glGetIntegerv call).
winx, winy, winz
The computed window coordinates.

Remarks
The gluProject function transforms the specified object coordinates into window coordinates using modelMatrix, projMatrix, and viewport. The result is stored in winx, winy, and winz. A return value of GL_TRUE indicates success, and GL_FALSE indicates failure.



Edited by - oztanharmanci on October 12, 2001 4:24:39 PM

This topic is closed to new replies.

Advertisement