0

I have a simple textured polygon with a bitmap image texture on it.

glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, _textureId);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glColor3f(1.0f, 1.0f, 1.0f);
    glBegin(GL_QUADS);

    //Front face

    glNormal3f(0.0, 0.0f, 1.0f);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(BOX_SIZE / 2, -BOX_SIZE / 2, BOX_SIZE / 2);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(-BOX_SIZE / 2, BOX_SIZE / 2, BOX_SIZE / 2);

    glEnd();

I want to rotate around the object so it will face directly at me. how can I change the position of the camera?

ProXicT
  • 1,903
  • 3
  • 22
  • 46
Ransar
  • 23
  • 5

1 Answers1

0

In OpenGL you can use gluLookAt function to move in space.

Think of the camera as a point in space.
The first 3 parameters determinate your position.
Next 3 parameters determinate another point in space, where the camera will look.

Here I've composed a picture: (The cartoon character is taken from here) How gluLookAt works

In the picture you can see a man standing in position pos.x, pos.y, pos.z looking at some point (the red dot) look.x, look.y, look.z;

The upVec is just a vector determinating a direction of your head.

In this post Carlos Scheidegger briefly explains what the upVec does:

The intuition behind the "up" vector in gluLookAt is simple: Look at anything. Now tilt your head 90 degrees. Where you are hasn't changed, the direction you're looking at hasn't changed, but the image in your retina clearly has. What's the difference? Where the top of your head is pointing to. That's the up vector.

In most cases, you want to set the upVec to (0,1,0) since that's the direction of your head in most cases.

Community
  • 1
  • 1
ProXicT
  • 1,903
  • 3
  • 22
  • 46