80 lines
3.6 KiB
C++
80 lines
3.6 KiB
C++
#include "terrain/terrain.h"
|
|
#include <iostream>
|
|
#include <cassert>
|
|
#include <cmath>
|
|
|
|
using namespace metin2::terrain;
|
|
|
|
int main() {
|
|
std::cout << "[Test 1] Procedural terrain generation & bilinear height sampling..." << std::endl;
|
|
TerrainHeightmap heightmap;
|
|
heightmap.GenerateProcedural(64, 64, 100.0f, 120.0f);
|
|
|
|
assert(heightmap.GetWidth() == 64);
|
|
assert(heightmap.GetHeight() == 64);
|
|
assert(heightmap.GetMaxHeight() > heightmap.GetMinHeight());
|
|
|
|
// Continuous world height query
|
|
float h_center = heightmap.GetHeightAtWorld(0.0f, 0.0f);
|
|
std::cout << " Height at world origin (0, 0): " << h_center << std::endl;
|
|
|
|
float normal[3];
|
|
heightmap.GetNormalAtWorld(0.0f, 0.0f, normal);
|
|
float norm_len = std::sqrt(normal[0]*normal[0] + normal[1]*normal[1] + normal[2]*normal[2]);
|
|
assert(std::abs(norm_len - 1.0f) < 1e-4f);
|
|
assert(normal[1] > 0.0f); // Y-up
|
|
std::cout << " Normal at world origin: (" << normal[0] << ", " << normal[1] << ", " << normal[2] << ")" << std::endl;
|
|
|
|
std::cout << "[Test 2] Quadtree & Frustum Culling..." << std::endl;
|
|
assert(heightmap.GetQuadtreeRoot() != nullptr);
|
|
assert(!heightmap.GetPatches().empty());
|
|
|
|
// Standard DirectX LookAt View matrix: Eye=(0, 500, -1000), Target=(0, 0, 0), Up=(0, 1, 0)
|
|
float view[16] = {
|
|
1.0f, 0.0f, 0.0f, 0.0f,
|
|
0.0f, 0.894427f, -0.447214f, 0.0f,
|
|
0.0f, 0.447214f, 0.894427f, 0.0f,
|
|
0.0f, 0.0f, 1118.034f, 1.0f
|
|
};
|
|
// Standard perspective projection matrix (FOV ~60 deg, near 1.0, far 10000.0)
|
|
float proj[16] = {
|
|
1.732f, 0.0f, 0.0f, 0.0f,
|
|
0.0f, 1.732f, 0.0f, 0.0f,
|
|
0.0f, 0.0f, 1.0001f, 1.0f,
|
|
0.0f, 0.0f, -1.0001f, 0.0f
|
|
};
|
|
|
|
auto culled_draws = heightmap.BuildCulledDraws(view, proj, 10000.0f);
|
|
std::cout << " Visible patches culled by frustum: " << culled_draws.size() << " / " << heightmap.GetPatches().size() << std::endl;
|
|
assert(!culled_draws.empty());
|
|
|
|
std::cout << "[Test 3] Attribute Map loading & querying..." << std::endl;
|
|
// Create dummy 256x256 attribute map with ATTR_BLOCK and ATTR_WATER
|
|
std::vector<uint8_t> dummy_attr(TerrainHeightmap::ATTRMAP_XSIZE * TerrainHeightmap::ATTRMAP_YSIZE, 0);
|
|
// Mark center cell as blocked
|
|
dummy_attr[128 * TerrainHeightmap::ATTRMAP_XSIZE + 128] = TerrainAttr::ATTR_BLOCK | TerrainAttr::ATTR_BANPK;
|
|
bool attr_ok = heightmap.LoadAttrFromBuffer(dummy_attr.data(), dummy_attr.size());
|
|
assert(attr_ok);
|
|
assert(heightmap.HasAttrMap());
|
|
assert(heightmap.GetAttrAtGrid(128, 128) == (TerrainAttr::ATTR_BLOCK | TerrainAttr::ATTR_BANPK));
|
|
assert(heightmap.IsAttrOn(0.0f, 0.0f, TerrainAttr::ATTR_BLOCK));
|
|
assert(heightmap.IsAttrOn(0.0f, 0.0f, TerrainAttr::ATTR_BANPK));
|
|
assert(!heightmap.IsAttrOn(0.0f, 0.0f, TerrainAttr::ATTR_WATER));
|
|
|
|
std::cout << "[Test 4] WaterManager & procedural wave generation..." << std::endl;
|
|
WaterManager water;
|
|
water.GenerateProceduralWater(25.0f, -1000.0f, 1000.0f, -1000.0f, 1000.0f, 100.0f);
|
|
assert(water.HasWater());
|
|
assert(water.GetWaterFaceCount() > 0);
|
|
|
|
TerrainDrawCommand water_draw = water.BuildDrawCommand(0.5f);
|
|
assert(!water_draw.positions.empty());
|
|
assert(!water_draw.indices.empty());
|
|
assert(water_draw.positions.size() == water_draw.normals.size());
|
|
std::cout << " Water mesh generated: " << water_draw.positions.size() / 3 << " vertices, "
|
|
<< water_draw.indices.size() / 3 << " triangles" << std::endl;
|
|
|
|
std::cout << "All Terrain SDK tests passed successfully!" << std::endl;
|
|
return 0;
|
|
}
|