Jump to content
  • Advertisement


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


3D space and camera/model movement.

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

If you intended to correct an error in the post then please contact us.

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.
	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.
	glTranslatef(0.0, 0.0, cubeZ);
	glRotatef(rotate, 1.0, 1.0, 1.0);

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

Share this post

Link to post
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 this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!