-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cc
More file actions
154 lines (114 loc) · 3.19 KB
/
main.cc
File metadata and controls
154 lines (114 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
Orbit: Solar System Simulation
Created by Jon Budd, Ritwik Gupta, and Ethan Welsh
Copyright (c) 2014 JRE. All rights reserved.
*/
#include "main.h"
#include "draw.h"
#include <string>
#include <iostream>
#define DELTA_TIME 100
#define min(a, b) ((a) < (b) ? a:b)
bool shouldRotate;
std::deque<Planet> planets;
int main(int argc, char **argv)
{
/* General initialization for GLUT and OpenGL
Must be called first */
glutInit(&argc, argv);
/* we define these setup procedures */
glut_setup();
gl_setup();
my_setup();
/* go into the main event loop */
glutMainLoop();
return (0);
}
/* This function sets up the windowing related glut calls */
void glut_setup(void)
{
/* specify display mode -- here we ask for a GLfloat buffer and RGB coloring */
/* NEW: tell display we care about depth now */
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
/* make a 400x400 window with the title of "GLUT Skeleton" placed at the top left corner */
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Orbit: Solar System Simulator");
/*initialize callback functions */
glutDisplayFunc(my_display);
glutReshapeFunc(my_reshape);
glutKeyboardFunc(my_keyboard);
}
/* This function sets up the initial states of OpenGL related environment */
void gl_setup(void)
{
/* specifies a background color: black in this case */
glClearColor(0, 0, 0, 0);
/* Setup for 2d projection */
glMatrixMode(GL_PROJECTION);
//This defines our "scale" for our solar system
gluOrtho2D(-50, 50, -50, 50);
}
void my_setup(void)
{
//draw_lighting(); Ignore for now, might do lighting later
shouldRotate = false;
int mass = 4;
int radius = 1;
Point origin(-10, -15);
Vector heading(-3, 2);
Planet planet(mass, radius, origin, heading, BLUE);
int mass1 = 100;
int radius1 = 7; //was 30
Point origin1(1, 1);
Vector heading1(0, 0);
Planet sun(mass1, radius1, origin1, heading1, YELLOW);
planets.push_front(sun);
planets.push_front(planet);
}
void my_reshape(int w, int h)
{
/* define view port -- x, y, (origin is at lower left corner) width, height */
glViewport(0, 0, min(w, h), min(w, h));
}
void my_keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 'p':
case 'P':
//shouldRotate = !shouldRotate;
shouldRotate = true;
break;
case 'q':
case 'Q':
exit(0);
default:
return;
break;
}
glutPostRedisplay();
}
void my_display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
std::cout << shouldRotate << std::endl;
if (shouldRotate)
{
for (int i = 0; i < planets.size(); i++)
{
//Planet tempPlanet = planets.at(i);
planets.at(i).sumVector(planets);
}
}
for (int i = 0; i < planets.size(); i++)
{
Planet tempPlanet = planets.at(i);
std::cout << tempPlanet.origin.toString() << std::endl;
}
drawSolarSystem(planets);
shouldRotate = false;
/* buffer is ready */
glutSwapBuffers();
}