Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/tests/test_Terrain.h
/* Copyright (C) 2010 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | void SetHighPlateau(CTerrain& terrain, int height) | ||||
SetVertex(terrain, 5, 1, 100 + height*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); | SetVertex(terrain, 5, 1, 100 + height*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); | ||||
SetVertex(terrain, 5, 2, 100 + height*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); | SetVertex(terrain, 5, 2, 100 + height*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); | ||||
} | } | ||||
public: | public: | ||||
void test_GetExactGroundLevel() | void test_GetExactGroundLevel() | ||||
{ | { | ||||
CTerrain terrain; | CTerrain terrain; | ||||
terrain.Initialize(4, NULL); | terrain.Initialize(4, nullptr); | ||||
Set45Slope(terrain); | Set45Slope(terrain); | ||||
SetHighPlateau(terrain, 20); | SetHighPlateau(terrain, 20); | ||||
float ground; | float ground; | ||||
ground = terrain.GetExactGroundLevel(0.f, 1.5f*TERRAIN_TILE_SIZE); | ground = terrain.GetExactGroundLevel(0.f, 1.5f*TERRAIN_TILE_SIZE); | ||||
TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE, 0.01f); | TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE, 0.01f); | ||||
Show All 11 Lines | void test_GetExactGroundLevel() | ||||
ground = terrain.GetExactGroundLevel(4.5f*TERRAIN_TILE_SIZE, 1.5f*TERRAIN_TILE_SIZE); | ground = terrain.GetExactGroundLevel(4.5f*TERRAIN_TILE_SIZE, 1.5f*TERRAIN_TILE_SIZE); | ||||
TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+20.f*TERRAIN_TILE_SIZE, 0.01f); | TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+20.f*TERRAIN_TILE_SIZE, 0.01f); | ||||
} | } | ||||
void test_GetExactGroundLevelFixed() | void test_GetExactGroundLevelFixed() | ||||
{ | { | ||||
CTerrain terrain; | CTerrain terrain; | ||||
terrain.Initialize(4, NULL); | terrain.Initialize(4, nullptr); | ||||
Set45Slope(terrain); | Set45Slope(terrain); | ||||
SetHighPlateau(terrain, 20); | SetHighPlateau(terrain, 20); | ||||
const double maxDelta = 0.0001; | const double maxDelta = 0.0001; | ||||
fixed ground; | fixed ground; | ||||
ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(0.f), fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE)); | ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(0.f), fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE)); | ||||
Show All 13 Lines | void test_GetExactGroundLevelFixed() | ||||
ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(4.5f*TERRAIN_TILE_SIZE), fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE)); | ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(4.5f*TERRAIN_TILE_SIZE), fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE)); | ||||
TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+20.0*TERRAIN_TILE_SIZE, maxDelta); | TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+20.0*TERRAIN_TILE_SIZE, maxDelta); | ||||
} | } | ||||
void test_GetExactGroundLevelFixed_max() | void test_GetExactGroundLevelFixed_max() | ||||
{ | { | ||||
CTerrain terrain; | CTerrain terrain; | ||||
terrain.Initialize(4, NULL); | terrain.Initialize(4, nullptr); | ||||
SetVertex(terrain, 0, 0, 65535); | SetVertex(terrain, 0, 0, 65535); | ||||
SetVertex(terrain, 0, 1, 65535); | SetVertex(terrain, 0, 1, 65535); | ||||
SetVertex(terrain, 1, 0, 65535); | SetVertex(terrain, 1, 0, 65535); | ||||
SetVertex(terrain, 1, 1, 65535); | SetVertex(terrain, 1, 1, 65535); | ||||
const double maxDelta = 0.024; | const double maxDelta = 0.024; | ||||
int p = 255; | int p = 255; | ||||
for (int zi = 0; zi < p; ++zi) | for (int zi = 0; zi < p; ++zi) | ||||
{ | { | ||||
for (int xi = 0; xi < p; ++xi) | for (int xi = 0; xi < p; ++xi) | ||||
{ | { | ||||
fixed ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(xi/(float)p*TERRAIN_TILE_SIZE), fixed::FromFloat(zi/(float)p*TERRAIN_TILE_SIZE)); | fixed ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(xi/(float)p*TERRAIN_TILE_SIZE), fixed::FromFloat(zi/(float)p*TERRAIN_TILE_SIZE)); | ||||
TS_ASSERT_DELTA(ground.ToDouble(), 65535.0/HEIGHT_UNITS_PER_METRE, maxDelta); | TS_ASSERT_DELTA(ground.ToDouble(), 65535.0/HEIGHT_UNITS_PER_METRE, maxDelta); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void test_CalcNormal() | void test_CalcNormal() | ||||
{ | { | ||||
CTerrain terrain; | CTerrain terrain; | ||||
terrain.Initialize(4, NULL); | terrain.Initialize(4, nullptr); | ||||
Set45Slope(terrain); | Set45Slope(terrain); | ||||
CVector3D vec; | CVector3D vec; | ||||
terrain.CalcNormal(1, 1, vec); | terrain.CalcNormal(1, 1, vec); | ||||
TS_ASSERT_DELTA(vec.X, -1.f/sqrt(2.f), 0.01f); | TS_ASSERT_DELTA(vec.X, -1.f/sqrt(2.f), 0.01f); | ||||
TS_ASSERT_DELTA(vec.Y, 1.f/sqrt(2.f), 0.01f); | TS_ASSERT_DELTA(vec.Y, 1.f/sqrt(2.f), 0.01f); | ||||
TS_ASSERT_EQUALS(vec.Z, 0.f); | TS_ASSERT_EQUALS(vec.Z, 0.f); | ||||
terrain.CalcNormal(2, 1, vec); | terrain.CalcNormal(2, 1, vec); | ||||
TS_ASSERT_DELTA(vec.X, (-1.f/sqrt(2.f)) / sqrt(2.f+sqrt(2.f)), 0.01f); | TS_ASSERT_DELTA(vec.X, (-1.f/sqrt(2.f)) / sqrt(2.f+sqrt(2.f)), 0.01f); | ||||
TS_ASSERT_DELTA(vec.Y, (1.f+1.f/sqrt(2.f)) / sqrt(2.f+sqrt(2.f)), 0.01f); | TS_ASSERT_DELTA(vec.Y, (1.f+1.f/sqrt(2.f)) / sqrt(2.f+sqrt(2.f)), 0.01f); | ||||
TS_ASSERT_EQUALS(vec.Z, 0); | TS_ASSERT_EQUALS(vec.Z, 0); | ||||
terrain.CalcNormal(5, 1, vec); | terrain.CalcNormal(5, 1, vec); | ||||
TS_ASSERT_EQUALS(vec.X, 0.f); | TS_ASSERT_EQUALS(vec.X, 0.f); | ||||
TS_ASSERT_EQUALS(vec.Y, 1.f); | TS_ASSERT_EQUALS(vec.Y, 1.f); | ||||
TS_ASSERT_EQUALS(vec.Z, 0.f); | TS_ASSERT_EQUALS(vec.Z, 0.f); | ||||
} | } | ||||
void test_CalcNormalFixed() | void test_CalcNormalFixed() | ||||
{ | { | ||||
CTerrain terrain; | CTerrain terrain; | ||||
terrain.Initialize(4, NULL); | terrain.Initialize(4, nullptr); | ||||
Set45Slope(terrain); | Set45Slope(terrain); | ||||
CFixedVector3D vec; | CFixedVector3D vec; | ||||
terrain.CalcNormalFixed(1, 1, vec); | terrain.CalcNormalFixed(1, 1, vec); | ||||
TS_ASSERT_DELTA(vec.X.ToFloat(), -1.f/sqrt(2.f), 0.01f); | TS_ASSERT_DELTA(vec.X.ToFloat(), -1.f/sqrt(2.f), 0.01f); | ||||
TS_ASSERT_DELTA(vec.Y.ToFloat(), 1.f/sqrt(2.f), 0.01f); | TS_ASSERT_DELTA(vec.Y.ToFloat(), 1.f/sqrt(2.f), 0.01f); | ||||
TS_ASSERT_EQUALS(vec.Z.ToFloat(), 0.f); | TS_ASSERT_EQUALS(vec.Z.ToFloat(), 0.f); | ||||
Show All 12 Lines |
Wildfire Games · Phabricator