[glut] mouselook

How can I do mouselook with glut? I can’t get it to work with SDL…

Neither SDL or glut does mouselook automatically.
You have to read the mouse coordinates manually and then apply them using glRotate.

I know that already, I don’t know how to do it and require assistance.

This is what I came up with (SDL)

void MouseUpdate() {
	static int old_x, old_y;
	int x, y;
	SDL_GetRelativeMouseState(&x,&y);

	SDL_WarpMouse(r_width/2,r_height/2);

	CamYaw+=x;
	CamPitch+=y;

	old_x=x;
	old_y=y;

	if(CamPitch<-90)
		CamPitch=-90;

	if(CamPitch>90)
		CamPitch=90;

}

A long time ago (well in february) i coded an arkanoid3D using opengGL with SDL…

Here’s how i did in pseudo code :



SDL_Event event;

int main()
{
  //Some initialization here
  while (42) // Main loop where you update graphical content
   {
     while (SDL_PollEvent(&event))
       //keyboards input here
       ;
   }
  return (0);
}


With PollEvent you get the events associated with your mouse and keyboard.

The mouse events are in event.motion.x and event.motion.y

Hope this will help you !

lol

yeah I know there are mousemotion events but that’s not what I need for mouselook afaik

So what is your problem? Did you succeed to get your mouse xy motion values?

Are your camPitch and camYaw variables correct?

No:

if the camera is rotated -20 it instantly rotates +20 again… :frowning:

I don’t know SDL… :frowning: I can’t help you about this until this not an opengl problem. You have to make your angle values correct before.

You can try to print each frame your camera angle, or best, after each function, you’ll rapidly trace when it is changed ^^

It’s always a great way to debug,
if it doesn’t work try to paste your code, luckly you’ll see when is the mistake (:

Dear Kitty! Why 42?

Edit: ah, of course… me idiot…

fixed

void MouseUpdate() {
	int x, y;
	SDL_GetMouseState(&x,&y);
	SDL_WarpMouse(r_width/2,r_height/2);

	CamYaw+=(x-r_width/2)*0.2;
	CamPitch+=(y-r_height/2)*0.2;

	if(CamPitch<-90) {
		CamPitch=-90;
	}

	if(CamPitch>90) {
		CamPitch=90;
	}
}

google: sdl mouse look opengl SDL_GetMouseState camera