1#pragma once
2#include "Reference9/SunPositionOverride.h"
3
4static void SunPositionOverrideTests()
5{
6 D3DXMATRIX orbit, rotation;
7 D3DXMatrixScaling(&orbit, 40.f, 40.f, 40.f);
8 orbit._42 = -100000.f;
9 const D3DXVECTOR3 locations[] = {
10 {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}, {3, 4, 5}
11 };
12 for (float angle : {0.f, .73f})
13 {
14 D3DXMatrixRotationZ(&rotation, angle);
15 const D3DXMATRIX natural = orbit * rotation;
16 for (auto up : locations)
17 {
18 D3DXVec3Normalize(&up, &up);
19 for (float mode : {1.f, 0.f, -1.f})
20 {
21 D3DXMATRIX world = natural;
22 D3DXVECTOR3 light(.2f, .3f, .4f);
23 const D3DXVECTOR3 naturalLight = light;
25 if (mode == -1.f)
26 {
27 Check(std::memcmp(&world, &natural, sizeof world) == 0 && light == naturalLight,
28 "SUN-1 preserves the current orbital matrix and light exactly");
29 continue;
30 }
31 const D3DXVECTOR3 center(world._41, world._42, world._43);
32 const D3DXVECTOR3 right(world._11, world._12, world._13);
33 D3DXVECTOR3 normal(world._21, world._22, world._23);
34 const D3DXVECTOR3 top(world._31, world._32, world._33);
35 Check(std::fabs(D3DXVec3Length(¢er) - 100000.f) < .02f,
36 "override retains solar distance");
37 Check(std::fabs(D3DXVec3Length(&right) - 40.f) < .001f &&
38 std::fabs(D3DXVec3Length(&top) - 40.f) < .001f,
39 "override retains solar disc size at both poles and opposite directions");
40 D3DXVec3Normalize(&normal, &normal);
41 Check(D3DXVec3Dot(&normal, &light) > .99999f,
42 "solar disc continues facing the observer after repositioning");
43 Check(std::fabs(D3DXVec3Dot(&light, &up) - (mode == 1.f ? -1.f : 1.f)) < .00001f,
44 "SUN1 is overhead and SUN0 is below the planet at every location");
45 Check(D3DXVec3Dot(¢er, &light) < -99999.f,
46 "visible sun and scene light agree on direction");
47 }
48 }
49 }
50}
void Apply(float mode, const RiseMath::Vector3 &outwardNormal, RiseMath::Matrix &sunWorld, RiseMath::Vector3 &incomingLight)