Repository navigation
Expand file tree
/
Copy pathSceneDirector.cpp
More file actions
80 lines (64 loc) · 2.43 KB
/
Copy pathSceneDirector.cpp
File metadata and controls
80 lines (64 loc) · 2.43 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
#include "SceneDirector.h"
#include "Common.h"
// Analytical Ray-Sphere Eclipse Test for Mars Sun Occlusion
float computeSunMarsOcclusion(float camX, float camY, float camZ) {
float rayDx = SUN_DIR_X;
float rayDy = SUN_DIR_Y;
float rayDz = SUN_DIR_Z;
normalize3(rayDx, rayDy, rayDz);
float ocX = -camX;
float ocY = -camY;
float ocZ = -camZ;
float tProj = ocX * rayDx + ocY * rayDy + ocZ * rayDz;
if (tProj <= 0.0f) {
return 1.0f; // Sun is behind camera
}
float perpSq = (ocX * ocX + ocY * ocY + ocZ * ocZ) - (tProj * tProj);
float dPerp = (perpSq > 0.0f) ? sqrtf(perpSq) : 0.0f;
const float MARS_R_OCCL = MARS_RADIUS * 1.045f;
if (dPerp < MARS_R_OCCL) {
return 0.0f; // Completely occluded by Mars
}
const float MARS_ATMOS_EDGE = MARS_RADIUS * 1.085f;
if (dPerp < MARS_ATMOS_EDGE) {
return smoothstep(MARS_R_OCCL, MARS_ATMOS_EDGE, dPerp);
}
return 1.0f;
}
void updateSceneDirector(float dt) {
marsSpinAngle += 3.5f * dt;
if (marsSpinAngle >= 360.0f) marsSpinAngle -= 360.0f;
uranusSpinAngle += 2.0f * dt;
if (uranusSpinAngle >= 360.0f) uranusSpinAngle -= 360.0f;
jupiterSpinAngle += 4.5f * dt;
if (jupiterSpinAngle >= 360.0f) jupiterSpinAngle -= 360.0f;
saturnSpinAngle += 3.8f * dt;
if (saturnSpinAngle >= 360.0f) saturnSpinAngle -= 360.0f;
phobosAngle += 0.045f * dt;
ringSpinAngle += 24.0f * dt;
if (ringSpinAngle >= 360.0f) ringSpinAngle -= 360.0f;
// Multi-scene sequencing
if (seqTime <= 35.0f) {
updateScene1(dt);
} else if (seqTime < 44.0f) {
updateScene2(dt);
} else if (seqTime < 65.0f) {
updateScene3(dt);
} else {
updateScene4(dt);
}
}
void computeCinematicCamera(float& eyeX, float& eyeY, float& eyeZ,
float& targetX, float& targetY, float& targetZ,
float& upX, float& upY, float& upZ) {
upX = 0.0f; upY = 1.0f; upZ = 0.0f;
if (seqTime <= 35.0f) {
computeCameraScene1(eyeX, eyeY, eyeZ, targetX, targetY, targetZ, upX, upY, upZ);
} else if (seqTime < 44.0f) {
computeCameraScene2(eyeX, eyeY, eyeZ, targetX, targetY, targetZ, upX, upY, upZ);
} else if (seqTime < 65.0f) {
computeCameraScene3(eyeX, eyeY, eyeZ, targetX, targetY, targetZ, upX, upY, upZ);
} else {
computeCameraScene4(eyeX, eyeY, eyeZ, targetX, targetY, targetZ, upX, upY, upZ);
}
}