Exposed exaggeration factor when rendering heightmap.

Added checkbox to select whether to run autoleveled program or not.
Heightmap can handle non integer from_x and to_x.
This commit is contained in:
2023-05-23 14:28:08 +03:00
parent 4e7e059e22
commit b7b9fed0dd
8 changed files with 118 additions and 143 deletions
+20 -16
View File
@@ -30,8 +30,8 @@ grbl::heightmap grbl::heightmap::from_params(float from_x, float from_y, float t
size_t grbl::heightmap::index_from_coords(float x, float y) const {
size_t result = 0;
for (auto& v: vertices) {
if (v.x == x && v.y == y) {
for (auto &v: vertices) {
if (float_equal(v.x, x) && float_equal(v.y, y)) {
return result;
}
result++;
@@ -44,21 +44,25 @@ float grbl::heightmap::get_z_at(float x, float y) const {
// TODO: make faster by precalculating indices
float x1 = x - fmodf(x, resolution);
float x2 = x1 + resolution;
float y1 = y - fmodf(y, resolution);
float y2 = y1 + resolution;
float z11 = vertices[index_from_coords(x1, y1)].z;
float z12 = vertices[index_from_coords(x1, y2)].z;
float z21 = vertices[index_from_coords(x2, y1)].z;
float z22 = vertices[index_from_coords(x2, y2)].z;
double x1 = x - fmod(x - from_x, resolution);
double x2 = x1 + resolution;
double y1 = y - fmod(y - from_y, resolution);
double y2 = y1 + resolution;
double z11 = vertices[index_from_coords(x1, y1)].z;
double z12 = vertices[index_from_coords(x1, y2)].z;
double z21 = vertices[index_from_coords(x2, y1)].z;
double z22 = vertices[index_from_coords(x2, y2)].z;
float alpha_x = (x - x1) / resolution;
float a = z11 + (z21 - z11) * alpha_x;
float b = z12 + (z22 - z12) * alpha_x;
double alpha_x = (x - x1) / (double) resolution;
double a = z11 + (z21 - z11) * alpha_x;
double b = z12 + (z22 - z12) * alpha_x;
float alpha_y = (y - y1) / resolution;
float c = a + (b - a) * alpha_y;
double alpha_y = (y - y1) / (double) resolution;
double c = a + (b - a) * alpha_y;
return c;
return (float) c;
}
bool grbl::float_equal(float a, float b) {
return fabs(a - b) < 0.0001;
}