Moved some functions to raymath
Exposed some raymath useful functions to raylib API
This commit is contained in:
parent
980d9d4cd4
commit
38d9fcb08e
5 changed files with 52 additions and 77 deletions
39
src/core.c
39
src/core.c
|
@ -1098,45 +1098,6 @@ float *ColorToFloat(Color color)
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converts Vector3 to float array
|
|
||||||
float *VectorToFloat(Vector3 vec)
|
|
||||||
{
|
|
||||||
static float buffer[3];
|
|
||||||
|
|
||||||
buffer[0] = vec.x;
|
|
||||||
buffer[1] = vec.y;
|
|
||||||
buffer[2] = vec.z;
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: Returned vector is a transposed version of the Matrix struct,
|
|
||||||
// it should be this way because, despite raymath use OpenGL column-major convention,
|
|
||||||
// Matrix struct memory alignment and variables naming are not coherent
|
|
||||||
float *MatrixToFloat(Matrix mat)
|
|
||||||
{
|
|
||||||
static float buffer[16];
|
|
||||||
|
|
||||||
buffer[0] = mat.m0;
|
|
||||||
buffer[1] = mat.m4;
|
|
||||||
buffer[2] = mat.m8;
|
|
||||||
buffer[3] = mat.m12;
|
|
||||||
buffer[4] = mat.m1;
|
|
||||||
buffer[5] = mat.m5;
|
|
||||||
buffer[6] = mat.m9;
|
|
||||||
buffer[7] = mat.m13;
|
|
||||||
buffer[8] = mat.m2;
|
|
||||||
buffer[9] = mat.m6;
|
|
||||||
buffer[10] = mat.m10;
|
|
||||||
buffer[11] = mat.m14;
|
|
||||||
buffer[12] = mat.m3;
|
|
||||||
buffer[13] = mat.m7;
|
|
||||||
buffer[14] = mat.m11;
|
|
||||||
buffer[15] = mat.m15;
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a Color struct from hexadecimal value
|
// Returns a Color struct from hexadecimal value
|
||||||
Color GetColor(int hexValue)
|
Color GetColor(int hexValue)
|
||||||
{
|
{
|
||||||
|
|
|
@ -742,8 +742,13 @@ RLAPI int GetHexValue(Color color); // Returns hex
|
||||||
RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value
|
RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value
|
||||||
RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
|
RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
|
||||||
RLAPI float *ColorToFloat(Color color); // Converts Color to float array and normalizes
|
RLAPI float *ColorToFloat(Color color); // Converts Color to float array and normalizes
|
||||||
RLAPI float *VectorToFloat(Vector3 vec); // Converts Vector3 to float array
|
|
||||||
RLAPI float *MatrixToFloat(Matrix mat); // Converts Matrix to float array
|
// Math useful functions (available from raymath.h)
|
||||||
|
RLAPI float *VectorToFloat(Vector3 vec); // Returns Vector3 as float array
|
||||||
|
RLAPI float *MatrixToFloat(Matrix mat); // Returns Matrix as float array
|
||||||
|
RLAPI Vector3 VectorZero(void); // Vector with components value 0.0f
|
||||||
|
RLAPI Vector3 VectorOne(void); // Vector with components value 1.0f
|
||||||
|
RLAPI Matrix MatrixIdentity(void); // Returns identity matrix
|
||||||
|
|
||||||
// Misc. functions
|
// Misc. functions
|
||||||
RLAPI void ShowLogo(void); // Activate raylib logo at startup (can be done with flags)
|
RLAPI void ShowLogo(void); // Activate raylib logo at startup (can be done with flags)
|
||||||
|
|
|
@ -154,6 +154,7 @@ RMDEF Vector3 VectorReflect(Vector3 vector, Vector3 normal); // Calculate ref
|
||||||
RMDEF Vector3 VectorMin(Vector3 vec1, Vector3 vec2); // Return min value for each pair of components
|
RMDEF Vector3 VectorMin(Vector3 vec1, Vector3 vec2); // Return min value for each pair of components
|
||||||
RMDEF Vector3 VectorMax(Vector3 vec1, Vector3 vec2); // Return max value for each pair of components
|
RMDEF Vector3 VectorMax(Vector3 vec1, Vector3 vec2); // Return max value for each pair of components
|
||||||
RMDEF Vector3 VectorBarycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c); // Barycenter coords for p in triangle abc
|
RMDEF Vector3 VectorBarycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c); // Barycenter coords for p in triangle abc
|
||||||
|
RMDEF float *VectorToFloat(Vector3 vec); // Returns Vector3 as float array
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Functions Declaration to work with Matrix
|
// Functions Declaration to work with Matrix
|
||||||
|
@ -177,6 +178,7 @@ RMDEF Matrix MatrixFrustum(double left, double right, double bottom, double top,
|
||||||
RMDEF Matrix MatrixPerspective(double fovy, double aspect, double near, double far); // Returns perspective projection matrix
|
RMDEF Matrix MatrixPerspective(double fovy, double aspect, double near, double far); // Returns perspective projection matrix
|
||||||
RMDEF Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far); // Returns orthographic projection matrix
|
RMDEF Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far); // Returns orthographic projection matrix
|
||||||
RMDEF Matrix MatrixLookAt(Vector3 position, Vector3 target, Vector3 up); // Returns camera look-at matrix (view matrix)
|
RMDEF Matrix MatrixLookAt(Vector3 position, Vector3 target, Vector3 up); // Returns camera look-at matrix (view matrix)
|
||||||
|
RMDEF float *MatrixToFloat(Matrix mat); // Returns float array of Matrix data
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Functions Declaration to work with Quaternions
|
// Functions Declaration to work with Quaternions
|
||||||
|
@ -502,6 +504,18 @@ RMDEF Vector3 VectorBarycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns Vector3 as float array
|
||||||
|
RMDEF float *VectorToFloat(Vector3 vec)
|
||||||
|
{
|
||||||
|
static float buffer[3];
|
||||||
|
|
||||||
|
buffer[0] = vec.x;
|
||||||
|
buffer[1] = vec.y;
|
||||||
|
buffer[2] = vec.z;
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition - Matrix math
|
// Module Functions Definition - Matrix math
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -943,6 +957,34 @@ RMDEF Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns float array of matrix data
|
||||||
|
// NOTE: Returned vector is a transposed version of the Matrix struct,
|
||||||
|
// it should be this way because, despite raymath use OpenGL column-major convention,
|
||||||
|
// Matrix struct memory alignment and variables naming are not coherent
|
||||||
|
RMDEF float *MatrixToFloat(Matrix mat)
|
||||||
|
{
|
||||||
|
static float buffer[16];
|
||||||
|
|
||||||
|
buffer[0] = mat.m0;
|
||||||
|
buffer[1] = mat.m4;
|
||||||
|
buffer[2] = mat.m8;
|
||||||
|
buffer[3] = mat.m12;
|
||||||
|
buffer[4] = mat.m1;
|
||||||
|
buffer[5] = mat.m5;
|
||||||
|
buffer[6] = mat.m9;
|
||||||
|
buffer[7] = mat.m13;
|
||||||
|
buffer[8] = mat.m2;
|
||||||
|
buffer[9] = mat.m6;
|
||||||
|
buffer[10] = mat.m10;
|
||||||
|
buffer[11] = mat.m14;
|
||||||
|
buffer[12] = mat.m3;
|
||||||
|
buffer[13] = mat.m7;
|
||||||
|
buffer[14] = mat.m11;
|
||||||
|
buffer[15] = mat.m15;
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition - Quaternion math
|
// Module Functions Definition - Quaternion math
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
38
src/rlgl.c
38
src/rlgl.c
|
@ -360,10 +360,6 @@ static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight);
|
||||||
static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight);
|
static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(RLGL_STANDALONE)
|
|
||||||
float *MatrixToFloat(Matrix mat); // Converts Matrix to float array
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition - Matrix operations
|
// Module Functions Definition - Matrix operations
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -477,15 +473,15 @@ void rlScalef(float x, float y, float z)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiply the current matrix by another matrix
|
// Multiply the current matrix by another matrix
|
||||||
void rlMultMatrixf(float *m)
|
void rlMultMatrixf(float *mat)
|
||||||
{
|
{
|
||||||
// Matrix creation from array
|
// Matrix creation from array
|
||||||
Matrix mat = { m[0], m[1], m[2], m[3],
|
Matrix mat2 = { m[0], m[1], m[2], m[3],
|
||||||
m[4], m[5], m[6], m[7],
|
m[4], m[5], m[6], m[7],
|
||||||
m[8], m[9], m[10], m[11],
|
m[8], m[9], m[10], m[11],
|
||||||
m[12], m[13], m[14], m[15] };
|
m[12], m[13], m[14], m[15] };
|
||||||
|
|
||||||
*currentMatrix = MatrixMultiply(*currentMatrix, mat);
|
*currentMatrix = MatrixMultiply(*currentMatrix, mat2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiply the current matrix by a perspective matrix generated by parameters
|
// Multiply the current matrix by a perspective matrix generated by parameters
|
||||||
|
@ -4176,32 +4172,4 @@ void TraceLog(int msgType, const char *text, ...)
|
||||||
|
|
||||||
if (msgType == LOG_ERROR) exit(1);
|
if (msgType == LOG_ERROR) exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converts Matrix to float array
|
|
||||||
// NOTE: Returned vector is a transposed version of the Matrix struct,
|
|
||||||
// it should be this way because, despite raymath use OpenGL column-major convention,
|
|
||||||
// Matrix struct memory alignment and variables naming are not coherent
|
|
||||||
float *MatrixToFloat(Matrix mat)
|
|
||||||
{
|
|
||||||
static float buffer[16];
|
|
||||||
|
|
||||||
buffer[0] = mat.m0;
|
|
||||||
buffer[1] = mat.m4;
|
|
||||||
buffer[2] = mat.m8;
|
|
||||||
buffer[3] = mat.m12;
|
|
||||||
buffer[4] = mat.m1;
|
|
||||||
buffer[5] = mat.m5;
|
|
||||||
buffer[6] = mat.m9;
|
|
||||||
buffer[7] = mat.m13;
|
|
||||||
buffer[8] = mat.m2;
|
|
||||||
buffer[9] = mat.m6;
|
|
||||||
buffer[10] = mat.m10;
|
|
||||||
buffer[11] = mat.m14;
|
|
||||||
buffer[12] = mat.m3;
|
|
||||||
buffer[13] = mat.m7;
|
|
||||||
buffer[14] = mat.m11;
|
|
||||||
buffer[15] = mat.m15;
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -465,7 +465,6 @@ void BeginVrDrawing(void); // Begin VR stereo rende
|
||||||
void EndVrDrawing(void); // End VR stereo rendering
|
void EndVrDrawing(void); // End VR stereo rendering
|
||||||
|
|
||||||
void TraceLog(int msgType, const char *text, ...); // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
|
void TraceLog(int msgType, const char *text, ...); // Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
|
||||||
float *MatrixToFloat(Matrix mat); // Converts Matrix to float array
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue