BsCLight.cpp 1.5 KB

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