Camera position based on model size?

634 views Asked by At

in C# WPF how to automatically set camera Position based on 3DModel size.

For example if I load small model,position be closer and if I load large model camera position be longer.

What I thought was to get the Max and Min Point3D from model from each side.

-Find Max and Min point3D by X value.

-Find Max and Min point3D by Y value.

this is done by foreach loop through all 3D points.

Now I have 4 points at the edges, but how to calculate camera position?

Is there any formula to get the right position and the add some additional length to position?

1

There are 1 answers

1
Melvin On BEST ANSWER

All depends on the framework / library you're using, but I'd guess you'd have to use the camera's FOV to calculate how wide and high the camera can 'see' at a certain distance.

Camera

If you look at the schematic of the camera, the FOV is the angle at which the camera sees stuff. It is probably a member variable of your Camera object. Splitting the triangle in two will give you two right triangles with a know angle ( 1/2 FOV ). Basic mathematics should let you calculate the distance and size of the viewwindow.

Since you already have 4 points you already know how big 'L' (in the schematic) should be.