Public Group

#### Archived

This topic is now archived and is closed to further replies.

# 3D space and camera/model movement.

This topic is 5229 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Are there any tutorials and/or articles on moving around in a 3D world? I'm not quite sure as to what the proper way is. I should go ahead and explain my sample program that I'm toying with and where I'm stumped at. With OGL, I've built a simple wire cube and am having it travel down the negative Z axis. What I'd like to do is have the "camera" follow it down the Z axis, but slowly lose it (code shown below for my display routine). Now the problem is (as I'm sure some of you have probably figured out by now), is that my cube disappears after a certain distance. I already know where this problem is, and that's with the way my gluPerspective is set up; gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0); So my question is, how do I properly do movement and camera positioning in 3D? It's not as cut and dry as I figured it'd be (ie; decreasing the z value for both gluLookAt and my cube). One thing I thought of was to change the glurPerspective values for near/far depending on how far out my camera is, but that doesn't make much sense from a logical stand point. There's something I'm missing, and could use a clue or two (or a tutorial and/or article). Thanks in advance.
void display()
{
cubeZ -= 0.2;
cameraZ -= 0.1;
rotate = (rotate + 1) % 360;

// Clear & set drawing color.
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);

// Set camera position.
gluLookAt(0.0, 0.0, cameraZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

// Draw cube.
glPushMatrix();
glTranslatef(0.0, 0.0, cubeZ);
glRotatef(rotate, 1.0, 1.0, 1.0);
glutWireCube(1.0);
glPopMatrix();

glutSwapBuffers();
glutPostRedisplay();
}

[edited by - wyrd on June 1, 2004 6:13:53 PM]

##### Share on other sites
Oh jeeze I''m such a dip. I didn''t change the gluLookAt parameters appropriately. It''s still being pointed at the default 0, 0, 0 vertex, gah!

Anyway.. changing the gluLookAt() call to the following solved the problems;

gluLookAt(0.0, 0.0, cameraZ, 0.0, 0.0, cubeZ, 0.0, 1.0, 0.0);

Now I''m just trying to get camera rotation down. Any help with that? Thanks again.

##### Share on other sites
Help is all around you. :-]

Nice. Thanks.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 16
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632660
• Total Posts
3007693
• ### Who's Online (See full list)

There are no registered users currently online

×