Jump to content
  • Advertisement
Sign in to follow this  
skz_

simple camera prob

This topic is 5025 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!