9#include "ps2gl/dlgmanager.h"
10#include "ps2gl/dlist.h"
11#include "ps2gl/glcontext.h"
12#include "ps2gl/immgmanager.h"
13#include "ps2gl/matrix.h"
25 return CDListCmd::GetNextCmd(
this);
29void CDListMatrixStack::Pop()
31 GLContext.GetDListGeomManager().Flush();
32 GLContext.GetDListManager().GetOpenDList() +=
CMatrixPopCmd();
33 GLContext.XformChanged();
42 return CDListCmd::GetNextCmd(
this);
46void CDListMatrixStack::Push()
52 cpu_mat_44 Matrix, Inverse;
62 pGLContext->GetCurMatrixStack().Concat(Matrix, Inverse);
63 return CDListCmd::GetNextCmd(
this);
67void CDListMatrixStack::Concat(
const cpu_mat_44& xform,
const cpu_mat_44& inverse)
69 GLContext.GetDListGeomManager().Flush();
70 GLContext.GetDListManager().GetOpenDList() +=
CMatrixConcatCmd(xform, inverse);
71 GLContext.XformChanged();
75 cpu_mat_44 Matrix, Inverse;
85 pGLContext->GetCurMatrixStack().SetTop(Matrix, Inverse);
86 return CDListCmd::GetNextCmd(
this);
90void CDListMatrixStack::SetTop(
const cpu_mat_44& newMat,
const cpu_mat_44& newInv)
92 GLContext.GetDListGeomManager().Flush();
93 GLContext.GetDListManager().GetOpenDList() +=
CMatrixSetTopCmd(newMat, newInv);
94 GLContext.XformChanged();
101void glMatrixMode(GLenum mode)
103 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
105 pGLContext->SetMatrixMode(mode);
108void glLoadIdentity(
void)
110 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
112 CMatrixStack& matStack = pGLContext->GetCurMatrixStack();
115 ident.set_identity();
116 matStack.SetTop(ident, ident);
119void glPushMatrix(
void)
121 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
123 CMatrixStack& matStack = pGLContext->GetCurMatrixStack();
127void glPopMatrix(
void)
129 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
131 CMatrixStack& matStack = pGLContext->GetCurMatrixStack();
136extern void Invert2(
float* mat,
float* dst);
138void glLoadMatrixf(
const GLfloat* m)
140 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
142 CMatrixStack& matStack = pGLContext->GetCurMatrixStack();
146 float* dest =
reinterpret_cast<float*
>(&newMat);
147 for (
int i = 0; i < 16; i++)
150 cpu_mat_44 invMatrix;
151 Invert2((
float*)&newMat, (
float*)&invMatrix);
153 matStack.SetTop(newMat, invMatrix);
156void glFrustum(GLdouble left, GLdouble right,
157 GLdouble bottom, GLdouble top,
158 GLdouble zNear, GLdouble zFar)
168 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
172 (2.0f * zNear) / (right - left),
178 (2.0f * zNear) / (top - bottom),
182 (right + left) / (right - left),
183 (top + bottom) / (top - bottom),
184 -(zFar + zNear) / (zFar - zNear),
189 (-2.0f * zFar * zNear) / (zFar - zNear),
195 (right - left) / (2 * zNear),
201 (top - bottom) / (2 * zNear),
208 -(zFar - zNear) / (2 * zFar * zNear)),
210 (right + left) / (2 * zNear),
211 (top + bottom) / (2 * zNear),
213 (zFar + zNear) / (2 * zFar * zNear))
216 CMatrixStack& matStack = pGLContext->GetCurMatrixStack();
217 matStack.Concat(xform, inv);
220void glOrtho(GLdouble left, GLdouble right,
221 GLdouble bottom, GLdouble top,
222 GLdouble zNear, GLdouble zFar)
232 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
236 (2.0f) / (right - left),
242 (2.0f) / (top - bottom),
251 -(right + left) / (right - left),
252 -(top + bottom) / (top - bottom),
253 -(zFar + zNear) / (zFar - zNear),
280 CMatrixStack& matStack = pGLContext->GetCurMatrixStack();
281 matStack.Concat(xform, inv);
284void glMultMatrixf(
const GLfloat* m)
286 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
290 cpu_mat_44 newMatrix(cpu_vec_xyzw((
float)m[0], (
float)m[1], (
float)m[2], (
float)m[3]),
291 cpu_vec_xyzw((
float)m[4], (
float)m[5], (
float)m[6], (
float)m[7]),
292 cpu_vec_xyzw((
float)m[8], (
float)m[9], (
float)m[10], (
float)m[11]),
293 cpu_vec_xyzw((
float)m[12], (
float)m[13], (
float)m[14], (
float)m[15]));
312 cpu_mat_44 invMatrix;
314 Invert2((
float*)&newMatrix, (
float*)&invMatrix);
315 CMatrixStack& matStack = pGLContext->GetCurMatrixStack();
316 matStack.Concat(newMatrix, invMatrix);
321void glRotatef(GLfloat angle,
322 GLfloat x, GLfloat y, GLfloat z)
324 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
326 cpu_mat_44 xform, inverse;
327 cpu_vec_xyz axis(x, y, z);
329 xform.set_rotate(Math::DegToRad(angle), axis);
330 inverse.set_rotate(Math::DegToRad(-angle), axis);
332 CMatrixStack& matStack = pGLContext->GetCurMatrixStack();
333 matStack.Concat(xform, inverse);
336void glScalef(GLfloat x, GLfloat y, GLfloat z)
338 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
340 cpu_mat_44 xform, inverse;
341 xform.set_scale(cpu_vec_xyz(x, y, z));
342 inverse.set_scale(cpu_vec_xyz(1.0f / x, 1.0f / y, 1.0f / z));
344 CMatrixStack& matStack = pGLContext->GetCurMatrixStack();
345 matStack.Concat(xform, inverse);
348void glTranslatef(GLfloat x, GLfloat y, GLfloat z)
350 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
352 cpu_mat_44 xform, inverse;
353 cpu_vec_xyz direction(x, y, z);
354 xform.set_translate(direction);
355 inverse.set_translate(-direction);
357 CMatrixStack& matStack = pGLContext->GetCurMatrixStack();
358 matStack.Concat(xform, inverse);