mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-31 22:00:48 +00:00
- moved the matrix code out of 'gl' because the model code also needs it.
This commit is contained in:
parent
637a9dff9b
commit
836970f012
18 changed files with 129 additions and 138 deletions
|
@ -796,7 +796,6 @@ set( FASTMATH_SOURCES
|
|||
sound/oalsound.cpp
|
||||
sound/sndfile_decoder.cpp
|
||||
sound/mididevices/music_timiditypp_mididevice.cpp
|
||||
gl/data/gl_matrix.cpp
|
||||
gl/utility/gl_clock.cpp
|
||||
gl/renderer/gl_2ddrawer.cpp
|
||||
gl/hqnx/init.cpp
|
||||
|
@ -826,6 +825,7 @@ set( FASTMATH_SOURCES
|
|||
gl/system/gl_load.c
|
||||
gl/models/gl_models.cpp
|
||||
r_data/models/models.cpp
|
||||
r_data/matrix.cpp
|
||||
)
|
||||
|
||||
set (PCH_SOURCES
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
#include "gl/scene/gl_drawinfo.h"
|
||||
#include "gl/models/gl_models.h"
|
||||
#include "gl/textures/gl_material.h"
|
||||
#include "gl/utility/gl_geometric.h"
|
||||
#include "gl/utility/gl_convert.h"
|
||||
#include "gl/renderer/gl_renderstate.h"
|
||||
#include "gl/shaders/gl_shader.h"
|
||||
|
|
|
@ -23,12 +23,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "tarray.h"
|
||||
#include "gl/utility/gl_geometric.h"
|
||||
#include "gl/data/gl_vertexbuffer.h"
|
||||
#include "p_pspr.h"
|
||||
#include "r_data/voxels.h"
|
||||
#include "r_data/models/models.h"
|
||||
|
||||
class GLSprite;
|
||||
|
||||
class FGLModelRenderer : public FModelRenderer
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <string.h>
|
||||
#include "gl/system/gl_interface.h"
|
||||
#include "gl/data/gl_data.h"
|
||||
#include "gl/data/gl_matrix.h"
|
||||
#include "r_data/matrix.h"
|
||||
#include "c_cvars.h"
|
||||
#include "r_defs.h"
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "gl/renderer/gl_renderer.h"
|
||||
#include "gl/renderer/gl_renderstate.h"
|
||||
#include "gl/renderer/gl_quaddrawer.h"
|
||||
#include "gl/data/gl_matrix.h"
|
||||
#include "r_data/matrix.h"
|
||||
|
||||
/*
|
||||
** For handling of dynamically created quads when no persistently mapped
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "v_video.h"
|
||||
#include "vectors.h"
|
||||
#include "r_renderer.h"
|
||||
#include "gl/data/gl_matrix.h"
|
||||
#include "r_data/matrix.h"
|
||||
#include "gl/dynlights/gl_shadowmap.h"
|
||||
|
||||
struct particle_t;
|
||||
|
|
|
@ -50,6 +50,11 @@ CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE)
|
|||
static VSMatrix identityMatrix(1);
|
||||
TArray<VSMatrix> gl_MatrixStack;
|
||||
|
||||
static void matrixToGL(const VSMatrix &mat, int loc)
|
||||
{
|
||||
glUniformMatrix4fv(loc, 1, false, (float*)&mat);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
|
@ -273,28 +278,28 @@ bool FRenderState::ApplyShader()
|
|||
}
|
||||
if (mTextureMatrixEnabled)
|
||||
{
|
||||
mTextureMatrix.matrixToGL(activeShader->texturematrix_index);
|
||||
matrixToGL(mTextureMatrix, activeShader->texturematrix_index);
|
||||
activeShader->currentTextureMatrixState = true;
|
||||
}
|
||||
else if (activeShader->currentTextureMatrixState)
|
||||
{
|
||||
activeShader->currentTextureMatrixState = false;
|
||||
identityMatrix.matrixToGL(activeShader->texturematrix_index);
|
||||
matrixToGL(identityMatrix, activeShader->texturematrix_index);
|
||||
}
|
||||
|
||||
if (mModelMatrixEnabled)
|
||||
{
|
||||
mModelMatrix.matrixToGL(activeShader->modelmatrix_index);
|
||||
matrixToGL(mModelMatrix, activeShader->modelmatrix_index);
|
||||
VSMatrix norm;
|
||||
norm.computeNormalMatrix(mModelMatrix);
|
||||
norm.matrixToGL(activeShader->normalmodelmatrix_index);
|
||||
matrixToGL(norm, activeShader->normalmodelmatrix_index);
|
||||
activeShader->currentModelMatrixState = true;
|
||||
}
|
||||
else if (activeShader->currentModelMatrixState)
|
||||
{
|
||||
activeShader->currentModelMatrixState = false;
|
||||
identityMatrix.matrixToGL(activeShader->modelmatrix_index);
|
||||
identityMatrix.matrixToGL(activeShader->normalmodelmatrix_index);
|
||||
matrixToGL(identityMatrix, activeShader->modelmatrix_index);
|
||||
matrixToGL(identityMatrix, activeShader->normalmodelmatrix_index);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <string.h>
|
||||
#include "gl/system/gl_interface.h"
|
||||
#include "gl/data/gl_data.h"
|
||||
#include "gl/data/gl_matrix.h"
|
||||
#include "r_data/matrix.h"
|
||||
#include "gl/textures/gl_material.h"
|
||||
#include "c_cvars.h"
|
||||
#include "r_defs.h"
|
||||
|
|
|
@ -57,7 +57,6 @@
|
|||
#include "gl/textures/gl_material.h"
|
||||
#include "gl/utility/gl_clock.h"
|
||||
#include "gl/utility/gl_templates.h"
|
||||
#include "gl/utility/gl_geometric.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
#include "gl/scene/gl_scenedrawer.h"
|
||||
#include "gl/textures/gl_material.h"
|
||||
#include "gl/utility/gl_clock.h"
|
||||
#include "gl/utility/gl_geometric.h"
|
||||
#include "gl/utility/gl_templates.h"
|
||||
#include "gl/shaders/gl_shader.h"
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include "gl/system/gl_interface.h"
|
||||
#include "gl/system/gl_debug.h"
|
||||
#include "gl/data/gl_data.h"
|
||||
#include "gl/data/gl_matrix.h"
|
||||
#include "r_data/matrix.h"
|
||||
#include "gl/renderer/gl_renderer.h"
|
||||
#include "gl/renderer/gl_renderstate.h"
|
||||
#include "gl/system/gl_cvars.h"
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
#include <cstring> // needed for memcpy on linux, which is needed by VSMatrix copy ctor
|
||||
#include "tarray.h"
|
||||
#include "gl/data/gl_matrix.h"
|
||||
#include "r_data/matrix.h"
|
||||
#include "gl/renderer/gl_renderer.h"
|
||||
|
||||
|
||||
|
|
|
@ -83,103 +83,4 @@ protected:
|
|||
float m_d;
|
||||
};
|
||||
|
||||
|
||||
class Matrix3x4 // used like a 4x4 matrix with the last row always being (0,0,0,1)
|
||||
{
|
||||
float m[3][4];
|
||||
|
||||
public:
|
||||
|
||||
void MakeIdentity()
|
||||
{
|
||||
memset(m, 0, sizeof(m));
|
||||
m[0][0] = m[1][1] = m[2][2] = 1.f;
|
||||
}
|
||||
|
||||
void Translate(float x, float y, float z)
|
||||
{
|
||||
m[0][3] = m[0][0]*x + m[0][1]*y + m[0][2]*z + m[0][3];
|
||||
m[1][3] = m[1][0]*x + m[1][1]*y + m[1][2]*z + m[1][3];
|
||||
m[2][3] = m[2][0]*x + m[2][1]*y + m[2][2]*z + m[2][3];
|
||||
}
|
||||
|
||||
void Scale(float x, float y, float z)
|
||||
{
|
||||
m[0][0] *=x;
|
||||
m[1][0] *=x;
|
||||
m[2][0] *=x;
|
||||
|
||||
m[0][1] *=y;
|
||||
m[1][1] *=y;
|
||||
m[2][1] *=y;
|
||||
|
||||
m[0][2] *=z;
|
||||
m[1][2] *=z;
|
||||
m[2][2] *=z;
|
||||
}
|
||||
|
||||
void Rotate(float ax, float ay, float az, float angle)
|
||||
{
|
||||
Matrix3x4 m1;
|
||||
|
||||
FVector3 axis(ax, ay, az);
|
||||
axis.MakeUnit();
|
||||
double c = cos(angle * M_PI/180.), s = sin(angle * M_PI/180.), t = 1 - c;
|
||||
double sx = s*axis.X, sy = s*axis.Y, sz = s*axis.Z;
|
||||
double tx, ty, txx, tyy, u, v;
|
||||
|
||||
tx = t*axis.X;
|
||||
m1.m[0][0] = float( (txx=tx*axis.X) + c );
|
||||
m1.m[0][1] = float( (u=tx*axis.Y) - sz);
|
||||
m1.m[0][2] = float( (v=tx*axis.Z) + sy);
|
||||
|
||||
ty = t*axis.Y;
|
||||
m1.m[1][0] = float( u + sz);
|
||||
m1.m[1][1] = float( (tyy=ty*axis.Y) + c );
|
||||
m1.m[1][2] = float( (u=ty*axis.Z) - sx);
|
||||
|
||||
m1.m[2][0] = float( v - sy);
|
||||
m1.m[2][1] = float( u + sx);
|
||||
m1.m[2][2] = float( (t-txx-tyy) + c );
|
||||
|
||||
m1.m[0][3] = 0.f;
|
||||
m1.m[1][3] = 0.f;
|
||||
m1.m[2][3] = 0.f;
|
||||
|
||||
*this = (*this) * m1;
|
||||
}
|
||||
|
||||
Matrix3x4 operator *(const Matrix3x4 &other)
|
||||
{
|
||||
Matrix3x4 result;
|
||||
|
||||
result.m[0][0] = m[0][0]*other.m[0][0] + m[0][1]*other.m[1][0] + m[0][2]*other.m[2][0];
|
||||
result.m[0][1] = m[0][0]*other.m[0][1] + m[0][1]*other.m[1][1] + m[0][2]*other.m[2][1];
|
||||
result.m[0][2] = m[0][0]*other.m[0][2] + m[0][1]*other.m[1][2] + m[0][2]*other.m[2][2];
|
||||
result.m[0][3] = m[0][0]*other.m[0][3] + m[0][1]*other.m[1][3] + m[0][2]*other.m[2][3] + m[0][3];
|
||||
|
||||
result.m[1][0] = m[1][0]*other.m[0][0] + m[1][1]*other.m[1][0] + m[1][2]*other.m[2][0];
|
||||
result.m[1][1] = m[1][0]*other.m[0][1] + m[1][1]*other.m[1][1] + m[1][2]*other.m[2][1];
|
||||
result.m[1][2] = m[1][0]*other.m[0][2] + m[1][1]*other.m[1][2] + m[1][2]*other.m[2][2];
|
||||
result.m[1][3] = m[1][0]*other.m[0][3] + m[1][1]*other.m[1][3] + m[1][2]*other.m[2][3] + m[1][3];
|
||||
|
||||
result.m[2][0] = m[2][0]*other.m[0][0] + m[2][1]*other.m[1][0] + m[2][2]*other.m[2][0];
|
||||
result.m[2][1] = m[2][0]*other.m[0][1] + m[2][1]*other.m[1][1] + m[2][2]*other.m[2][1];
|
||||
result.m[2][2] = m[2][0]*other.m[0][2] + m[2][1]*other.m[1][2] + m[2][2]*other.m[2][2];
|
||||
result.m[2][3] = m[2][0]*other.m[0][3] + m[2][1]*other.m[1][3] + m[2][2]*other.m[2][3] + m[2][3];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
FVector3 operator *(const FVector3 &vec)
|
||||
{
|
||||
FVector3 result;
|
||||
|
||||
result.X = vec.X*m[0][0] + vec.Y*m[0][1] + vec.Z*m[0][2] + m[0][3];
|
||||
result.Y = vec.X*m[1][0] + vec.Y*m[1][1] + vec.Z*m[1][2] + m[1][3];
|
||||
result.Z = vec.X*m[2][0] + vec.Y*m[2][1] + vec.Z*m[2][2] + m[2][3];
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "polyrenderer/drawers/poly_triangle.h"
|
||||
#include "gl/data/gl_matrix.h"
|
||||
#include "r_data/matrix.h"
|
||||
#include "gl/models/gl_models.h"
|
||||
|
||||
void PolyRenderModel(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, uint32_t stencilValue, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor);
|
||||
|
|
|
@ -11,13 +11,16 @@ This is a simplified version of VSMatrix that has been adjusted for GZDoom's nee
|
|||
----------------------------------------------------*/
|
||||
|
||||
#include <algorithm>
|
||||
#include "gl/system/gl_system.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "doomtype.h"
|
||||
#include "gl/data/gl_matrix.h"
|
||||
#include "matrix.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4244) // truncate from double to float
|
||||
#endif
|
||||
|
||||
static inline FLOATTYPE
|
||||
DegToRad(FLOATTYPE degrees)
|
||||
|
@ -310,22 +313,6 @@ VSMatrix::get(MatrixTypes aType)
|
|||
SEND MATRICES TO OPENGL
|
||||
------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
// universal
|
||||
void
|
||||
VSMatrix::matrixToGL(int loc)
|
||||
{
|
||||
#ifdef USE_DOUBLE
|
||||
float copyto[16];
|
||||
copy(copyto);
|
||||
glUniformMatrix4fv(loc, 1, false, copyto);
|
||||
#else
|
||||
glUniformMatrix4fv(loc, 1, false, mMatrix);
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// AUX functions
|
||||
// -----------------------------------------------------
|
|
@ -21,6 +21,8 @@
|
|||
#define __VSMatrix__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "vectors.h"
|
||||
#include "doomtype.h"
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
typedef double FLOATTYPE;
|
||||
|
@ -82,7 +84,6 @@ class VSMatrix {
|
|||
return mMatrix;
|
||||
}
|
||||
|
||||
void matrixToGL(int location);
|
||||
void multMatrixPoint(const FLOATTYPE *point, FLOATTYPE *res);
|
||||
|
||||
#ifdef USE_DOUBLE
|
||||
|
@ -112,4 +113,103 @@ class VSMatrix {
|
|||
|
||||
};
|
||||
|
||||
|
||||
class Matrix3x4 // used like a 4x4 matrix with the last row always being (0,0,0,1)
|
||||
{
|
||||
float m[3][4];
|
||||
|
||||
public:
|
||||
|
||||
void MakeIdentity()
|
||||
{
|
||||
memset(m, 0, sizeof(m));
|
||||
m[0][0] = m[1][1] = m[2][2] = 1.f;
|
||||
}
|
||||
|
||||
void Translate(float x, float y, float z)
|
||||
{
|
||||
m[0][3] = m[0][0]*x + m[0][1]*y + m[0][2]*z + m[0][3];
|
||||
m[1][3] = m[1][0]*x + m[1][1]*y + m[1][2]*z + m[1][3];
|
||||
m[2][3] = m[2][0]*x + m[2][1]*y + m[2][2]*z + m[2][3];
|
||||
}
|
||||
|
||||
void Scale(float x, float y, float z)
|
||||
{
|
||||
m[0][0] *=x;
|
||||
m[1][0] *=x;
|
||||
m[2][0] *=x;
|
||||
|
||||
m[0][1] *=y;
|
||||
m[1][1] *=y;
|
||||
m[2][1] *=y;
|
||||
|
||||
m[0][2] *=z;
|
||||
m[1][2] *=z;
|
||||
m[2][2] *=z;
|
||||
}
|
||||
|
||||
void Rotate(float ax, float ay, float az, float angle)
|
||||
{
|
||||
Matrix3x4 m1;
|
||||
|
||||
FVector3 axis(ax, ay, az);
|
||||
axis.MakeUnit();
|
||||
double c = cos(angle * M_PI/180.), s = sin(angle * M_PI/180.), t = 1 - c;
|
||||
double sx = s*axis.X, sy = s*axis.Y, sz = s*axis.Z;
|
||||
double tx, ty, txx, tyy, u, v;
|
||||
|
||||
tx = t*axis.X;
|
||||
m1.m[0][0] = float( (txx=tx*axis.X) + c );
|
||||
m1.m[0][1] = float( (u=tx*axis.Y) - sz);
|
||||
m1.m[0][2] = float( (v=tx*axis.Z) + sy);
|
||||
|
||||
ty = t*axis.Y;
|
||||
m1.m[1][0] = float( u + sz);
|
||||
m1.m[1][1] = float( (tyy=ty*axis.Y) + c );
|
||||
m1.m[1][2] = float( (u=ty*axis.Z) - sx);
|
||||
|
||||
m1.m[2][0] = float( v - sy);
|
||||
m1.m[2][1] = float( u + sx);
|
||||
m1.m[2][2] = float( (t-txx-tyy) + c );
|
||||
|
||||
m1.m[0][3] = 0.f;
|
||||
m1.m[1][3] = 0.f;
|
||||
m1.m[2][3] = 0.f;
|
||||
|
||||
*this = (*this) * m1;
|
||||
}
|
||||
|
||||
Matrix3x4 operator *(const Matrix3x4 &other)
|
||||
{
|
||||
Matrix3x4 result;
|
||||
|
||||
result.m[0][0] = m[0][0]*other.m[0][0] + m[0][1]*other.m[1][0] + m[0][2]*other.m[2][0];
|
||||
result.m[0][1] = m[0][0]*other.m[0][1] + m[0][1]*other.m[1][1] + m[0][2]*other.m[2][1];
|
||||
result.m[0][2] = m[0][0]*other.m[0][2] + m[0][1]*other.m[1][2] + m[0][2]*other.m[2][2];
|
||||
result.m[0][3] = m[0][0]*other.m[0][3] + m[0][1]*other.m[1][3] + m[0][2]*other.m[2][3] + m[0][3];
|
||||
|
||||
result.m[1][0] = m[1][0]*other.m[0][0] + m[1][1]*other.m[1][0] + m[1][2]*other.m[2][0];
|
||||
result.m[1][1] = m[1][0]*other.m[0][1] + m[1][1]*other.m[1][1] + m[1][2]*other.m[2][1];
|
||||
result.m[1][2] = m[1][0]*other.m[0][2] + m[1][1]*other.m[1][2] + m[1][2]*other.m[2][2];
|
||||
result.m[1][3] = m[1][0]*other.m[0][3] + m[1][1]*other.m[1][3] + m[1][2]*other.m[2][3] + m[1][3];
|
||||
|
||||
result.m[2][0] = m[2][0]*other.m[0][0] + m[2][1]*other.m[1][0] + m[2][2]*other.m[2][0];
|
||||
result.m[2][1] = m[2][0]*other.m[0][1] + m[2][1]*other.m[1][1] + m[2][2]*other.m[2][1];
|
||||
result.m[2][2] = m[2][0]*other.m[0][2] + m[2][1]*other.m[1][2] + m[2][2]*other.m[2][2];
|
||||
result.m[2][3] = m[2][0]*other.m[0][3] + m[2][1]*other.m[1][3] + m[2][2]*other.m[2][3] + m[2][3];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
FVector3 operator *(const FVector3 &vec)
|
||||
{
|
||||
FVector3 result;
|
||||
|
||||
result.X = vec.X*m[0][0] + vec.Y*m[0][1] + vec.Z*m[0][2] + m[0][3];
|
||||
result.Y = vec.X*m[1][0] + vec.Y*m[1][1] + vec.Z*m[1][2] + m[1][3];
|
||||
result.Z = vec.X*m[2][0] + vec.Y*m[2][1] + vec.Z*m[2][2] + m[2][3];
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -24,8 +24,7 @@
|
|||
#define __GL_MODELS_H_
|
||||
|
||||
#include "tarray.h"
|
||||
#include "gl/utility/gl_geometric.h"
|
||||
#include "gl/data/gl_matrix.h"
|
||||
#include "r_data/matrix.h"
|
||||
#include "actor.h"
|
||||
#include "dobject.h"
|
||||
#include "p_pspr.h"
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "textures/bitmap.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "models.h"
|
||||
#include "v_palette.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data
|
||||
|
|
Loading…
Reference in a new issue