Solar System - demo scence
main.cpp File Reference
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include <tinyxml2.h>

Go to the source code of this file.

Macros

#define _USE_MATH_DEFINES
 
#define DEFAULT_GLOBAL_ANGLE_STEP   16
 
#define DEFAULT_GLOBAL_TRANSLATE_STEP   1
 
#define DEFAULT_GLOBAL_SCALE_STEP   1
 
#define DEFAULT_GLOBAL_EYE_STEP   1.0f
 
#define DEFAULT_GLOBAL_EYE_X   5.0f
 
#define DEFAULT_GLOBAL_EYE_Y   (-2.0f)
 
#define DEFAULT_GLOBAL_EYE_Z   (3.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
 
#define DEFAULT_GLOBAL_STACK   10
 
#define DEFAULT_GLOBAL_SLICE   10
 

Functions

void render3d (const char *path)
 
size_t readModelToBuffer (const char *path, float *p, unsigned int n)
 
void renderTriangleVertexSeq (float *p, int n)
 
void changeSize (int w, int h)
 
void cylinderVertex (float radius, float height, float theta)
 
void drawCylinder (float r, float height, int slices)
 
void coneVertex (float r, float height, float theta, float h)
 
void drawCone (float r, float height, unsigned int slices, unsigned int stacks)
 
void sphereVertex (float r, float theta, float phi)
 
void drawSphere (float r, unsigned int slices, unsigned int stacks)
 
void drawPlane (float length, unsigned int divisions)
 
void drawAxes ()
 
void drawCube (float length, unsigned int divisions)
 
void renderScene (void)
 
void keyboardFunc (unsigned char key, int xmouse, int ymouse)
 
void processSpecialKeys (int key, int xx, int yy)
 
int main2 (int argc, char **argv)
 
int main (int argc, char **argv)
 

Variables

float globalAngleStep = DEFAULT_GLOBAL_ANGLE_STEP
 
float globalAngle = 0
 
float globalRotateX = 0
 
float globalRotateY = 0
 
float globalRotateZ = 0
 
float globalTranslateStep = DEFAULT_GLOBAL_TRANSLATE_STEP
 
float globalTranslateX = 0
 
float globalTranslateY = 0
 
float globalTranslateZ = 0
 
float globalScaleStep = DEFAULT_GLOBAL_SCALE_STEP
 
float globalScaleX = 1
 
float globalScaleY = 1
 
float globalScaleZ = 1
 
float globalBackgroundColorStep = 1
 
float globalBackgroundColorR = 0
 
float globalBackgroundColorG = 0
 
float globalBackgroundColorB = 0
 
float globalEyeStep = DEFAULT_GLOBAL_EYE_STEP
 
float globalEyeX = DEFAULT_GLOBAL_EYE_X
 
float globalEyeY = DEFAULT_GLOBAL_EYE_Y
 
float globalEyeZ = DEFAULT_GLOBAL_EYE_Z
 
float globalCenterStep = DEFAULT_GLOBAL_CENTER_STEP
 
float globalCenterX = DEFAULT_GLOBAL_CENTER_X
 
float globalCenterY = DEFAULT_GLOBAL_CENTER_Y
 
float globalCenterZ = DEFAULT_GLOBAL_CENTER_Z
 
float globalUpStep = DEFAULT_GLOBAL_UP_STEP
 
float globalUpX = DEFAULT_GLOBAL_UP_X
 
float globalUpY = DEFAULT_GLOBAL_UP_Y
 
float globalUpZ = DEFAULT_GLOBAL_UP_Z
 
int globalStackSliceStep = 1
 
int globalStack = DEFAULT_GLOBAL_STACK
 
int globalSlice = DEFAULT_GLOBAL_SLICE
 
static float globalFOV = 60.0f
 
static float globalNear = 1.0f
 
static float globalFar = 1000.0f
 

Macro Definition Documentation

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

◆ DEFAULT_GLOBAL_ANGLE_STEP

#define DEFAULT_GLOBAL_ANGLE_STEP   16

◆ 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   5.0f

◆ DEFAULT_GLOBAL_EYE_Y

#define DEFAULT_GLOBAL_EYE_Y   (-2.0f)

◆ DEFAULT_GLOBAL_EYE_Z

#define DEFAULT_GLOBAL_EYE_Z   (3.0f)

◆ DEFAULT_GLOBAL_SCALE_STEP

#define DEFAULT_GLOBAL_SCALE_STEP   1

◆ DEFAULT_GLOBAL_SLICE

