cameraComponent.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef CAMERA_COMPONENT_H
  23. #define CAMERA_COMPONENT_H
  24. #ifndef COMPONENT_H
  25. #include "T3D/components/component.h"
  26. #endif
  27. #ifndef _SCENERENDERSTATE_H_
  28. #include "scene/sceneRenderState.h"
  29. #endif
  30. #ifndef _MBOX_H_
  31. #include "math/mBox.h"
  32. #endif
  33. #ifndef ENTITY_H
  34. #include "T3D/entity.h"
  35. #endif
  36. #ifndef CORE_INTERFACES_H
  37. #include "T3D/components/coreInterfaces.h"
  38. #endif
  39. class SceneRenderState;
  40. struct CameraScopeQuery;
  41. //////////////////////////////////////////////////////////////////////////
  42. ///
  43. ///
  44. //////////////////////////////////////////////////////////////////////////
  45. class CameraComponent : public Component, public CameraInterface
  46. {
  47. typedef Component Parent;
  48. F32 mCameraFov; ///< The camera vertical FOV in degrees.
  49. Point2F mClientScreen; ///< The dimensions of the client's screen. Used to calculate the aspect ratio.
  50. F32 mCameraDefaultFov; ///< Default vertical FOV in degrees.
  51. F32 mCameraMinFov; ///< Min vertical FOV allowed in degrees.
  52. F32 mCameraMaxFov; ///< Max vertical FOV allowed in degrees.
  53. protected:
  54. Point3F mPosOffset;
  55. RotationF mRotOffset;
  56. StringTableEntry mTargetNode;
  57. S32 mTargetNodeIdx;
  58. bool mUseParentTransform;
  59. enum
  60. {
  61. FOVMask = Parent::NextFreeMask,
  62. OffsetMask = Parent::NextFreeMask << 1,
  63. NextFreeMask = Parent::NextFreeMask << 2,
  64. };
  65. public:
  66. CameraComponent();
  67. virtual ~CameraComponent();
  68. DECLARE_CONOBJECT(CameraComponent);
  69. virtual bool onAdd();
  70. virtual void onRemove();
  71. static void initPersistFields();
  72. static bool _setCameraFov(void *object, const char *index, const char *data);
  73. virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
  74. virtual void unpackUpdate(NetConnection *con, BitStream *stream);
  75. static bool _setNode(void *object, const char *index, const char *data);
  76. static bool _setPosOffset(void *object, const char *index, const char *data);
  77. static bool _setRotOffset(void *object, const char *index, const char *data);
  78. void setRotOffset(RotationF rot)
  79. {
  80. mRotOffset = rot;
  81. setMaskBits(OffsetMask);
  82. }
  83. RotationF getRotOffset()
  84. {
  85. return mRotOffset;
  86. }
  87. Point3F getPosOffset()
  88. {
  89. return mPosOffset;
  90. }
  91. /// Gets the minimum viewing distance, maximum viewing distance, camera offsetand rotation
  92. /// for this object, if the world were to be viewed through its eyes
  93. /// @param min Minimum viewing distance
  94. /// @param max Maximum viewing distance
  95. /// @param offset Offset of the camera from the origin in local space
  96. /// @param rot Rotation matrix
  97. virtual void getCameraParameters(F32 *min, F32* max, Point3F* offset, MatrixF* rot);
  98. /// Gets the camera to world space transform matrix
  99. /// @todo Find out what pos does
  100. /// @param pos TODO: Find out what this does
  101. /// @param mat Camera transform (out)
  102. virtual bool getCameraTransform(F32* pos, MatrixF* mat);
  103. /// Returns the vertical field of view in degrees for
  104. /// this object if used as a camera.
  105. virtual F32 getCameraFov() { return mCameraFov; }
  106. /// Returns the default vertical field of view in degrees
  107. /// if this object is used as a camera.
  108. virtual F32 getDefaultCameraFov() { return mCameraDefaultFov; }
  109. /// Sets the vertical field of view in degrees for this
  110. /// object if used as a camera.
  111. /// @param yfov The vertical FOV in degrees to test.
  112. virtual void setCameraFov(F32 fov);
  113. /// Returns true if the vertical FOV in degrees is within
  114. /// allowable parameters of the datablock.
  115. /// @param yfov The vertical FOV in degrees to test.
  116. /// @see ShapeBaseData::cameraMinFov
  117. /// @see ShapeBaseData::cameraMaxFov
  118. virtual bool isValidCameraFov(F32 fov);
  119. /// @}
  120. virtual Frustum getFrustum();
  121. /// Control object scoping
  122. void onCameraScopeQuery(NetConnection *cr, CameraScopeQuery *camInfo);
  123. void setForwardVector(VectorF newForward, VectorF upVector = VectorF::Zero);
  124. void setPosition(Point3F newPos);
  125. void setRotation(RotationF newRot);
  126. protected:
  127. DECLARE_CALLBACK(F32, validateCameraFov, (F32 fov));
  128. };
  129. #endif // CAMERA_BEHAVIOR_H