creates a radially-varying heightfield
| 243 | |
| 244 | // creates a radially-varying heightfield |
| 245 | static void |
| 246 | setRadial |
| 247 | ( |
| 248 | byte_t * grid, |
| 249 | int bytesPerElement, |
| 250 | PHY_ScalarType type, |
| 251 | btScalar phase = 0.0 |
| 252 | ) |
| 253 | { |
| 254 | btAssert(grid); |
| 255 | btAssert(bytesPerElement > 0); |
| 256 | |
| 257 | // min/max |
| 258 | btScalar period = 0.5 / s_gridSpacing; |
| 259 | btScalar floor = 0.0; |
| 260 | btScalar min_r = 3.0 * btSqrt(s_gridSpacing); |
| 261 | btScalar magnitude = 5.0 * btSqrt(s_gridSpacing); |
| 262 | |
| 263 | // pick a base_phase such that phase = 0 results in max height |
| 264 | // (this way, if you create a heightfield with phase = 0, |
| 265 | // you can rely on the min/max heights that result) |
| 266 | btScalar base_phase = (0.5 * SIMD_PI) - (period * min_r); |
| 267 | phase += base_phase; |
| 268 | |
| 269 | // center of grid |
| 270 | btScalar cx = 0.5 * s_gridSize * s_gridSpacing; |
| 271 | btScalar cy = cx; // assume square grid |
| 272 | byte_t * p = grid; |
| 273 | for (int i = 0; i < s_gridSize; ++i) { |
| 274 | float x = i * s_gridSpacing; |
| 275 | for (int j = 0; j < s_gridSize; ++j) { |
| 276 | float y = j * s_gridSpacing; |
| 277 | |
| 278 | float dx = x - cx; |
| 279 | float dy = y - cy; |
| 280 | |
| 281 | float r = sqrt((dx * dx) + (dy * dy)); |
| 282 | |
| 283 | float z = period; |
| 284 | if (r < min_r) { |
| 285 | r = min_r; |
| 286 | } |
| 287 | z = (1.0 / r) * sin(period * r + phase); |
| 288 | if (z > period) { |
| 289 | z = period; |
| 290 | } |
| 291 | else if (z < -period) { |
| 292 | z = -period; |
| 293 | } |
| 294 | z = floor + magnitude * z; |
| 295 | |
| 296 | convertFromFloat(p, z, type); |
| 297 | p += bytesPerElement; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 |
no test coverage detected