| 1 | /**************************************************************************************** | 
| 2 |   | 
| 3 |    Copyright (C) 2015 Autodesk, Inc. | 
| 4 |    All rights reserved. | 
| 5 |   | 
| 6 |    Use of this software is subject to the terms of the Autodesk license agreement | 
| 7 |    provided at the time of installation or download, or which otherwise accompanies | 
| 8 |    this software in either electronic or hard copy form. | 
| 9 |   | 
| 10 | ****************************************************************************************/ | 
| 11 |  | 
| 12 | //! \file fbxmanipulators.h | 
| 13 | #ifndef _FBXSDK_UTILS_MANIPULATORS_H_ | 
| 14 | #define _FBXSDK_UTILS_MANIPULATORS_H_ | 
| 15 |  | 
| 16 | #include <fbxsdk/fbxsdk_def.h> | 
| 17 |  | 
| 18 | #include <fbxsdk/core/fbxobject.h> | 
| 19 | #include <fbxsdk/core/math/fbxvector2.h> | 
| 20 | #include <fbxsdk/core/math/fbxvector4.h> | 
| 21 | #include <fbxsdk/scene/geometry/fbxcamera.h> | 
| 22 |  | 
| 23 | #include <fbxsdk/fbxsdk_nsbegin.h> | 
| 24 |  | 
| 25 | class FbxCameraManipulationState; | 
| 26 |  | 
| 27 | /** This class can be used to provide basic camera manipulation in any program using this library. | 
| 28 |   * \nosubgrouping | 
| 29 |   */ | 
| 30 | class FBXSDK_DLL FbxCameraManipulator : public FbxObject | 
| 31 | { | 
| 32 | 	FBXSDK_OBJECT_DECLARE(FbxCameraManipulator, FbxObject); | 
| 33 |  | 
| 34 | public: | 
| 35 | 	//! All possible manipulation actions that can be performed on a camera using this manipulator. | 
| 36 | 	enum EAction | 
| 37 | 	{ | 
| 38 | 		eNone,		//!< No action. | 
| 39 | 		eOrbit,		//!< Orbiting camera around LootAt/Interest position. | 
| 40 | 		eDolly,		//!< Moving camera closer or away from its LookAt/Intest position. | 
| 41 | 		ePan,		//!< Panning camera up, down and sideways. | 
| 42 | 		eFreePan	//!< Panning and dollying all at once. | 
| 43 | 	}; | 
| 44 |  | 
| 45 | 	/** Begin manipulation of the camera. | 
| 46 | 	* \param pAction The action performed for this manipulation scope. | 
| 47 | 	* \param pX Begin horizontal position of the manipulation, in pixels. | 
| 48 | 	* \param pY Begin vertical position of the manipulation, in pixels. */ | 
| 49 | 	void Begin(EAction pAction, float pX, float pY); | 
| 50 |  | 
| 51 | 	/** Notify manipulation of latest input. | 
| 52 | 	* \param pTimeDelta Elapsed time since the last notify. Only used if Smoothing is enabled. | 
| 53 | 	* \param pX Horizontal position of the manipulation, in pixels. | 
| 54 | 	* \param pY Vertical position of the manipulation, in pixels. | 
| 55 | 	* \param pScale Scaling value of the manipulation. Only used by eFreePan action. */ | 
| 56 | 	void Notify(float pX, float pY, float pScale=0); | 
| 57 |  | 
| 58 | 	//! End current manipulation. | 
| 59 | 	void End(); | 
| 60 |  | 
| 61 | 	/** Update the camera position. This must be called periodically in order for the camera to update its position. | 
| 62 | 	* \param pTimeDelta Elapsed time since the last update. If Smooth is disabled, you can leave this value to zero. | 
| 63 | 	* \remark Begin, Notify and End will not change the current camera position. */ | 
| 64 | 	void Update(const FbxTime& pTimeDelta=FBXSDK_TIME_ZERO); | 
| 65 |  | 
| 66 | 	/** Do a complete manipulation action in a single operation. This is the equivalent of calling Begin, Notify and End successively. | 
| 67 | 	* \param pAction The action performed for this manipulation scope. | 
| 68 | 	* \param pX Horizontal position of the manipulation, in pixels. | 
| 69 | 	* \param pY Vertical position of the manipulation, in pixels. | 
| 70 | 	* \param pScale Scaling value of the manipulation. Only used by eFreePan action. */ | 
| 71 | 	void Action(EAction pAction, float pX, float pY, float pScale=0); | 
| 72 |  | 
| 73 | 	/** Retrieve current manipulation action. | 
| 74 | 	* \return The action currently performed by the camera manipulator. */ | 
| 75 | 	EAction GetCurrentAction() const; | 
| 76 |  | 
| 77 | 	/** Change camera position and LookAt node to frame all objects. | 
| 78 | 	* \param pTime Time to use to evaluate mesh deformations. Leave at default value to cancel mesh evaluation. */ | 
| 79 | 	void FrameAll(const FbxTime& pTime=FBXSDK_TIME_INFINITE); | 
| 80 |  | 
| 81 | 	/** Change camera position and LookAt to frame all selected objects. | 
| 82 | 	* \param pTime Time to use to evaluate mesh deformations. Leave at default value to cancel mesh evaluation. */ | 
| 83 | 	void FrameSelected(const FbxTime& pTime=FBXSDK_TIME_INFINITE); | 
| 84 |  | 
| 85 | 	/** Change camera position and LookAt to frame the selected position on screen. The LookAt will be placed | 
| 86 | 	* at first closest intersecting geometry, and the distance between camera and LookAt will be preserved. | 
| 87 | 	* \param pX The horizontal screen coordinate. | 
| 88 | 	* \param pY The vertical screen coordinate. | 
| 89 | 	* \param pCulling If \c true, only test triangles that are front-facing, otherwise test both sides. | 
| 90 | 	* \param pTime Time to use to evaluate mesh deformations. Leave at default value to cancel mesh evaluation. */ | 
| 91 | 	void FrameScreenPosition(float pX, float pY, bool pCulling=false, const FbxTime& pTime=FBXSDK_TIME_INFINITE); | 
| 92 |  | 
| 93 | 	/** The camera controlled by the manipulator. */ | 
| 94 | 	FbxPropertyT<FbxReference> Camera; | 
| 95 |  | 
| 96 | 	/** Width of the camera viewport, in pixels. This is used to accurately calculate to movement speed. | 
| 97 | 	* \remark If this property is not correctly set, movements will be erronous. */ | 
| 98 | 	FbxPropertyT<FbxFloat> ViewportWidth; | 
| 99 |  | 
| 100 | 	/** Height of the camera viewport, in pixels. This is used to accurately calculate to movement speed. | 
| 101 | 	* \remark If this property is not correctly set, movements will be erronous. */ | 
| 102 | 	FbxPropertyT<FbxFloat> ViewportHeight; | 
| 103 |  | 
| 104 | 	/** Camera manipulations will be smooth if enabled. True by default. */ | 
| 105 | 	FbxPropertyT<FbxBool> Smooth; | 
| 106 |  | 
| 107 | 	/** Camera manipulations smoothing speed. Higher speed will stabilize the camera more quickly. Default is 10.0 */ | 
| 108 | 	FbxPropertyT<FbxDouble> SmoothSpeed; | 
| 109 |  | 
| 110 | 	/** Invert the camera horizontal manipulation direction if set to true. False by default. */ | 
| 111 | 	FbxPropertyT<FbxBool> InvertX; | 
| 112 |  | 
| 113 | 	/** Invert the camera vertical manipulation direction if set to true. False by default. */ | 
| 114 | 	FbxPropertyT<FbxBool> InvertY; | 
| 115 |  | 
| 116 | 	/** Restore the camera transform upon destruction of the manipulator. */ | 
| 117 | 	FbxPropertyT<FbxBool> Restore; | 
| 118 |  | 
| 119 | /***************************************************************************************************************************** | 
| 120 | ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! ** | 
| 121 | *****************************************************************************************************************************/ | 
| 122 | #ifndef DOXYGEN_SHOULD_SKIP_THIS | 
| 123 | protected: | 
| 124 | 	virtual void Construct(const FbxObject* pFrom); | 
| 125 | 	virtual void Destruct(bool pRecursive); | 
| 126 | 	virtual void ConstructProperties(bool pForceSet); | 
| 127 | 	virtual bool ConnectNotify(const FbxConnectEvent& pEvent); | 
| 128 | 	virtual bool PropertyNotify(EPropertyNotifyType pType, FbxProperty& pProperty); | 
| 129 |  | 
| 130 | private: | 
| 131 | 	void		Reset(); | 
| 132 | 	FbxCamera*	GetCamera() const; | 
| 133 | 	FbxNode*	GetCameraNode() const; | 
| 134 | 	FbxNode*	GetCameraLookAtNode() const; | 
| 135 | 	FbxNode*	GetCameraTargetUpNode() const; | 
| 136 | 	FbxVector4	GetCameraPosition() const; | 
| 137 | 	void		SetCameraPosition(const FbxVector4& pPosition); | 
| 138 | 	FbxVector4	GetCameraRotation() const; | 
| 139 | 	void		SetCameraRotation(const FbxVector4& pRotation); | 
| 140 | 	FbxVector4	GetCameraLookAtPosition() const; | 
| 141 | 	void		SetCameraLookAtPosition(const FbxVector4& pPosition); | 
| 142 | 	FbxVector4	GetCameraTargetUpPosition() const; | 
| 143 | 	void		SetCameraTargetUpPosition(const FbxVector4& pPosition); | 
| 144 | 	FbxAMatrix	GetCameraRotationMatrix() const; | 
| 145 | 	void		SetCameraRotationMatrix(const FbxAMatrix& pRM); | 
| 146 |  | 
| 147 | 	double		ComputeRotationAxis(FbxVector4& pFront, FbxVector4& pUp, FbxVector4& pRight, const FbxVector4& pEye, const FbxVector4& pLookAt, const FbxVector4& pUpVector) const; | 
| 148 | 	void		ComputeRotationMatrix(FbxAMatrix& pRM, const FbxVector4& pEye, const FbxVector4& pLookAt, const FbxVector4& pUpVector); | 
| 149 | 	void		UpdateCameraRotation(); | 
| 150 |  | 
| 151 | 	bool		FrameObjects(bool pSelected, const FbxTime& pTime); | 
| 152 | 	FbxVector4	ComputePositionToFitBBoxInFrustum(const FbxVector4& pBBoxMin, const FbxVector4& pBBoxMax, const FbxVector4& pBBoxCenter, const FbxVector4& pCameraPosition, const FbxAMatrix& pCameraRM, const FbxTime& pTime); | 
| 153 |  | 
| 154 | 	EAction		mCurrentAction; | 
| 155 | 	FbxFloat	mBeginMouse[3], mLastMouse[3]; | 
| 156 | 	FbxVector4	mBeginPosition, mBeginAxis[3]; | 
| 157 | 	FbxBool		mBeginFlipped; | 
| 158 |  | 
| 159 | 	FbxDouble	mDestOrthoZoom; | 
| 160 | 	FbxVector4	mDestPosition, mDestLookAt, mDestTargetUp; | 
| 161 | 	FbxAMatrix	mDestRotation; | 
| 162 |  | 
| 163 |   	FbxVector4	mInitialPosition, mInitialRotation, mInitialLookAt; | 
| 164 | #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/ | 
| 165 | }; | 
| 166 |  | 
| 167 | #include <fbxsdk/fbxsdk_nsend.h> | 
| 168 |  | 
| 169 | #endif /* _FBXSDK_UTILS_MANIPULATORS_H_ */ | 
| 170 |  |