#define DEFAULT_GLOBAL_SLICE   10

◆ DEFAULT_GLOBAL_STACK

#define DEFAULT_GLOBAL_STACK   10

◆ DEFAULT_GLOBAL_TRANSLATE_STEP

#define DEFAULT_GLOBAL_TRANSLATE_STEP   1

◆ 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

Function Documentation

◆ changeSize()

void changeSize ( int  w,
int  h 
)
119 {
120
121 // Prevent a divide by zero, when window is too short
122 // (you cant make a window with zero width).
123 if (h == 0)
124 h = 1;
125
126 // compute window's aspect ratio
127 float ratio = w * 1.0 / h;
128
129 // Set the projection matrix as current
130 glMatrixMode(GL_PROJECTION);
131 // Load Identity Matrix
132 glLoadIdentity();
133
134 // Set the viewport to be the entire window
135 glViewport(0, 0, w, h);
136
137 // Set perspective
138 gluPerspective(globalFOV, ratio, globalNear, globalFar);
139
140 // return to the model view matrix mode
141 glMatrixMode(GL_MODELVIEW);
142}
static float globalFar
Definition: main.cpp:82
static float globalNear
Definition: main.cpp:81
static float globalFOV
Definition: main.cpp:80

References globalFar, globalFOV, and globalNear.

Referenced by main().

◆ coneVertex()

void coneVertex ( float  r,
float  height,
float  theta,
float  h 
)
188 {
189 glVertex3d(r * h * cos(theta), 2 * (height + h), r * h * sin(theta));
190}

Referenced by drawCone().

◆ cylinderVertex()

void cylinderVertex ( float  radius,
float  height,
float  theta 
)
144 {
145 glVertex3d(radius * sin(theta), height, radius * cos(theta));
146}

Referenced by drawCylinder().

◆ drawAxes()

void drawAxes ( )
316 {
317 glBegin(GL_LINES);
318 /*X-axis in red*/
319 glColor3f(1.0f, 0.0f, 0.0f);
320 glVertex3f(-100.0f, 0.0f, 0.0f);
321 glVertex3f(100.0f, 0.0f, 0.0f);
322
323 /*Y-Axis in Green*/
324 glColor3f(0.0f, 1.0f, 0.0f);
325 glVertex3f(0.0f, -100.0f, 0.0f);
326 glVertex3f(0.0f, 100.0f, 0.0f);
327
328 /*Z-Axis in Blue*/
329 glColor3f(0.0f, 0.0f, 1.0f);
330 glVertex3f(0.0f, 0.0f, -100.0f);
331 glVertex3f(0.0f, 0.0f, 100.0f);
332 glEnd();
333}

◆ drawCone()

void drawCone ( float  r,
float  height,
unsigned int  slices,
unsigned int  stacks 
)
192 {
193 /*coloring*/
194 float c1 = 1;
195 float c2 = 1;
196 float color_step = (float) 1.0 / (float) (slices + 4);
197
198 // https://www.math3d.org/5gLCN9yBz
199
200 float s = 2.0f * (float) M_PI / (float) slices;
201 float t = height / (float) stacks;
202 float theta = -M_PI;
203 float h = -height;
204
205 glBegin(GL_TRIANGLES);
206 for (int m = 1; m <= slices; m++) {
207 for (int n = 1; n <= stacks; n++) {
208 float i = (float) m;
209 float j = (float) n;
210
211 //base
212 glColor3f(c1, c2, c2);
213 glVertex3d(0, 0, 0); //O
214 coneVertex(r, height, theta + s * (i - 1), h); //P1
215 coneVertex(r, height, theta + s * i, h); //P2
216
217 glColor3f(c1, 0, c2);
218 coneVertex(r, height, theta + s * i, h + t * (j - 1)); // P2
219 coneVertex(r, height, theta + s * (i - 1), h + t * j); // P1'
220 coneVertex(r, height, theta + s * i, h + t * j); //P2'
221
222 glColor3f(c1, c2, 0);
223 coneVertex(r, height, theta + s * i, h + t * (j - 1)); // P2
224 coneVertex(r, height, theta + s * (i - 1), h + t * (j - 1)); // P1
225 coneVertex(r, height, theta + s * (i - 1), h + t * j); // P1'
226
227 c2 -= color_step;
228 }
229 c1 -= color_step;
230 c2 = 1;
231 }
232 glEnd();
233}
void coneVertex(float r, float height, float theta, float h)
Definition: main.cpp:188

References coneVertex().

Referenced by renderScene().

◆ drawCube()

void drawCube ( float  length,
unsigned int  divisions 
)
335 {
336 /*coloring*/
337 float c1 = 1;
338 float c2 = 1;
339 float color_step = (float) 1.0 / (float) (divisions + 4);
340
341 float o = -length / 2.0f;
342 float d = length / (float) divisions;
343 glBegin(GL_TRIANGLES);
344 for (int m = 1; m <= divisions; m++) {
345 for (int n = 1; n <= divisions; n++) {
346 float i = (float) m;
347 float j = (float) n;
348
349 // top
350 glColor3f(c1, c2, 0);
351 glVertex3d(o + d * (i - 1), -o, o + d * (j - 1)); //P1
352 glVertex3d(o + d * (i - 1), -o, o + d * j); //P1'z
353 glVertex3d(o + d * i, -o, o + d * (j - 1)); //P1'x
354
355 glColor3f(c1, 0, c2);
356 glVertex3d(o + d * i, -o, o + d * (j - 1)); //P1'x
357 glVertex3d(o + d * (i - 1), -o, o + d * j); //P1'z
358 glVertex3d(o + d * i, -o, o + d * j); //P2
359
360 // bottom
361 glColor3f(c1, c2, 0);
362 glVertex3d(o + d * (i - 1), o, o + d * j); //P1'z
363 glVertex3d(o + d * (i - 1), o, o + d * (j - 1)); //P1
364 glVertex3d(o + d * i, o, o + d * (j - 1)); //P1'x
365
366 glColor3f(c1, 0, c2);
367 glVertex3d(o + d * (i - 1), o, o + d * j); //P1'z
368 glVertex3d(o + d * i, o, o + d * (j - 1)); //P1'x
369 glVertex3d(o + d * i, o, o + d * j); //P2
370
371 // left
372 glColor3f(c1, c2, 0);
373 glVertex3d(o, o + d * (i - 1), o + d * (j - 1)); //P1
374 glVertex3d(o, o + d * (i - 1), o + d * j); //P1'z
375 glVertex3d(o, o + d * i, o + d * (j - 1)); //P1'x
376
377 glColor3f(c1, 0, c2);
378 glVertex3d(o, o + d * i, o + d * (j - 1)); //P1'x
379 glVertex3d(o, o + d * (i - 1), o + d * j); //P1'z
380 glVertex3d(o, o + d * i, o + d * j); //P2
381
382 // right
383 glColor3f(c1, c2, 0);
384 glVertex3d(-o, o + d * (i - 1), o + d * j); //P1'z
385 glVertex3d(-o, o + d * (i - 1), o + d * (j - 1)); //P1
386 glVertex3d(-o, o + d * i, o + d * (j - 1)); //P1'x
387
388 glColor3f(c1, 0, c2);
389 glVertex3d(-o, o + d * (i - 1), o + d * j); //P1'z
390 glVertex3d(-o, o + d * i, o + d * (j - 1)); //P1'x
391 glVertex3d(-o, o + d * i, o + d * j); //P2
392
393 // front
394 glColor3f(c1, c2, 0);
395 glVertex3d(o + d * (i - 1), o + d * (j - 1), o); //P1
396 glVertex3d(o + d * (i - 1), o + d * j, o); //P1'z
397 glVertex3d(o + d * i, o + d * (j - 1), o); //P1'x
398
399 glColor3f(c1, 0, c2);
400 glVertex3d(o + d * i, o + d * (j - 1), o); //P1'x
401 glVertex3d(o + d * (i - 1), o + d * j, o); //P1'z
402 glVertex3d(o + d * i, o + d * j, o); //P2
403
404 // back
405 glColor3f(c1, c2, 0);
406 glVertex3d(o + d * (i - 1), o + d * j, -o); //P1'z
407 glVertex3d(o + d * (i - 1), o + d * (j - 1), -o); //P1
408 glVertex3d(o + d * i, o + d * (j - 1), -o); //P1'x
409
410 glColor3f(c1, 0, c2);
411 glVertex3d(o + d * (i - 1), o + d * j, -o); //P1'z
412 glVertex3d(o + d * i, o + d * (j - 1), -o); //P1'x
413 glVertex3d(o + d * i, o + d * j, -o); //P2
414 }
415 c1 -= color_step;
416 c2 = 1;
417 }
418 glEnd();
419}

◆ drawCylinder()

void drawCylinder ( float  r,
float  height,
int  slices 
)
148 {
149 /*coloring*/
150 float c = 1;
151 float color_step = (float) 1.0 / (float) (slices + 4);
152
153 float s = 2.0f * (float) M_PI / (float) slices;
154 float theta = -M_PI;
155
156 glBegin(GL_TRIANGLES);
157 for (int m = 1; m <= slices; m++) {
158 float i = (float) m;
159
160 //base
161 glColor3f(0, 0, c);
162 glVertex3d(0, 0, 0); //O
163 cylinderVertex(r, 0, theta + s * i); //P2
164 cylinderVertex(r, 0, theta + s * (i - 1)); //P1
165
166 //top
167 glColor3f(0, c, 0);
168 glVertex3d(0, height, 0); //O'
169 cylinderVertex(r, height, theta + s * (i - 1)); //P1'
170 cylinderVertex(r, height, theta + s * i); //P2'
171
172 // midsection
173 glColor3f(c, 0, 0);
174 cylinderVertex(r, 0, theta + s * (i - 1)); //P1
175 cylinderVertex(r, 0, theta + s * i); // P2
176 cylinderVertex(r, height, theta + s * (i - 1)); // P1'
177
178 glColor3f(c, 0, c);
179 cylinderVertex(r, height, theta + s * i); // P2'
180 cylinderVertex(r, height, theta + s * (i - 1)); // P1'
181 cylinderVertex(r, 0, theta + s * i); //P2
182
183 c -= color_step;
184 }
185 glEnd();
186}
void cylinderVertex(float radius, float height, float theta)
Definition: main.cpp:144

References cylinderVertex().

◆ drawPlane()

void drawPlane ( float  length,
unsigned int  divisions 
)
276 {
277 /*coloring*/
278 float c1 = 1;
279 float c2 = 1;
280 float color_step = (float) 1.0 / (float) (divisions + 4);
281
282 float o = -length / 2.0f;
283 float d = length / (float) divisions;
284 glBegin(GL_TRIANGLES);
285 for (int m = 1; m <= divisions; m++) {
286 for (int n = 1; n <= divisions; n++) {
287 float i = (float) m;
288 float j = (float) n;
289 glColor3f(c1, c2, 0);
290 glVertex3d(o + d * (i - 1), 0, o + d * (j - 1)); //P1
291 glVertex3d(o + d * (i - 1), 0, o + d * j); //P1'z
292 glVertex3d(o + d * i, 0, o + d * (j - 1)); //P1'x
293
294 glColor3f(c1, 0, c2);
295 glVertex3d(o + d * i, 0, o + d * (j - 1)); //P1'x
296 glVertex3d(o + d * (i - 1), 0, o + d * j); //P1'z
297 glVertex3d(o + d * i, 0, o + d * j); //P2
298
299 /*Cull face*/
300 glColor3f(c1, c2, 0);
301 glVertex3d(o + d * (i - 1), 0, o + d * j); //P1'z
302 glVertex3d(o + d * (i - 1), 0, o + d * (j - 1)); //P1
303 glVertex3d(o + d * i, 0, o + d * (j - 1)); //P1'x
304
305 glColor3f(c1, 0, c2);
306 glVertex3d(o + d * (i - 1), 0, o + d * j); //P1'z
307 glVertex3d(o + d * i, 0, o + d * (j - 1)); //P1'x
308 glVertex3d(o + d * i, 0, o + d * j); //P2
309 }
310 c1 -= color_step;
311 c2 = 1;
312 }
313 glEnd();
314}

◆ drawSphere()

void drawSphere ( float  r,
unsigned int  slices,
unsigned int  stacks 
)
239 {
240 /*coloring*/
241 float c1 = 1;
242 float c2 = 1;
243 float color_step = (float) 1.0 / (float) (slices + 4);
244
245 // https://www.math3d.org/EumEEZBKe
246 // https://www.math3d.org/zE4n6xayX
247
248 float s = 2.0f * (float) M_PI / (float) slices;
249 float t = M_PI / (float) stacks;
250 float theta = -M_PI;
251 float phi = -M_PI / 2.0f;
252 glBegin(GL_TRIANGLES);
253 for (int m = 1; m <= slices; m++) {
254 for (int n = 1; n <= stacks; n++) {
255 float i = (float) m;
256 float j = (float) n;
257
258 glColor3f(c1, 0, c2);
259 sphereVertex(r, theta + s * (i - 1), phi + t * j); // P1'
260 sphereVertex(r, theta + s * i, phi + t * (j - 1)); // P2
261 sphereVertex(r, theta + s * i, phi + t * j); //P2'
262
263 glColor3f(c1, c2, 0);
264 sphereVertex(r, theta + s * (i - 1), phi + t * (j - 1)); // P1
265 sphereVertex(r, theta + s * i, phi + t * (j - 1)); // P2
266 sphereVertex(r, theta + s * (i - 1), phi + t * j); // P1'
267
268 c2 -= color_step;
269 }
270 c1 -= color_step;
271 c2 = 1;
272 }
273 glEnd();
274}
void sphereVertex(float r, float theta, float phi)
Definition: main.cpp:235

