BsCLight.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "BsCLight.h"
  2. #include "BsCLightRTTI.h"
  3. #include "BsSceneManager.h"
  4. namespace BansheeEngine
  5. {
  6. CLight::CLight(const HSceneObject& parent, LightType type, Color color,
  7. float intensity, float range, bool castsShadows, Degree spotAngle, Degree spotFalloffAngle)
  8. : Component(parent), mType(type), mColor(color), mIntensity(intensity), mRange(range),
  9. mCastsShadows(castsShadows), mSpotAngle(spotAngle), mSpotFalloffAngle(spotFalloffAngle)
  10. {
  11. setName("Light");
  12. }
  13. CLight::~CLight()
  14. {
  15. mInternal->destroy();
  16. }
  17. Sphere CLight::getBounds() const
  18. {
  19. mInternal->_updateTransform(SO());
  20. return mInternal->getBounds();
  21. }
  22. void CLight::onInitialized()
  23. {
  24. // If mInternal already exists this means this object was deserialized,
  25. // so all we need to do is initialize it.
  26. if (mInternal != nullptr)
  27. mInternal->initialize();
  28. else
  29. {
  30. mInternal = Light::create(mType, mColor, mIntensity,
  31. mRange, mCastsShadows, mSpotAngle, mSpotFalloffAngle);
  32. }
  33. gSceneManager()._registerLight(mInternal, sceneObject());
  34. }
  35. void CLight::onDestroyed()
  36. {
  37. gSceneManager()._unregisterLight(mInternal);
  38. }
  39. RTTITypeBase* CLight::getRTTIStatic()
  40. {
  41. return CLightRTTI::instance();
  42. }
  43. RTTITypeBase* CLight::getRTTI() const
  44. {
  45. return CLight::getRTTIStatic();
  46. }
  47. }