Object Position in 3D Space and Scaling

Started by
0 comments, last by Buckeye 14 years, 4 months ago
Hi, I have a little Problem and hope anyone of you can help me with this. I have 2 identical transparent objects in 3D space. From the Camera object one (lets call it A) is behind the other one (lets call this one B). Obviously A looks smaller as it is further away. And on screen it looks as if they are centered around the same point, which of course they aren't in 3D space but only because of the conversion to 2D and the current camera position. My problem now is that I need to increase the scale of object A so that the they match each other on screen. In 3D space object A would be much bigger than object B but because B is closer they would look the same. Kind of complicated but I can't really figure the math out as to how to scale object A based on its distance to B. I would really appreciate some help with this. Thanks in advance.
Advertisement
I have to make some assumptions about what you know about your objects. Assume you know the radii of object A and object B and you know the distances from the camera to each object. From your description, it sounds like you want to know how to scale the radius of Object A such that it appears to be the same size as object B from the camera's point of view.

Assume:
float A = radius of Object A
float B = radius of Object B
float C = distance to Object A from the camera
float D = distance to Object B from the camera

Calculate float E = B * C/D;
scale S = E/A;

That is, the new radius of object A when scaled = A*S = E.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement