Solar System - demo scence
Engine

Classes

struct  model
 

Macros

#define DEFAULT_GLOBAL_EYE_STEP   1.0f
 
#define DEFAULT_GLOBAL_EYE_X   1.0f
 
#define DEFAULT_GLOBAL_EYE_Y   (-5.0f)
 
#define DEFAULT_GLOBAL_EYE_Z   (-30.0f)
 
#define DEFAULT_GLOBAL_CENTER_STEP   1.0f
 
#define DEFAULT_GLOBAL_CENTER_X   0.0f
 
#define DEFAULT_GLOBAL_CENTER_Y   0.0f
 
#define DEFAULT_GLOBAL_CENTER_Z   0.0f
 
#define DEFAULT_GLOBAL_UP_STEP   1.0f
 
#define DEFAULT_GLOBAL_UP_X   0.0f
 
#define DEFAULT_GLOBAL_UP_Y   1.0f
 
#define DEFAULT_GLOBAL_UP_Z   0.0f
 

Typedefs

typedef struct model * Model
 

Functions

Model allocModel (const char *path)
 
void renderModel (Model model)
 
void renderAllModels ()
 
size_t readModelToBuffer (const char *path, float *p, unsigned int n)
 
void renderTriangleVertexSeq (float *p, unsigned int nVertices)
 
void changeSize (int w, int h)
 
void renderScene ()
 
void xml_load_and_set_env (const char *filename)
 
void engine_run (int argc, char **argv)
 
int main (int argc, char **argv)
 

Variables

static float globalAngle = 0
 
static float globalRotateX = 0
 
static float globalRotateY = 0
 
static float globalRotateZ = 0
 
static float globalTranslateX = 0
 
static float globalTranslateY = 0
 
static float globalTranslateZ = 0
 
static float globalScaleX = 1
 
static float globalScaleY = 1
 
static float globalScaleZ = 1
 
static float globalEyeX = DEFAULT_GLOBAL_EYE_X
 
static float globalEyeY = DEFAULT_GLOBAL_EYE_Y
 
static float globalEyeZ = DEFAULT_GLOBAL_EYE_Z
 
static float globalCenterX = DEFAULT_GLOBAL_CENTER_X
 
static float globalCenterY = DEFAULT_GLOBAL_CENTER_Y
 
static float globalCenterZ = DEFAULT_GLOBAL_CENTER_Z
 
static float globalUpX = DEFAULT_GLOBAL_UP_X
 
static float globalUpY = DEFAULT_GLOBAL_UP_Y
 
static float globalUpZ = DEFAULT_GLOBAL_UP_Z
 
static float globalFOV = 45.0f
 
static float globalNear = 1.0f
 
static float globalFar = 1000.0f
 
static std::vector< Model > globalModels
 
static std::vector< float > globalOperations
 

Detailed Description

Macro Definition Documentation

◆ DEFAULT_GLOBAL_CENTER_STEP

#define DEFAULT_GLOBAL_CENTER_STEP   1.0f

◆ DEFAULT_GLOBAL_CENTER_X

#define DEFAULT_GLOBAL_CENTER_X   0.0f

◆ DEFAULT_GLOBAL_CENTER_Y

#define DEFAULT_GLOBAL_CENTER_Y   0.0f

◆ DEFAULT_GLOBAL_CENTER_Z

#define DEFAULT_GLOBAL_CENTER_Z   0.0f

◆ DEFAULT_GLOBAL_EYE_STEP

#define DEFAULT_GLOBAL_EYE_STEP   1.0f

◆ DEFAULT_GLOBAL_EYE_X

#define DEFAULT_GLOBAL_EYE_X   1.0f

◆ DEFAULT_GLOBAL_EYE_Y

#define DEFAULT_GLOBAL_EYE_Y   (-5.0f)

◆ DEFAULT_GLOBAL_EYE_Z

#define DEFAULT_GLOBAL_EYE_Z   (-30.0f)

◆ DEFAULT_GLOBAL_UP_STEP

#define DEFAULT_GLOBAL_UP_STEP   1.0f

◆ DEFAULT_GLOBAL_UP_X

#define DEFAULT_GLOBAL_UP_X   0.0f

◆ DEFAULT_GLOBAL_UP_Y

#define DEFAULT_GLOBAL_UP_Y   1.0f

◆ DEFAULT_GLOBAL_UP_Z

#define DEFAULT_GLOBAL_UP_Z   0.0f

Typedef Documentation

◆ Model

typedef struct model * Model

Function Documentation

◆ allocModel()

Model allocModel ( const char *  path)
74 {
75 FILE *fp = fopen(path, "r");
76 if (!fp) {
77 fprintf(stderr, "failed to open model: %s", path);
78 return NULL;
79 }
80
81 unsigned int nVertices;
82 fread(&nVertices, sizeof(unsigned int), 1, fp);
83 float *modelBuf = (float *) malloc(3 * nVertices * sizeof(float));
84
85 fread(modelBuf, 3 * sizeof(float), nVertices, fp);
86 fclose(fp);
87
88
89 Model model = (Model) malloc(sizeof(Model));
90
91 model->nVertices = nVertices;
92 model->vertices = modelBuf;
93
94 return model;
95}
struct model * Model
Definition: engine.cpp:66
unsigned int nVertices
Definition: engine.cpp:68
float * vertices
Definition: engine.cpp:67

References model::nVertices, and model::vertices.

Referenced by load_xml1(), and operations_render().

◆ changeSize()

void changeSize ( int  w,
int  h 
)
130 {
131
132 // Prevent a divide by zero, when window is too short
133 // (you cant make a window with zero width).
134 if (h == 0)
135 h = 1;
136
137 // compute window's aspect ratio
138 float ratio = (float) w * 1.0f / (float) h;
139
140 // Set the projection matrix as current
141 glMatrixMode(GL_PROJECTION);
142 // Load Identity Matrix
143 glLoadIdentity();
144
145 // Set the viewport to be the entire window
146 glViewport(0, 0, w, h);
147
148 // Set perspective
149 gluPerspective(globalFOV, ratio, globalNear, globalFar); //fox,near,far
150
151 // return to the model view matrix mode
152 glMatrixMode(GL_MODELVIEW);
153}
static float globalFar
Definition: engine.cpp:64
static float globalNear
Definition: engine.cpp:63
static float globalFOV
Definition: engine.cpp:62

References globalFar, globalFOV, and globalNear.

Referenced by engine_run().

◆ engine_run()

void engine_run ( int  argc,
char **  argv 
)
253 {
254
255 if (argc > 0) xml_load_and_set_env(argv[1]);
256
257 // init GLUT and the window
258 glutInit(&argc,argv);
259 glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
260 glutInitWindowPosition(100, 100);
261 glutInitWindowSize(800, 800);
262 glutCreateWindow("engine");
263
264 // Required callback registry
265 glutDisplayFunc(renderScene);
266 glutReshapeFunc(changeSize);
267
268 // OpenGL settings
269 glEnable(GL_DEPTH_TEST);
270 glEnable(GL_CULL_FACE);
271 glPolygonMode(GL_FRONT, GL_LINE);
272
273 // enter GLUT's main cycle
274 glutMainLoop();
275}
void xml_load_and_set_env(const char *filename)
Definition: engine.cpp:248
void changeSize(int w, int h)
Definition: engine.cpp:130
void renderScene()
Definition: engine.cpp:224

References changeSize(), renderScene(), and xml_load_and_set_env().

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)
278 {
279 engine_run(argc,argv);
280 return 1;
281}
void engine_run(int argc, char **argv)
Definition: engine.cpp:253

References engine_run().

◆ readModelToBuffer()

size_t readModelToBuffer ( const char *  path,
float *  p,
unsigned int  n 
)
112 {
113 FILE *fp = fopen(path, "r");
114 size_t r = fread(p, sizeof(float), n, fp);
115 fclose(fp);
116 return r;
117}

◆ renderAllModels()

void renderAllModels ( )
108 {
109 for (Model m: globalModels) renderModel(m);
110}
static std::vector< Model > globalModels
Definition: engine.cpp:71
void renderModel(Model model)
Definition: engine.cpp:97

References globalModels, and renderModel().

◆ renderModel()

void renderModel ( Model  model)
97 {
98 if (!model->nVertices % 3) {
99 fprintf(stderr, "Number of coordinates is not divisible by 3");
100 exit(1);
101 }
102 glBegin(GL_TRIANGLES);
103 for (unsigned int i = 0; i < 3 * model->nVertices; i += 3)
104 glVertex3f(model->vertices[i], model->vertices[i + 1], model->vertices[i + 2]);
105 glEnd();
106}

References model::nVertices, and model::vertices.

Referenced by operations_render(), and renderAllModels().

◆ renderScene()

