Heightmap probing ... done?
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#include "heightmap.h"
|
||||
|
||||
grbl::heightmap grbl::heightmap::from_params(float from_x, float from_y, float to_x, float to_y, float resolution) {
|
||||
heightmap result{};
|
||||
|
||||
result.from_x = from_x;
|
||||
result.from_y = from_y;
|
||||
result.to_x = to_x;
|
||||
result.to_y = to_y;
|
||||
result.resolution = resolution;
|
||||
|
||||
result.x_segments = static_cast<size_t>(ceilf((to_x - from_x) / resolution));
|
||||
result.y_segments = static_cast<size_t>(ceilf((to_y - from_y) / resolution));
|
||||
|
||||
float y_pos = from_y;
|
||||
for (int y = 0; y < (result.y_segments + 1); y++) {
|
||||
float x_pos = from_x;
|
||||
for (int x = 0; x < (result.x_segments + 1); x++) {
|
||||
// add a bit of random wobble to make it visible [-10, +10]
|
||||
// float z = ((rand() / (float) RAND_MAX) - 0.5f) * 2.0f * 1.0f;
|
||||
float z = 0.0f;
|
||||
result.vertices.emplace_back(x_pos, y_pos, z);
|
||||
x_pos += resolution;
|
||||
}
|
||||
y_pos += resolution;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user