PDA

View Full Version : Perspective trouble



hurricane
11-24-2003, 05:56 AM
I have created a wire cube and want the perspective to be from the centre of the cube looking out, so that when the cube is rotated you get a view as if in the center of the cube. I have managed to get the perspective inside the cube but it is not centralised. My code so far is as follows any help is much appreciated.

#include <windows.h> /* must include this before GL/gl.h */
#include <GL/gl.h>
#include <GL/glut.h> /* OpenGL utilities header file */
#include <gl/glaux.h>
#include <stdio.h>


static int shoulder = 0;

void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef((GLfloat) room, 0.0, 1.0, 0.0);
glutWireCube(1.1);
glPopMatrix();

glutSwapBuffers();

}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -0.5);

}

void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 's':
shoulder = (room + 5) % 360;
glutPostRedisplay();
break;
case'S':
shoulder = (room + 5) % 360;
glutPostRedisplay();
break;
}
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

11-25-2003, 01:55 AM
You need to set scale on your scene, that way you will be able to zoom out to the center of your rooom

mithun_daa
11-25-2003, 06:21 AM
u could either try makin the near plane = 0.1 or translate the wirecube by 1 before sawpping the buffers