aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-06-02 20:23:09 +0200
committerraysan5 <raysan5@gmail.com>2016-06-02 20:23:09 +0200
commit0bc71d84f8ca2b8cbe48eae8769fb16958b98531 (patch)
tree0bf28414c77626e12235b857eb156e04b78e8640 /src
parent2168d8aa1af1e60467983099c5f72b7ac5ab5144 (diff)
downloadraylib-0bc71d84f8ca2b8cbe48eae8769fb16958b98531.tar.gz
raylib-0bc71d84f8ca2b8cbe48eae8769fb16958b98531.zip
Added functions to customize internal matrix
Internal modelview and projection matrices can be replaced before drawing.
Diffstat (limited to 'src')
-rw-r--r--src/raylib.h3
-rw-r--r--src/raymath.h5
-rw-r--r--src/rlgl.c25
-rw-r--r--src/rlgl.h3
4 files changed, 26 insertions, 10 deletions
diff --git a/src/raylib.h b/src/raylib.h
index a00c0ff9..efd96a67 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -868,6 +868,9 @@ void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // S
void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int)
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
+void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
+void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
+
void BeginShaderMode(Shader shader); // Begin custom shader drawing
void EndShaderMode(void); // End custom shader drawing (use default shader)
void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)
diff --git a/src/raymath.h b/src/raymath.h
index 188bd610..4075a1a9 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -339,15 +339,14 @@ RMDEF Vector3 VectorReflect(Vector3 vector, Vector3 normal)
return result;
}
-// Transforms a Vector3 with a given Matrix
+// Transforms a Vector3 by a given Matrix
+// TODO: Review math (matrix transpose required?)
RMDEF void VectorTransform(Vector3 *v, Matrix mat)
{
float x = v->x;
float y = v->y;
float z = v->z;
- //MatrixTranspose(&mat);
-
v->x = mat.m0*x + mat.m4*y + mat.m8*z + mat.m12;
v->y = mat.m1*x + mat.m5*y + mat.m9*z + mat.m13;
v->z = mat.m2*x + mat.m6*y + mat.m10*z + mat.m14;
diff --git a/src/rlgl.c b/src/rlgl.c
index cfa6e2e6..6beececb 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -28,7 +28,7 @@
#include "rlgl.h"
-#include <stdio.h> // Standard input / output lib
+#include <stdio.h> // Required for: fopen(), fclose(), fread()... [Used only on ReadTextFile()]
#include <stdlib.h> // Required for: malloc(), free(), rand()
#include <string.h> // Required for: strcmp(), strlen(), strtok()
@@ -59,8 +59,8 @@
#endif
#if defined(RLGL_STANDALONE)
- #include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
-#endif // NOTE: Used on TraceLog()
+ #include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end() [Used only on TraceLog()]
+#endif
//----------------------------------------------------------------------------------
// Defines and Macros
@@ -355,7 +355,6 @@ void rlRotatef(float angleDeg, float x, float y, float z)
Vector3 axis = (Vector3){ x, y, z };
VectorNormalize(&axis);
matRotation = MatrixRotate(axis, angleDeg*DEG2RAD);
-
MatrixTranspose(&matRotation);
*currentMatrix = MatrixMultiply(*currentMatrix, matRotation);
@@ -2153,7 +2152,7 @@ void UnloadShader(Shader shader)
}
}
-// Set custom shader to be used on batch draw
+// Begin custom shader mode
void BeginShaderMode(Shader shader)
{
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
@@ -2165,7 +2164,7 @@ void BeginShaderMode(Shader shader)
#endif
}
-// Set default shader to be used in batch draw
+// End custom shader mode (returns to default shader)
void EndShaderMode(void)
{
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
@@ -2251,6 +2250,18 @@ void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat)
#endif
}
+// Set a custom projection matrix (replaces internal projection matrix)
+void SetMatrixProjection(Matrix proj)
+{
+ projection = proj;
+}
+
+// Set a custom modelview matrix (replaces internal modelview matrix)
+void SetMatrixModelview(Matrix view)
+{
+ modelview = view;
+}
+
// Begin blending mode (alpha, additive, multiplied)
// NOTE: Only 3 blending modes supported, default blend mode is alpha
void BeginBlendMode(int mode)
@@ -3068,7 +3079,7 @@ static void UnloadDefaultBuffers(void)
free(quads.indices);
}
-// Sets shader uniform values for lights array
+// Setup shader uniform values for lights array
// NOTE: It would be far easier with shader UBOs but are not supported on OpenGL ES 2.0f
static void SetShaderLights(Shader shader)
{
diff --git a/src/rlgl.h b/src/rlgl.h
index 00482d2e..2a578a1f 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -329,6 +329,9 @@ void SetShaderValue(Shader shader, int uniformLoc, float *value, int size); // S
void SetShaderValuei(Shader shader, int uniformLoc, int *value, int size); // Set shader uniform value (int)
void SetShaderValueMatrix(Shader shader, int uniformLoc, Matrix mat); // Set shader uniform value (matrix 4x4)
+void SetMatrixProjection(Matrix proj); // Set a custom projection matrix (replaces internal projection matrix)
+void SetMatrixModelview(Matrix view); // Set a custom modelview matrix (replaces internal modelview matrix)
+
void BeginShaderMode(Shader shader); // Begin custom shader drawing
void EndShaderMode(void); // End custom shader drawing (use default shader)
void BeginBlendMode(int mode); // Begin blending mode (alpha, additive, multiplied)