Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/freeglut.h>
- #include <math.h>
- #include <time.h>
- #include <stdio.h>
- float const pi = 3.14159;
- int Mx = 0, My = 0;
- class Moon
- {
- public:
- float r;
- float x, y;
- float dist;
- float theta;
- Moon() {
- theta = rand();
- }
- void setVar(float tr,float tdist, float tx, float ty) {
- r = tr;
- x = tx;
- y = ty;
- dist = tdist;
- }
- void update() {
- theta -= 0.005;
- }
- void display() {
- int n = 360;
- float lx = (dist * cos(theta));
- float ly = (dist * sin(theta));
- float theta2;
- glColor3f(1.0, 0.8, 0.3);
- glBegin(GL_POLYGON);
- for (int j = 0; j < 360; j++) {
- theta2 = (pi * 2.0)*j / n;
- glVertex2f(x + lx + (r * cos(theta2)), (y + ly + (r * sin(theta2))));
- }
- glEnd();
- glColor3f(0.0, 0.0, 0.0);
- glBegin(GL_LINE_LOOP);
- for (int j = 0; j < 360; j++) {
- theta2 = (pi * 2.0)*j / n;
- glVertex2f(x + lx + (r * cos(theta2)), (y + ly + (r * sin(theta2))));
- }
- glEnd();
- }
- };
- class Planet
- {
- public:
- float r;
- float dist;
- float theta;
- //float distEtoM = rand()%10+15;
- Moon moon;
- Planet(float tr,float tdist) {
- r = tr;
- dist = tdist;
- theta = rand();
- }
- void update() {
- theta += 0.001;
- }
- void display() {
- int n = 360;
- //theta = rand();
- float lx = (dist * cos(theta));
- float ly = (dist * sin(theta));
- moon.setVar(r / 3, r + 20, lx, ly);
- float theta2;
- glColor3f(1.0, 0.8, 0.3);
- glBegin(GL_POLYGON);
- for (int j = 0; j < 360; j++) {
- theta2 = (pi * 2.0)*j / n;
- glVertex2f(lx + (r * cos(theta2)), (ly + (r * sin(theta2))));
- }
- glEnd();
- moon.display();
- moon.update();
- glColor3f(0.0, 0.0, 0.0);
- glBegin(GL_LINE_LOOP);
- for (int j = 0; j < 360; j++) {
- theta2 = (pi * 2.0)*j / n;
- glVertex2f(lx + (r * cos(theta2)), (ly + (r * sin(theta2))));
- }
- glEnd();
- }
- };
- void init(void)
- {
- glClearColor(0.8, 0.8, 0.8, 1.0);
- gluOrtho2D(-500, 500.0, -500.0, 500.0);
- }
- Planet a1(20, 160);
- Planet a2(15, 200);
- Planet a3(25, 250);
- Planet a4(30, 310);
- Planet a5(20, 370);
- Planet a6(50, 430);
- //Planet a7(20, 180);
- //Planet a8(20, 180);
- void display()
- {
- srand(time(0));
- glClear(GL_COLOR_BUFFER_BIT);
- int x = 0;
- int y = 0;
- glColor3f(0.3, 0.2, 0.1);
- glBegin(GL_POLYGON);
- for (int i = 0; i < 360; i++) {
- float theta = (pi * 2.0)*i / 360;
- glVertex2f((100 * cos(theta)), ((100 * sin(theta))));
- }
- glEnd();
- glColor3f(0.0, 0.0, 0.0);
- glBegin(GL_LINE_LOOP);
- for (int i = 0; i < 360; i++) {
- float theta = (pi * 2.0)*i / 360;
- glVertex2f((100 * cos(theta)), ((100 * sin(theta))));
- }
- glEnd();
- a1.display();
- a1.update();
- a2.display();
- a2.update();
- a3.display();
- a3.update();
- a4.display();
- a4.update();
- a5.display();
- a5.update();
- a6.display();
- a6.update();
- glutPostRedisplay();
- //
- glFlush();
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGBA);
- glutInitWindowSize(800, 800);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("Test OpenGL");
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard);
- init();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement