임의의 버튼을 눌러 glOrtho에서 gluPerspective로 바꾸려 하는데 이상태에서 계속 오쏘그래픽으로만 바라보네요..
바꿀수 있는 방법이 없을까요?
#include <math.h>
#include <stdlib.h>
#include <glut.h>
static float t = 0.0f, PI = 3.141592;
static GLfloat theta[]={0.0,0.0,0.0};
static GLint axis = 2;
static GLdouble viewer[]={0, 2 ,1};
static int proj=0;
void Two_Quads()
{
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3f(-1.1 ,-1.1 ,0);
glVertex3f(-1.1 , 1.1 ,0);
glVertex3f( 1.1 , 1.1 ,0);
glVertex3f( 1.1 ,-1.1 ,0);
glColor3f(0,1,1);
glVertex3f(-1 ,-1 ,1);
glVertex3f(-1 , 1 ,1);
glVertex3f( 1 , 1 ,1);
glVertex3f( 1 ,-1 ,1);
glEnd();
glFlush();
}
void MyKeyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 'q':
t += 2;
viewer[0] = sin(t*PI/180);
viewer[2] = cos(t*PI/180);
glutPostRedisplay();
break;
case 'e':
t -= 2;
viewer[0] = sin(t*PI/180);
viewer[2] = cos(t*PI/180);
glutPostRedisplay();
break;
case 'z':
t += 2;
viewer[1] = sin(t*PI/180);
viewer[2] = cos(t*PI/180);
glutPostRedisplay();
break;
case 'c':
t -= 2;
viewer[1] = sin(t*PI/180);
viewer[2] = cos(t*PI/180);
glutPostRedisplay();
break;
case 'x':
t = 0;
viewer[0] = 0;
viewer[1] = 2;
viewer[2] = 1;
glutPostRedisplay();
break;
case 'o':
proj=0;
break;
case 'p':
proj=1;
break;
default:
break;
}
}
void MyReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(proj == 0 )
{
if(w>h)
glOrtho(-5*(float)w/(float)h,5*(float)w/(float)h,-5,5,-10,10);
else
glOrtho(-5,5,-5*(float)h/(float)w,5*(float)h/(float)w,-10,10);
}
if(proj == 1 )
{
gluPerspective(60, w/(float)h, 0.1, 3000.0);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void MyDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(viewer[0],viewer[1],viewer[2],0.0,0.0,0.0,0.0,1.0,0.0);
glRotatef(theta[0], 1.0, 0.0, 0.0);
glRotatef(theta[1], 0.0, 1.0, 0.0);
glRotatef(theta[2], 0.0, 0.0, 1.0);
Two_Quads();
glutSwapBuffers( );
}
int main( ){
glutInitWindowSize(700, 700);
glutInitWindowPosition(0, 0);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutCreateWindow("OpenGL Drawing Example");
glutDisplayFunc(MyDisplay);
glutKeyboardFunc(MyKeyboard);
glutReshapeFunc(MyReshape);
glEnable(GL_DEPTH_TEST);
glutMainLoop( );
return 0;
}
댓글에 전체 코드 보여달라하셔서..ㅎㅎ
감사합니다
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.