PixelLightAPI  .
Transform3.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Transform3.h                                   *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLMATH_TRANSFORM3_H__
00024 #define __PLMATH_TRANSFORM3_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLCore/Base/Event/Event.h>
00032 #include <PLMath/Matrix3x4.h>
00033 #include <PLMath/Quaternion.h>
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLMath {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Classes                                               ]
00044 //[-------------------------------------------------------]
00045 /**
00046 *  @brief
00047 *    3D transform class
00048 *
00049 *  @remarks
00050 *    The design goal of this class was not to be as memory compact as possible - for such a use case, one can use
00051 *    for example directly Matrix3x4. The design goal was to provide a class that is able to convert between different
00052 *    representations of a 3D transform in an efficient way. To achieve this, the "Lazy Evaluation"-scheme is used. This
00053 *    means that, for example, the inverse transform is only recalculated if it's really required. To allow a practical
00054 *    usage of this transform class within more advanced systems, events are provided to inform when transform data has
00055 *    been changed.
00056 */
00057 class Transform3 {
00058 
00059 
00060     //[-------------------------------------------------------]
00061     //[ Events                                                ]
00062     //[-------------------------------------------------------]
00063     public:
00064         PLCore::Event<> EventPosition;  /**< Position change event */
00065         PLCore::Event<> EventRotation;  /**< Rotation change event */
00066         PLCore::Event<> EventScale;     /**< Scale change event */
00067 
00068 
00069     //[-------------------------------------------------------]
00070     //[ Public functions                                      ]
00071     //[-------------------------------------------------------]
00072     public:
00073         /**
00074         *  @brief
00075         *    Default constructor (set's an identity transform matrix)
00076         */
00077         PLMATH_API Transform3();
00078 
00079         /**
00080         *  @brief
00081         *    Copy constructor (event data is not copied)
00082         *
00083         *  @param[in] cSource
00084         *    Source to copy from
00085         */
00086         PLMATH_API Transform3(const Transform3 &cSource);
00087 
00088         /**
00089         *  @brief
00090         *    Copy operator (event data is not copied)
00091         *
00092         *  @param[in] cSource
00093         *    Source to copy from
00094         *
00095         *  @return
00096         *    Reference to this instance
00097         *
00098         *  @note
00099         *    - EventPosition, EventRotation and EventScale events are emitted
00100         */
00101         PLMATH_API Transform3 &operator =(const Transform3 &cSource);
00102 
00103         /**
00104         *  @brief
00105         *    Gets the position
00106         *
00107         *  @return
00108         *    Position
00109         */
00110         inline const Vector3 &GetPosition() const;
00111 
00112         /**
00113         *  @brief
00114         *    Sets the position
00115         *
00116         *  @param[in] vPosition
00117         *    New position
00118         */
00119         PLMATH_API void SetPosition(const Vector3 &vPosition);
00120 
00121         /**
00122         *  @brief
00123         *    Gets the rotation
00124         *
00125         *  @return
00126         *    Rotation
00127         */
00128         inline const Quaternion &GetRotation() const;
00129 
00130         /**
00131         *  @brief
00132         *    Sets the rotation
00133         *
00134         *  @param[in] qRotation
00135         *    New rotation
00136         */
00137         PLMATH_API void SetRotation(const Quaternion &qRotation);
00138 
00139         /**
00140         *  @brief
00141         *    Gets the scale
00142         *
00143         *  @return
00144         *    Scale
00145         */
00146         inline const Vector3 &GetScale() const;
00147 
00148         /**
00149         *  @brief
00150         *    Sets the scale
00151         *
00152         *  @param[in] vScale
00153         *    New scale
00154         */
00155         PLMATH_API void SetScale(const Vector3 &vScale);
00156 
00157         /**
00158         *  @brief
00159         *    Returns the current final transform matrix
00160         *
00161         *  @return
00162         *    The current final transform matrix
00163         *
00164         *  @note
00165         *    - If position, rotation or scale was changed, the current transform matrix
00166         *      is recalculated internally before it is returned
00167         */
00168         PLMATH_API const Matrix3x4 &GetMatrix();
00169 
00170         /**
00171         *  @brief
00172         *    Sets the current final transform matrix
00173         *
00174         *  @param[in] mTrans
00175         *    The current final transform matrix
00176         *
00177         *  @note
00178         *    - The scale can't be extracted correctly from the given transform matrix if one or
00179         *      two scale components are negative while another is/are not (we can't figure out
00180         *      WHICH axis are negative!)
00181         */
00182         PLMATH_API void SetMatrix(const Matrix3x4 &mTrans);
00183 
00184         /**
00185         *  @brief
00186         *    Returns the current final inverse transform matrix
00187         *
00188         *  @return
00189         *    The current final inverse transform matrix
00190         *
00191         *  @note
00192         *    - If position, rotation or scale was changed, the current inverse transform matrix
00193         *      is recalculated internally before it is returned
00194         */
00195         PLMATH_API const Matrix3x4 &GetInverseMatrix();
00196 
00197 
00198     //[-------------------------------------------------------]
00199     //[ Private definitions                                   ]
00200     //[-------------------------------------------------------]
00201     private:
00202         /**
00203         *  @brief
00204         *    Flags which hold ínternal information
00205         */
00206         enum EInternalFlags {
00207             RecalculateTransformMatrix         = 1<<0,  /**< Recalculation of transform matrix required */
00208             RecalculateInverseTransformMatrix  = 1<<1   /**< Recalculation of inverse transform matrix required */
00209         };
00210 
00211 
00212     //[-------------------------------------------------------]
00213     //[ Private data                                          ]
00214     //[-------------------------------------------------------]
00215     private:
00216         PLCore::uint8 m_nInternalFlags; /**< Internal flags */
00217         Vector3       m_vPosition;      /**< Position as vector */
00218         Quaternion    m_qRotation;      /**< Rotation as quaternion */
00219         Vector3       m_vScale;         /**< Scale as vector */
00220         Matrix3x4     m_mTrans;         /**< Current final composed transform matrix */
00221         Matrix3x4     m_mInvTrans;      /**< Current final composed inverse transform matrix */
00222 
00223 
00224 };
00225 
00226 
00227 //[-------------------------------------------------------]
00228 //[ Namespace                                             ]
00229 //[-------------------------------------------------------]
00230 } // PLMath
00231 
00232 
00233 //[-------------------------------------------------------]
00234 //[ Implementation                                        ]
00235 //[-------------------------------------------------------]
00236 #include "PLMath/Transform3.inl"
00237 
00238 
00239 #endif // __PLMATH_TRANSFORM3_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:01
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported