BsCLight.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Components/BsCLight.h"
  4. #include "RTTI/BsCLightRTTI.h"
  5. #include "Scene/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. Sphere CLight::getBounds() const
  24. {
  25. mInternal->_updateState(*SO());
  26. return mInternal->getBounds();
  27. }
  28. void CLight::onInitialized()
  29. {
  30. // If mInternal already exists this means this object was deserialized,
  31. // so all we need to do is initialize it.
  32. if (mInternal != nullptr)
  33. mInternal->initialize();
  34. else
  35. {
  36. mInternal = Light::create(
  37. mType,
  38. mColor,
  39. mIntensity,
  40. mRange,
  41. mCastsShadows,
  42. mSpotAngle,
  43. mSpotFalloffAngle);
  44. }
  45. gSceneManager()._bindActor(mInternal, sceneObject());
  46. }
  47. void CLight::onDestroyed()
  48. {
  49. gSceneManager()._unbindActor(mInternal);
  50. mInternal->destroy();
  51. }
  52. RTTITypeBase* CLight::getRTTIStatic()
  53. {
  54. return CLightRTTI::instance();
  55. }
  56. RTTITypeBase* CLight::getRTTI() const
  57. {
  58. return CLight::getRTTIStatic();
  59. }
  60. }