|
@@ -19,6 +19,9 @@
|
|
|
*/
|
|
*/
|
|
|
double PerlinNoise2::
|
|
double PerlinNoise2::
|
|
|
noise(const LVecBase2d &value) const {
|
|
noise(const LVecBase2d &value) const {
|
|
|
|
|
+ // If this triggers, you passed in 0 for table_size.
|
|
|
|
|
+ nassertr(!_index.empty(), make_nan(0.0));
|
|
|
|
|
+
|
|
|
// Convert the vector to our local coordinate space.
|
|
// Convert the vector to our local coordinate space.
|
|
|
LVecBase2d vec = _input_xform.xform_point(value);
|
|
LVecBase2d vec = _input_xform.xform_point(value);
|
|
|
|
|
|
|
@@ -41,9 +44,13 @@ noise(const LVecBase2d &value) const {
|
|
|
double v = fade(y);
|
|
double v = fade(y);
|
|
|
|
|
|
|
|
// Hash coordinates of the 4 square corners (A, B, A + 1, and B + 1)
|
|
// Hash coordinates of the 4 square corners (A, B, A + 1, and B + 1)
|
|
|
|
|
+ nassertr(X >= 0 && X + 1 < _index.size(), make_nan(0.0));
|
|
|
int A = _index[X] + Y;
|
|
int A = _index[X] + Y;
|
|
|
int B = _index[X + 1] + Y;
|
|
int B = _index[X + 1] + Y;
|
|
|
|
|
|
|
|
|
|
+ nassertr(A >= 0 && A + 1 < _index.size(), make_nan(0.0));
|
|
|
|
|
+ nassertr(B >= 0 && B + 1 < _index.size(), make_nan(0.0));
|
|
|
|
|
+
|
|
|
// and add blended results from 4 corners of square.
|
|
// and add blended results from 4 corners of square.
|
|
|
double result =
|
|
double result =
|
|
|
lerp(v, lerp(u, grad(_index[A], x, y),
|
|
lerp(v, lerp(u, grad(_index[A], x, y),
|