-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·140 lines (109 loc) · 3.19 KB
/
main.cpp
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
/**************************************************************************************************\
*
* "main.cpp" - Main file of the 'Big Bang' program.
* Contains the main() function plus initialisation and event handling functions.
*
* Author - Tom McDonnell 2004
*
\**************************************************************************************************/
// Includes ////////////////////////////////////////////////////////////////////////////////////////
#include "lib_tom_cpp/vector.h"
#include "universe.h"
#include <GL/glut.h>
#include <iostream>
// Global Variable Definitions /////////////////////////////////////////////////////////////////////
namespace bigBang
{
rec2vector
mainWinDim(600, 600),
halfMainWinDim(mainWinDim.x / 2, mainWinDim.y / 2);
universe U;
}
// File Scope Function Declarations ////////////////////////////////////////////////////////////////
namespace
{
void display(void);
void reshape(int, int);
void idle(void);
void setupView(void);
}
// Main Function Definition ////////////////////////////////////////////////////////////////////////
/*
*
*/
int main(int argc, char *argv[])
{
using namespace bigBang;
// Initialise glut.
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
// Create main window.
glutInitWindowSize(mainWinDim.x, mainWinDim.y);
glutInitWindowPosition(0, 0);
glutCreateWindow("Big Bang Simulator");
// Register functions for main window.
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
U.init();
glutMainLoop();
return 0;
}
// File Scope Function Definitions /////////////////////////////////////////////////////////////////
namespace
{
using namespace bigBang;
/*
*
*/
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
U.draw();
setupView();
glutSwapBuffers();
}
/*
*
*/
void reshape(int w, int h)
{
using namespace bigBang;
mainWinDim.x = w;
mainWinDim.y = h;
halfMainWinDim = mainWinDim / 2; // keep as integer
glutPostRedisplay();
}
/*
*
*/
void idle(void)
{
U.simulate(1.0);
glutPostRedisplay();
}
/*
* Set up modelview matrix for viewing x-y plane from -tve z direction.
*/
void setupView(void)
{
using namespace bigBang;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho
(
-halfMainWinDim.x, halfMainWinDim.x, // Left , right.
-halfMainWinDim.y, halfMainWinDim.y, // Bottom, top .
0.0 , 200.0 // Near , far .
);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt
(
halfMainWinDim.x, halfMainWinDim.y, 100.0, // Look from.
halfMainWinDim.x, halfMainWinDim.y, 0.0, // Look at .
0.0 , 1.0, 0.0 // Up vector.
);
}
}
/*******************************************END*OF*FILE********************************************/