BsCCamera.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Components/BsCCamera.h"
  4. #include "RTTI/BsCCameraRTTI.h"
  5. #include "Scene/BsSceneObject.h"
  6. #include "Scene/BsSceneManager.h"
  7. #include "BsCoreApplication.h"
  8. namespace bs
  9. {
  10. CCamera::CCamera()
  11. {
  12. setFlag(ComponentFlag::AlwaysRun, true);
  13. setName("Camera");
  14. }
  15. CCamera::CCamera(const HSceneObject& parent)
  16. : Component(parent)
  17. {
  18. setFlag(ComponentFlag::AlwaysRun, true);
  19. setName("Camera");
  20. }
  21. CCamera::~CCamera()
  22. {
  23. }
  24. ConvexVolume CCamera::getWorldFrustum() const
  25. {
  26. const Vector<Plane>& frustumPlanes = getFrustum().getPlanes();
  27. Matrix4 worldMatrix = SO()->getWorldMatrix();
  28. Vector<Plane> worldPlanes(frustumPlanes.size());
  29. UINT32 i = 0;
  30. for (auto& plane : frustumPlanes)
  31. {
  32. worldPlanes[i] = worldMatrix.multiplyAffine(plane);
  33. i++;
  34. }
  35. return ConvexVolume(worldPlanes);
  36. }
  37. void CCamera::updateView() const
  38. {
  39. mInternal->_updateState(*SO());
  40. }
  41. void CCamera::setMain(bool main)
  42. {
  43. mInternal->setMain(main);
  44. gSceneManager()._notifyMainCameraStateChanged(mInternal);
  45. }
  46. void CCamera::_instantiate()
  47. {
  48. // If mInternal already exists this means this object was deserialized,
  49. // so all we need to do is initialize it.
  50. if (mInternal != nullptr)
  51. mInternal->initialize();
  52. else
  53. mInternal = Camera::create();
  54. }
  55. void CCamera::onInitialized()
  56. {
  57. gSceneManager()._bindActor(mInternal, SO());
  58. // Make sure primary RT gets applied if camera gets deserialized with main camera state
  59. gSceneManager()._notifyMainCameraStateChanged(mInternal);
  60. }
  61. void CCamera::onDestroyed()
  62. {
  63. gSceneManager()._unbindActor(mInternal);
  64. mInternal->destroy();
  65. }
  66. RTTITypeBase* CCamera::getRTTIStatic()
  67. {
  68. return CCameraRTTI::instance();
  69. }
  70. RTTITypeBase* CCamera::getRTTI() const
  71. {
  72. return CCamera::getRTTIStatic();
  73. }
  74. }