comparison src/solar-system.cpp @ 4:7ae4ee5c27f8

Corrected orientation and orbital speed of Moon
author Eris Caffee <discordia@eldalin.com>
date Sun, 28 Apr 2013 18:36:00 -0500
parents c24af3462002
children
comparison
equal deleted inserted replaced
0:d13c292333fc 2:5158ed2c6aca
12 #include <stdlib.h> 12 #include <stdlib.h>
13 #include <string.h> 13 #include <string.h>
14 14
15 #include <dirent.h> 15 #include <dirent.h>
16 16
17 #include <string>
18
17 #include <GL/glut.h> 19 #include <GL/glut.h>
18 #include <GL/glx.h> 20 #include <GL/glx.h>
21
22 ////////////////////////////////////////////////////////////////////////////////
19 23
20 GLShaderManager shaderManager; 24 GLShaderManager shaderManager;
21 GLMatrixStack modelViewMatrix; 25 GLMatrixStack modelViewMatrix;
22 GLMatrixStack projectionMatrix; 26 GLMatrixStack projectionMatrix;
23 GLFrustum viewFrustum; 27 GLFrustum viewFrustum;
27 31
28 GLenum polymode = GL_FILL; 32 GLenum polymode = GL_FILL;
29 33
30 int width = 800; 34 int width = 800;
31 int height = 600; 35 int height = 600;
32 int fullscreen = 0; 36 int fullscreen = 1;
33 37
34 #define NUM_SPHERES 50 38 ////////////////////////////////////////////////////////////////////////////////
35 GLFrame spheres[NUM_SPHERES];
36 39
37 GLTriangleBatch jupiterBatch; 40 GLTriangleBatch jupiterBatch;
38 GLTriangleBatch sphereBatch;
39 GLTriangleBatch earthBatch; 41 GLTriangleBatch earthBatch;
40 GLTriangleBatch moonBatch; 42 GLTriangleBatch moonBatch;
41 GLTriangleBatch sunBatch; 43 GLTriangleBatch sunBatch;
42 GLBatch floorBatch; 44
45 ////////////////////////////////////////////////////////////////////////////////
43 46
44 #define TEX_EARTH 1 47 #define TEX_EARTH 1
45 #define TEX_MOON 2 48 #define TEX_MOON 2
46 #define TEX_JUPITER 3 49 #define TEX_JUPITER 3
47 #define TEX_SUN 4 50 #define TEX_SUN 4
48 #define NUM_TEXTURES 5 51 #define NUM_TEXTURES 5
49 GLuint uiTextures[NUM_TEXTURES]; 52 GLuint uiTextures[NUM_TEXTURES];
50 53
51 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
55
56 const std::string Data_Dir("../textures/");
57
58 ////////////////////////////////////////////////////////////////////////////////
59
52 #define SCREENSHOT_FILENAME_BASE "screenshot-" 60 #define SCREENSHOT_FILENAME_BASE "screenshot-"
53 #define SCREENSHOT_FILENAME_BASELEN 11 61 #define SCREENSHOT_FILENAME_BASELEN 11
54 #define SCREENSHOT_FILENAME_EXT ".tga" 62 #define SCREENSHOT_FILENAME_EXT ".tga"
55 #define SCREENSHOT_FILENAME_EXTLEN 4 63 #define SCREENSHOT_FILENAME_EXTLEN 4
56 64
146 float EarthRotSpeed = 1.0/24 * RotScale; 154 float EarthRotSpeed = 1.0/24 * RotScale;
147 float EarthAxialTilt = 23.5; 155 float EarthAxialTilt = 23.5;
148 156
149 float MoonRotSpeed = 1.0/29.5 * RotScale; 157 float MoonRotSpeed = 1.0/29.5 * RotScale;
150 float MoonAxialTilt = 6.7; 158 float MoonAxialTilt = 6.7;
151 float MoonOrbitSpeed = 1.0/29.5 * RotScale; 159 float MoonOrbitSpeed = 1.0/(24*29.5) * RotScale;
152 float MoonOrbitTilt = 5.145; 160 float MoonOrbitTilt = 5.145;
153 161
154 static CStopWatch rotTimer; 162 static CStopWatch rotTimer;
155 163
156 // Get the light position in eye space 164 // Get the light position in eye space
269 // Begin Moon 277 // Begin Moon
270 278
271 279
272 // orbit the Earth 280 // orbit the Earth
273 modelViewMatrix.Rotate(MoonOrbitTilt, 0.0f, 0.0f, 1.0f); 281 modelViewMatrix.Rotate(MoonOrbitTilt, 0.0f, 0.0f, 1.0f);
282
274 // NOrth is up! 283 // NOrth is up!
275 modelViewMatrix.Rotate(-90.0f - MoonAxialTilt, 0.0f, 1.0f, 0.0f); 284 modelViewMatrix.Rotate(90.0f - MoonAxialTilt, -1.0f, 0.0f, 0.0f);
285 modelViewMatrix.Rotate(90.0f, 0.0f, 0.0f, 1.0f);
276 286
277 float MoonRot = rotTimer.GetElapsedSeconds() * MoonOrbitSpeed * 10; 287 float MoonRot = rotTimer.GetElapsedSeconds() * MoonOrbitSpeed * 10;
278 modelViewMatrix.Rotate(MoonRot, 0.0f, 1.0f, 0.0f); 288 modelViewMatrix.Rotate(MoonRot, 0.0f, 0.0f, 1.0f);
279 289
280 modelViewMatrix.Translate(0.5f, 0.0f, 0.0f); 290 modelViewMatrix.Translate(0.0f, 0.5f, 0.0f);
281 291
282 292
283 glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_MOON]); 293 glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_MOON]);
284 if (polymode == GL_FILL) 294 if (polymode == GL_FILL)
285 { 295 {
345 gltMakeSphere(moonBatch, 0.1f, 26, 26); 355 gltMakeSphere(moonBatch, 0.1f, 26, 26);
346 gltMakeSphere(sunBatch, 1.0f, 26, 26); 356 gltMakeSphere(sunBatch, 1.0f, 26, 26);
347 357
348 glGenTextures(NUM_TEXTURES, uiTextures); 358 glGenTextures(NUM_TEXTURES, uiTextures);
349 359
360 std::string f;
361
362 f.assign(Data_Dir).append("earth.tga");
350 glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_EARTH]); 363 glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_EARTH]);
351 LoadTGATexture("../textures/earth.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); 364 LoadTGATexture(f.c_str(), GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
352 365
366 f.assign(Data_Dir).append("moon.tga");
353 glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_MOON]); 367 glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_MOON]);
354 LoadTGATexture("../textures/moon.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); 368 LoadTGATexture(f.c_str(), GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
355 369
370 f.assign(Data_Dir).append("jupiter.tga");
356 glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_JUPITER]); 371 glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_JUPITER]);
357 LoadTGATexture("../textures/jupiter.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); 372 LoadTGATexture(f.c_str(), GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
358 373
374 f.assign(Data_Dir).append("sun.tga");
359 glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_SUN]); 375 glBindTexture(GL_TEXTURE_2D, uiTextures[TEX_SUN]);
360 LoadTGATexture("../textures/sun.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); 376 LoadTGATexture(f.c_str(), GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE);
361 377
362 static M3DMatrix44f mCamera; 378 static M3DMatrix44f mCamera;
363 cameraFrame.GetCameraMatrix(mCamera); 379 cameraFrame.GetCameraMatrix(mCamera);
364 cameraFrame.MoveForward(-10.0); 380 cameraFrame.MoveForward(-10.0);
365 // cameraFrame.RotateWorld(15.0, 0.0f, 1.0f, 0.0f); 381 // cameraFrame.RotateWorld(15.0, 0.0f, 1.0f, 0.0f);
520 { 536 {
521 gltSetWorkingDirectory(argv[0]); 537 gltSetWorkingDirectory(argv[0]);
522 glutInit(&argc, argv); 538 glutInit(&argc, argv);
523 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL); 539 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
524 glutInitWindowSize(800, 600); 540 glutInitWindowSize(800, 600);
525 glutCreateWindow("OpenGL SphereWorld"); 541 glutCreateWindow("OpenGL Solar System");
526 542
527 glutReshapeFunc(ChangeSize); 543 glutReshapeFunc(ChangeSize);
528 glutDisplayFunc(RenderScene); 544 glutDisplayFunc(RenderScene);
529 glutSpecialFunc(SpecialKeys); 545 glutSpecialFunc(SpecialKeys);
530 glutKeyboardFunc(KeyboardFunc); 546 glutKeyboardFunc(KeyboardFunc);
550 566
551 if (SwapInterval) 567 if (SwapInterval)
552 SwapInterval(1); 568 SwapInterval(1);
553 569
554 SetupRC(); 570 SetupRC();
571
572 glutFullScreen();
573 fullscreen = 1;
574
555 glutMainLoop(); 575 glutMainLoop();
556 ShutDownRC(); 576 ShutDownRC();
557 577
558 return 0; 578 return 0;
559 } 579 }