BsCCamera.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "BsCCamera.h"
  2. #include "BsCCameraRTTI.h"
  3. #include "BsMath.h"
  4. #include "BsMatrix3.h"
  5. #include "BsVector2.h"
  6. #include "BsAABox.h"
  7. #include "BsSphere.h"
  8. #include "BsHardwareBufferManager.h"
  9. #include "BsVertexBuffer.h"
  10. #include "BsIndexBuffer.h"
  11. #include "BsException.h"
  12. #include "BsRenderAPI.h"
  13. #include "BsSceneObject.h"
  14. #include "BsDebug.h"
  15. #include "BsSceneManager.h"
  16. namespace BansheeEngine
  17. {
  18. CCamera::CCamera(const HSceneObject& parent, RenderTargetPtr target, float left, float top, float width, float height)
  19. : Component(parent), mTarget(target), mLeft(left), mTop(top), mWidth(width), mHeight(height)
  20. {
  21. setName("Camera");
  22. }
  23. CCamera::~CCamera()
  24. {
  25. mInternal->destroy();
  26. }
  27. ConvexVolume CCamera::getWorldFrustum() const
  28. {
  29. const Vector<Plane>& frustumPlanes = getFrustum().getPlanes();
  30. Matrix4 worldMatrix = SO()->getWorldTfrm();
  31. Vector<Plane> worldPlanes(frustumPlanes.size());
  32. UINT32 i = 0;
  33. for (auto& plane : frustumPlanes)
  34. {
  35. worldPlanes[i] = worldMatrix.multiplyAffine(plane);
  36. i++;
  37. }
  38. return ConvexVolume(worldPlanes);
  39. }
  40. void CCamera::updateView() const
  41. {
  42. UINT32 curHash = SO()->getTransformHash();
  43. if (curHash != mInternal->_getLastModifiedHash())
  44. {
  45. mInternal->setPosition(SO()->getWorldPosition());
  46. mInternal->setRotation(SO()->getWorldRotation());
  47. mInternal->_setLastModifiedHash(curHash);
  48. }
  49. }
  50. void CCamera::update()
  51. {
  52. }
  53. void CCamera::onInitialized()
  54. {
  55. // If mInternal already exists this means this object was deserialized,
  56. // so all we need to do is initialize it.
  57. if (mInternal != nullptr)
  58. mInternal->initialize();
  59. else
  60. {
  61. mInternal = Camera::create(mTarget, mLeft, mTop, mWidth, mHeight);
  62. mTarget = nullptr;
  63. }
  64. gSceneManager()._registerCamera(mInternal, SO());
  65. }
  66. void CCamera::onDestroyed()
  67. {
  68. gSceneManager()._unregisterCamera(mInternal);
  69. }
  70. RTTITypeBase* CCamera::getRTTIStatic()
  71. {
  72. return CCameraRTTI::instance();
  73. }
  74. RTTITypeBase* CCamera::getRTTI() const
  75. {
  76. return CCamera::getRTTIStatic();
  77. }
  78. }