References sphereVertex().

◆ keyboardFunc()

void keyboardFunc ( unsigned char  key,
int  xmouse,
int  ymouse 
)
457 {
458/*
459 Rotation:
460 x y z x↓ y↓ z↓
461 X Y Z x↑ y↑ z↑
462 angle:
463 , . θ-=s θ+=s
464 < > s↓ s↑
465 translation:
466 q w e y↓ z↑ y↑
467 a s d x↓ z↓ x↑
468 scaling:
469 u i o y↓ z↑ y↑
470 j k l x↓ z↓ x↑
471 background color: r g b R G B
472 camera:
473 1 2 3 ⎫ ! @ # ⎫ EyeX EyeY EyeZ
474 4 5 6 ⎬↓ $ % ^ ⎬↑ CenterX CenterY CenterZ
475 7 8 9 ⎭ & * ( ⎭ UpX UpY UpZ
476 */
477 switch (key) {
478 case 'x':
479 globalRotateX -= 1;
480 break;
481
482 case 'X':
483 globalRotateX += 1;
484 break;
485
486 case 'y':
487 globalRotateY -= 1;
488 break;
489
490 case 'Y':
491 globalRotateY += 1;
492 break;
493
494 case 'z':
495 globalRotateZ -= 1;
496 break;
497
498 case 'Z':
499 globalRotateZ += 1;
500 break;
501
502 case ',':
504 break;
505
506 case '.':
508 break;
509
510 case '<':
511 globalAngleStep /= 2;
512 break;
513
514 case '>':
515 globalAngleStep *= 2;
516 break;
517
518 /*translation*/
519
520 /*z-axis*/
521 case 'w':
523 break;
524 case 's':
526 break;
527
528 /*x-axis*/
529 case 'a':
531 break;
532 case 'd':
534 break;
535
536 /*y-axis*/
537 case 'q':
539 break;
540 case 'e':
542 break;
543 /*end of translation*/
544
545 /*scaling*/
546
547 /*z-axis*/
548 case 'i':
550 break;
551 case 'k':
553 break;
554
555 /*x-axis*/
556 case 'j':
558 break;
559 case 'l':
561 break;
562
563 /*y-axis*/
564 case 'u':
566 break;
567 case 'o':
569 break;
570 /*end of scaling*/
571
572 /*coloring*/
573 case 'r':
575 break;
576 case 'R':
578 break;
579 case 'g':
581 break;
582 case 'G':
584 break;
585 case 'b':
587 break;
588 case 'B':
590 break;
591
592 /*camera*/
593 case '1':
595 break;
596 case '!':
598 break;
599 case '2':
601 break;
602 case '@':
604 break;
605 case '3':
607 break;
608 case '#':
610 break;
611
612 case '4':
614 break;
615 case '$':
617 break;
618 case '5':
620 break;
621 case '%':
623 break;
624 case '6':
626 break;
627 case '^':
629 break;
630 case '7':
632 break;
633 case '&':
635 break;
636 case '8':
638 break;
639 case '*':
641 break;
642 case '9':
644 break;
645 case '(':
647 break;
648 case '[':
650 break;
651 case '{':
653 break;
654 case ']':
656 break;
657 case '}':
659 break;
660
661 /*reset environment*/
662 case '0':
663 /*Reset Rotation*/
664 globalAngle = 0;
665 globalRotateX = 0;
666 globalRotateY = 0;
667 globalRotateZ = 0;
669
670 /*Reset Translation*/
675
676 /*Reset Scale*/
678 globalScaleX = 1;
679 globalScaleY = 1;
680 globalScaleZ = 1;
681
682 /*Reset Background Color*/
686
687 /*Reset Camera*/
692
697
702
705 break;
706
707 default:
708 break;
709 }
710 glClearColor(globalBackgroundColorR, globalBackgroundColorG, globalBackgroundColorB, 1.0); //update background color
711 glutPostRedisplay(); //request display() call ASAP
712}
float globalUpStep
Definition: main.cpp:68
#define DEFAULT_GLOBAL_EYE_Y
Definition: main.cpp:45
float globalTranslateY
Definition: main.cpp:27
#define DEFAULT_GLOBAL_EYE_X
Definition: main.cpp:44
float globalBackgroundColorG
Definition: main.cpp:39
#define DEFAULT_GLOBAL_SCALE_STEP
Definition: main.cpp:15
float globalCenterStep
Definition: main.cpp:63
#define DEFAULT_GLOBAL_EYE_STEP
Definition: main.cpp:43
#define DEFAULT_GLOBAL_CENTER_Y
Definition: main.cpp:50
float globalCenterX
Definition: main.cpp:64
float globalAngleStep
Definition: main.cpp:18
float globalTranslateX
Definition: main.cpp:26
float globalEyeY
Definition: main.cpp:60
float globalTranslateStep
Definition: main.cpp:25
#define DEFAULT_GLOBAL_CENTER_X
Definition: main.cpp:49
float globalAngle
Definition: main.cpp:19
float globalBackgroundColorB
Definition: main.cpp:40
float globalScaleStep
Definition: main.cpp:31
int globalStack
Definition: main.cpp:77
int globalSlice
Definition: main.cpp:78
float globalScaleY
Definition: main.cpp:33
#define DEFAULT_GLOBAL_CENTER_STEP
Definition: main.cpp:48
#define DEFAULT_GLOBAL_UP_X
Definition: main.cpp:54
float globalScaleZ
Definition: main.cpp:34
float globalUpX
Definition: main.cpp:69
#define DEFAULT_GLOBAL_EYE_Z
Definition: main.cpp:46
float globalScaleX
Definition: main.cpp:32
float globalRotateY
Definition: main.cpp:21
#define DEFAULT_GLOBAL_UP_Z
Definition: main.cpp:56
#define DEFAULT_GLOBAL_UP_STEP
Definition: main.cpp:53
float globalEyeZ
Definition: main.cpp:61
float globalEyeStep
Definition: main.cpp:58
float globalUpZ
Definition: main.cpp:71
float globalBackgroundColorR
Definition: main.cpp:38
float globalUpY
Definition: main.cpp:70
#define DEFAULT_GLOBAL_STACK
Definition: main.cpp:73
float globalBackgroundColorStep
Definition: main.cpp:37
float globalCenterZ
Definition: main.cpp:66
#define DEFAULT_GLOBAL_UP_Y
Definition: main.cpp:55
#define DEFAULT_GLOBAL_SLICE
Definition: main.cpp:74
#define DEFAULT_GLOBAL_CENTER_Z
Definition: main.cpp:51
float globalEyeX
Definition: main.cpp:59
float globalRotateZ
Definition: main.cpp:22
#define DEFAULT_GLOBAL_ANGLE_STEP
Definition: main.cpp:13
#define DEFAULT_GLOBAL_TRANSLATE_STEP
Definition: main.cpp:14
float globalRotateX
Definition: main.cpp:20
float globalTranslateZ
Definition: main.cpp:28
float globalCenterY
Definition: main.cpp:65
int globalStackSliceStep
Definition: main.cpp:76

