MercuryObjectBase.h

Go to the documentation of this file.
00001 #ifndef MERCURYOBJECTBASE_H
00002 #define MERCURYOBJECTBASE_H
00003 
00004 //#include "MercuryUtil.h"
00005 #include "MercuryTypes.h"
00006 
00008 
00010 enum RotationMode
00011 {
00012     RM_NORMAL,
00013     RM_BILLBOARD,
00014     RM_MATRIX,
00015     RM_QUATERNION,
00016     RM_OFF
00017 };
00018 
00020 class MercuryObjectBase 
00021 {
00022 public:
00023     MercuryObjectBase();
00024     virtual ~MercuryObjectBase() {};
00025     virtual void Init();
00026 
00027     virtual void CalculateMatrices();
00028 
00029     void Debug( const float z );
00030 
00031     //Position
00032     inline void SetX(const float x) { m_taintedMatrix |= m_position.SetX(x); }
00033     inline void SetY(const float y) { m_taintedMatrix |= m_position.SetY(y); }
00034     inline void SetZ(const float z) { m_taintedMatrix |= m_position.SetZ(z); }
00035     inline void SetPosition(const MercuryPoint& position) { m_taintedMatrix = true; m_position = position; }
00036     inline float GetX() const { return m_position.GetX(); }
00037     inline float GetY() const { return m_position.GetY(); }
00038     inline float GetZ() const { return m_position.GetZ(); }
00039     inline const MercuryPoint& GetPosition() const { return m_position; }
00040     inline void MoveX(const float x) { m_taintedMatrix |= m_position.SetX(x + m_position.GetX()); }
00041     inline void MoveY(const float y) { m_taintedMatrix |= m_position.SetY(y + m_position.GetY()); }
00042     inline void MoveZ(const float z) { m_taintedMatrix |= m_position.SetZ(z + m_position.GetZ()); }
00043 
00044     //Rotation
00045     inline void SetRotX(const float x) { m_taintedMatrix |= m_rotation.SetX(x); }
00046     inline void SetRotY(const float y) { m_taintedMatrix |= m_rotation.SetY(y); }
00047     inline void SetRotZ(const float z) { m_taintedMatrix |= m_rotation.SetZ(z); }
00048     inline void SetRot(const MercuryPoint& rotation) { m_taintedMatrix = true; m_rotation = rotation; }
00049     inline float GetRotX() const { return m_rotation.GetX(); }
00050     inline float GetRotY() const { return m_rotation.GetY(); }
00051     inline float GetRotZ() const { return m_rotation.GetZ(); }
00052     inline const MercuryPoint& GetRot() const { return m_rotation; }
00053     inline void MoveRotX(const float x) { m_taintedMatrix |= m_rotation.SetX(x + m_rotation.GetX()); }
00054     inline void MoveRotY(const float y) { m_taintedMatrix |= m_rotation.SetY(y + m_rotation.GetY()); }
00055     inline void MoveRotZ(const float z) { m_taintedMatrix |= m_rotation.SetZ(z + m_rotation.GetZ()); }
00056     inline RotationMode GetRotMode() const { return m_rotMode; }
00057 
00058     //Scale
00059     inline void SetScaleX(const float x) { m_taintedMatrix |= m_scale.SetX(x); }
00060     inline void SetScaleY(const float y) { m_taintedMatrix |= m_scale.SetY(y); }
00061     inline void SetScaleZ(const float z) { m_taintedMatrix |= m_scale.SetZ(z); }
00062     inline void SetScale(const MercuryPoint& scale) { m_taintedMatrix = true; m_scale = scale; }
00063     inline float GetScaleX() const { return m_scale.GetX(); }
00064     inline float GetScaleY() const { return m_scale.GetY(); }
00065     inline float GetScaleZ() const { return m_scale.GetZ(); }
00066     inline const MercuryPoint& GetScale() const { return m_scale; }
00067     inline void MoveScaleX(const float x) { m_taintedMatrix |= m_scale.SetX(x + m_scale.GetX()); }
00068     inline void MoveScaleY(const float y) { m_taintedMatrix |= m_scale.SetY(y + m_scale.GetY()); }
00069     inline void MoveScaleZ(const float z) { m_taintedMatrix |= m_scale.SetZ(z + m_scale.GetZ()); }
00070 
00071     //Parent Stuffs
00072     inline void SetParentObject(MercuryObjectBase* parent) { m_parentObject = parent; }
00073     MercuryPoint GetGlobalPosition() const;
00074     inline MercuryObjectBase * GetParentObject() { return m_parentObject; }
00075 
00076     void SetRotationMode( const RotationMode mode ) { m_taintedMatrix = true; m_rotMode = mode; }
00077 
00078     inline void SetAfterMatrix( const float* inmat ) { m_taintedMatrix = true; m_matrix = inmat; }
00079     inline const MercuryMatrix& GetAfterMatrix( ) const { return m_matrix; }
00080 
00081     inline void SetRotationQuaternion( const MQuaternion& q) { m_taintedMatrix = true; m_rotQuat = q; }
00082     inline const MQuaternion& GetRotationQuaternion() const { return m_rotQuat; }
00083     
00084     inline void SetAlignX(float x) { if (x != m_xalign) { m_taintedMatrix = true; m_xalign = x; } }
00085     inline void SetAlignY(float y) { if (y != m_yalign) { m_taintedMatrix = true; m_yalign = y; } }
00086 
00087     inline void SetHide(bool hide) { m_hidden = hide; }
00088     inline bool GetHide() const { return m_hidden; }
00089     bool IsHidden() const;
00090 
00091     //Lower numbers are drawn first.
00092     virtual void SetDrawOrder(int order) { m_drawOrder = order; }
00093     inline int GetDrawOrder() const { return m_drawOrder; }
00094 
00095     inline bool operator<(const MercuryObjectBase& r) const { return m_drawOrder < r.m_drawOrder; }
00096     inline bool operator>=(const MercuryObjectBase& r) const { return m_drawOrder >= r.m_drawOrder; }
00097 
00098     inline bool IsMatrixTainted() const { return m_taintedMatrix; }
00099     void SetMatrixTainted(bool taint) { m_taintedMatrix = taint; }
00100     const MercuryMatrix& GetLocalMatrix() const { return m_localMatrix; }
00101     const MercuryMatrix& GetFinalMatrix() const { return m_finalMatrix; }
00102     MercuryPoint GetTruePosition() const;
00103 
00104 protected:
00105 
00107     float m_fVisRadius;
00108 
00109     bool m_hidden;
00110     int m_drawOrder;
00111     
00112     MercuryObjectBase* m_parentObject;
00113 
00114     MercuryMatrix m_localMatrix;
00115     MercuryMatrix m_finalMatrix;
00116 
00117 //private:
00118     MercuryPoint m_scale;
00119     MercuryPoint m_position;
00120     MercuryPoint m_rotation;
00121 
00122     MercuryMatrix m_matrix; //After-matrix.  This is used for any additional manual changes)
00123     MQuaternion m_rotQuat;
00124 
00125     RotationMode m_rotMode;
00126 
00127     float m_xalign, m_yalign;
00128 
00129     bool m_taintedMatrix;
00130 };
00131 
00132 #endif
00133 
00134 /* 
00135  * Copyright (c) 2005-2006 Joshua Allen
00136  * All rights reserved.
00137  *
00138  * Redistribution and use in source and binary forms, with or
00139  * without modification, are permitted provided that the following
00140  * conditions are met:
00141  *  -   Redistributions of source code must retain the above
00142  *      copyright notice, this list of conditions and the following disclaimer.
00143  *  -   Redistributions in binary form must reproduce the above copyright
00144  *      notice, this list of conditions and the following disclaimer in
00145  *      the documentation and/or other materials provided with the distribution.
00146  *  -   Neither the name of the Mercury Engine nor the names of its
00147  *      contributors may be used to endorse or promote products derived from
00148  *      this software without specific prior written permission.
00149  *
00150  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00151  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00152  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00153  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00154  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00155  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00156  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00157  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00158  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00159  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00160  */

Hosted by SourceForge.net Logo