| 222 | } |
| 223 | |
| 224 | void RenderShapeExample::prepRenderImage( SceneRenderState *state ) |
| 225 | { |
| 226 | // Make sure we have a TSShapeInstance |
| 227 | if ( !mShapeInstance ) |
| 228 | return; |
| 229 | |
| 230 | // Calculate the distance of this object from the camera |
| 231 | Point3F cameraOffset; |
| 232 | getRenderTransform().getColumn( 3, &cameraOffset ); |
| 233 | cameraOffset -= state->getDiffuseCameraPosition(); |
| 234 | F32 dist = cameraOffset.len(); |
| 235 | if ( dist < 0.01f ) |
| 236 | dist = 0.01f; |
| 237 | |
| 238 | // Set up the LOD for the shape |
| 239 | F32 invScale = ( 1.0f / getMax( getMax( mObjScale.x, mObjScale.y ), mObjScale.z ) ); |
| 240 | |
| 241 | mShapeInstance->setDetailFromDistance( state, dist * invScale ); |
| 242 | |
| 243 | // Make sure we have a valid level of detail |
| 244 | if ( mShapeInstance->getCurrentDetail() < 0 ) |
| 245 | return; |
| 246 | |
| 247 | // GFXTransformSaver is a handy helper class that restores |
| 248 | // the current GFX matrices to their original values when |
| 249 | // it goes out of scope at the end of the function |
| 250 | GFXTransformSaver saver; |
| 251 | |
| 252 | // Set up our TS render state |
| 253 | TSRenderState rdata; |
| 254 | rdata.setSceneState( state ); |
| 255 | rdata.setFadeOverride( 1.0f ); |
| 256 | |
| 257 | // We might have some forward lit materials |
| 258 | // so pass down a query to gather lights. |
| 259 | LightQuery query; |
| 260 | query.init( getWorldSphere() ); |
| 261 | rdata.setLightQuery( &query ); |
| 262 | |
| 263 | // Set the world matrix to the objects render transform |
| 264 | MatrixF mat = getRenderTransform(); |
| 265 | mat.scale( mObjScale ); |
| 266 | GFX->setWorldMatrix( mat ); |
| 267 | |
| 268 | // Animate the the shape |
| 269 | mShapeInstance->animate(); |
| 270 | |
| 271 | // Allow the shape to submit the RenderInst(s) for itself |
| 272 | mShapeInstance->render( rdata ); |
| 273 | } |
nothing calls this directly
no test coverage detected