PDA

Click to See Complete Forum and Search --> : Open Gl Camera


PsyVision
Dec 23rd, 2000, 04:41 AM
Hi,

Here is What I have so far:

int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, triz);
glRotatef(triy, 0.0f, 1.0f, 0.0f);
glRotatef(trix, 1.0f, 0.0f, 0.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);

glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 1.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, -1.0f);

glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, -1.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f, -1.0f);

glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f,-1.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 1.0f);
glEnd();

if (keys[VK_LEFT])
{
triy++;
}

if (keys[VK_RIGHT])
{
triy--;
}

if (keys[VK_UP])
{
trix--;
}

if (keys[VK_DOWN])
{
trix++;
}

if (keys[VK_F2])
{
triz = triz + 0.1f;
}

if (keys[VK_F3])
{
triz = triz - 0.1f;
}


return TRUE;
}

This code works fine for drawing a triangle to the screen and then you can move the camera around the triangle. What my problem is, is that I want to be able to rotate the camera on the spot as opposed to rotating it relative to the trangle.

Ok, I have figured that I have to use the glLookAt();

Does any one know hot to use this ?

[Edited by PsyVision on 12-23-2000 at 05:47 AM]

Devion
Dec 28th, 2000, 04:40 AM
Why write in C++ ?

parksie
Dec 28th, 2000, 08:00 AM
Because it's faster, and pointers make it much more flexible for graphics. (chains of doubly linked lists, for example).

pollier
Dec 28th, 2000, 02:51 PM
Without gluLookat:

Put the viewer at (0,0,0), then glrotate.

With gluLookAt:

Visual Basic:

gluLookAt cameraX, cameraY, cameraZ, pointtolookatX, _
pointtolookatY, pointtolookatZ, 0, 1, 0

If you want to tilt the camera you'll need to alter the last three values: 0, 1, 0