@@ -399,22 +399,70 @@ void lcLight::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
399
399
ObjectBoxTest.Objects .emplace_back (const_cast <lcLight*>(this ));
400
400
return ;
401
401
}
402
-
403
- lcVector3 Min (-LC_LIGHT_POSITION_EDGE, -LC_LIGHT_POSITION_EDGE, -LC_LIGHT_POSITION_EDGE); // todo: fix light box test
404
- lcVector3 Max ( LC_LIGHT_POSITION_EDGE, LC_LIGHT_POSITION_EDGE, LC_LIGHT_POSITION_EDGE);
405
402
403
+ lcMatrix44 InverseWorldMatrix = lcMatrix44AffineInverse (mWorldMatrix );
406
404
lcVector4 LocalPlanes[6 ];
407
405
408
- for (int PlaneIdx = 0 ; PlaneIdx < 6 ; PlaneIdx ++)
406
+ for (int PlaneIndex = 0 ; PlaneIndex < 6 ; PlaneIndex ++)
409
407
{
410
- const lcVector3 Normal = lcMul30 (ObjectBoxTest.Planes [PlaneIdx ], mWorldMatrix );
411
- LocalPlanes[PlaneIdx ] = lcVector4 (Normal , ObjectBoxTest.Planes [PlaneIdx ][3 ] - lcDot3 (mWorldMatrix [3 ], Normal ));
408
+ const lcVector3 PlaneNormal = lcMul30 (ObjectBoxTest.Planes [PlaneIndex ], InverseWorldMatrix );
409
+ LocalPlanes[PlaneIndex ] = lcVector4 (PlaneNormal , ObjectBoxTest.Planes [PlaneIndex ][3 ] - lcDot3 (InverseWorldMatrix [3 ], PlaneNormal ));
412
410
}
413
411
414
- if (lcBoundingBoxIntersectsVolume (Min, Max, LocalPlanes))
412
+ // TODO: Check meshes after the bounding fox test.
413
+ if (mLightType == lcLightType::Spot)
415
414
{
416
- ObjectBoxTest.Objects .emplace_back (const_cast <lcLight*>(this ));
417
- return ;
415
+ lcVector3 Min (-LC_LIGHT_SPOT_CONE_RADIUS, -LC_LIGHT_SPOT_CONE_RADIUS, 0 );
416
+ lcVector3 Max ( LC_LIGHT_SPOT_CONE_RADIUS, LC_LIGHT_SPOT_CONE_RADIUS, LC_LIGHT_SPOT_CONE_HEIGHT);
417
+
418
+ if (lcBoundingBoxIntersectsVolume (Min, Max, LocalPlanes))
419
+ {
420
+ ObjectBoxTest.Objects .emplace_back (const_cast <lcLight*>(this ));
421
+ return ;
422
+ }
423
+ }
424
+ else if (mLightType == lcLightType::Area)
425
+ {
426
+ lcVector3 Min (-mAreaSizeX / 2 .0f , -mAreaSizeY / 2 .0f , 0 );
427
+ lcVector3 Max ( mAreaSizeX / 2 .0f , mAreaSizeY / 2 .0f , 0 );
428
+
429
+ if (lcBoundingBoxIntersectsVolume (Min, Max, LocalPlanes))
430
+ {
431
+ ObjectBoxTest.Objects .emplace_back (const_cast <lcLight*>(this ));
432
+ return ;
433
+ }
434
+ }
435
+ else if (mLightType == lcLightType::Directional)
436
+ {
437
+ lcVector3 Min (-LC_LIGHT_DIRECTIONAL_RADIUS, -LC_LIGHT_DIRECTIONAL_RADIUS, 0 );
438
+ lcVector3 Max ( LC_LIGHT_DIRECTIONAL_RADIUS, LC_LIGHT_DIRECTIONAL_RADIUS, LC_LIGHT_DIRECTIONAL_HEIGHT);
439
+
440
+ if (lcBoundingBoxIntersectsVolume (Min, Max, LocalPlanes))
441
+ {
442
+ ObjectBoxTest.Objects .emplace_back (const_cast <lcLight*>(this ));
443
+ return ;
444
+ }
445
+ }
446
+
447
+ if (IsSelected ())
448
+ {
449
+ lcVector3 TargetPosition = lcMul31 (lcVector3 (0 .0f , 0 .0f , -mTargetDistance ), mWorldMatrix );
450
+ bool Outside = false ;
451
+
452
+ for (int PlaneIdx = 0 ; PlaneIdx < 6 ; PlaneIdx++)
453
+ {
454
+ if (lcDot3 (TargetPosition, ObjectBoxTest.Planes [PlaneIdx]) + ObjectBoxTest.Planes [PlaneIdx][3 ] > LC_LIGHT_TARGET_RADIUS)
455
+ {
456
+ Outside = true ;
457
+ break ;
458
+ }
459
+ }
460
+
461
+ if (!Outside)
462
+ {
463
+ ObjectBoxTest.Objects .emplace_back (const_cast <lcLight*>(this ));
464
+ return ;
465
+ }
418
466
}
419
467
}
420
468
0 commit comments