Skip to main content
GameDev.net gamedev.net
🔒 Locked

Controlling a camera

Started by Ruudje Dec 26, 2004 at 6:33 AM 3 replies 550+ views
Original Post
Ruudje
Ruudje
Hi all, I'm looking for some help with my camera control :$ I can't get my sinus/cosinnus to work properly. I have an rotation (float) and the delta's for x (int) and y (int) current code:

void UpdateCamera()
{
	int dx = mouse.last_left - mouse.left;
	int dy = mouse.last_top - mouse.top;

	if(mouse.button[1])
	{
		Camera.Lookat.x += float(dx) / sin( (Camera.RotAngle * 2 * M_PI) ) * mouse.sensitivity;
//		Camera.Lookat.z += cos( (Camera.RotAngle * 2 * M_PI) ) * ( dy ) * mouse.sensitivity;
	}

	if(mouse.button[2])
	{
		Camera.RotAngle += float(dx) * mouse.sensitivity;
	}
}
But nomatter what the rotation is, my camera always moves as if I would execute this: Camera.Lookat.x += dx; Camera.Lookat.z += dy; in other words, straight, and ignore the rotation factor.. What am I doing wrong? Also, I seem unable to get the mouse scroll wheel to work unless I define my program to run only on winXP. Is there no other way? [Edited by - Ruudje on December 26, 2004 8:53:48 AM]
Enigma
Enigma
What type is Camera.RotAngle? Would it by any chance be an integer representing rotation in degrees? If so your rotate line should be Camera.Lookat.x += float(dx) / sin( (Camera.RotAngle * 2 * M_PI) / 180 ) * mouse.sensitivity;.

Enigma
Ruudje
Ruudje
The value is a normal floating point. the higher it gets the more it rotates... or that was the plan ;)

Unfortunately your code made no difference.. :s
ajas95
ajas95
you never update mouse.last_left to be mouse.left. Is that done somewhere else?

I don't get why you're dividing dx by sin...

why not just:
Camera.Lookat.x += dx * sin(Camera.RotAngle) * mouse.sensitivity;Camera.Lookat.z += dy * cos(Camera.RotAngle) * mouse.sensitivity;


and shouldn't that be moving the Camera's position, not its LookAt?
Ruudje
Ruudje
the last position is updated elsewhere yes and no it shouldnt be the position, but indeed lookat, since the position is calculated around the lookat point

also, tat code won't do it..

Here's the deal:

I have 1 point in 3D space, and I need to move it over the x and z.
I have 2 delta's, one for the amount of pixels the mouse moved over x, and one for over y. (screenpixels)
In addition the camera has a rotation amount for the y axis.

Pointing the camera in the right way isnt a problem, that already works. But when moving the camera with the mouse it goes wrong.

When dragging the mouse right e.g. I want the camera to move left(and so on), but including the angle of the camera in the calculations. I can't get it to work...

Topic Locked

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

Sign in to reply to this topic.