Camera... Grr...

Hi,

Very new to opengl and am stuck, big time… I have programmed a game and am looking at it at an overview… I want to be able to flip from overview to looking at the game from the sidelines… Can’t seem to get it though

void newAngle()
{
    gluLookAt(cx, cy, cz, cx + nx,cy + ny,cz + nz,0.0f,1.0f,0.0f);
}

void moveCamera(int direction)
{
   cz = cz + direction*(nz)*0.4;
   glLoadIdentity();
   newAngle();
}

void inputKey(int key, int x, int y)
{
  switch(key)
  {
      case GLUT_KEY_UP:
	  	                          moveCamera(1);
	  	                          break;
      case GLUT_KEY_DOWN:
	  	                         moveCamera(-1);
	  	                         break;
  }
  glutPostRedisplay();
}
  

This moves the cmaera back and forth, I have tried messing with the x, y co-ordinates but I just can’t get it.

Cheers,

Walbert

that’s a tough one. have you tried learning a little math? works wonders in problems like this one.

hello

i would suggest making your own camera class if you need to move around with your camera freely (move/strafe/fly/yaw/pitch/roll)

its very useful even if you dont want to use all functions, you can just restrict your camera… that way if you are going to make another game you can reuse your camera and adjust it to how you want it to move

here is a camera tutorial thats good enough to get you started
http://pixwiki.bafsoft.com/mags/10/articles/agl-c/agl15.html

:slight_smile: