| | 57 | void SetHighPlateau(CTerrain& terrain, int height) |
| | 58 | { |
| | 59 | SetVertex(terrain, 4, 0, 100 +height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); |
| | 60 | SetVertex(terrain, 4, 1, 100 +height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); |
| | 61 | SetVertex(terrain, 4, 2, 100 +height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); |
| | 62 | SetVertex(terrain, 5, 0, 100 +height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); |
| | 63 | SetVertex(terrain, 5, 1, 100 +height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); |
| | 64 | SetVertex(terrain, 5, 2, 100 +height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); |
| | 65 | } |
| | 66 | |
| | 68 | void test_GetExactGroundLevel() |
| | 69 | { |
| | 70 | CTerrain terrain; |
| | 71 | terrain.Initialize(6, NULL); |
| | 72 | Set45Slope(terrain); |
| | 73 | SetHighPlateau(terrain, 20); |
| | 74 | |
| | 75 | float ground; |
| | 76 | |
| | 77 | ground = terrain.GetExactGroundLevel(0.f, 1.5f*CELL_SIZE); |
| | 78 | TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE, 0.01f); |
| | 79 | |
| | 80 | ground = terrain.GetExactGroundLevel(0.5f*CELL_SIZE, 1.5f*CELL_SIZE); |
| | 81 | TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+0.5f*CELL_SIZE, 0.01f); |
| | 82 | |
| | 83 | ground = terrain.GetExactGroundLevel(1.5f*CELL_SIZE, 1.5f*CELL_SIZE); |
| | 84 | TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+1.5f*CELL_SIZE, 0.01f); |
| | 85 | |
| | 86 | ground = terrain.GetExactGroundLevel(2.5f*CELL_SIZE, 1.5f*CELL_SIZE); |
| | 87 | TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+2.f*CELL_SIZE, 0.01f); |
| | 88 | |
| | 89 | ground = terrain.GetExactGroundLevel(3.5f*CELL_SIZE, 1.5f*CELL_SIZE); |
| | 90 | TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+11.f*CELL_SIZE, 0.01f); |
| | 91 | |
| | 92 | ground = terrain.GetExactGroundLevel(4.5f*CELL_SIZE, 1.5f*CELL_SIZE); |
| | 93 | TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+20.f*CELL_SIZE, 0.01f); |
| | 94 | } |
| | 95 | |
| | 96 | void test_GetExactGroundLevelFixed() |
| | 97 | { |
| | 98 | CTerrain terrain; |
| | 99 | terrain.Initialize(4, NULL); |
| | 100 | Set45Slope(terrain); |
| | 101 | SetHighPlateau(terrain, 20); |
| | 102 | |
| | 103 | CFixed_23_8 ground; |
| | 104 | |
| | 105 | ground = terrain.GetExactGroundLevelFixed(CFixed_23_8::FromFloat(0.f), CFixed_23_8::FromFloat(1.5f*CELL_SIZE)); |
| | 106 | TS_ASSERT_DELTA(ground.ToFloat(), 100.f/HEIGHT_UNITS_PER_METRE, 0.01f); |
| | 107 | |
| | 108 | ground = terrain.GetExactGroundLevelFixed(CFixed_23_8::FromFloat(0.5f*CELL_SIZE), CFixed_23_8::FromFloat(1.5f*CELL_SIZE)); |
| | 109 | TS_ASSERT_DELTA(ground.ToFloat(), 100.f/HEIGHT_UNITS_PER_METRE+0.5f*CELL_SIZE, 0.01f); |
| | 110 | |
| | 111 | ground = terrain.GetExactGroundLevelFixed(CFixed_23_8::FromFloat(1.5f*CELL_SIZE), CFixed_23_8::FromFloat(1.5f*CELL_SIZE)); |
| | 112 | TS_ASSERT_DELTA(ground.ToFloat(), 100.f/HEIGHT_UNITS_PER_METRE+1.5f*CELL_SIZE, 0.01f); |
| | 113 | |
| | 114 | ground = terrain.GetExactGroundLevelFixed(CFixed_23_8::FromFloat(2.5f*CELL_SIZE), CFixed_23_8::FromFloat(1.5f*CELL_SIZE)); |
| | 115 | TS_ASSERT_DELTA(ground.ToFloat(), 100.f/HEIGHT_UNITS_PER_METRE+2.f*CELL_SIZE, 0.01f); |
| | 116 | |
| | 117 | ground = terrain.GetExactGroundLevelFixed(CFixed_23_8::FromFloat(3.5f*CELL_SIZE), CFixed_23_8::FromFloat(1.5f*CELL_SIZE)); |
| | 118 | TS_ASSERT_DELTA(ground.ToFloat(), 100.f/HEIGHT_UNITS_PER_METRE+11.f*CELL_SIZE, 0.01f); |
| | 119 | |
| | 120 | ground = terrain.GetExactGroundLevelFixed(CFixed_23_8::FromFloat(4.5f*CELL_SIZE), CFixed_23_8::FromFloat(1.5f*CELL_SIZE)); |
| | 121 | TS_ASSERT_DELTA(ground.ToFloat(), 100.f/HEIGHT_UNITS_PER_METRE+20.f*CELL_SIZE, 0.01f); |
| | 122 | } |
| | 123 | |