Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "GL\glut.h"
- #include <math.h>
- #define GL_PI 3.1415f
- static GLfloat xRot = 0.0f;
- static GLfloat yRot = 0.0f;
- void RenderScene()
- {
- GLfloat x, y, z, angle;
- glClear(GL_COLOR_BUFFER_BIT);
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glColor3f(0.0f, 1.0f, 0.0f);
- //しばらく後に解説
- glPushMatrix();
- glRotatef(xRot, 1.0f, 0.0f, 0.0f);
- glRotatef(yRot, 0.0f, 1.0f, 0.0f);
- glBegin(GL_LINES);
- z = 0.0f;
- for (angle = 0.0f; angle <= GL_PI; angle += (GL_PI / 20.0f))
- {
- x = 50.0f * cos(angle);
- y = 50.0f * sin(angle);
- glVertex3f(x, y, z);
- //180度移動して点を取得
- x = 50.0f * cos(angle+GL_PI);
- y = 50.0f * sin(angle+GL_PI);
- glVertex3f(x, y, z);
- }
- glEnd();
- glPopMatrix();
- glutSwapBuffers();
- }
- void controlKeys(int key, int x, int y)
- {
- if (key == GLUT_KEY_UP)
- xRot -= 5.0f;
- if (key == GLUT_KEY_DOWN)
- xRot += 5.0f;
- if (key == GLUT_KEY_LEFT)
- yRot -= 5.0f;
- if (key == GLUT_KEY_RIGHT)
- yRot += 5.0f;
- if (key > 356.0f)
- xRot = 0.0f;
- if (key < -1.0f)
- xRot = 355.0f;
- if (key > 356.0f)
- yRot = 0.0f;
- if (key < -1.0f)
- yRot = 355.0f;
- glutPostRedisplay();
- }
- void ChangeSize(int w, int h)
- {
- GLfloat nRange = 100.0f;
- if (h == 0) h = 1; //0除算を防ぐためのチェッカー
- glViewport(0, 0, w, h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- if (w <= h) {
- GLfloat aspect = h / w;
- glOrtho(-nRange, nRange, -nRange * aspect, nRange*aspect, -nRange, nRange);
- }
- else
- {
- GLfloat aspect = w / h;
- glOrtho(-nRange * aspect, nRange * aspect, -nRange, nRange, -nRange, nRange);
- }
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- int main(int argc, char* argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowSize(800, 600);
- glutCreateWindow("Complex Line");
- glutReshapeFunc(ChangeSize);
- glutSpecialFunc(controlKeys);
- glutDisplayFunc(RenderScene);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement