Sign in to follow this  
adasko007

Problem with camera

Recommended Posts

I need to make project for study - aquarium with fish, where user can operate fish by keys... So I've made the scene and I've gave there some plants, and now I'm trying to make something with fish... I'm using gluLookAt camera, so I can move on the scene, but I cant operate fish (I can't turn right and left it)... I know that I should use glTranslatef and glRotatef to solve this problem, but I don't know how... Could someone remake this code? I really need it... :(
BOOL DisplayScene()
{
 // śledzi położenie gracza
 static GLfloat s_eye[] = { MAP_X * MAP_SCALE * 0.5, 8.0, -MAP_Z * MAP_SCALE * 0.5};
 static GLfloat s_at[]  = { 0.0, 0.0, 0.0 };
 static GLfloat rybka[] = {0.0, 0.0, 0.0};
 static GLfloat s_angle = -90.0;
 float speed = 0.1f;

 // sprawdza obrót
 if (g_keys[VK_LEFT])
 {
   s_angle -= 2.0;
 }
 if (g_keys[VK_RIGHT])
 {
   s_angle += 2.0;
 }

 // jeśli naciśnięty klawisz Shift, to gracz porusza się biegiem
 if (KEY_DOWN(VK_SHIFT))
   speed = speed * 2;

 float rad =  float(PI*s_angle/180.0f);

 // kierunek ruchu: do przodu lub wstecz
 if (g_keys[VK_UP])
 {
   s_eye[2] += (float)sin(rad) * speed;
   s_eye[0] += (float)cos(rad) * speed;
 }
 if (g_keys[VK_DOWN])
 {
   s_eye[2] -= (float)sin(rad) * speed;
   s_eye[0] -= (float)cos(rad) * speed;
 }

 // granice terenu
 if (s_eye[0] < MAP_SCALE)
   s_eye[0] = MAP_SCALE;
 if (s_eye[0] > (MAP_X - 2) * MAP_SCALE)
   s_eye[0] = (MAP_X - 2) * MAP_SCALE;
 if (s_eye[2] < -(MAP_Z - 2) * MAP_SCALE)
   s_eye[2] = -(MAP_Z - 2) * MAP_SCALE;
 if (s_eye[2] > - MAP_SCALE)
   s_eye[2] = -MAP_SCALE;

 // położenie obserwatora w stosunku do powierzchni terenu
 s_eye[1] = GetHeight(s_eye[0], s_eye[2]) + 2.0f;

 // punkt wycelowania kamery
 s_at[0] = float(s_eye[0] + 100*cos(rad));
 s_at[2] = float(s_eye[2] + 100*sin(rad));
 s_at[1] = s_eye[1];


 rybka[0] = s_eye[0]+0.2f;
 rybka[2] = s_eye[2]-1.0f;
 rybka[1] = s_eye[1];

 // konfiguruje macierz modelowania
 glLoadIdentity();
 gluLookAt(s_eye[0], s_eye[1], s_eye[2],
   s_at[0], s_at[1], s_at[2],
   0.0, 1.0, 0.0
   );

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glPushMatrix();
 glTranslatef(rybka[0], rybka[1], rybka[2]);
pModel->draw();
glPopMatrix();
 DrawSand();
 DrawCacti();
 DrawEchinorodus();
 DrawVesicularia();

  



 return TRUE;
} 
I can give you all project if you want... P.S. Sorry for my english :p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this