PDA

View Full Version : Rotation with camera view inside cube



reps4ta@aol.com
07-06-2003, 02:58 PM
I am having trouble rotating my cube with the camera view at the center of the cube. Can anyone help?

//need to rotate the cube to simulate camera movement. camera will give
//the effect of being in one position but will be able to view 360 degrees
//around. These 3 rotating functions do not work and need to be fixed.
glTranslatef(0.0f,0.0f,z); // Translate Into/Out Of The Screen By z
glRotatef(5.0f,1.0f,0.0f,0.0f);
glRotatef(5.0f,0.0f,1.0f,0.0f);


// Draw Front side
glBindTexture( GL_TEXTURE_2D, FRONT_ID );
glBegin( GL_QUADS );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( x, y, z+length );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( x, y+height, z+length );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( x+width, y+height, z+length );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( x+width, y, z+length );
glEnd( );

// Draw Back side
glBindTexture( GL_TEXTURE_2D, BACK_ID );
glBegin( GL_QUADS );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( x+width, y, z );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( x+width, y+height, z );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( x, y+height, z );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( x, y, z );
glEnd( );

// Draw Left side
glBindTexture( GL_TEXTURE_2D, LEFT_ID );
glBegin( GL_QUADS );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( x, y+height, z );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( x, y+height, z+length );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( x, y, z+length );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( x, y, z );
glEnd( );

// Draw Right side
glBindTexture( GL_TEXTURE_2D, RIGHT_ID );
glBegin( GL_QUADS );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( x+width, y, z );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( x+width, y, z+length );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( x+width, y+height, z+length );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( x+width, y+height, z );
glEnd( );

// Draw Up side
glBindTexture( GL_TEXTURE_2D, TOP_ID );
glBegin( GL_QUADS );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( x+width, y+height, z );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( x+width, y+height, z+length );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( x, y+height, z+length );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( x, y+height, z );
glEnd( );

// Draw Down side
glBindTexture( GL_TEXTURE_2D, BOTTOM_ID );
glBegin( GL_QUADS );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( x, y, z );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( x, y, z+length );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( x+width, y, z+length );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( x+width, y, z );
glEnd( );