Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <glut.h>
- #include <vector>
- #include <conio.h>
- #include <cmath>
- #define RANGE 0
- using namespace std;
- class Star
- {
- public:
- float x, y, z;
- };
- vector<Star> starList;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- for (vector<Star>::iterator i = starList.begin(); i != starList.end(); ++i)
- {
- const float L = 70 / abs(i->z - (70 + 50));
- glPointSize(1.0f + 1.0f - (50 - i->z) / 550.0f);
- glColor3f(L, L, L);
- glBegin(GL_POINTS);
- glVertex3f(i->x, i->y, i->z);
- glEnd();
- }
- glutSwapBuffers();
- }
- void timer(int = 0)
- {
- glutPostRedisplay();
- glutTimerFunc(1, timer, 0);
- }
- void Keyboard(unsigned char key, int x, int y)
- {
- if(key == 'w')
- {
- for (vector<Star>::iterator i = starList.begin(); i != starList.end(); ++i)
- {
- i->z += 10;
- }
- }
- if(key == 's')
- {
- for (vector<Star>::iterator i = starList.begin(); i != starList.end(); ++i)
- {
- i->z -= 10;
- }
- }
- if(key == 'd')
- {
- for (vector<Star>::iterator i = starList.begin(); i != starList.end(); ++i)
- {
- i->x -= 10;
- }
- }
- if(key == 'a')
- {
- for (vector<Star>::iterator i = starList.begin(); i != starList.end(); ++i)
- {
- i->x += 10;
- }
- }
- }
- int main(int argc, char **argv)
- {
- for (int i = 0; i < 10000; i++)
- {
- Star star = {
- 1.0f * (rand() % (2 * RANGE) - RANGE),
- 1.0f * (rand() % (2 * RANGE) - RANGE),
- 1.0f * (rand() % 2000)
- };
- starList.push_back(star);
- }
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(852, 480);
- glutInitWindowPosition(0, 86);
- glutCreateWindow("Stars");
- glClearColor(0, 0, 0, 1.0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45, 1, 0, 100);
- glutDisplayFunc(display);
- glutKeyboardFunc(Keyboard);
- timer();
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement