Sign in to follow this  
G-Man9566

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

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
To get them aligned I think they will both need to be rendered as perspective.

That leaves Tom's suggestion of scaling the gizmo up as it moves further away from the camera. I believe scaling by k*distance should give a constant size, where k is a constant that controls how big it is.

Share this post


Link to post
Share on other sites
Another option would be to convert the 3D perspective coordinate (The centre of the model where you want to draw the gyzmo) to 2D with D3DXVec3Project, and then project it back into 3D orthographic space with D3DXVec3Unproject. That way, you should be drawing the gyzmo at the same screen-space location as the object.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Another option would be to convert the 3D perspective coordinate (The centre of the model where you want to draw the gyzmo) to 2D with D3DXVec3Project, and then project it back into 3D orthographic space with D3DXVec3Unproject. That way, you should be drawing the gyzmo at the same screen-space location as the object.


That is actually exactly what I thought of doing in principle/theory, but did not know how I would do it in code. Thanks for the great help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this