Skip to main content
gamedev.net
🔒 Locked

Camera Proportional Controller

Started by treeway 1 reply 300+ views
Original Post
treeway
treeway
Okay so heres my problem: "The Basic Proportional Controller (PC) The PC is common in many camera systems. If you have worked on a camera system, you have probably used a PC, though it might have been called something else--terminology for this particular construct is not very consistent. The typical implementation is to set the velocity vector, V, equal to a proportion, C, of the difference between the current position, P, and a target position, Pt: V = C(P1 - P)" to implement this I have created a function in my camera:

void Camera::flyTo(D3DXVECTOR3* destination,float speed)
{
	if(destination == NULL)
		return;

	if(speed == 100 || speed < 0)
		return;

	//Find the difference between the current position and the target pos
	
	// Figure if current item is closest to viewer
	if(Position.x > destination->x)
		difference.x = (Position.x - destination->x);
	else
		difference.x = (destination->x - Position.x);

	if(Position.y > destination->y)
		difference.y = (Position.y - destination->y);
	else
		difference.y = (destination->y - Position.y);

	if(Position.z > destination->z)
		difference.z = (Position.z - destination->z);
	else
		difference.z = (destination->z - Position.z);

	velocity.x  = speed* (Position.x - difference.x);
	velocity.y  = speed* (Position.y - difference.y);
	velocity.z  = speed* (Position.z - difference.z);


	setPositionRel(&velocity);
}
but this seems to make the camera fly away from the target not towards it. Is probably something realy simple that I've overlooked but can anyone help? thanks.
Supernat02
Supernat02
I think you should let the math work itself out. I don't believe you need all of the if / else constructs. Just calculate it the same way you wrote it:

V = C(P1 - P).

Consider it in a single dimension. If the target is further away, the velocity is positive. If the target is behind P, the velocity is negative. You may end up with a spring-like damping if you don't create a dead zone around the position also. If V < 0.001, then V = 0 kind of thing.

Good luck,
Chris
Chris ByersMicrosoft DirectX MVP - 2005
treeway
treeway
thanks

your absolutely right i didnt need the if statements. :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.