BsCLight.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if(mInternal != nullptr)
  24. mInternal->destroy();
  25. }
  26. Sphere CLight::getBounds() const
  27. {
  28. mInternal->_updateState(*SO());
  29. return mInternal->getBounds();
  30. }
  31. void CLight::onInitialized()
  32. {
  33. // If mInternal already exists this means this object was deserialized,
  34. // so all we need to do is initialize it.
  35. if (mInternal != nullptr)
  36. mInternal->initialize();
  37. else
  38. {
  39. mInternal = Light::create(mType, mColor, mIntensity,
  40. mRange, mCastsShadows, mSpotAngle, mSpotFalloffAngle);
  41. }
  42. gSceneManager()._bindActor(mInternal, sceneObject());
  43. }
  44. void CLight::onDestroyed()
  45. {
  46. gSceneManager()._unbindActor(mInternal);
  47. }
  48. RTTITypeBase* CLight::getRTTIStatic()
  49. {
  50. return CLightRTTI::instance();
  51. }
  52. RTTITypeBase* CLight::getRTTI() const
  53. {
  54. return CLight::getRTTIStatic();
  55. }
  56. }