BsCamera.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "BsCamera.h"
  2. #include "BsCameraRTTI.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 "BsRenderSystem.h"
  13. #include "BsSceneObject.h"
  14. #include "BsDebug.h"
  15. namespace BansheeEngine
  16. {
  17. Camera::Camera(const HSceneObject& parent, RenderTargetPtr target, float left, float top, float width, float height)
  18. : Component(parent), mLastUpdateHash(std::numeric_limits<UINT32>::max())
  19. {
  20. mInternal = bs_shared_ptr<CameraHandler>(target, left, top, width, height);
  21. setName("Camera");
  22. }
  23. Camera::~Camera()
  24. {
  25. }
  26. ConvexVolume Camera::getWorldFrustum() const
  27. {
  28. const Vector<Plane>& frustumPlanes = getFrustum().getPlanes();
  29. Matrix4 worldMatrix = SO()->getWorldTfrm();
  30. Vector<Plane> worldPlanes(frustumPlanes.size());
  31. UINT32 i = 0;
  32. for (auto& plane : frustumPlanes)
  33. {
  34. worldPlanes[i] = worldMatrix.multiply3x4(plane);
  35. i++;
  36. }
  37. return ConvexVolume(worldPlanes);
  38. }
  39. void Camera::updateView() const
  40. {
  41. UINT32 curHash = SO()->getTransformHash();
  42. if (curHash != mLastUpdateHash)
  43. {
  44. mInternal->setPosition(SO()->getWorldPosition());
  45. mInternal->setRotation(SO()->getWorldRotation());
  46. mLastUpdateHash = curHash;
  47. }
  48. }
  49. RTTITypeBase* Camera::getRTTIStatic()
  50. {
  51. return CameraRTTI::instance();
  52. }
  53. RTTITypeBase* Camera::getRTTI() const
  54. {
  55. return Camera::getRTTIStatic();
  56. }
  57. }