[DX9 - Solved] Object to be constant size relative to screen

Started by
11 comments, last by G-Man9566 14 years, 1 month ago
I want to render/draw an object to be the same size relative to the screen, no matter how far away or close to the object I am. How can I do that? I believe that it will have someting to do with the way i set the world, view and projection matrix for that object when drawing it. [Edited by - G-Man9566 on March 9, 2010 11:17:06 PM]
Advertisement
Using an orthographic projection matrix will give you that effect.
Quote:Original post by Adam_42
Using an orthographic projection matrix will give you that effect.


ok, so i can do that even with the rest of my scene being draw as normal perspective?
What are you drawing, exactly? If you use a perspective transform and an orthographic transform, the Z-buffer values will be meaningless - so you'll need to disable the Z-buffer for one object type (Probably the orthographic one).
Quote:Original post by Evil Steve
What are you drawing, exactly?


Im drawing move and rotate gizmos, so that the user can move the object around in the scene. i want the gizmos to be the same size relative to the screen, as 3ds max does it, for instance.

is there another or better way of doing this that drawing the gizmo orthographically?

[Edited by - G-Man9566 on March 9, 2010 4:26:13 AM]
I would probably try to resize the object based on its distance to the camera. Both sounds like an easy operation to do (get the distance, resize), but I cannot guarantee the result, I haven't tried it.
If you're just drawing a gizmo, you don't need the Z-buffer at all - back-facing triangles will be culled anyway, and you won't really have any overlapping meshes.
Ok, so using a orthographic matrix to render the gizmo works nicely to keep it at a constant size relative to the screen.

The problem I have now is that the gizmo is not render at the center of the object that I want to move, as it did before. If I render it with the perspective matrix, it sits nicely at the center of the object, but when I use the ortho, it moves around as I look around.

When I look straight at the object, the gizmo is positioned at its center but as I look away the gizmo also "moves" away but is not positioned at the center of the object anymore or the viewport.
Apply a translation matrix to your gizmo with center point values of the object in question.
Quote:Original post by ddlox
Apply a translation matrix to your gizmo with center point values of the object in question.


Well, i have done that, otherwise it would not have rendered correctly using the Perspective matrix and it does render in the correct position when I use the Perspective matrix, but when I use the Ortographic matrix it only renders in the correct position when the object is in the center of my viewport.

This topic is closed to new replies.

Advertisement