Use multidimensional subscript operator in Grid
This commit is contained in:
parent
618b75792b
commit
b564918e1c
2 changed files with 6 additions and 7 deletions
|
@ -58,10 +58,10 @@ glm::vec3 Grid::normal_at(const size_t x, const size_t y,
|
||||||
|
|
||||||
const auto x_diff =
|
const auto x_diff =
|
||||||
glm::vec3(static_cast<float>(high_x - low_x), 0,
|
glm::vec3(static_cast<float>(high_x - low_x), 0,
|
||||||
amplification * (get(high_x, y) - get(low_x, y)));
|
amplification * ((*this)[high_x, y] - (*this)[low_x, y]));
|
||||||
const auto y_diff =
|
const auto y_diff =
|
||||||
glm::vec3(0, static_cast<float>(high_y - low_y),
|
glm::vec3(0, static_cast<float>(high_y - low_y),
|
||||||
amplification * (get(x, high_y) - get(x, low_y)));
|
amplification * ((*this)[x, high_y] - (*this)[x, low_y]));
|
||||||
return normalize(cross(x_diff, y_diff));
|
return normalize(cross(x_diff, y_diff));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,12 +135,11 @@ Grid *Grid::PerlinNoise(const int globalX, const int globalY,
|
||||||
|
|
||||||
// Interpolates between the dot_major results of the four grid vectors
|
// Interpolates between the dot_major results of the four grid vectors
|
||||||
// around the current point
|
// around the current point
|
||||||
const auto val = Interpolate(
|
(*grid)[x, y] = Interpolate(
|
||||||
x_offset,
|
x_offset,
|
||||||
Interpolate(y_offset, dot_major(false, false),
|
Interpolate(y_offset, dot_major(false, false),
|
||||||
dot_major(false, true)),
|
dot_major(false, true)),
|
||||||
Interpolate(y_offset, dot_major(true, false), dot_major(true, true)));
|
Interpolate(y_offset, dot_major(true, false), dot_major(true, true)));
|
||||||
grid->set(x, y, val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,11 @@ constexpr std::size_t index(const std::size_t x, const std::size_t y) {
|
||||||
|
|
||||||
class Grid {
|
class Grid {
|
||||||
public:
|
public:
|
||||||
float get(const std::size_t x, const std::size_t y) const {
|
float &operator[](const std::size_t x, const std::size_t y) {
|
||||||
return (*data_)[index(x, y)];
|
return (*data_)[index(x, y)];
|
||||||
}
|
}
|
||||||
void set(const std::size_t x, const std::size_t y, const float value) const {
|
float &operator[](const std::size_t x, const std::size_t y) const {
|
||||||
(*data_)[index(x, y)] = value;
|
return (*data_)[index(x, y)];
|
||||||
}
|
}
|
||||||
|
|
||||||
Grid operator+(const Grid &) const;
|
Grid operator+(const Grid &) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue