Sign in to follow this  
skz_

simple camera prob

Recommended Posts

Hey everyone This is my first post here :) I'm no good at math so you most certainly know more about this than me :( okay I'm trying to take two moving objects and place the camera at the exact center of both of them -20 units on the z axis and still be able to see both objects through the camera at all times i know there is a simple solution to this! but i thought maybe you might be able to give me some advice on this thanks for your help

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
well find the distance between them divide that by two and place thats the center position....but then again you might have to bring the camera back so that you can see both objects as they move away from each other

Share this post


Link to post
Share on other sites

Vector Up(0, 1, 0);
Vector Centre = (Obj2.Pos + Obj1.Pos) / 2;
Vector Extent = (Obj2.Pos - Obj1.Pos) / 2;
Vector Dir = Extent.Cross(Up);
Dir.Normalise();

float e = Extent.Magnitude();
distance = e / tan(DegreesToRadians(Camera.FiendOfViewAngle / 2));

Camera.Position = Centre + Dir * distance;
Camera.Direction = -Dir;
Camera.Up = Up;


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this