Positioning 3d-objects with 2d-coordinates

Hi!

I was just wondering how you guys would solve the problem of positioning 3d-objects with 2d-coordinates?

Say for instance that you have some 3d-world you’re flying through and at the same time you wan’t a little 3d-logo(or someting else) spinning around a the bottom of your screen, how would you position the 3d-logo if know that you wan’t it at e.g 2d_x=200,2d_y=350?

I guess what I’m after is some function like this:

struct Rect
{
int 2d_x,2d_y;
int width,height;
};

void Draw3dThingie(Rect& where);

And then the function would render it’s stuff so that it’s inside this rectangle which describes a 2d-section of the screen.

Or maybe this is not the way to do it, maybe you just render away with e.g a 3d-cube and then fiddle with the 3d-coordinates until the cube is positioned correctly 2d-wise i.e onscreen?

Any help would be appreciated.

/D

What everyone else do, I have noe idea. But what I THINK people would do, and what I would do, is to draw the logo with a completely new modelview and projection matrix.

Draw the entire scene as usual. When done, reset the modelview and projection matrix and use precalculated 3D coordinates.

Draw the entire scene as usual. When done, reset the modelview and projection matrix and use precalculated 3D coordinates.

What do you mean when you say I should reset the projection matrix?

And does “precalculated 3D coordinates” mean that you’re suggesting that I “pre-render” the entire logo-animation and store it like some quake-mdl file(which contains animation frames)?

I think a good example of what I’m trying to do can be found in the tankgame Treadmarks by Longbow digital arts (www.longbowdigitalarts.com). In the game they have a menu where the mouse cursor is some transparent 3d-object that spins constantly. Although the cursor is a 3d-object it is still positioned (I guess) through 2d-coordinates.

Maybe I should use gluProject or calculate the 2d-coordinates myself?

Anyway, further discussion and examples(source code?) from people who know more about this stuff would really be appreciated.

Thank you in advance.

/D

[This message has been edited by DJ (edited 07-08-2001).]

Just a thought…

I have not tried it yet, but I would define two viewports. The upper viewport displays your game, and the lower displays your rectangle.

Ritchie

as bob said the standard way (as with any 3d game out there eg quake1/2/3)is to have a ‘HUD’ projection matrix usually a orthogonal one
draw 3d scene
setup new matrice
turn off depth (if necessary)
draw the hud.

and no the performance hit from using 2 matrices is very small

as bob said the standard way (as with any 3d game out there eg quake1/2/3)is to have a ‘HUD’ projection matrix usually a orthogonal one draw 3d scene
setup new matrice turn off depth (if necessary) draw the hud.
and no the performance hit from using 2 matrices is very small

I am familiar with this technique(used it myself :-)) but a HUD is usually made up of 2d-text and flat 2d-textures with no real depth. And this is perfect in combination with an orthoview since you can position the “widgets” using 2d-coordinates(=screen/pixel coordinates).
But what about when you wan’t to “overlay” your “3d-game” with a HUD/menu that contains 3d-objects like 3d-text, spinning 3d-cubes, things that require a perspective view to be rendered so that they look the way they’re supposed to. How do you then position these objects correctly if you want them to be placed at particular screen coordinates?

Is gluProject or “manually” calculating the screencoordinates for 3d-points the best way/only way/right way?

/D