Commits

Jeremy Sandell committed 565dd49 Draft

pass by const reference rather than values, when possible

Comments (0)

Files changed (4)

CameraControlSystem/include/CCSBasicCameraModes.h

             return true;
         }
 
-        virtual void update(const Ogre::Real &timeSinceLastFrame){};
+        virtual void update(const Ogre::Real& timeSinceLastFrame){};
         virtual void instantUpdate()
         {
             mCameraPosition = mLastPosition;
 
         // Specific methods
 
-        inline virtual void setCameraPosition(Ogre::Vector3 pos)
+        inline virtual void setCameraPosition(const Ogre::Vector3& pos)
         {
             mLastPosition = pos;
             mCameraPosition = pos;
         }
 
-        inline virtual void setCameraOrientation(Ogre::Quaternion orient)
+        inline virtual void setCameraOrientation(const Ogre::Quaternion& orient)
         {
             mLastOrientation = orient;
             mCameraOrientation = mLastOrientation;
 	{
 	public:
 
-        FixedTrackingCameraMode(CameraControlSystem* cam, const Ogre::Vector3 &fixedAxis = Ogre::Vector3::UNIT_Y) 
+        FixedTrackingCameraMode(CameraControlSystem* cam, const Ogre::Vector3& fixedAxis = Ogre::Vector3::UNIT_Y) 
             : FixedCameraMode(cam,fixedAxis)
         { };
 
 		/**
 		 * @param fixedStep true to try to avoid camera jittering (experimental)
 		 */
-        ChaseCameraMode(CameraControlSystem* cam, const Ogre::Vector3 &relativePositionToCameraTarget
+        ChaseCameraMode(CameraControlSystem* cam, const Ogre::Vector3& relativePositionToCameraTarget
 			, Ogre::Real margin = 0.1f
 			, bool fixedStep = false, Ogre::Real delta = 0.001
-			, const Ogre::Vector3 &fixedAxis = Ogre::Vector3::UNIT_Y) 
+			, const Ogre::Vector3& fixedAxis = Ogre::Vector3::UNIT_Y) 
             : CameraControlSystem::CameraModeWithTightness(cam)	
 			, CameraControlSystem::CollidableCamera(cam, margin)
             , mFixedAxis(fixedAxis)
             return true;
         }
 
-        virtual void update(const Ogre::Real &timeSinceLastFrame)
+        virtual void update(const Ogre::Real& timeSinceLastFrame)
         {           
 			if(mCameraCS->getTargetSceneNode())
 			{
 
         // Specific methods
 
-        inline virtual void setCameraRelativePosition(Ogre::Vector3 posRelativeToCameraTarget)
+        inline virtual void setCameraRelativePosition(const Ogre::Vector3& posRelativeToCameraTarget)
         {
             mRelativePositionToCameraTarget = posRelativeToCameraTarget;
             instantUpdate();
         }
 
-        inline virtual void setFixedYawAxis(bool useFixedAxis, const Ogre::Vector3 &fixedAxis = Ogre::Vector3::UNIT_Y)
+        inline virtual void setFixedYawAxis(bool useFixedAxis, const Ogre::Vector3& fixedAxis = Ogre::Vector3::UNIT_Y)
         {
             mFixedAxis = mFixedAxis;
             mCameraCS->setFixedYawAxis(true,mFixedAxis);
 	{
 	public:
 
-        ChaseFreeYawAxisCameraMode(CameraControlSystem* cam, const Ogre::Vector3 &relativePositionToCameraTarget
-            , Ogre::Quaternion rotation, Ogre::Real collisionmargin = 0.1f) 
+        ChaseFreeYawAxisCameraMode(CameraControlSystem* cam, const Ogre::Vector3& relativePositionToCameraTarget
+            , const Ogre::Quaternion& rotation, Ogre::Real collisionmargin = 0.1f) 
             : ChaseCameraMode(cam, relativePositionToCameraTarget, collisionmargin)
         {
             mRotationOffset = rotation;
         }
 
-        ChaseFreeYawAxisCameraMode(CameraControlSystem* cam, const Ogre::Vector3 &relativePositionToCameraTarget
+        ChaseFreeYawAxisCameraMode(CameraControlSystem* cam, const Ogre::Vector3& relativePositionToCameraTarget
 			, const Ogre::Radian roll, const Ogre::Radian yaw, const Ogre::Radian pitch, Ogre::Real collisionmargin = 0.1f) 
 			: ChaseCameraMode(cam, relativePositionToCameraTarget, collisionmargin)
         {
             return true;
         }
 
-        virtual void update(const Ogre::Real &timeSinceLastFrame)
+        virtual void update(const Ogre::Real& timeSinceLastFrame)
         {            
             // Update camera position
             ChaseCameraMode::update(timeSinceLastFrame);
 
         // Specific methods
 
-        inline virtual void setCameraRelativePosition(Ogre::Vector3 posRelativeToCameraTarget
-            , Ogre::Quaternion rotation)
+        inline virtual void setCameraRelativePosition(const Ogre::Vector3& posRelativeToCameraTarget
+            , const Ogre::Quaternion& rotation)
         {
             mRelativePositionToCameraTarget = posRelativeToCameraTarget;
 
             instantUpdate();
         }
 
-        inline virtual void setCameraRelativePosition(Ogre::Vector3 posRelativeToCameraTarget
+        inline virtual void setCameraRelativePosition(const Ogre::Vector3& posRelativeToCameraTarget
             , const Ogre::Radian roll, const Ogre::Radian yaw, const Ogre::Radian pitch)
         {
             mRelativePositionToCameraTarget = posRelativeToCameraTarget;
 	{
 	public:
 
-        AttachedCameraMode(CameraControlSystem* cam, const Ogre::Vector3 &relativePositionToCameraTarget
-            , Ogre::Quaternion rotation) 
+        AttachedCameraMode(CameraControlSystem* cam, const Ogre::Vector3& relativePositionToCameraTarget
+            , const Ogre::Quaternion& rotation)
             : CameraMode(cam)
             , mRotation(rotation)
             , mRelativePositionToCameraTarget(relativePositionToCameraTarget)
         { }
 
-        AttachedCameraMode(CameraControlSystem* cam, const Ogre::Vector3 &relativePositionToCameraTarget, 
+        AttachedCameraMode(CameraControlSystem* cam, const Ogre::Vector3& relativePositionToCameraTarget,
             const Ogre::Radian roll, const Ogre::Radian yaw, const Ogre::Radian pitch) 
             : CameraMode(cam)
             , mRelativePositionToCameraTarget(relativePositionToCameraTarget)
             mCameraPreviousParentSceneNode->addChild(mCameraCS->getCameraSceneNode());
         }
 
-        virtual void update(const Ogre::Real &timeSinceLastFrame) { }
+        virtual void update(const Ogre::Real& timeSinceLastFrame) { }
         virtual void instantUpdate() { }
 
     protected:
 	{
 	public:
 
-        FirstPersonCameraMode(CameraControlSystem* cam, const Ogre::Vector3 &relativePositionToCameraTarget
-            , Ogre::Quaternion rotation)
+        FirstPersonCameraMode(CameraControlSystem* cam, const Ogre::Vector3& relativePositionToCameraTarget
+            , const Ogre::Quaternion& rotation)
 			: AttachedCameraMode(cam, relativePositionToCameraTarget,rotation)
             , mCharacterVisible(true)
         { }
 
-        FirstPersonCameraMode(CameraControlSystem* cam, const Ogre::Vector3 &relativePositionToCameraTarget
+        FirstPersonCameraMode(CameraControlSystem* cam, const Ogre::Vector3& relativePositionToCameraTarget
             , const Ogre::Radian roll, const Ogre::Radian yaw, const Ogre::Radian pitch) 
 			: AttachedCameraMode(cam, relativePositionToCameraTarget,roll,yaw,pitch)
             , mCharacterVisible(true)
             }
         }
 
-        bool getCharacterVisible(){ return mCharacterVisible; }
+        bool getCharacterVisible() const { return mCharacterVisible; }
 
 	protected:
 		bool mCharacterVisible;
 	{
 	public:
 
-        PlaneBindedCameraMode(CameraControlSystem* cam, Ogre::Plane &plane, const Ogre::Vector3 &fixedAxis = Ogre::Vector3::UNIT_Y) 
+        PlaneBindedCameraMode(CameraControlSystem* cam, const Ogre::Plane& plane, const Ogre::Vector3& fixedAxis = Ogre::Vector3::UNIT_Y) 
             : CameraControlSystem::CameraModeWithTightness(cam)
 			, mFixedAxis(fixedAxis)
 			, mPlane(plane)
             return true;
         }
 
-        virtual void update(const Ogre::Real &timeSinceLastFrame)
+        virtual void update(const Ogre::Real& timeSinceLastFrame)
         {
             Ogre::Real distance = mPlane.getDistance(mCameraCS->getCameraTargetPosition());
 
-            Ogre::Vector3 cameraCurrentPosition = mCameraCS->getCameraPosition();
+            const Ogre::Vector3& cameraCurrentPosition = mCameraCS->getCameraPosition();
             Ogre::Vector3 cameraFinalPositionIfNoTightness = mCameraCS->getCameraTargetPosition() -
                 mPlane.normal.normalisedCopy() * distance;
 
 	public:
 
         ThroughTargetCameraMode(CameraControlSystem* cam, Ogre::Real margin, bool inverse = false
-            , Ogre::Vector3 focusPos = Ogre::Vector3::ZERO, const Ogre::Vector3 &fixedAxis = Ogre::Vector3::UNIT_Y) 
+            , const Ogre::Vector3& focusPos = Ogre::Vector3::ZERO, const Ogre::Vector3& fixedAxis = Ogre::Vector3::UNIT_Y) 
             : CameraControlSystem::CameraMode(cam),
 			  mFixedAxis(fixedAxis),
 			  mFocusPos(focusPos),
             return true;
         }
 
-        virtual void update(const Ogre::Real &timeSinceLastFrame)
+        virtual void update(const Ogre::Real& timeSinceLastFrame)
         {
             instantUpdate();
         };
 
         // Specific methods
 
-        inline virtual void setCameraFocusPosition(Ogre::Vector3 pos)
+        inline virtual void setCameraFocusPosition(const Ogre::Vector3& pos)
         { 
             mFocusPos = pos; 
             init();
         };
 
         void setInverse(bool value){ mInverse = value; }
-        bool getInverse(){ return mInverse; }
+        bool getInverse() const { return mInverse; }
 		
     protected:
         Ogre::Vector3 mFixedAxis;
 	public:
 
         ClosestToTargetCameraMode(CameraControlSystem* cam, Ogre::Real timeInterval = 1
-            , const Ogre::Vector3 &fixedAxis = Ogre::Vector3::UNIT_Y) 
+            , const Ogre::Vector3& fixedAxis = Ogre::Vector3::UNIT_Y) 
             : FixedTrackingCameraMode(cam, fixedAxis)
 			, mTimeInterval(timeInterval)
             , mTime(timeInterval)
 
         virtual ~ClosestToTargetCameraMode(){};
 
-        virtual void update(const Ogre::Real &timeSinceLastFrame)
+        virtual void update(const Ogre::Real& timeSinceLastFrame)
         {
             instantUpdate();
             return;
 
         // Specific methods
 
-        inline virtual void addCameraPosition(Ogre::Vector3 &pos)
+        inline virtual void addCameraPosition(const Ogre::Vector3& pos)
         { 
             mPositionsList.push_back(pos); 
             init();
 	{
 	public:
 
-        FixedDirectionCameraMode(CameraControlSystem* cam, const Ogre::Vector3 &direction, const Ogre::Real distance
-			, const Ogre::Vector3 &fixedAxis = Ogre::Vector3::UNIT_Y) 
+        FixedDirectionCameraMode(CameraControlSystem* cam, const Ogre::Vector3& direction, const Ogre::Real distance
+			, const Ogre::Vector3& fixedAxis = Ogre::Vector3::UNIT_Y) 
             : CameraControlSystem::CameraModeWithTightness(cam)
 			, mFixedAxis(fixedAxis)
             , mDistance(distance)
             return true;
         }
 
-        virtual void update(const Ogre::Real &timeSinceLastFrame)
+        virtual void update(const Ogre::Real& timeSinceLastFrame)
         {            
-            Ogre::Vector3 cameraCurrentPosition = mCameraCS->getCameraPosition();
-            Ogre::Vector3 cameraFinalPositionIfNoTightness = mCameraCS->getCameraTargetPosition() 
+            const Ogre::Vector3 &cameraCurrentPosition = mCameraCS->getCameraPosition();
+            const Ogre::Vector3 &cameraFinalPositionIfNoTightness = mCameraCS->getCameraTargetPosition() 
                 - mDirection * mDistance;
 
             Ogre::Vector3 diff = (cameraFinalPositionIfNoTightness - cameraCurrentPosition) * mTightness;
 
         // Specific methods
 
-        inline virtual void setDirection(Ogre::Vector3 direction)
+        inline virtual void setDirection(const Ogre::Vector3& direction)
         {
             mDirection = direction.normalisedCopy();
             instantUpdate();
 	public:
 
         RTSCameraMode(CameraControlSystem* cam
-            , const Ogre::Vector3 &initialPosition = Ogre::Vector3::ZERO
-            , const Ogre::Vector3 &upAxis = Ogre::Vector3::NEGATIVE_UNIT_Z
-            , const Ogre::Vector3 &leftAxis = Ogre::Vector3::NEGATIVE_UNIT_X
+            , const Ogre::Vector3& initialPosition = Ogre::Vector3::ZERO
+            , const Ogre::Vector3& upAxis = Ogre::Vector3::NEGATIVE_UNIT_Z
+            , const Ogre::Vector3& leftAxis = Ogre::Vector3::NEGATIVE_UNIT_X
             , const Ogre::Radian cameraPitch = Ogre::Radian(Ogre::Degree(90))
             , Ogre::Real minZoom = 0, Ogre::Real maxZoom = 0) 
             : CameraControlSystem::CameraMode(cam),
             return true;
         }
 
-        virtual void update(const Ogre::Real &timeSinceLastFrame)
+        virtual void update(const Ogre::Real& timeSinceLastFrame)
         {
             Ogre::Vector3 displacement = ((mUpAxis * mVerticalDisplacement)
                 + (mHeightAxis * mHeightDisplacement)
             mRotation = Ogre::Quaternion(mCameraPitch, mLeftAxis);
         }
 
-        Ogre::Radian getCameraPitch(){ return mCameraPitch; };
+        Ogre::Radian getCameraPitch() const { return mCameraPitch; };
 
         /**
 		 * @brief Set the moving speed factor (increase the height)
             instantUpdate();
         }
 
-        Ogre::Real getZoom(){ return mZoom; };
+        Ogre::Real getZoom() const { return mZoom; };
 
 		/**
 		 * @brief Tell the camera to zoom in (reduce the height)

CameraControlSystem/include/CCSCameraControlSystem.h

 
 			// A CollisionDelegate takes as params the position of the target and the camera, and returns the 
 			// the new camera position.
-			typedef fastdelegate::FastDelegate2<Ogre::Vector3, Ogre::Vector3, Ogre::Vector3> CollisionDelegate;
+			typedef fastdelegate::FastDelegate2<const Ogre::Vector3&, const Ogre::Vector3&, Ogre::Vector3> CollisionDelegate;
 			
 			CollisionDelegate collisionDelegate;
 
 			template <class X, class Y>
-			static CollisionDelegate newCollisionDelegate(Y* x, Ogre::Vector3 (X::*func)(Ogre::Vector3 targetPosition, Ogre::Vector3 cameraPosition)) { 
+			static CollisionDelegate newCollisionDelegate(Y* x, Ogre::Vector3 (X::*func)(const Ogre::Vector3& targetPosition, const Ogre::Vector3& cameraPosition)) { 
 				return fastdelegate::MakeDelegate(x, func);
 			}
 
 			 *
 			 * @return the first hit between the camera target position and the camera position.
 			 */
-			Ogre::Vector3 DefaultCollisionDetectionFunction(Ogre::Vector3 cameraTargetPosition, Ogre::Vector3 cameraPosition);
+			Ogre::Vector3 DefaultCollisionDetectionFunction(const Ogre::Vector3& cameraTargetPosition, const Ogre::Vector3& cameraPosition);
 
 			/**
 			* @brief Ignore the object in collision delegates that use Ogre's ray scene queries.
 		 * @param name the name to assign to the camera mode
 		 * @param cameraMode cameraMode the camera mode to be registered
 		 */
-        inline void registerCameraMode(Ogre::String name, CameraMode* cameraMode)
+        inline void registerCameraMode(const Ogre::String& name, CameraMode* cameraMode)
         {
             mCameraModes[name] = cameraMode;
         }
 		 * @param fixedAxis the axis which will be used to completely 
 		 * define the rotation when using autotracking
 		 */
-        inline void setFixedYawAxis(bool useFixedAxis, const Ogre::Vector3 &fixedAxis = Ogre::Vector3::UNIT_Y )
+        inline void setFixedYawAxis(bool useFixedAxis, const Ogre::Vector3& fixedAxis = Ogre::Vector3::UNIT_Y )
         {
             mCameraNode->setFixedYawAxis(useFixedAxis,fixedAxis);
         }
 		 *
 		 * @param position The position of the camera node
 		 */
-		void _setCameraPosition(Ogre::Vector3& position);
+		void _setCameraPosition(const Ogre::Vector3& position);
 
 		/**
 		 * @brief Set camera orientation manually. Use it with care: the orientation of the camera will be overridden by any camera mode (if set).
 		 *
 		 * @param orientation The orientation of the camera node
 		 */
-		void _setCameraOrientation(Ogre::Quaternion& orientation);
+		void _setCameraOrientation(const Ogre::Quaternion& orientation);
 
 	protected:
 

CameraControlSystem/src/CCSCameraControlSystem.cpp

         }
     }
 
-	Ogre::Vector3 CameraControlSystem::CollidableCamera::DefaultCollisionDetectionFunction(Ogre::Vector3 cameraTargetPosition, Ogre::Vector3 cameraPosition)
+	Ogre::Vector3 CameraControlSystem::CollidableCamera::DefaultCollisionDetectionFunction(const Ogre::Vector3& cameraTargetPosition, const Ogre::Vector3& cameraPosition)
 	{
 //		funciona con atenea y con barril pero no con el suelo
 		Ogre::Vector3 finalCameraPosition (cameraPosition.x, cameraPosition.y, cameraPosition.z);
         }
 	}
 
-	void CameraControlSystem::_setCameraPosition(Ogre::Vector3& position)
+	void CameraControlSystem::_setCameraPosition(const Ogre::Vector3& position)
 	{
 		if(mCameraNode)
 		{
 		}
 	}
 
-	void CameraControlSystem::_setCameraOrientation(Ogre::Quaternion& orientation)
+	void CameraControlSystem::_setCameraOrientation(const Ogre::Quaternion& orientation)
 	{
 		if(mCameraNode)
 		{

CameraControlSystem/src/CCSFreeCameraMode.cpp

     return true;
 }
 
-void CCS::FreeCameraMode::update(const Ogre::Real &timeSinceLastFrame)
+void CCS::FreeCameraMode::update(const Ogre::Real& timeSinceLastFrame)
 {
     Ogre::Vector3 dirVector = mCameraCS->getOgreCamera()->getRealDirection();
     Ogre::Vector3 lateralVector = dirVector.crossProduct(mFixedAxis).normalisedCopy();
 	mRotY = mInitialRotationY;
 }
 
-Ogre::Vector2 CCS::FreeCameraMode::getYawAndPitch (const Ogre::Vector3& direction)
+Ogre::Vector2 CCS::FreeCameraMode::getYawAndPitch(const Ogre::Vector3& direction)
 {
 	// Adapted from http://www.ogre3d.org/forums/viewtopic.php?f=2&t=27086