#ifndef _PROJECTIONMATRIX_H_ #define _PROJECTIONMATRIX_H_ #include #pragma warning(disable: 4003) #include "gmtl/gmtl.h" namespace projection { /** * Projection matrix class. */ class ProjectionMatrix { public: /** * Constructor. * * Default projection matrix value is : FOV=30.0, * AspectRatio=4/3, Near=0.1, Far=100.0 */ ProjectionMatrix(); /** * Destructor. */ virtual ~ProjectionMatrix(); /** * Copy constructor. * * @param matrix Copy source matrix. */ ProjectionMatrix(const ProjectionMatrix &matrix); /** * Set Field of View. * * @param fov Field of View. */ void setFOV(float fov) { m_fov = fov; } /** * Retrieve Field of View. * * @return Field of View. */ float getFOV() const { return m_fov; } /** * Set aspect ratio. * * @param ratio Aspect ratio. */ void setAspectRatio(float ratio) { m_aspectRatio = ratio; } /** * Retrieve aspect ratio. * * @return Aspect ratio. */ float getAspectRatio() const { return m_aspectRatio; } /** * Set near clip distance. * * @param Near clip distance. */ void setNear(float nearDist) { m_near = nearDist; } /** * Retrieve near clip distance. * * @return Near clip distance. */ float getNear() const { return m_near; } /** * Set far clip plane distance. * * @param Far clip plane distance. */ void setFar(float farDist) { m_far = farDist; } /** * Retrieve far clip plane distance. * * @return Far clip plane distance. */ float getFar() const { return m_far; } /** * Set vertical off-axis distane on the Z=1.0 plane. * * @param Vertical off-axis distane. */ void setOffaxisX(float offaxisX) { m_offaxisX = offaxisX; } /** * Retrieve horizontal off-axis distane on the Z=1.0 plane. * * @return Horizontal off-axis distane. */ float getOffaxisX() const { return m_offaxisX; } /** * Set horizontal off-axis distane on the Z=1.0 plane. * * @param Horizontal off-axis distane. */ void setOffaxisY(float offaxisY) { m_offaxisY = offaxisY; } /** * Retrieve vertical off-axis distane on the Z=1.0 plane. * * @return Vertical off-axis distane. */ float getOffaxisY() const { return m_offaxisY; } /** * Retrieve matrix values for glMultMatrixd(). * * @return Matrix values. */ float* getMatrix(); /** * Retrieve four corner vectors. * * @param Four corner vectors. */ void getCorners(gmtl::Vec3f vecs[4]) const; /** * Retrieve frustum parameters as 'Frustum left right bottom top near far;'. * * @param numSpaces Number of space characters for indent. * @return Frustum params. */ QString getParams(int numSpaces=0) const; /** * Assignment operator. * * @param m Assignment source projection matrix. */ ProjectionMatrix& operator=(const ProjectionMatrix& m) { if (this != &m) { m_fov = m.m_fov; m_aspectRatio = m.m_aspectRatio; m_near = m.m_near; m_far = m.m_far; m_offaxisX = m.m_offaxisX; m_offaxisY = m.m_offaxisY; } return *this; } /** * Equal operator. * * @param a Operand projection matrix. * @param b Operand projection matrix. */ friend bool operator==(const ProjectionMatrix &a, const ProjectionMatrix &b) { return (a.m_fov == b.m_fov && a.m_aspectRatio == b.m_aspectRatio && a.m_near == b.m_near && a.m_far == b.m_far && a.m_offaxisX == b.m_offaxisX && a.m_offaxisY == b.m_offaxisY); } /** * Not equal operator. * * @param a Operand projection matrix. * @param b Operand projection matrix. */ friend bool operator!=(const ProjectionMatrix &a, const ProjectionMatrix &b) { return !(a==b); } /** * Restore the projection matrix from XML data. * * @param element Parent XML element of the projection matrix data. */ virtual void initFromDOMElement(const QDomElement& element); /** * Store the current projection matrix as XML data. * * @param name XML node name of the data. * @param doc XML document to store the data. * @return Current projection matrix data as XML data. */ virtual QDomElement domElement(const QString& name, QDomDocument& doc) const; private: float m_fov; //!< Field of View (FOV). float m_aspectRatio; //!< Aspect ratio (width / height). float m_near; //!< Near clip plane distance. float m_far; //!< Far clip plane distance. float m_offaxisX; //!< Horizontal off-axis distance. float m_offaxisY; //!< Vertical off-axis distance. float m_mat[16]; //!< Matrix values. Calculated when getMatrix() called. }; }; // projection #endif // _PROJECTIONMATRIX_H_