PDA

View Full Version : Rendering at constant size.

Aeluned
09-27-2007, 06:22 AM
I hope this will make sense:

Anyone that is familiar with 3DSMax will notice that when a light is placed in the scene as well as a camera and the camera is moved about the light icon stays a fixed size.

In other words, suppose I want to render a unit cube and regardless of where I move the camera I want the cube to remain unit size (even if the camera moves far from the cube or I move the cube far back along the Z-axis).

Currently, I'm using gluProject to project the vertices of the cube and find the size of it after camera transforms. I then determine a scale value based on the projected size of the cube and scale the cube up or down as needed. This sort of works but seems a bit quirky.

Sorry about the long post. If anyone has any idea what I'm talking about and knows how to implement this I would be greatful.

Cheers.

flatus
09-27-2007, 07:34 AM
I'm using the same approach, and, like you said, it works pretty well but is slightly quirky. I would be interested in developing a better method as well.

Zengar
09-27-2007, 08:32 AM
I would try using an orthogonal projection for the cube.

Aeluned
09-27-2007, 09:28 AM
There are two problems with that approach:

1) It distorts the cube.
2) Suppose my cube is resting on a plane. I haven't found a way to have the camera transformations affect the plane (rendered in a perspective projection) and the cube (rendered in an ortho projection) in the same way. Different transformations are needed when transforming in perspective versus ortho.

remdul
09-27-2007, 12:11 PM
I think you can just measure the distance from near plane to the cube center, and use that to scale the cube when drawing it. You may need to do some extra work to take in account FOV changes.

Aeluned
09-27-2007, 12:53 PM
Or perhaps better yet use the distance from the camera to the cube center? This way changing the near clip plane won't scale the cube.

This is an interesting idea and seems simple and elegant. Thank you, i'll give it a try.

Aeluned
09-28-2007, 08:35 AM
Flatus, here's what I did and it works rather well, no more quirkyness!

Take the vector defined by the two points that are the camera position and the center of the object you wish to keep at constant size.

The length of this vector becomes your scale value.

So, when the camera is 1 unit away from the object the length of the vector is one and so is your scale value. As you move the camera further away - say to two units your object becomes half the size (it is twice as far away). Now the length of the vector is 2. Scaling up the object twice as large.

It's simple, straight forward, and most importantly, it works :)

Thank you for the suggestion remdul.

flatus
09-28-2007, 03:18 PM
Yeah, that is pretty slick. Thanks guys!