Controller distance based on width of object in view

Software: Away3D 4.x

RvdBroeck, Newbie
Posted: 01 August 2013 04:21 PM   Total Posts: 1

Hi All,

Im trying to zoom out a controller to fill the view completely with the width of the target object that the controller is facing. Does anyone know how to do a calculation like that?
I the thing i know is the with of the object the controller is looking at.

Would help me alot!

   

lior_hai, Newbie
Posted: 02 August 2013 07:29 AM   Total Posts: 10   [ # 1 ]

As i see it, what you need to do is simple triangle geometry.

You need the angle of the camera (camera perspective I think), and the size of the base opposed to the angle (target object width).


Suppose you have a triangle with vertices A, B and C, A,B being the bace verts and C being the camera position
.
The distances are a=BC, b=AC and c=AB

You are given that:
AB(base) = Object width (for example 1000)
angle at C = camera perspective (for exemple 60);

I assume thie triangle is a Isosceles Triangle as this is how camera view usualy works…

With this info, you can calculate the angles at A, B:
angle at B=(180°-60°)/2 = 60°
angle at A=(180°-60°)/2 = 60°

Now you have the angles.

Using the sine rule, you can calculate the other sides:
a/sinA=b/sinB=c/sinB

a/sin(60)=b/sin(60)=1000/sin(60)

After calculating the sides, use something like the formula:
Area = (1/2)*c*b*sin(A) to get the area.

Lastly:
Area = Base*Height—-> Height=Area/1000

When you have the height you have the needed distance from camera.

Simple exemple… Hope it works!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X