MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / generateHeightField

Method generateHeightField

testbed/common/HeightField.cpp:150–181  ·  view source on GitHub ↗

Compute the heights of the height field

Source from the content-addressed store, hash-verified

148
149// Compute the heights of the height field
150void HeightField::generateHeightField() {
151
152 double persistence = 9;
153 double frequency = 0.28;
154 double amplitude = 12;
155 int octaves = 1;
156 int randomseed = 23;
157 PerlinNoise perlinNoise(persistence, frequency, amplitude, octaves, randomseed);
158
159 mMinHeight = 0;
160 mMaxHeight = 0;
161
162 float width = (NB_POINTS_WIDTH - 1);
163 float length = (NB_POINTS_LENGTH - 1);
164
165 for (int i=0; i<NB_POINTS_WIDTH; i++) {
166 for (int j=0; j<NB_POINTS_LENGTH; j++) {
167
168 int arrayIndex = j * NB_POINTS_WIDTH + i;
169
170 mHeightData[arrayIndex] = (float)(perlinNoise.GetHeight(-width * 0.5 + i, -length * 0.5 + j));
171
172 if (i==0 && j==0) {
173 mMinHeight = mHeightData[arrayIndex] ;
174 mMaxHeight = mHeightData[arrayIndex] ;
175 }
176
177 if (mHeightData[arrayIndex] > mMaxHeight) mMaxHeight = mHeightData[arrayIndex] ;
178 if (mHeightData[arrayIndex] < mMinHeight) mMinHeight = mHeightData[arrayIndex] ;
179 }
180 }
181}
182
183// Generate the graphics mesh to render the height field
184void HeightField::generateGraphicsMesh() {

Callers

nothing calls this directly

Calls 1

GetHeightMethod · 0.80

Tested by

no test coverage detected