Im wondering how I can track an object in motion with gluLookAt();
If I were rotating a gluSphere() around a point, how would I track it? Ive given the short version of what Im trying to do below…
GLfloat tM[4][4];
struct targetObj
{
GLfloat x, y;
} ball;
struct theCamera
{
GLfloat ex;
GLfloat ey;
GLfloat ez;
GLfloat tx;
GLfloat ty;
GLfloat tz;
GLfloat ux;
GLfloat uy;
GLfloat uz;
} cam;
//Move the red sphere
void IdleTime()
{
int r = 10;
static int a=0;
a++ == 359 ? a=0 : a;
ball.x = r * cos(D2R(a));
ball.y = r * sin(D2R(a));
RenderMain();
}
void RenderMain()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt( cam.ex, cam.ey, cam.ez,
cam.tx, cam.ty, cam.tz,
cam.ux, cam.uy, cam.uz);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
glPushMatrix();
glRotatef(80, 0, 1, 0);
glTranslatef(ball.x, ball.y, 0);
glGetFloatv(GL_MODELVIEW_MATRIX, *tM);
gluSphere(qObj, .25, 30, 30);
glPopMatrix();
//Green sphere @ (0,0,0)
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
gluSphere(qObj, .25, 30, 30);
glutSwapBuffers();
}
Someone on the OpenGL news group told me I could extract the current Modelview matrix ( tM[4][4] above ), multiply a zero vector by it and that would give me the spheres position. I tried that but I doesnt track the Sphere. If you multiply a zero vector by a matrix, you simply get the Tx, Ty, Tz in return correct? Can someone fill me in on how this is accomplished? I’ve tried ditching gluLookAt() and the extracted Tx, Ty & Tz are correct, but when I add gluLookAt the sphere location isnt even close.
Sean
BTW, Im using gluPerspective(50.0f, aspect, .1, 100); in my Resize func.