지금 아래에 있는 코드는
제가 막힌거는 3D 좌표 (x,y,z 좌표 (coordinates))들을 그리고
마우스로 화면을 움직이면은 화면을 왔다갔다하는걸로 만들려고하는데....
현재는 키보드로만 왔다갔다할수있습니다...
근데 마우스로 하는거는 어떻게 하는지 모르겟네요..
약 20시간 넘게 공부 + 인터넷 뒤지고해서 이제 마우스 function들은 대충 알아낸거같은데 = _=
이것들을 도저히 어떻게 코드에 삽입해야할지 모르겠네요;
마우스로는 도데체 어떻게 할지 모르겟네요 ㅠㅠ
좀 도와주세요 ㅠ
마우스로 드레그하면은 화면이 움직이게 하고싶은데 ㅠㅠ
#include <stdafx.h>
#include <GL/glut.h> // Once you include glut.h (you don't need gl.h or glu.h)
GLfloat X = 0.0f; // Translate screen to x direction (left or right)
GLfloat Y = 0.0f; // Translate screen to y direction (up or down)
GLfloat Z = 0.0f; // Translate screen to z direction (zoom in or out)
GLfloat rotX = 0.0f; // Rotate screen on x axis
GLfloat rotY = 0.0f; // Rotate screen on y axis
GLfloat rotZ = 0.0f; // Rotate screen on z axis
GLfloat rotLx = 0.0f; // Translate screen by using the glulookAt function (left or right)
GLfloat rotLy = 0.0f; // Translate screen by using the glulookAt function (up or down)
GLfloat rotLz = 0.0f; // Translate screen by using the glulookAt function (zoom in or out)
void glDisplayLines(void); // Did declare the function so I did not have to check for order of the functions
// Initiliaze the OpenGL window
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0); // Clear the color
glShadeModel (GL_FLAT); // Set the shading model to GL_FLAT
glEnable (GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // Set Line Antialiasing
}
// Draw the lines (x,y,z)
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT); // Clear the Color Buffer
glPushMatrix(); // It is important to push the Matrix before calling glRotatef and glTranslatef
glRotatef(rotX,1.0,0.0,0.0); // Rotate on x
glRotatef(rotY,0.0,1.0,0.0); // Rotate on y
glRotatef(rotZ,0.0,0.0,1.0); // Rotate on z
glTranslatef(X, Y, Z); // Translates the screen left or right, up or down or zoom in zoom out
// Draw the positive side of the lines x,y,z
glBegin(GL_LINES);
glColor3f (0.0, 1.0, 0.0); // Green for x axis
glVertex3f(0,0,0);
glVertex3f(10,0,0);
glColor3f(1.0,0.0,0.0); // Red for y axis
glVertex3f(0,0,0);
glVertex3f(0,10,0);
glColor3f(0.0,0.0,1.0); // Blue for z axis
glVertex3f(0,0,0);
glVertex3f(0,0,10);
glEnd();
// Dotted lines for the negative sides of x,y,z
glEnable(GL_LINE_STIPPLE); // Enable line stipple to use a dotted pattern for the lines
glLineStipple(1, 0x0101); // Dotted stipple pattern for the lines
glBegin(GL_LINES);
glColor3f (0.0, 1.0, 0.0); // Green for x axis
glVertex3f(-10,0,0);
glVertex3f(0,0,0);
glColor3f(1.0,0.0,0.0); // Red for y axis
glVertex3f(0,0,0);
glVertex3f(0,-10,0);
glColor3f(0.0,0.0,1.0); // Blue for z axis
glVertex3f(0,0,0);
glVertex3f(0,0,-10);
glEnd();
glDisable(GL_LINE_STIPPLE); // Disable the line stipple
glPopMatrix(); // Don't forget to pop the Matrix
glutSwapBuffers();
}
// This function is called whenever the window size is changed
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h); // Set the viewport
glMatrixMode (GL_PROJECTION); // Set the Matrix mode
glLoadIdentity ();
gluPerspective(75, (GLfloat) w /(GLfloat) h , 0.10, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt (rotLx, rotLy, 15.0 + rotLz, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
// called on special key pressed
void specialKey(int key, int x, int y) {
// The keys below are using the gluLookAt() function for navigation
// Check which key is pressed
switch(key) {
case GLUT_KEY_LEFT : // Rotate on x axis
X -= 0.1f;
break;
case GLUT_KEY_RIGHT : // Rotate on x axis (opposite)
X += 0.1f;
break;
case GLUT_KEY_UP : // Rotate on y axis
Y += 0.1f;
break;
case GLUT_KEY_DOWN : // Rotate on y axis (opposite)
Y -= 0.1f;
break;
case GLUT_KEY_PAGE_UP: // Roatae on z axis
Z -= 0.1f;
break;
case GLUT_KEY_PAGE_DOWN:// Roatae on z axis (opposite)
Z += 0.1f;
break;
}
glutPostRedisplay(); // Redraw the scene
}
// Main entry point of the program
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); // Setup display mode to double buffer and RGB color
glutInitWindowSize (600,600); // Set the screen size
glutCreateWindow("OpenGL 3D Navigation Program");
init ();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutSpecialFunc(specialKey); // set window's to specialKey callback
glutMainLoop();
return 0;
}
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.