웃긴건 카메라보다 뒤쪽으로 가는건 괜찮음..
화면 안쪽으로 -Z 축인건 맞은데 도대체 멀까나...
(코드 붙여 넣고 보니.. scale을 1/4로 줘서 그렇군 .. 3.6 길이가 그러면 0.9가 되니 1 안에 들어옴)
접기
#include "GL/gl.h"
#include "GL/glu.h"
#include "GL/glut.h"
#include "math.h"
static int x_angle = 0, y_angle = 0, z_angle = 0;
void dump_matrix(GLint line)
{
GLint idx;
GLdouble mat[16];
printf("*** LINE : %d\n",line);
glGetDoublev(GL_MODELVIEW_MATRIX, mat);
printf("GL_MODELVIEW_MATRIX\n");
for(idx=0;idx<16;idx++)
{
printf("%f ",mat[idx]);
if(idx % 4 == 3) printf("\n");
}
glGetDoublev(GL_PROJECTION_MATRIX, mat);
printf("GL_PROJECTION_MATRIX\n");
for(idx=0;idx<16;idx++)
{
printf("%f ",mat[idx]);
if(idx % 4 == 3) printf("\n");
}
printf("\n");
}
void draw_sin()
{
int temp;
glPushMatrix();
// glLoadIdentity();
printf("angle [%d,%d,%d]\n",x_angle,y_angle,z_angle);
glScalef(0.25,0.25,0.25);
glRotated(x_angle,1,0,0);
glRotated(y_angle,0,1,0);
glRotated(z_angle,0,0,1);
// X-axis - RED
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glEnd();
// Y-axis - GRREN
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINE);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glEnd();
// Z-axis - BLUE
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINE);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 1.0);
glEnd();
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
for(temp = 0; temp < 360; temp++)
{
glVertex3f(0.01*temp,sin(3.1415927/180*temp),0);
}
glEnd();
glPopMatrix();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //GL_PROJECTION
glPushMatrix();
glViewport(0, 0, 250, 250);
gluLookAt(0.10, 0.0, 0.2, 0.0, 0.0, -2.0, 0.0, 1.0, 0.0);
draw_sin();
glPopMatrix();
glPushMatrix();
glViewport(250, 0, 250, 250);
gluLookAt(0.2, 0.0, 0.2, 0.0, 0.0, -2.0, 0.0, 1.0, 0.0);
draw_sin();
glPopMatrix();
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
#if 0
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
#endif
#if 0
glMatrixMode(GL_MODELVIEW); //GL_PROJECTION
glLoadIdentity();
gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);
#endif
// dump_matrix(__LINE__);
}
void keyboard(unsigned char key, int x, int y)
{
printf("key[%d] x[%d] y[%d]\n",key,x,y);
switch (key)
{
default:
break;
}
}
void keyboard_spe(int key, int x, int y)
{
printf("key[%d] x[%d] y[%d]\n",key,x,y);
switch (key)
{
case GLUT_KEY_F1:
case GLUT_KEY_F2:
case GLUT_KEY_F3:
case GLUT_KEY_F4:
case GLUT_KEY_F5:
case GLUT_KEY_F6:
case GLUT_KEY_F7:
case GLUT_KEY_F8:
case GLUT_KEY_F9:
case GLUT_KEY_F10:
case GLUT_KEY_F11:
case GLUT_KEY_F12:
break;
case GLUT_KEY_LEFT:
y_angle = (y_angle - 15) % 360;
glutPostRedisplay();
break;
case GLUT_KEY_RIGHT:
y_angle = (y_angle + 15) % 360;
glutPostRedisplay();
break;
case GLUT_KEY_UP:
x_angle = (x_angle + 15) % 360;
glutPostRedisplay();
break;
case GLUT_KEY_DOWN:
x_angle = (x_angle - 15) % 360;
glutPostRedisplay();
break;
case GLUT_KEY_PAGE_UP:
z_angle = (z_angle + 15) % 360;
glutPostRedisplay();
break;
case GLUT_KEY_PAGE_DOWN:
z_angle = (z_angle - 15) % 360;
glutPostRedisplay();
break;
case GLUT_KEY_HOME:
case GLUT_KEY_END:
case GLUT_KEY_INSERT:
break;
default:
break;
}
}
void mouse(int button, int state, int x, int y)
{
printf("button[%d] state[%d] x[%d] y[%d]\n",button,state,x,y);
switch(button)
{
case GLUT_LEFT_BUTTON:
break;
case GLUT_MIDDLE_BUTTON:
break;
case GLUT_RIGHT_BUTTON:
break;
}
switch(state)
{
case GLUT_UP:
break;
case GLUT_DOWN:
break;
}
}
void mouse_motion(int x, int y)
{
printf("motion x[%d] y[%d]\n",x,y);
}
void mouse_passive(int x, int y)
{
printf("passive x[%d] y[%d]\n",x,y);
}
void idlefunc()
{
glutPostRedisplay();
}
void timerfunc(int value)
{
glutTimerFunc(1000, timerfunc, 0);
}
void entry(int state)
{
printf("entry state[%d]\n",state);
switch(state)
{
case GLUT_LEFT:
break;
case GLUT_ENTERED:
break;
}
}
void visibility(int state)
{
printf("visibility state[%d]\n",state);
switch(state)
{
case GLUT_NOT_VISIBLE:
break;
case GLUT_VISIBLE:
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
// GLUT Window
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
glClearColor(0.0, 0.0, 0.0, 0.0);
// glShadeModel(GL_FLAT); //GL_SMOOTH
glutDisplayFunc(display); // Draw callback
// glutReshapeFunc(reshape); // Draw callback
glutKeyboardFunc(keyboard); // Keyboard callback
glutSpecialFunc(keyboard_spe); // Keyboard callback
// glutMouseFunc(mouse); // Mouse callback
// glutMotionFunc(mouse_motion); // Mouse callback
// glutPassiveMotionFunc(mouse_passive); // Mouse callback
// glutIdleFunc(idlefunc); // Period callback
// glutTimerFunc(1000, timerfunc, 0); // Period callback
// glutEntryFunc(entry); // Window callback
// glutVisibilityFunc(visibility); // Window callback
glutMainLoop();
return 0;
}
접기