Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

matrix.h

Go to the documentation of this file.
00001 /*        Copyright (C) 2000,2001,2002  Sony Computer Entertainment America
00002           
00003           This file is subject to the terms and conditions of the GNU Lesser
00004           General Public License Version 2.1. See the file "COPYING" in the
00005           main directory of this archive for more details.                             */
00006 
00007 #ifndef ps2gl_matrix_h
00008 #define ps2gl_matrix_h
00009 
00010 #include "ps2gl/debug.h"
00011 #include "ps2s/cpu_matrix.h"
00012 
00013 #include "ps2gl/glcontext.h"
00014 #include "ps2gl/drawcontext.h"
00015 
00016 /********************************************
00017  * CMatrixStack
00018  */
00019 
00020 class CGLContext;
00021 
00022 class CMatrixStack {
00023    protected:
00024       CGLContext        &GLContext;
00025       static const int  MaxStackDepth = 16;
00026       cpu_mat_44                Matrices[MaxStackDepth], InverseMatrices[MaxStackDepth];
00027       int               CurStackDepth;
00028 
00029    public:
00030       CMatrixStack( CGLContext &context )
00031          : GLContext(context), CurStackDepth(0)
00032       {
00033          Matrices[0].set_identity();
00034          InverseMatrices[0].set_identity();
00035       }
00036 
00037       virtual void Pop() = 0;
00038       virtual void Push() = 0;
00039       virtual void Concat( const cpu_mat_44& xform, const cpu_mat_44& inverse ) = 0;
00040       virtual void SetTop( const cpu_mat_44 &newMat, const cpu_mat_44 &newInv ) = 0;
00041 };
00042 
00043 /********************************************
00044  * CImmMatrixStack
00045  */
00046 
00047 class CImmMatrixStack : public CMatrixStack {
00048    public:
00049       CImmMatrixStack( CGLContext &context ) : CMatrixStack(context) {}
00050 
00051       void Pop() {
00052          mErrorIf( CurStackDepth == 0, "No matrices to pop!" );
00053          --CurStackDepth;
00054          GLContext.GetImmDrawContext().SetVertexXformValid(false);
00055       }
00056 
00057       void Push() {
00058          mErrorIf( CurStackDepth == MaxStackDepth - 1,
00059                    "No room on stack!" );
00060          Matrices[CurStackDepth + 1] = Matrices[CurStackDepth];
00061          InverseMatrices[CurStackDepth + 1] = InverseMatrices[CurStackDepth];
00062          ++CurStackDepth;
00063       }
00064 
00065       void Concat( const cpu_mat_44& xform, const cpu_mat_44& inverse ) {
00066          cpu_mat_44 &curMat = Matrices[CurStackDepth];
00067          cpu_mat_44 &curInv = InverseMatrices[CurStackDepth];
00068          curMat = curMat * xform;
00069          curInv = inverse * curInv;
00070          GLContext.GetImmDrawContext().SetVertexXformValid(false);
00071       }
00072 
00073       void SetTop( const cpu_mat_44 &newMat, const cpu_mat_44 &newInv ) {
00074          Matrices[CurStackDepth] = newMat;
00075          InverseMatrices[CurStackDepth] = newInv;
00076          GLContext.GetImmDrawContext().SetVertexXformValid(false);
00077       }
00078 
00079       const cpu_mat_44 & GetTop() const { return Matrices[CurStackDepth]; }
00080       const cpu_mat_44 & GetInvTop() const { return InverseMatrices[CurStackDepth]; }
00081 };
00082 
00083 /********************************************
00084  * CDListMatrixStack
00085  */
00086 
00087 class CDListMatrixStack : public CMatrixStack {
00088    public:
00089       CDListMatrixStack( CGLContext &context ) : CMatrixStack(context) {}
00090 
00091       void Pop();
00092       void Push();
00093       void Concat( const cpu_mat_44& xform, const cpu_mat_44& inverse );
00094       void SetTop( const cpu_mat_44 &newMat, const cpu_mat_44 &newInv );
00095 };
00096 
00097 #endif // ps2gl_matrix_h

ps2gl version cvs