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