Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How can I display objects in a 3D perspective projection that look like as if their size does not change, despite of the camera's position? I am using DirectX 9.0. I know of PositionTransformed declaration usage, but I was thinking of scaling the objects in every frame as the camera zooms in/out to achieve this. Is there a way to know the "scale" of a perspective projection?

An example usage would be to show lines with constant width. E.g. roads on a map.

Update, I've found the solution

check the accepted answer.

share|improve this question
3  
If you have an answer to your question, please post it as answer and not as an edit to your question. Also accept your answer if it's the "correct" one. –  bummzack Mar 8 '12 at 15:33
    
Is there a reason you have to use a perspective projection? Could you not change to an orthographic projection for just those objects? –  Josh Petrie Mar 8 '12 at 16:14
    
Hello, sorry i'm a newbie here, I will post it as an answer. I have both ortho 2D and perspective 3D. I want to display 3-axis when the user selects an object, in order to move it. –  kagelos Mar 8 '12 at 17:37
add comment

3 Answers 3

up vote 2 down vote accepted

Suppose we want an object to appear that it has constant size, regardless of the camera's position, in a 3D perspective projection. The solution is to scale the object in every frame, to increase/reduce it's size. Suppose we want the object to be 1/4 of the size of the viewport. This can be calculated as follows :

const double fov = Math.PI / 4.0;  //suppose 45 degrees FOV
float cameraObjectDistance = Vector3.Distance(Camera.Position, Object.Position);
float worldSize = (2 * Math.Tan(fov / 2.0)) * cameraObjectDistance;
float size = 0.25f * worldSize;

I hope this will be useful to others as well.

share|improve this answer
    
Thatwas extremely unobvious and awesome. Thanks. –  ufomorace Jun 26 at 14:37
add comment

I haven't tried this but theoretically you could create the matrix without the 1/D projection transform. http://msdn.microsoft.com/en-us/library/bb147302.aspx to render these and you'd still get them settled properly into the 3D scene.

share|improve this answer
add comment

Just thinking out loud here:

Depending on if you zoom by changing camera position or changing FOV, apply this concept to the view matrix for the former, the projection matrix for the latter.

If you want some objects in the scene to follow normal size changes during zoom, but others to not change... You could use two view (or projection) matrices. One for everything in the scene that changes normally, and one for the object you are trying to keep uniform size. Simply keep it's position (or FOV) a constant distance (or value) but in alignment and orientation with the other normally zooming matrix.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.