Sign in to follow this  
Ed Welch

Panning camera so object is at edge of screen

Recommended Posts

I'm trying to write a formula to pan the camera enough so that an object is just visible at the edge of the screen.
So, in other words if the object is out of view to the right, I would change the x and y position of the camera, so that the object is just at the right edge of the screen (without changing camera angle or z co-ordinate).

Any tips how to do this would be greatly appreciated.

cheers,

Ed
 

Share this post


Link to post
Share on other sites

In the example above the right plane of the viewing frustrum should be a supporting plane of the object.

that is the object and the plane must intersect and the object must lie on one side of the plane.

Share this post


Link to post
Share on other sites

Yeah, but what about the maths?
So far, I have worked out the following:
camPos + camDir*t + tan(fov)*t = p
where t = distance to object and p = postion of object
now t = sqrt((camPos.x-p.x)^2 + (camPos.y-p.y)^2 + (camPos.z-p.z)^2)
but I have no idea how I can solve that because I only have one equation and two variables
 

Share this post


Link to post
Share on other sites

Think in terms of frustrum planes, not view rays.

You could try something like this, again using the right frustrum plane for example:

1. get the plane equation

2. cast ray R along x-axis to find object-plane distance

3. move camera along x-axis so that distance is 0

depending on the object or which bounding geometry you use you should

sample the distance at every vertex and use the minimum or something like that.

im not really sure what you are trying to do. after the camera translation the object

should still be outside the camera view, right?

Share this post


Link to post
Share on other sites

Think in terms of frustrum planes, not view rays.

You could try something like this, again using the right frustrum plane for example:

1. get the plane equation

2. cast ray R along x-axis to find object-plane distance

3. move camera along x-axis so that distance is 0

depending on the object or which bounding geometry you use you should

sample the distance at every vertex and use the minimum or something like that.

im not really sure what you are trying to do. after the camera translation the object

should still be outside the camera view, right?

I'm trying to pan the camera the minimum amount so the object moves just into the view frustrum. The object position p is in the center of the object, so moving it into the edge of the frustrum would make it half visible (which is good enough)

Share this post


Link to post
Share on other sites

I sort of got it working. This is the code that I used:

	m_plane[RIGHT].Normalize();

	Vector3D up(0, 0, 1.0f);
	Vector3D xAxis = up.crossProduct(m_dir);
	xAxis.normalize();

	float distToPlane = m_plane[RIGHT].GetDistance(pos);
	xDist = distToPlane / m_plane[RIGHT].DotProduct(xAxis);

It almost positions the object correctly, but it's slightly off. I can't figure out where the error is.

Anyways, thanks for the answer ;)

Edited by Ed Welch

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