mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-29 00:23:31 -04:00
Create Matrix function headers in C
This commit is contained in:
parent
9ccba753c5
commit
36863b0cec
@ -2,6 +2,7 @@
|
|||||||
#include "GraphicsAPI.h"
|
#include "GraphicsAPI.h"
|
||||||
#include "D3D9Api.h"
|
#include "D3D9Api.h"
|
||||||
#include "ErrorHandler.h"
|
#include "ErrorHandler.h"
|
||||||
|
#include "GraphicsEnums.h"
|
||||||
|
|
||||||
#define USE_DX true
|
#define USE_DX true
|
||||||
#ifdef USE_DX
|
#ifdef USE_DX
|
||||||
@ -166,18 +167,44 @@ void Gfx_SetDepthWrite(bool enabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
*Sets the matrix type that load / push / pop operations should be applied to. * /
|
void Gfx_SetMatrixMode(Int32 matrixType) {
|
||||||
void Gfx_SetMatrixMode(Int32 matrixType);
|
if (matrixType == MatrixType_Projection) {
|
||||||
|
curStack = &projStack;
|
||||||
|
} else if (matrixType == MatrixType_Modelview) {
|
||||||
|
curStack = &viewStack;
|
||||||
|
} else if (matrixType == MatrixType_Texture) {
|
||||||
|
curStack = &texStack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Sets the current matrix to the given matrix.*/
|
void Gfx_LoadMatrix(Matrix* matrix) {
|
||||||
void Gfx_LoadMatrix(Matrix* matrix);
|
if (curStack == &texStack) {
|
||||||
|
matrix->Row2.X = matrix->Row3.X; // NOTE: this hack fixes the texture movements.
|
||||||
|
IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
|
||||||
|
}
|
||||||
|
|
||||||
/* Sets the current matrix to the identity matrix. */
|
Int32 idx = curStack->Index;
|
||||||
void Gfx_LoadIdentityMatrix();
|
curStack->Stack[idx] = *matrix;
|
||||||
|
|
||||||
|
ReturnCode hresult = IDirect3DDevice9_SetTransform(device, curStack->Type, &curStack->Stack[idx]);
|
||||||
|
ErrorHandler_CheckOrFail(hresult, "D3D9_LoadMatrix");
|
||||||
|
}
|
||||||
|
|
||||||
/* Multiplies the current matrix by the given matrix, then
|
void Gfx_LoadIdentityMatrix() {
|
||||||
sets the current matrix to the result of the multiplication. */
|
if (curStack == &texStack) {
|
||||||
void Gfx_MultiplyMatrix(Matrix* matrix);
|
IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
Int32 idx = curStack->Index;
|
||||||
|
curStack->Stack[idx] = *matrix;
|
||||||
|
|
||||||
|
ReturnCode hresult = IDirect3DDevice9_SetTransform(device, curStack->Type, &curStack->Stack[idx]);
|
||||||
|
ErrorHandler_CheckOrFail(hresult, "D3D9_LoadIdentityMatrix");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Gfx_MultiplyMatrix(Matrix* matrix) {
|
||||||
|
curStack.MultiplyTop(ref matrix);
|
||||||
|
}
|
||||||
|
|
||||||
void Gfx_PushMatrix() {
|
void Gfx_PushMatrix() {
|
||||||
Int32 idx = curStack->Index;
|
Int32 idx = curStack->Index;
|
||||||
@ -195,6 +222,7 @@ void Gfx_PopMatrix() {
|
|||||||
ErrorHandler_Fail("Unable to pop matrix, at 0 already");
|
ErrorHandler_Fail("Unable to pop matrix, at 0 already");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
D3DMATRIX m;
|
||||||
curStack->Index--; idx--;
|
curStack->Index--; idx--;
|
||||||
ReturnCode hresult = IDirect3DDevice9_SetTransform(device, curStack->Type, &curStack->Stack[idx]);
|
ReturnCode hresult = IDirect3DDevice9_SetTransform(device, curStack->Type, &curStack->Stack[idx]);
|
||||||
ErrorHandler_CheckOrFail(hresult, "D3D9_PopMatrix");
|
ErrorHandler_CheckOrFail(hresult, "D3D9_PopMatrix");
|
||||||
|
@ -7,7 +7,7 @@ void EventHandler_Register(void** handlers, Int32* count, void* handler) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (*count == EventHandler_Size) {
|
if (*count == EventHandler_Size) {
|
||||||
ErrorHandler_Fail("Unable to add another event handler"));
|
ErrorHandler_Fail("Unable to add another event handler");
|
||||||
}
|
}
|
||||||
handlers[*count] = handler;
|
handlers[*count] = handler;
|
||||||
*count++;
|
*count++;
|
||||||
|
@ -19,7 +19,7 @@ void GfxCommon_LoseContext(String reason) {
|
|||||||
Platform_Log(String_FromConstant("Lost graphics context:"));
|
Platform_Log(String_FromConstant("Lost graphics context:"));
|
||||||
Platform_Log(reason);
|
Platform_Log(reason);
|
||||||
|
|
||||||
EventHandler_Call_Void(Gfx_ContextLost, Gfx_ContextLostCount);
|
EventHandler_Raise_Void(Gfx_ContextLost, Gfx_ContextLostCount);
|
||||||
GfxCommon_Free();
|
GfxCommon_Free();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ void GfxCommon_RecreateContext() {
|
|||||||
Gfx_LostContext = false;
|
Gfx_LostContext = false;
|
||||||
Platform_Log(String_FromConstant("Recreating graphics context"));
|
Platform_Log(String_FromConstant("Recreating graphics context"));
|
||||||
|
|
||||||
EventHandler_Call_Void(Gfx_ContextRecreated, Gfx_ContextRecreatedCount);
|
EventHandler_Raise_Void(Gfx_ContextRecreated, Gfx_ContextRecreatedCount);
|
||||||
GfxCommon_Init();
|
GfxCommon_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
Vector4 Vector4_Create4(Real32 x, Real32 y, Real32 z, Real32 w) {
|
Vector4 Vector4_Create4(Real32 x, Real32 y, Real32 z, Real32 w) {
|
||||||
Vector4 v; v.X = x; v.Y = y; v.Z = z; v.W = w; return v;
|
Vector4 v; v.X = x; v.Y = y; v.Z = z; v.W = w; return v;
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef CS_MATRIX_H
|
#ifndef CS_MATRIX_H
|
||||||
#define CS_MATRIX_H
|
#define CS_MATRIX_H
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
#include "Vectors.h"
|
||||||
/* Represents a 4 by 4 matrix.
|
/* Represents a 4 by 4 matrix.
|
||||||
Copyright 2017 ClassicalSharp | Licensed under BSD-3
|
Copyright 2017 ClassicalSharp | Licensed under BSD-3
|
||||||
*/
|
*/
|
||||||
@ -30,4 +31,47 @@ typedef struct Matrix {
|
|||||||
/* Bottom row of the matrix */
|
/* Bottom row of the matrix */
|
||||||
Vector4 Row3;
|
Vector4 Row3;
|
||||||
} Matrix;
|
} Matrix;
|
||||||
|
|
||||||
|
/* Identity matrix. */
|
||||||
|
Matrix Matrix_Identity = {
|
||||||
|
1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 1.0f, 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 1.0f
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Transformation matrix representing rotation angle radians around X axis. */
|
||||||
|
void Matrix_RotateX(Real32 angle, Matrix* result);
|
||||||
|
|
||||||
|
/* Transformation matrix representing rotation angle radians around Y axis. */
|
||||||
|
void Matrix_RotateY(Real32 angle, Matrix* result);
|
||||||
|
|
||||||
|
/* Transformation matrix representing rotation angle radians around Z axis. */
|
||||||
|
void Matrix_RotateZ(Real32 angle, Matrix* result);
|
||||||
|
|
||||||
|
/* Transformation matrix representing translation of given coordinates. */
|
||||||
|
void Matrix_Translate(Real32 x, Real32 y, Real32 z, Matrix* result);
|
||||||
|
|
||||||
|
/* Transformation matrix representing scaling of given axes. */
|
||||||
|
void Matrix_Scale(Real32 x, Real32 y, Real32 z, Matrix* result);
|
||||||
|
|
||||||
|
/* Multiplies two matrices.*/
|
||||||
|
void Matrix_Mul(Matrix* left, Matrix* right, Matrix* result);
|
||||||
|
|
||||||
|
|
||||||
|
/* Transformation matrix representing orthographic projection. */
|
||||||
|
void Matrix_Orthographic(Real32 width, Real32 height, Real32 zNear, Real32 zFar, Matrix* result);
|
||||||
|
|
||||||
|
/* Transformation matrix representing orthographic projection. */
|
||||||
|
void Matrix_OrthographicOffCenter(Real32 left, Real32 right, Real32 bottom, Real32 top, Real32 zNear, Real32 zFar, Matrix* result);
|
||||||
|
|
||||||
|
/* Transformation matrix representing perspective projection. */
|
||||||
|
void Matrix_PerspectiveFieldOfView(Real32 fovy, Real32 aspect, Real32 zNear, Real32 zFar, Matrix* result);
|
||||||
|
|
||||||
|
/* Transformation matrix representing perspective projection. */
|
||||||
|
void Matrix_PerspectiveOffCenter(Real32 left, Real32 right, Real32 bottom, Real32 top, Real32 zNear, Real32 zFar, Matrix* result);
|
||||||
|
|
||||||
|
/* Transformation matrix representing camera look at. */
|
||||||
|
void Matrix_LookAt(Vector3 eye, Vector3 target, Vector3 up, Matrix* result);
|
||||||
#endif
|
#endif
|
@ -17,7 +17,7 @@ void World_SetNewMap(BlockID* blocks, Int32 blocksSize, Int32 width, Int32 heigh
|
|||||||
if (World_BlocksSize == 0) World_Blocks = NULL;
|
if (World_BlocksSize == 0) World_Blocks = NULL;
|
||||||
|
|
||||||
if (blocksSize != (width * height * length)) {
|
if (blocksSize != (width * height * length)) {
|
||||||
ErrorHandler_Fail(String_FromConstant("Blocks array size does not match volume of map."));
|
ErrorHandler_Fail("Blocks array size does not match volume of map");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WorldEnv_EdgeHeight == -1) {
|
if (WorldEnv_EdgeHeight == -1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user