References DEFAULT_GLOBAL_ANGLE_STEP, DEFAULT_GLOBAL_CENTER_STEP, DEFAULT_GLOBAL_CENTER_X, DEFAULT_GLOBAL_CENTER_Y, DEFAULT_GLOBAL_CENTER_Z, DEFAULT_GLOBAL_EYE_STEP, DEFAULT_GLOBAL_EYE_X, DEFAULT_GLOBAL_EYE_Y, DEFAULT_GLOBAL_EYE_Z, DEFAULT_GLOBAL_SCALE_STEP, DEFAULT_GLOBAL_SLICE, DEFAULT_GLOBAL_STACK, DEFAULT_GLOBAL_TRANSLATE_STEP, DEFAULT_GLOBAL_UP_STEP, DEFAULT_GLOBAL_UP_X, DEFAULT_GLOBAL_UP_Y, DEFAULT_GLOBAL_UP_Z, globalAngle, globalAngleStep, globalBackgroundColorB, globalBackgroundColorG, globalBackgroundColorR, globalBackgroundColorStep, globalCenterStep, globalCenterX, globalCenterY, globalCenterZ, globalEyeStep, globalEyeX, globalEyeY, globalEyeZ, globalRotateX, globalRotateY, globalRotateZ, globalScaleStep, globalScaleX, globalScaleY, globalScaleZ, globalSlice, globalStack, globalStackSliceStep, globalTranslateStep, globalTranslateX, globalTranslateY, globalTranslateZ, globalUpStep, globalUpX, globalUpY, and globalUpZ.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)
732 {
733
734// init GLUT and the window
735 glutInit(&argc, argv);
736 glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
737 glutInitWindowPosition(100, 100);
738 glutInitWindowSize(800, 800);
739 glutCreateWindow("proj");
740
741// Required callback registry
742 glutDisplayFunc(renderScene);
743 glutReshapeFunc(changeSize);
744
745// Callback registration for keyboard processing
746 glutKeyboardFunc(keyboardFunc);
747 glutSpecialFunc(processSpecialKeys);
748
749// OpenGL settings
750 glEnable(GL_DEPTH_TEST);
751 glEnable(GL_CULL_FACE);
752 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
753
754// enter GLUT's main cycle
755 glutMainLoop();
756
757 return 1;
758}
void processSpecialKeys(int key, int xx, int yy)
Definition: main.cpp:715
void renderScene(void)
Definition: main.cpp:422
void changeSize(int w, int h)
Definition: main.cpp:119
void keyboardFunc(unsigned char key, int xmouse, int ymouse)
Definition: main.cpp:457