void renderScene ( void  )
224 {
225
226 // clear buffers
227 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
228
229 // set the camera
230 glLoadIdentity();
231 // helps in avoiding rounding mistakes, discards old matrix, read more
232
233 gluLookAt(globalEyeX, globalEyeY, globalEyeZ,
236 // put the geometric transformations here
240
242
243 // End of frame
244 glutSwapBuffers();
245}
void operations_render(std::vector< float > *operations)
Definition: engine.cpp:157
static float globalTranslateY
Definition: engine.cpp:26
static float globalCenterX
Definition: engine.cpp:54
static float globalTranslateX
Definition: engine.cpp:25
static float globalEyeY
Definition: engine.cpp:51
static float globalAngle
Definition: engine.cpp:19
static float globalScaleY
Definition: engine.cpp:31
static std::vector< float > globalOperations
Definition: engine.cpp:72
static float globalScaleZ
Definition: engine.cpp:32
static float globalUpX
Definition: engine.cpp:58
static float globalScaleX
Definition: engine.cpp:30
static float globalRotateY
Definition: engine.cpp:21
static float globalEyeZ
Definition: engine.cpp:52
static float globalUpZ
Definition: engine.cpp:60
static float globalUpY
Definition: engine.cpp:59
static float globalCenterZ
Definition: engine.cpp:56
static float globalEyeX
Definition: engine.cpp:50
static float globalRotateZ
Definition: engine.cpp:22
static float globalRotateX
Definition: engine.cpp:20
static float globalTranslateZ
Definition: engine.cpp:27
static float globalCenterY
Definition: engine.cpp:55

References globalAngle, globalCenterX, globalCenterY, globalCenterZ, globalEyeX, globalEyeY, globalEyeZ, globalOperations, globalRotateX, globalRotateY, globalRotateZ, globalScaleX, globalScaleY, globalScaleZ, globalTranslateX, globalTranslateY, globalTranslateZ, globalUpX, globalUpY, globalUpZ, and operations_render().

Referenced by engine_run().

◆ renderTriangleVertexSeq()

void renderTriangleVertexSeq ( float *  p,
unsigned int  nVertices 
)
119 {
120 if (!nVertices % 3) {
121 fprintf(stderr, "Number of coordinates is not divisible by 3");
122 exit(-1);
123 }
124 glBegin(GL_TRIANGLES);
125 for (unsigned int i = 0; i < nVertices; i += 3)
126 glVertex3f(p[i], p[i + 1], p[i + 2]);
127 glEnd();
128}

◆ xml_load_and_set_env()

void xml_load_and_set_env ( const char *  filename)
248 {
251}
void operations_load_xml(const char *filename, std::vector< float > *operations)
Definition: parsing.cpp:133

References globalOperations, operations_load_xml(), and operations_render().

Referenced by engine_run().

Variable Documentation

◆ globalAngle

float globalAngle = 0
static

Referenced by renderScene().

◆ globalCenterX

float globalCenterX = DEFAULT_GLOBAL_CENTER_X
static

◆ globalCenterY

float globalCenterY = DEFAULT_GLOBAL_CENTER_Y
static

◆ globalCenterZ

float globalCenterZ = DEFAULT_GLOBAL_CENTER_Z
static

◆ globalEyeX

float globalEyeX = DEFAULT_GLOBAL_EYE_X
static

◆ globalEyeY

float globalEyeY = DEFAULT_GLOBAL_EYE_Y
static

◆ globalEyeZ

float globalEyeZ = DEFAULT_GLOBAL_EYE_Z
static

◆ globalFar

float globalFar = 1000.0f
static

◆ globalFOV

float globalFOV = 45.0f
static

◆ globalModels

std::vector<Model> globalModels
static

Referenced by load_xml1(), and renderAllModels().

◆ globalNear

float globalNear = 1.0f
static

◆ globalOperations

std::vector<float> globalOperations
static

◆ globalRotateX

float globalRotateX = 0
static

Referenced by renderScene().

◆ globalRotateY

float globalRotateY = 0
static

Referenced by renderScene().

◆ globalRotateZ

float globalRotateZ = 0
static

Referenced by renderScene().

◆ globalScaleX

float globalScaleX = 1
static

Referenced by renderScene().

◆ globalScaleY

float globalScaleY = 1
static

Referenced by renderScene().

◆ globalScaleZ

float globalScaleZ = 1
static

Referenced by renderScene().

◆ globalTranslateX

float globalTranslateX = 0
static

Referenced by renderScene().

◆ globalTranslateY

float globalTranslateY = 0
static

Referenced by renderScene().

◆ globalTranslateZ

float globalTranslateZ = 0
static

Referenced by renderScene().

◆ globalUpX

float globalUpX = DEFAULT_GLOBAL_UP_X
static

◆ globalUpY

float globalUpY = DEFAULT_GLOBAL_UP_Y
static

◆ globalUpZ

float globalUpZ = DEFAULT_GLOBAL_UP_Z
static