| 343 | } |
| 344 | |
| 345 | void ForestBrushTool::_paint( const Point3F &point ) |
| 346 | { |
| 347 | AssertFatal( mForest, "ForestBrushTool::_paint() - Can't paint without a Forest!" ); |
| 348 | |
| 349 | if ( mElements.empty() ) |
| 350 | return; |
| 351 | |
| 352 | // Iterators, pointers, and temporaries. |
| 353 | ForestBrushElement *pElement; |
| 354 | ForestItemData *pData; |
| 355 | F32 radius, area; |
| 356 | |
| 357 | // How much area do we have to fill with trees ( within the brush ). |
| 358 | F32 fillArea = mCircleArea( mSize ); |
| 359 | |
| 360 | // Scale that down by pressure, this is how much area we want to fill. |
| 361 | fillArea *= mPressure; |
| 362 | |
| 363 | // Create an MRandomSet we can get items we are painting out of with |
| 364 | // the desired distribution. |
| 365 | // Also grab the smallest and largest radius elements while we are looping. |
| 366 | |
| 367 | ForestBrushElement *smallestElement, *largestElement; |
| 368 | smallestElement = largestElement = mElements[0]; |
| 369 | |
| 370 | MRandomSet<ForestBrushElement*> randElementSet(&mRandom); |
| 371 | |
| 372 | for ( S32 i = 0; i < mElements.size(); i++ ) |
| 373 | { |
| 374 | pElement = mElements[i]; |
| 375 | |
| 376 | if ( pElement->mData->mRadius > largestElement->mData->mRadius ) |
| 377 | largestElement = pElement; |
| 378 | if ( pElement->mData->mRadius < smallestElement->mData->mRadius ) |
| 379 | smallestElement = pElement; |
| 380 | |
| 381 | randElementSet.add( pElement, pElement->mProbability ); |
| 382 | } |
| 383 | |
| 384 | // Pull elements from the random set until we would theoretically fill |
| 385 | // the desired area. |
| 386 | |
| 387 | F32 areaLeft = fillArea; |
| 388 | F32 scaleFactor, sink, randRot, worldCoordZ, slope; |
| 389 | Point2F worldCoords; |
| 390 | Point3F normalVector, right; |
| 391 | Point2F temp; |
| 392 | |
| 393 | const S32 MaxTries = 5; |
| 394 | |
| 395 | |
| 396 | while ( areaLeft > 0.0f ) |
| 397 | { |
| 398 | pElement = randElementSet.get(); |
| 399 | pData = pElement->mData; |
| 400 | |
| 401 | scaleFactor = mLerp( pElement->mScaleMin, pElement->mScaleMax, mClampF( mPow( mRandom.randF(), pElement->mScaleExponent ), 0.0f, 1.0f ) ); |
| 402 | radius = getMax( pData->mRadius * scaleFactor, 0.1f ); |
nothing calls this directly
no test coverage detected