BsCLight.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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()
  9. {
  10. setFlag(ComponentFlag::AlwaysRun, true);
  11. setName("Light");
  12. }
  13. CLight::CLight(const HSceneObject& parent, LightType type, Color color,
  14. float intensity, float range, bool castsShadows, Degree spotAngle, Degree spotFalloffAngle)
  15. : Component(parent), mType(type), mColor(color), mIntensity(intensity), mRange(range),
  16. mCastsShadows(castsShadows), mSpotAngle(spotAngle), mSpotFalloffAngle(spotFalloffAngle)
  17. {
  18. setFlag(ComponentFlag::AlwaysRun, true);
  19. setName("Light");
  20. }
  21. CLight::~CLight()
  22. {
  23. mInternal->destroy();
  24. }
  25. Sphere CLight::getBounds() const
  26. {
  27. mInternal->_updateTransform(SO());
  28. return mInternal->getBounds();
  29. }
  30. void CLight::onInitialized()
  31. {
  32. // If mInternal already exists this means this object was deserialized,
  33. // so all we need to do is initialize it.
  34. if (mInternal != nullptr)
  35. mInternal->initialize();
  36. else
  37. {
  38. mInternal = Light::create(mType, mColor, mIntensity,
  39. mRange, mCastsShadows, mSpotAngle, mSpotFalloffAngle);
  40. }
  41. gSceneManager()._registerLight(mInternal, sceneObject());
  42. }
  43. void CLight::onDestroyed()
  44. {
  45. gSceneManager()._unregisterLight(mInternal);
  46. }
  47. RTTITypeBase* CLight::getRTTIStatic()
  48. {
  49. return CLightRTTI::instance();
  50. }
  51. RTTITypeBase* CLight::getRTTI() const
  52. {
  53. return CLight::getRTTIStatic();
  54. }
  55. }