Weird camera behavior

Started by
5 comments, last by Tylon 20 years, 8 months ago
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?
Advertisement
Ok, wait a minute I think I see the problem actually...
Yes, DOH the last 3 rowns are meant to be lookat.? += view.?

And I didnt spot this until posting on a forum damnit!
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.
f@dzhttp://festini.device-zero.de
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]
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 ,-)
f@dzhttp://festini.device-zero.de
Ah, thanks!

This topic is closed to new replies.

Advertisement