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) 2001 Sony Computer Entertainment America
00002                               All Rights Reserved
00003                                SCEA Confidential                                */
00004 
00005 #ifndef ps2gl_matrix_h
00006 #define ps2gl_matrix_h
00007 
00008 #include "ps2gl/debug.h"
00009 #include "ps2s/cpu_matrix.h"
00010 
00011 #include "ps2gl/glcontext.h"
00012 #include "ps2gl/drawcontext.h"
00013 
00014 /********************************************
00015  * CMatrixStack
00016  */
00017 
00018 class CGLContext;
00019 
00020 class CMatrixStack {
00021    protected:
00022       CGLContext        &GLContext;
00023       static const int  MaxStackDepth = 16;
00024       cpu_mat_44                Matrices[MaxStackDepth], InverseMatrices[MaxStackDepth];
00025       int               CurStackDepth;
00026 
00027    public:
00028       CMatrixStack( CGLContext &context )
00029          : GLContext(context), CurStackDepth(0)
00030       {
00031          Matrices[0].set_identity();
00032          InverseMatrices[0].set_identity();
00033       }
00034 
00035       virtual void Pop() = 0;
00036       virtual void Push() = 0;
00037       virtual void Concat( const cpu_mat_44& xform, const cpu_mat_44& inverse ) = 0;
00038       virtual void SetTop( const cpu_mat_44 &newMat, const cpu_mat_44 &newInv ) = 0;
00039 };
00040 
00041 /********************************************
00042  * CImmMatrixStack
00043  */
00044 
00045 class CImmMatrixStack : public CMatrixStack {
00046    public:
00047       CImmMatrixStack( CGLContext &context ) : CMatrixStack(context) {}
00048 
00049       void Pop() {
00050          mErrorIf( CurStackDepth == 0, "No matrices to pop!" );
00051          --CurStackDepth;
00052          GLContext.GetImmDrawContext().SetVertexXformValid(false);
00053       }
00054 
00055       void Push() {
00056          mErrorIf( CurStackDepth == MaxStackDepth - 1,
00057                    "No room on stack!" );
00058          Matrices[CurStackDepth + 1] = Matrices[CurStackDepth];
00059          InverseMatrices[CurStackDepth + 1] = InverseMatrices[CurStackDepth];
00060          ++CurStackDepth;
00061       }
00062 
00063       void Concat( const cpu_mat_44& xform, const cpu_mat_44& inverse ) {
00064          cpu_mat_44 &curMat = Matrices[CurStackDepth];
00065          cpu_mat_44 &curInv = InverseMatrices[CurStackDepth];
00066          curMat = curMat * xform;
00067          curInv = inverse * curInv;
00068          GLContext.GetImmDrawContext().SetVertexXformValid(false);
00069       }
00070 
00071       void SetTop( const cpu_mat_44 &newMat, const cpu_mat_44 &newInv ) {
00072          Matrices[CurStackDepth] = newMat;
00073          InverseMatrices[CurStackDepth] = newInv;
00074          GLContext.GetImmDrawContext().SetVertexXformValid(false);
00075       }
00076 
00077       const cpu_mat_44 & GetTop() const { return Matrices[CurStackDepth]; }
00078       const cpu_mat_44 & GetInvTop() const { return InverseMatrices[CurStackDepth]; }
00079 };
00080 
00081 /********************************************
00082  * CDListMatrixStack
00083  */
00084 
00085 class CDListMatrixStack : public CMatrixStack {
00086    public:
00087       CDListMatrixStack( CGLContext &context ) : CMatrixStack(context) {}
00088 
00089       void Pop();
00090       void Push();
00091       void Concat( const cpu_mat_44& xform, const cpu_mat_44& inverse );
00092       void SetTop( const cpu_mat_44 &newMat, const cpu_mat_44 &newInv );
00093 };
00094 
00095 #endif // ps2gl_matrix_h

ps2gl version 0.2