Archived

This topic is now archived and is closed to further replies.

Weird camera behavior

This topic is 5237 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

When I move the camera forward towards the origin (0, 0, 0) I get this weird behavior, where the camera bounces back and for over the origin, alternating the direction it is facing every frame. Here is the algorithm I use to move the camera forward. (C#)
if(KeyDown(VK_UP))
{
	Vector3 view = lookat - position;
	view.Normalize();

	position.X += view.X * speed;
	position.Y += view.Y * speed;
	position.Z += view.Z * speed;

	view.X += view.X * speed;
	view.Y += view.Y * speed;
	view.Z += view.Z * speed;
}
 
Can anyone tell me whats wrong with it?

Share this post


Link to post
Share on other sites
you could avoid it by dropping that lookat stuff at all and start directions instead of points. no direction will change if you just move and your forward direction would make this lookat-pos obsolete. also: lookatX() will build exactly those vectors anyway.

Share this post


Link to post
Share on other sites
Yes, but the camera in both OpenGL and DirectX used the position-lookat-upvector system, so at some point it would have to be used anyway? (Im using DirectX btw)

[edited by - Tylon on August 11, 2003 10:28:27 AM]

Share this post


Link to post
Share on other sites
there is no camera and lookat is just a little helper to set up the view (which uses right/up/forward).

but storing a lookat point you a) have to calc the forward vector everytime you move (even more work for strafing) and pass it to lookat, which will then calculate the same vector. also you always have to update the lookat point. using directx means you have matrices and a lot of math functions, so using a matrix camera is a matter of a few lines. and it will be a lot less code as soon as you want to rotate your view ,-)

Share this post


Link to post
Share on other sites