PDA

View Full Version : Setting up a 3D view



ltrain_riders
10-16-2002, 04:54 PM
I'm trying to set up my view so I can see two boxes I made in 3D. I created a box 100 units wide (x direction), 1 unit tall (y direction), and 80 units deep (z direction) at the origin (0,0,0), so the left side of the box is at -50 and the right side is at 50 units, same with the z direction. I made another box on top of this one and when I go to view them it doesn't look 3D and I can't see the entire box from left to right, it is cut off from my view. I'm using:

glFrustum( -1.0, 1.0, -1.0, 1.0, 1.0, 102.0 );

to view. Is there any way I can set up a view or camera so I would be able to see these boxes from a corner looking down from above? Please help, I am very new at this and I setting up the viewing is causing me grief. Anyone have code/suggestions/tips/tricks/etc/etc...?

ltrain_riders
10-16-2002, 05:04 PM
this is what i have for setting up and viewing my draws:
#include "model.h"

void init ( void )
{
glEnable ( GL_DEPTH_TEST );
glClearColor ( 1.0, 1.0, 1.0, 0.0 );
}

void display ( void )
{
glClearDepth( 1.0 );
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
Draw_Base( );
Draw_Outside_Wall( );
glutSwapBuffers ( );
}

void reshape(int w, int h)
{
glViewport ( 0, 0, w, h );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
glFrustum( -1.0, 1.0, -1.0, 1.0, 1.0, 102.0 );
/* if ( h==0 )
gluPerspective ( 80, ( float ) w, 1.0, 5000.0 );
else
gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
*/
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ( );

}

#pragma argsused
void keyboard ( unsigned char key, int x, int y )
{
switch ( key ) {
case 27: /* Escape key */
exit ( 0 );
break;
case 'f':
glutFullScreen ( );
break;
case 'w':
glutReshapeWindow ( 250, 250 );
break;
default:
break;
}
}

/* Main Loop
* Open window with initial window size, title bar,
* RGBA display mode, and handle input events.
*/
int main ( int argc, char** argv )
{
glutInit ( &argc, argv );
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutInitWindowSize ( 800, 600 );
glutCreateWindow ( "3D Maze" );
init ( );
glutReshapeFunc ( reshape );
glutKeyboardFunc ( keyboard );
glutDisplayFunc ( display );
glEnable( GL_DEPTH_TEST );
glutMainLoop ( );
return 0;
}

nexusone
10-16-2002, 05:23 PM
You can do the following:

Use gluLookAt( x1, y1, z1, x2, y2, z2, x3,y3,z3)

xyz1 = Origin of camera.
xyz2 = Point you are looking at.
xyz3 = camera rotation, 0,1,0 camera up right.

It is used in the modelview:
example

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( x1, y1, z1, x2, y2, z2, x3,y3,z3)

Other option would be to use glRotate and gltranslate is simulate a camera in place of gluLookat



Originally posted by ltrain_riders:
I'm trying to set up my view so I can see two boxes I made in 3D. I created a box 100 units wide (x direction), 1 unit tall (y direction), and 80 units deep (z direction) at the origin (0,0,0), so the left side of the box is at -50 and the right side is at 50 units, same with the z direction. I made another box on top of this one and when I go to view them it doesn't look 3D and I can't see the entire box from left to right, it is cut off from my view. I'm using:

glFrustum( -1.0, 1.0, -1.0, 1.0, 1.0, 102.0 );

to view. Is there any way I can set up a view or camera so I would be able to see these boxes from a corner looking down from above? Please help, I am very new at this and I setting up the viewing is causing me grief. Anyone have code/suggestions/tips/tricks/etc/etc...?



[This message has been edited by nexusone (edited 10-16-2002).]

ltrain_riders
10-16-2002, 05:46 PM
Thanks, I'll try gluLookAt. In my example gluLookAt will after
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ( );
gluLookAt(...);
in the reshape function, posted earlier? Do I have to delete the glFrustum() line I have?

lgnnn
10-17-2002, 12:25 AM
glFrustum(
GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble znear,
GLdouble zfar
) indicates the perspective matrix, how the world project to the camera! gluLookat indicates that the cameras' position and orientation in the world coordinates!