References changeSize(), keyboardFunc(), processSpecialKeys(), and renderScene().

◆ main2()

int main2 ( int  argc,
char **  argv 
)
721 {
722 tinyxml2::XMLDocument doc;
723 doc.LoadFile("./test_files_phase_1/test_1_1.xml");
724
725 const float title = doc.FirstChildElement("world")->FirstChildElement("camera")->FirstChildElement(
726 "position")->FloatAttribute("x");
727 printf("%f", title);
728 return 1;
729}

◆ processSpecialKeys()

void processSpecialKeys ( int  key,
int  xx,
int  yy 
)
715 {
716
717// put code to process special keys in here
718
719}

Referenced by main().

◆ readModelToBuffer()

size_t readModelToBuffer ( const char *  path,
float *  p,
unsigned int  n 
)
101 {
102 FILE *fp = fopen(path, "r");
103 size_t r = fread(p, sizeof(float), n, fp);
104 fclose(fp);
105 return r;
106}

◆ render3d()

void render3d ( const char *  path)
87 {
88 FILE *fp;
89 float p[3];
90 fp = fopen(path, "r");
91
92 glBegin(GL_TRIANGLES);
93
94 while (fread(p, sizeof(float), 3, fp))
95 glVertex3f(p[0], p[1], p[2]);
96
97 glEnd();
98 fclose(fp);
99}

◆ renderScene()

