# Thread: Rendering at constant size.

1. ## Rendering at constant size.

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.

2. ## Re: Rendering at constant size.

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.

3. ## Re: Rendering at constant size.

I would try using an orthogonal projection for the cube.

4. ## Re: Rendering at constant size.

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.

5. ## Re: Rendering at constant size.

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.

6. ## Re: Rendering at constant size.

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.

7. ## Re: Rendering at constant size.

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.

8. ## Re: Rendering at constant size.

Yeah, that is pretty slick. Thanks guys!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•