mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -04:00
Simplify Gfx matrices
This commit is contained in:
parent
cd2d70bd8c
commit
67d4e33fa8
@ -134,10 +134,8 @@ void EnvRenderer_RenderClouds(double deltaTime) {
|
||||
time = Game_Accumulator;
|
||||
offset = (float)(time / 2048.0f * 0.6f * Env_CloudsSpeed);
|
||||
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_TEXTURE);
|
||||
m = Matrix_Identity; m.Row3.X = offset; /* translate X axis */
|
||||
Gfx_LoadMatrix(&m);
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
|
||||
Gfx_LoadMatrix(MATRIX_TEXTURE, &m);
|
||||
|
||||
Gfx_SetAlphaTest(true);
|
||||
Gfx_SetTexturing(true);
|
||||
@ -148,9 +146,7 @@ void EnvRenderer_RenderClouds(double deltaTime) {
|
||||
Gfx_SetAlphaTest(false);
|
||||
Gfx_SetTexturing(false);
|
||||
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_TEXTURE);
|
||||
Gfx_LoadIdentityMatrix();
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
|
||||
Gfx_LoadIdentityMatrix(MATRIX_TEXTURE);
|
||||
}
|
||||
|
||||
static void EnvRenderer_DrawCloudsY(int x1, int z1, int x2, int z2, int y, VertexP3fT2fC4b* vertices) {
|
||||
@ -232,9 +228,9 @@ void EnvRenderer_RenderSky(double deltaTime) {
|
||||
m.Row3.X += dy * m.Row1.X; m.Row3.Y += dy * m.Row1.Y;
|
||||
m.Row3.Z += dy * m.Row1.Z; m.Row3.W += dy * m.Row1.W;
|
||||
|
||||
Gfx_LoadMatrix(&m);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &m);
|
||||
Gfx_DrawVb_IndexedTris(sky_vertices);
|
||||
Gfx_LoadMatrix(&Gfx_View);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx_View);
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,12 +312,12 @@ void EnvRenderer_RenderSkybox(double deltaTime) {
|
||||
Camera_Active->GetView(&view); Matrix_MulBy(&m, &view);
|
||||
Camera_CurrentPos = pos;
|
||||
|
||||
Gfx_LoadMatrix(&m);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &m);
|
||||
Gfx_BindVb(skybox_vb);
|
||||
Gfx_DrawVb_IndexedTris(SKYBOX_COUNT);
|
||||
|
||||
Gfx_SetTexturing(false);
|
||||
Gfx_LoadMatrix(&Gfx_View);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx_View);
|
||||
Gfx_SetDepthWrite(true);
|
||||
}
|
||||
|
||||
|
@ -163,9 +163,7 @@ void Game_UpdateProjection(void) {
|
||||
Game_DefaultFov = Options_GetInt(OPT_FIELD_OF_VIEW, 1, 150, 70);
|
||||
Camera_Active->GetProjection(&Gfx_Projection);
|
||||
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_PROJECTION);
|
||||
Gfx_LoadMatrix(&Gfx_Projection);
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
|
||||
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx_Projection);
|
||||
Event_RaiseVoid(&GfxEvents_ProjectionChanged);
|
||||
}
|
||||
|
||||
@ -569,9 +567,8 @@ static void Game_LimitFPS(uint64_t frameStart) {
|
||||
}
|
||||
|
||||
static void Game_UpdateViewMatrix(void) {
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
|
||||
Camera_Active->GetView(&Gfx_View);
|
||||
Gfx_LoadMatrix(&Gfx_View);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx_View);
|
||||
FrustumCulling_CalcFrustumEquations(&Gfx_Projection, &Gfx_View);
|
||||
}
|
||||
|
||||
|
@ -132,10 +132,8 @@ void Gfx_Mode2D(int width, int height) {
|
||||
struct Matrix ortho;
|
||||
Gfx_CalcOrthoMatrix((float)width, (float)height, &ortho);
|
||||
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_PROJECTION);
|
||||
Gfx_LoadMatrix(&ortho);
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
|
||||
Gfx_LoadIdentityMatrix();
|
||||
Gfx_LoadMatrix(MATRIX_PROJECTION, &ortho);
|
||||
Gfx_LoadIdentityMatrix(MATRIX_VIEW);
|
||||
|
||||
Gfx_SetDepthTest(false);
|
||||
Gfx_SetAlphaBlending(true);
|
||||
@ -144,10 +142,8 @@ void Gfx_Mode2D(int width, int height) {
|
||||
}
|
||||
|
||||
void Gfx_Mode3D(void) {
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_PROJECTION);
|
||||
Gfx_LoadMatrix(&Gfx_Projection);
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
|
||||
Gfx_LoadMatrix(&Gfx_View);
|
||||
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx_Projection);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx_View);
|
||||
|
||||
Gfx_SetDepthTest(true);
|
||||
Gfx_SetAlphaBlending(false);
|
||||
@ -274,7 +270,6 @@ static DWORD d3d9_formatMappings[2] = { D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DFVF_XYZ
|
||||
|
||||
static IDirect3D9* d3d;
|
||||
static IDirect3DDevice9* device;
|
||||
static D3DTRANSFORMSTATETYPE curMatrix;
|
||||
static DWORD createFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
|
||||
static D3DFORMAT d3d9_viewFormat, d3d9_depthFormat;
|
||||
|
||||
@ -815,32 +810,28 @@ void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex) {
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------------Matrices--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void Gfx_SetMatrixMode(MatrixType type) {
|
||||
if (type == MATRIX_TYPE_PROJECTION) { curMatrix = D3DTS_PROJECTION; }
|
||||
else if (type == MATRIX_TYPE_VIEW) { curMatrix = D3DTS_VIEW; }
|
||||
else if (type == MATRIX_TYPE_TEXTURE) { curMatrix = D3DTS_TEXTURE0; }
|
||||
}
|
||||
static D3DTRANSFORMSTATETYPE matrix_modes[3] = { D3DTS_PROJECTION, D3DTS_VIEW, D3DTS_TEXTURE0 };
|
||||
|
||||
void Gfx_LoadMatrix(struct Matrix* matrix) {
|
||||
void Gfx_LoadMatrix(MatrixType type, struct Matrix* matrix) {
|
||||
ReturnCode res;
|
||||
if (curMatrix == D3DTS_TEXTURE0) {
|
||||
if (type == MATRIX_TEXTURE) {
|
||||
matrix->Row2.X = matrix->Row3.X; /* NOTE: this hack fixes the texture movements. */
|
||||
IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
|
||||
}
|
||||
|
||||
if (Gfx_LostContext) return;
|
||||
res = IDirect3DDevice9_SetTransform(device, curMatrix, matrix);
|
||||
res = IDirect3DDevice9_SetTransform(device, matrix_modes[type], matrix);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_LoadMatrix");
|
||||
}
|
||||
|
||||
void Gfx_LoadIdentityMatrix(void) {
|
||||
void Gfx_LoadIdentityMatrix(MatrixType type) {
|
||||
ReturnCode res;
|
||||
if (curMatrix == D3DTS_TEXTURE0) {
|
||||
if (type == MATRIX_TEXTURE) {
|
||||
IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
|
||||
}
|
||||
|
||||
if (Gfx_LostContext) return;
|
||||
res = IDirect3DDevice9_SetTransform(device, curMatrix, &Matrix_Identity);
|
||||
res = IDirect3DDevice9_SetTransform(device, matrix_modes[type], &Matrix_Identity);
|
||||
if (res) ErrorHandler_Fail2(res, "D3D9_LoadIdentityMatrix");
|
||||
}
|
||||
|
||||
@ -1462,18 +1453,18 @@ void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex) {
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------------Matrices--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static int gl_lastMatrixType;
|
||||
static GLenum matrix_modes[3] = { GL_PROJECTION, GL_MODELVIEW, GL_TEXTURE };
|
||||
static int lastMatrix;
|
||||
|
||||
void Gfx_SetMatrixMode(MatrixType type) {
|
||||
static GLenum modes[3] = { GL_PROJECTION, GL_MODELVIEW, GL_TEXTURE };
|
||||
if (type == gl_lastMatrixType) return;
|
||||
|
||||
gl_lastMatrixType = type;
|
||||
glMatrixMode(modes[type]);
|
||||
void Gfx_LoadMatrix(MatrixType type, struct Matrix* matrix) {
|
||||
if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); }
|
||||
glLoadMatrixf((float*)matrix);
|
||||
}
|
||||
|
||||
void Gfx_LoadMatrix(struct Matrix* matrix) { glLoadMatrixf((float*)matrix); }
|
||||
void Gfx_LoadIdentityMatrix(void) { glLoadIdentity(); }
|
||||
void Gfx_LoadIdentityMatrix(MatrixType type) {
|
||||
if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); }
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
void Gfx_CalcOrthoMatrix(float width, float height, struct Matrix* matrix) {
|
||||
Matrix_OrthographicOffCenter(matrix, 0.0f, width, height, 0.0f, -10000.0f, 10000.0f);
|
||||
|
@ -28,7 +28,7 @@ typedef enum FogFunc_ {
|
||||
FOG_LINEAR, FOG_EXP, FOG_EXP2
|
||||
} FogFunc;
|
||||
typedef enum MatrixType_ {
|
||||
MATRIX_TYPE_PROJECTION, MATRIX_TYPE_VIEW, MATRIX_TYPE_TEXTURE
|
||||
MATRIX_PROJECTION, MATRIX_VIEW, MATRIX_TEXTURE
|
||||
} MatrixType;
|
||||
|
||||
void Gfx_Init(void);
|
||||
@ -139,12 +139,10 @@ void Gfx_DrawVb_IndexedTris(int verticesCount);
|
||||
/* Special case Gfx_DrawVb_IndexedTris_Range for map renderer */
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex);
|
||||
|
||||
/* Sets the currently active matrix. */
|
||||
void Gfx_SetMatrixMode(MatrixType type);
|
||||
/* Loads the given matrix over the currently active matrix. */
|
||||
void Gfx_LoadMatrix(struct Matrix* matrix);
|
||||
void Gfx_LoadMatrix(MatrixType type, struct Matrix* matrix);
|
||||
/* Loads the identity matrix over the currently active matrix. */
|
||||
void Gfx_LoadIdentityMatrix(void);
|
||||
void Gfx_LoadIdentityMatrix(MatrixType type);
|
||||
/* Calculates an orthographic matrix suitable with this backend. (usually for 2D) */
|
||||
void Gfx_CalcOrthoMatrix(float width, float height, struct Matrix* matrix);
|
||||
/* Calculates a projection matrix suitable with this backend. (usually for 3D) */
|
||||
|
@ -216,9 +216,7 @@ void HeldBlockRenderer_Render(double delta) {
|
||||
held_block = Inventory_SelectedBlock;
|
||||
view = Gfx_View;
|
||||
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_PROJECTION);
|
||||
Gfx_LoadMatrix(&held_blockProjection);
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
|
||||
Gfx_LoadMatrix(MATRIX_PROJECTION, &held_blockProjection);
|
||||
HeldBlockRenderer_SetMatrix();
|
||||
|
||||
HeldBlockRenderer_ResetHeldState();
|
||||
@ -227,9 +225,7 @@ void HeldBlockRenderer_Render(double delta) {
|
||||
if (!Camera_Active->IsThirdPerson) HeldBlockRenderer_RenderModel();
|
||||
|
||||
Gfx_View = view;
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_PROJECTION);
|
||||
Gfx_LoadMatrix(&Gfx_Projection);
|
||||
Gfx_SetMatrixMode(MATRIX_TYPE_VIEW);
|
||||
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx_Projection);
|
||||
}
|
||||
|
||||
struct EntityVTABLE heldEntity_VTABLE = {
|
||||
|
@ -134,7 +134,7 @@ void IsometricDrawer_BeginBatch(VertexP3fT2fC4b* vertices, GfxResourceID vb) {
|
||||
iso_vertices_base = vertices;
|
||||
iso_vb = vb;
|
||||
|
||||
Gfx_LoadMatrix(&iso_transform);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &iso_transform);
|
||||
}
|
||||
|
||||
void IsometricDrawer_DrawBatch(BlockID block, float size, float x, float y) {
|
||||
@ -191,5 +191,5 @@ void IsometricDrawer_EndBatch(void) {
|
||||
}
|
||||
|
||||
iso_lastTexIndex = -1;
|
||||
Gfx_LoadIdentityMatrix();
|
||||
Gfx_LoadIdentityMatrix(MATRIX_VIEW);
|
||||
}
|
||||
|
@ -112,9 +112,9 @@ void Model_Render(struct Model* model, struct Entity* entity) {
|
||||
model->GetTransform(entity, pos, &entity->Transform);
|
||||
Matrix_Mul(&m, &entity->Transform, &Gfx_View);
|
||||
|
||||
Gfx_LoadMatrix(&m);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &m);
|
||||
model->DrawModel(entity);
|
||||
Gfx_LoadMatrix(&Gfx_View);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx_View);
|
||||
}
|
||||
|
||||
void Model_SetupState(struct Model* model, struct Entity* entity) {
|
||||
@ -270,11 +270,11 @@ void Model_RenderArm(struct Model* model, struct Entity* entity) {
|
||||
Matrix_Mul(&m, &m, &Gfx_View);
|
||||
Matrix_Mul(&m, &translate, &m);
|
||||
|
||||
Gfx_LoadMatrix(&m);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &m);
|
||||
Model_Rotation = ROTATE_ORDER_YZX;
|
||||
model->DrawArm(entity);
|
||||
Model_Rotation = ROTATE_ORDER_ZYX;
|
||||
Gfx_LoadMatrix(&Gfx_View);
|
||||
Gfx_LoadMatrix(MATRIX_VIEW, &Gfx_View);
|
||||
}
|
||||
|
||||
void Model_DrawArmPart(struct ModelPart* part) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user