| 340 | } |
| 341 | |
| 342 | void LightsWindow3::UpdateConstants() |
| 343 | { |
| 344 | // The pvw-matrices are updated automatically whenever the camera moves |
| 345 | // or the trackball is rotated, which happens before this call. Here we |
| 346 | // need to update the camera model position, light model position, and |
| 347 | // light model direction. |
| 348 | |
| 349 | // Compute the model-to-world transforms for the planes and spheres. |
| 350 | Matrix4x4<float> wMatrix[GNUM][SNUM]; |
| 351 | Matrix4x4<float> rotate = mTrackBall.GetOrientation(); |
| 352 | wMatrix[GPLN][SVTX] = DoTransform(rotate, mPlane[SVTX]->worldTransform.GetHMatrix()); |
| 353 | wMatrix[GPLN][SPXL] = DoTransform(rotate, mPlane[SPXL]->worldTransform.GetHMatrix()); |
| 354 | wMatrix[GSPH][SVTX] = DoTransform(rotate, mSphere[SVTX]->worldTransform.GetHMatrix()); |
| 355 | wMatrix[GSPH][SPXL] = DoTransform(rotate, mSphere[SPXL]->worldTransform.GetHMatrix()); |
| 356 | |
| 357 | // Compute the world-to-model transforms for the planes and spheres. |
| 358 | Matrix4x4<float> invWMatrix[GNUM][SNUM]; |
| 359 | for (int32_t gt = 0; gt < GNUM; ++gt) |
| 360 | { |
| 361 | for (int32_t st = 0; st < SNUM; ++st) |
| 362 | { |
| 363 | invWMatrix[gt][st] = Inverse(wMatrix[gt][st]); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | Vector4<float> cameraWorldPosition = mCamera->GetPosition(); |
| 368 | for (int32_t lt = 0; lt < LNUM; ++lt) |
| 369 | { |
| 370 | for (int32_t gt = 0; gt < GNUM; ++gt) |
| 371 | { |
| 372 | for (int32_t st = 0; st < SNUM; ++st) |
| 373 | { |
| 374 | auto effect = mEffect[lt][gt][st]; |
| 375 | auto lighting = mEffect[lt][gt][st]->GetLighting(); |
| 376 | auto geometry = mEffect[lt][gt][st]->GetGeometry(); |
| 377 | auto const& invwmat = invWMatrix[gt][st]; |
| 378 | geometry->lightModelPosition = DoTransform(invwmat, mLightWorldPosition[st]); |
| 379 | geometry->lightModelDirection = DoTransform(invwmat, mLightWorldDirection); |
| 380 | geometry->cameraModelPosition = DoTransform(invwmat, cameraWorldPosition); |
| 381 | effect->UpdateGeometryConstant(); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
| 387 |
nothing calls this directly
no test coverage detected