void renderScene ( void  )
422 {
423
424 // clear buffers
425 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
426
427 // set the camera
428 glLoadIdentity(); /*helps in avoiding rounding mistakes, discards old matrix, read more*/
429 gluLookAt(globalEyeX, globalEyeY, globalEyeZ,
432// drawAxes();
433 // put the geometric transformations here
437
438 // put drawing instructions here
439// drawSphere(2,10,10);
440// drawPlane(2222, 2222);
441// drawCylinder(2,10,10);
442// drawCube(10, 10);
443
444// glBegin(GL_TRIANGLES);
445// for (size_t i = 0;i+2 <= r; i+=3)
446// glVertex3f(buf[i],buf[i+1],buf[i+2]);
447// glEnd();
448// render3d("cone.3d");
449 drawCone(1, 2, 4, 3);
450// puts("here");
451// drawCone(1, 3, 10, 10);
452// End of frame
453
454 glutSwapBuffers();
455}
void drawCone(float r, float height, unsigned int slices, unsigned int stacks)
Definition: main.cpp:192

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

Referenced by main().

◆ renderTriangleVertexSeq()

void renderTriangleVertexSeq ( float *  p,
int  n 
)
108 {
109 if (!n % 3) {
110 fprintf(stderr, "Number of coordinates is not divisible by 3");
111 exit(-1);
112 }
113 glBegin(GL_TRIANGLES);
114 for (int i = 0; i < n; i += 3)
115 glVertex3f(p[i], p[i + 1], p[i + 2]);
116 glEnd();
117}

◆ sphereVertex()

void sphereVertex ( float  r,
float  theta,
float  phi 
)
235 {
236 glVertex3d(r * sin(theta) * cos(phi), r * sin(phi), r * cos(theta) * cos(phi));
237}

Referenced by drawSphere().

Variable Documentation

◆ globalAngle

float globalAngle = 0

Referenced by keyboardFunc(), and renderScene().

◆ globalAngleStep

float globalAngleStep = DEFAULT_GLOBAL_ANGLE_STEP

Referenced by keyboardFunc().

◆ globalBackgroundColorB

float globalBackgroundColorB = 0

Referenced by keyboardFunc().

◆ globalBackgroundColorG

float globalBackgroundColorG = 0

Referenced by keyboardFunc().

◆ globalBackgroundColorR

float globalBackgroundColorR = 0

Referenced by keyboardFunc().

◆ globalBackgroundColorStep

float globalBackgroundColorStep = 1

Referenced by keyboardFunc().

◆ globalCenterStep

float globalCenterStep = DEFAULT_GLOBAL_CENTER_STEP

Referenced by keyboardFunc().

◆ globalCenterX

float globalCenterX = DEFAULT_GLOBAL_CENTER_X

Referenced by keyboardFunc(), and renderScene().

◆ globalCenterY

float globalCenterY = DEFAULT_GLOBAL_CENTER_Y

Referenced by keyboardFunc(), and renderScene().

◆ globalCenterZ

float globalCenterZ = DEFAULT_GLOBAL_CENTER_Z

Referenced by keyboardFunc(), and renderScene().

◆ globalEyeStep

float globalEyeStep = DEFAULT_GLOBAL_EYE_STEP

Referenced by keyboardFunc().

◆ globalEyeX

float globalEyeX = DEFAULT_GLOBAL_EYE_X

Referenced by keyboardFunc(), and renderScene().

◆ globalEyeY

float globalEyeY = DEFAULT_GLOBAL_EYE_Y

Referenced by keyboardFunc(), and renderScene().

◆ globalEyeZ

float globalEyeZ = DEFAULT_GLOBAL_EYE_Z

Referenced by keyboardFunc(), and renderScene().

◆ globalFar

float globalFar = 1000.0f
static

Referenced by changeSize().

◆ globalFOV

float globalFOV = 60.0f
static

Referenced by changeSize().

◆ globalNear

float globalNear = 1.0f
static

Referenced by changeSize().

◆ globalRotateX

float globalRotateX = 0

Referenced by keyboardFunc(), and renderScene().

◆ globalRotateY

float globalRotateY = 0

Referenced by keyboardFunc(), and renderScene().

◆ globalRotateZ

float globalRotateZ = 0

Referenced by keyboardFunc(), and renderScene().

◆ globalScaleStep

float globalScaleStep = DEFAULT_GLOBAL_SCALE_STEP

Referenced by keyboardFunc().

◆ globalScaleX

float globalScaleX = 1

Referenced by keyboardFunc(), and renderScene().

◆ globalScaleY

float globalScaleY = 1

Referenced by keyboardFunc(), and renderScene().

◆ globalScaleZ

float globalScaleZ = 1

Referenced by keyboardFunc(), and renderScene().

◆ globalSlice

int globalSlice = DEFAULT_GLOBAL_SLICE

Referenced by keyboardFunc().

◆ globalStack

int globalStack = DEFAULT_GLOBAL_STACK

Referenced by keyboardFunc().

◆ globalStackSliceStep

int globalStackSliceStep = 1

Referenced by keyboardFunc().

◆ globalTranslateStep

float globalTranslateStep = DEFAULT_GLOBAL_TRANSLATE_STEP

Referenced by keyboardFunc().

◆ globalTranslateX

float globalTranslateX = 0

Referenced by keyboardFunc(), and renderScene().

◆ globalTranslateY

float globalTranslateY = 0

Referenced by keyboardFunc(), and renderScene().

◆ globalTranslateZ

float globalTranslateZ = 0

Referenced by keyboardFunc(), and renderScene().

◆ globalUpStep

float globalUpStep = DEFAULT_GLOBAL_UP_STEP

Referenced by keyboardFunc().

◆ globalUpX

float globalUpX = DEFAULT_GLOBAL_UP_X

Referenced by keyboardFunc(), and renderScene().

◆ globalUpY

float globalUpY = DEFAULT_GLOBAL_UP_Y

Referenced by keyboardFunc(), and renderScene().

◆ globalUpZ

float globalUpZ = DEFAULT_GLOBAL_UP_Z

Referenced by keyboardFunc(), and renderScene().