From 43cb6414f6d579f891f4e0dec4440060a31981c5 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 5 Jun 2017 18:53:37 +0200 Subject: Added note about transposing --- src/raymath.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/raymath.h') diff --git a/src/raymath.h b/src/raymath.h index 1dbebc07..2bde2042 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -413,6 +413,12 @@ RMDEF void VectorTransform(Vector3 *v, Matrix 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; + + /* + v->x = mat.m0*x + mat.m1*y + mat.m2*z + mat.m3; + v->y = mat.m4*x + mat.m5*y + mat.m6*z + mat.m7; + v->z = mat.m8*x + mat.m9*y + mat.m10*z + mat.m11; + */ }; // Calculate linear interpolation between two vectors -- cgit v1.2.3 From 402a8bfd6842f15df940e7ed4f50fc36e0d73aff Mon Sep 17 00:00:00 2001 From: raysan5 Date: Mon, 5 Jun 2017 18:53:53 +0200 Subject: Added note about transposing --- src/raymath.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/raymath.h') diff --git a/src/raymath.h b/src/raymath.h index 2bde2042..499f9eec 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -414,6 +414,7 @@ RMDEF void VectorTransform(Vector3 *v, Matrix mat) 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; + // TODO: Transposed matrix (?) /* v->x = mat.m0*x + mat.m1*y + mat.m2*z + mat.m3; v->y = mat.m4*x + mat.m5*y + mat.m6*z + mat.m7; -- cgit v1.2.3 From aba3739c1354cac4ef302d9b43c3fc5e9699b373 Mon Sep 17 00:00:00 2001 From: Wilhem Barbier Date: Thu, 29 Jun 2017 10:29:01 +0200 Subject: Fix some typos in raymath.h --- src/raymath.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/raymath.h') diff --git a/src/raymath.h b/src/raymath.h index 499f9eec..6961845c 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -124,7 +124,7 @@ RMDEF Vector2 Vector2Zero(void); // Vector with c RMDEF Vector2 Vector2One(void); // Vector with components value 1.0f RMDEF Vector2 Vector2Add(Vector2 v1, Vector2 v2); // Add two vectors (v1 + v2) RMDEF Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); // Subtract two vectors (v1 - v2) -RMDEF float Vector2Lenght(Vector2 v); // Calculate vector lenght +RMDEF float Vector2Lenght(Vector2 v); // Calculate vector length RMDEF float Vector2DotProduct(Vector2 v1, Vector2 v2); // Calculate two vectors dot product RMDEF float Vector2Distance(Vector2 v1, Vector2 v2); // Calculate distance between two vectors RMDEF float Vector2Angle(Vector2 v1, Vector2 v2); // Calculate angle between two vectors in X-axis @@ -142,7 +142,7 @@ RMDEF Vector3 VectorAdd(Vector3 v1, Vector3 v2); // Add two vecto RMDEF Vector3 VectorSubtract(Vector3 v1, Vector3 v2); // Substract two vectors RMDEF Vector3 VectorCrossProduct(Vector3 v1, Vector3 v2); // Calculate two vectors cross product RMDEF Vector3 VectorPerpendicular(Vector3 v); // Calculate one vector perpendicular vector -RMDEF float VectorLength(const Vector3 v); // Calculate vector lenght +RMDEF float VectorLength(const Vector3 v); // Calculate vector length RMDEF float VectorDotProduct(Vector3 v1, Vector3 v2); // Calculate two vectors dot product RMDEF float VectorDistance(Vector3 v1, Vector3 v2); // Calculate distance between two points RMDEF void VectorScale(Vector3 *v, float scale); // Scale provided vector @@ -236,8 +236,8 @@ RMDEF Vector2 Vector2Subtract(Vector2 v1, Vector2 v2) return (Vector2){ v1.x - v2.x, v1.y - v2.y }; } -// Calculate vector lenght -RMDEF float Vector2Lenght(Vector2 v) +// Calculate vector length +RMDEF float Vector2Length(Vector2 v) { return sqrtf((v.x*v.x) + (v.y*v.y)); } @@ -348,7 +348,7 @@ RMDEF Vector3 VectorPerpendicular(Vector3 v) return result; } -// Calculate vector lenght +// Calculate vector length RMDEF float VectorLength(const Vector3 v) { return sqrtf(v.x*v.x + v.y*v.y + v.z*v.z); -- cgit v1.2.3 From 056a494baf3b4c450e734967c033919facfdec5c Mon Sep 17 00:00:00 2001 From: Wilhem Barbier Date: Thu, 29 Jun 2017 10:36:58 +0200 Subject: Fix some other typos --- docs/cheatsheet/raylib_models.c | 6 +++--- examples/others/standard_lighting.c | 4 ++-- src/raymath.h | 4 ++-- src/textures.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/raymath.h') diff --git a/docs/cheatsheet/raylib_models.c b/docs/cheatsheet/raylib_models.c index 909d7bee..d7540136 100644 --- a/docs/cheatsheet/raylib_models.c +++ b/docs/cheatsheet/raylib_models.c @@ -3,11 +3,11 @@ void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); // Draw a line in 3D world space void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space - void DrawCube(Vector3 position, float width, float height, float lenght, Color color); // Draw cube + void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) - void DrawCubeWires(Vector3 position, float width, float height, float lenght, Color color); // Draw cube wires + void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires void DrawCubeTexture(Texture2D texture, Vector3 position, float width, - float height, float lenght, Color color); // Draw cube textured + float height, float length, Color color); // Draw cube textured void DrawSphere(Vector3 centerPos, float radius, Color color); // Draw sphere void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere with extended parameters void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color); // Draw sphere wires diff --git a/examples/others/standard_lighting.c b/examples/others/standard_lighting.c index 14fda32e..a7f634e2 100644 --- a/examples/others/standard_lighting.c +++ b/examples/others/standard_lighting.c @@ -69,7 +69,7 @@ static void GetShaderLightsLocations(Shader shader); // Get shader locations static void SetShaderLightsValues(Shader shader); // Set shader uniform values for lights // Vector3 math functions -static float VectorLength(const Vector3 v); // Calculate vector lenght +static float VectorLength(const Vector3 v); // Calculate vector length static void VectorNormalize(Vector3 *v); // Normalize provided vector static Vector3 VectorSubtract(Vector3 v1, Vector3 v2); // Substract two vectors @@ -444,7 +444,7 @@ static void SetShaderLightsValues(Shader shader) } } -// Calculate vector lenght +// Calculate vector length float VectorLength(const Vector3 v) { float length; diff --git a/src/raymath.h b/src/raymath.h index 6961845c..c4db0f3f 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -124,7 +124,7 @@ RMDEF Vector2 Vector2Zero(void); // Vector with c RMDEF Vector2 Vector2One(void); // Vector with components value 1.0f RMDEF Vector2 Vector2Add(Vector2 v1, Vector2 v2); // Add two vectors (v1 + v2) RMDEF Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); // Subtract two vectors (v1 - v2) -RMDEF float Vector2Lenght(Vector2 v); // Calculate vector length +RMDEF float Vector2Length(Vector2 v); // Calculate vector length RMDEF float Vector2DotProduct(Vector2 v1, Vector2 v2); // Calculate two vectors dot product RMDEF float Vector2Distance(Vector2 v1, Vector2 v2); // Calculate distance between two vectors RMDEF float Vector2Angle(Vector2 v1, Vector2 v2); // Calculate angle between two vectors in X-axis @@ -287,7 +287,7 @@ RMDEF void Vector2Divide(Vector2 *v, float div) // Normalize provided vector RMDEF void Vector2Normalize(Vector2 *v) { - Vector2Divide(v, Vector2Lenght(*v)); + Vector2Divide(v, Vector2Length(*v)); } //---------------------------------------------------------------------------------- diff --git a/src/textures.c b/src/textures.c index 9b0067cf..5196b1e1 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2397,7 +2397,7 @@ static Image LoadASTC(const char *fileName) unsigned char blockZ; // Block Z dimensions (1 for 2D images) unsigned char width[3]; // Image width in pixels (24bit value) unsigned char height[3]; // Image height in pixels (24bit value) - unsigned char lenght[3]; // Image Z-size (1 for 2D images) + unsigned char length[3]; // Image Z-size (1 for 2D images) } ASTCHeader; Image image; -- cgit v1.2.3 From 84aff31973667e6bec29915d60971f9a5bb02a44 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 21 Jul 2017 10:42:41 +0200 Subject: MatrixPerspective() angle required in radians Consistent with similar functions in raymath --- src/core.c | 4 ++-- src/raymath.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/raymath.h') diff --git a/src/core.c b/src/core.c index 5cdd8e6b..fc653195 100644 --- a/src/core.c +++ b/src/core.c @@ -980,7 +980,7 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera) TraceLog(LOG_DEBUG, "Device coordinates: (%f, %f, %f)", deviceCoords.x, deviceCoords.y, deviceCoords.z); // Calculate projection matrix (from perspective instead of frustum) - Matrix matProj = MatrixPerspective(camera.fovy, ((double)GetScreenWidth()/(double)GetScreenHeight()), 0.01, 1000.0); + Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), 0.01, 1000.0); // Calculate view matrix from camera look at Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); @@ -1033,7 +1033,7 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera) Vector2 GetWorldToScreen(Vector3 position, Camera camera) { // Calculate projection matrix (from perspective instead of frustum - Matrix matProj = MatrixPerspective(camera.fovy, (double)GetScreenWidth()/(double)GetScreenHeight(), 0.01, 1000.0); + Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, (double)GetScreenWidth()/(double)GetScreenHeight(), 0.01, 1000.0); // Calculate view matrix from camera look at (and transpose it) Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); diff --git a/src/raymath.h b/src/raymath.h index c4db0f3f..70d1bedd 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -873,9 +873,10 @@ RMDEF Matrix MatrixFrustum(double left, double right, double bottom, double top, } // Returns perspective projection matrix +// NOTE: Angle should be provided in radians RMDEF Matrix MatrixPerspective(double fovy, double aspect, double near, double far) { - double top = near*tan(fovy*PI/360.0); + double top = near*tan(fovy); double right = top*aspect; return MatrixFrustum(-right, right, -top, top, near, far); -- cgit v1.2.3 From 38d9fcb08ef81cd5a3ab93df825eac7714d03e45 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 21 Jul 2017 15:25:35 +0200 Subject: Moved some functions to raymath Exposed some raymath useful functions to raylib API --- src/core.c | 39 --------------------------------------- src/raylib.h | 9 +++++++-- src/raymath.h | 42 ++++++++++++++++++++++++++++++++++++++++++ src/rlgl.c | 38 +++----------------------------------- src/rlgl.h | 1 - 5 files changed, 52 insertions(+), 77 deletions(-) (limited to 'src/raymath.h') diff --git a/src/core.c b/src/core.c index fc653195..32d4666b 100644 --- a/src/core.c +++ b/src/core.c @@ -1098,45 +1098,6 @@ float *ColorToFloat(Color color) 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 Color GetColor(int hexValue) { diff --git a/src/raylib.h b/src/raylib.h index cc5b0bb6..ec5e61fd 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -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 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 *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 RLAPI void ShowLogo(void); // Activate raylib logo at startup (can be done with flags) diff --git a/src/raymath.h b/src/raymath.h index 70d1bedd..ec824408 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -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 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 float *VectorToFloat(Vector3 vec); // Returns Vector3 as float array //------------------------------------------------------------------------------------ // 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 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 float *MatrixToFloat(Matrix mat); // Returns float array of Matrix data //------------------------------------------------------------------------------------ // Functions Declaration to work with Quaternions @@ -502,6 +504,18 @@ RMDEF Vector3 VectorBarycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c) 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 //---------------------------------------------------------------------------------- @@ -943,6 +957,34 @@ RMDEF Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up) 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 //---------------------------------------------------------------------------------- diff --git a/src/rlgl.c b/src/rlgl.c index a27645dd..54b30b90 100644 --- a/src/rlgl.c +++ b/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); #endif -#if defined(RLGL_STANDALONE) -float *MatrixToFloat(Matrix mat); // Converts Matrix to float array -#endif - //---------------------------------------------------------------------------------- // Module Functions Definition - Matrix operations //---------------------------------------------------------------------------------- @@ -477,15 +473,15 @@ void rlScalef(float x, float y, float z) } // Multiply the current matrix by another matrix -void rlMultMatrixf(float *m) +void rlMultMatrixf(float *mat) { // 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[8], m[9], m[10], m[11], 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 @@ -4176,32 +4172,4 @@ void TraceLog(int msgType, const char *text, ...) 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 diff --git a/src/rlgl.h b/src/rlgl.h index a9ee6ec6..84ece706 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -465,7 +465,6 @@ void BeginVrDrawing(void); // Begin VR stereo rende 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) -float *MatrixToFloat(Matrix mat); // Converts Matrix to float array #endif #ifdef __cplusplus -- cgit v1.2.3 From e52032f64660008fdcf0c8d707ef6aed1e6fc32f Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 21 Jul 2017 17:19:28 +0200 Subject: Complete review of raymath Now it should be coherent with OpenGL math standards --- src/core.c | 7 +++-- src/models.c | 30 ++++++++++----------- src/raymath.h | 83 +++++++++++++++++++++++++++++------------------------------ src/rlgl.c | 35 +++++++++---------------- src/rlgl.h | 2 +- 5 files changed, 71 insertions(+), 86 deletions(-) (limited to 'src/raymath.h') diff --git a/src/core.c b/src/core.c index 32d4666b..5e7cc811 100644 --- a/src/core.c +++ b/src/core.c @@ -895,8 +895,8 @@ void Begin3dMode(Camera camera) rlLoadIdentity(); // Reset current matrix (MODELVIEW) // Setup Camera view - Matrix cameraView = MatrixLookAt(camera.position, camera.target, camera.up); - rlMultMatrixf(MatrixToFloat(cameraView)); // Multiply MODELVIEW matrix by view matrix (camera) + Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); + rlMultMatrixf(MatrixToFloat(matView)); // Multiply MODELVIEW matrix by view matrix (camera) rlEnableDepthTest(); // Enable DEPTH_TEST for 3D } @@ -991,7 +991,7 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera) // For example, if you get view matrix, transpose and inverted and you transform it // to a vector, you will get its 3d world position coordinates (camera.position). // If you don't transpose, final position will be wrong. - MatrixTranspose(&matView); + //MatrixTranspose(&matView); //#define USE_RLGL_UNPROJECT #if defined(USE_RLGL_UNPROJECT) // OPTION 1: Use rlUnproject() @@ -1037,7 +1037,6 @@ Vector2 GetWorldToScreen(Vector3 position, Camera camera) // Calculate view matrix from camera look at (and transpose it) Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); - MatrixTranspose(&matView); // Convert world position vector to quaternion Quaternion worldPos = { position.x, position.y, position.z, 1.0f }; diff --git a/src/models.c b/src/models.c index 7dce9fa6..cfcefc2f 100644 --- a/src/models.c +++ b/src/models.c @@ -119,10 +119,10 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c rlPushMatrix(); - // NOTE: Be careful! Function order matters (rotate -> scale -> translate) + // NOTE: Be careful! Function order matters (scale -> rotate -> translate) + rlScalef(1.0f, 3.0f, 1.0f); + rlRotatef(45, 0, 1, 0); rlTranslatef(position.x, position.y, position.z); - //rlScalef(2.0f, 2.0f, 2.0f); - //rlRotatef(45, 0, 1, 0); rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); @@ -199,8 +199,8 @@ void DrawCubeWires(Vector3 position, float width, float height, float length, Co rlPushMatrix(); - rlTranslatef(position.x, position.y, position.z); //rlRotatef(45, 0, 1, 0); + rlTranslatef(position.x, position.y, position.z); rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); @@ -271,10 +271,10 @@ void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float hei rlEnableTexture(texture.id); //rlPushMatrix(); - // NOTE: Be careful! Function order matters (scale, translate, rotate) + // NOTE: Be careful! Function order matters (scale -> rotate -> translate) //rlScalef(2.0f, 2.0f, 2.0f); - //rlTranslatef(2.0f, 0.0f, 0.0f); //rlRotatef(45, 0, 1, 0); + //rlTranslatef(2.0f, 0.0f, 0.0f); rlBegin(RL_QUADS); rlColor4ub(color.r, color.g, color.b, color.a); @@ -330,8 +330,8 @@ void DrawSphere(Vector3 centerPos, float radius, Color color) void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color) { rlPushMatrix(); - rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlScalef(radius, radius, radius); + rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); @@ -369,8 +369,8 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color) { rlPushMatrix(); - rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlScalef(radius, radius, radius); + rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); @@ -496,8 +496,8 @@ void DrawPlane(Vector3 centerPos, Vector2 size, Color color) { // NOTE: Plane is always created on XZ ground rlPushMatrix(); - rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlScalef(size.x, 1.0f, size.y); + rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); @@ -567,9 +567,8 @@ void DrawGizmo(Vector3 position) float length = 1.0f; rlPushMatrix(); - rlTranslatef(position.x, position.y, position.z); - //rlRotatef(rotation, 0, 1, 0); rlScalef(length, length, length); + rlTranslatef(position.x, position.y, position.z); rlBegin(RL_LINES); rlColor3f(1.0f, 0.0f, 0.0f); rlVertex3f(0.0f, 0.0f, 0.0f); @@ -1347,11 +1346,10 @@ void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vec // NOTE: Billboard size will maintain sourceRec aspect ratio, size will represent billboard width Vector2 sizeRatio = { size, size*(float)sourceRec.height/sourceRec.width }; - Matrix viewMatrix = MatrixLookAt(camera.position, camera.target, camera.up); - MatrixTranspose(&viewMatrix); + Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); - Vector3 right = { viewMatrix.m0, viewMatrix.m4, viewMatrix.m8 }; - //Vector3 up = { viewMatrix.m1, viewMatrix.m5, viewMatrix.m9 }; + Vector3 right = { matView.m0, matView.m4, matView.m8 }; + //Vector3 up = { matView.m1, matView.m5, matView.m9 }; // NOTE: Billboard locked on axis-Y Vector3 up = { 0.0f, 1.0f, 0.0f }; @@ -1660,7 +1658,7 @@ RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight) } // Calculate mesh bounding box limits -// NOTE: minVertex and maxVertex should be transformed by model transform matrix (position, scale, rotate) +// NOTE: minVertex and maxVertex should be transformed by model transform matrix BoundingBox CalculateBoundingBox(Mesh mesh) { // Get min and max vertex to construct bounds (AABB) diff --git a/src/raymath.h b/src/raymath.h index ec824408..a4f3f895 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -706,10 +706,10 @@ RMDEF Matrix MatrixSubstract(Matrix left, Matrix right) // Returns translation matrix RMDEF Matrix MatrixTranslate(float x, float y, float z) { - Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - x, y, z, 1.0f }; + Matrix result = { 1.0f, 0.0f, 0.0f, x, + 0.0f, 1.0f, 0.0f, y, + 0.0f, 0.0f, 1.0f, z, + 0.0f, 0.0f, 0.0f, 1.0f }; return result; } @@ -834,22 +834,22 @@ RMDEF Matrix MatrixMultiply(Matrix left, Matrix right) { Matrix result; - result.m0 = right.m0*left.m0 + right.m1*left.m4 + right.m2*left.m8 + right.m3*left.m12; - result.m1 = right.m0*left.m1 + right.m1*left.m5 + right.m2*left.m9 + right.m3*left.m13; - result.m2 = right.m0*left.m2 + right.m1*left.m6 + right.m2*left.m10 + right.m3*left.m14; - result.m3 = right.m0*left.m3 + right.m1*left.m7 + right.m2*left.m11 + right.m3*left.m15; - result.m4 = right.m4*left.m0 + right.m5*left.m4 + right.m6*left.m8 + right.m7*left.m12; - result.m5 = right.m4*left.m1 + right.m5*left.m5 + right.m6*left.m9 + right.m7*left.m13; - result.m6 = right.m4*left.m2 + right.m5*left.m6 + right.m6*left.m10 + right.m7*left.m14; - result.m7 = right.m4*left.m3 + right.m5*left.m7 + right.m6*left.m11 + right.m7*left.m15; - result.m8 = right.m8*left.m0 + right.m9*left.m4 + right.m10*left.m8 + right.m11*left.m12; - result.m9 = right.m8*left.m1 + right.m9*left.m5 + right.m10*left.m9 + right.m11*left.m13; - result.m10 = right.m8*left.m2 + right.m9*left.m6 + right.m10*left.m10 + right.m11*left.m14; - result.m11 = right.m8*left.m3 + right.m9*left.m7 + right.m10*left.m11 + right.m11*left.m15; - result.m12 = right.m12*left.m0 + right.m13*left.m4 + right.m14*left.m8 + right.m15*left.m12; - result.m13 = right.m12*left.m1 + right.m13*left.m5 + right.m14*left.m9 + right.m15*left.m13; - result.m14 = right.m12*left.m2 + right.m13*left.m6 + right.m14*left.m10 + right.m15*left.m14; - result.m15 = right.m12*left.m3 + right.m13*left.m7 + right.m14*left.m11 + right.m15*left.m15; + result.m0 = left.m0*right.m0 + left.m1*right.m4 + left.m2*right.m8 + left.m3*right.m12; + result.m1 = left.m0*right.m1 + left.m1*right.m5 + left.m2*right.m9 + left.m3*right.m13; + result.m2 = left.m0*right.m2 + left.m1*right.m6 + left.m2*right.m10 + left.m3*right.m14; + result.m3 = left.m0*right.m3 + left.m1*right.m7 + left.m2*right.m11 + left.m3*right.m15; + result.m4 = left.m4*right.m0 + left.m5*right.m4 + left.m6*right.m8 + left.m7*right.m12; + result.m5 = left.m4*right.m1 + left.m5*right.m5 + left.m6*right.m9 + left.m7*right.m13; + result.m6 = left.m4*right.m2 + left.m5*right.m6 + left.m6*right.m10 + left.m7*right.m14; + result.m7 = left.m4*right.m3 + left.m5*right.m7 + left.m6*right.m11 + left.m7*right.m15; + result.m8 = left.m8*right.m0 + left.m9*right.m4 + left.m10*right.m8 + left.m11*right.m12; + result.m9 = left.m8*right.m1 + left.m9*right.m5 + left.m10*right.m9 + left.m11*right.m13; + result.m10 = left.m8*right.m2 + left.m9*right.m6 + left.m10*right.m10 + left.m11*right.m14; + result.m11 = left.m8*right.m3 + left.m9*right.m7 + left.m10*right.m11 + left.m11*right.m15; + result.m12 = left.m12*right.m0 + left.m13*right.m4 + left.m14*right.m8 + left.m15*right.m12; + result.m13 = left.m12*right.m1 + left.m13*right.m5 + left.m14*right.m9 + left.m15*right.m13; + result.m14 = left.m12*right.m2 + left.m13*right.m6 + left.m14*right.m10 + left.m15*right.m14; + result.m15 = left.m12*right.m3 + left.m13*right.m7 + left.m14*right.m11 + left.m15*right.m15; return result; } @@ -936,50 +936,49 @@ RMDEF Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up) VectorNormalize(&x); Vector3 y = VectorCrossProduct(z, x); VectorNormalize(&y); - + result.m0 = x.x; result.m1 = x.y; result.m2 = x.z; - result.m3 = -((x.x*eye.x) + (x.y*eye.y) + (x.z*eye.z)); + result.m3 = 0.0f; result.m4 = y.x; result.m5 = y.y; result.m6 = y.z; - result.m7 = -((y.x*eye.x) + (y.y*eye.y) + (y.z*eye.z)); + result.m7 = 0.0f; result.m8 = z.x; result.m9 = z.y; result.m10 = z.z; - result.m11 = -((z.x*eye.x) + (z.y*eye.y) + (z.z*eye.z)); - result.m12 = 0.0f; - result.m13 = 0.0f; - result.m14 = 0.0f; + result.m11 = 0.0f; + result.m12 = eye.x; + result.m13 = eye.y; + result.m14 = eye.z; result.m15 = 1.0f; + MatrixInvert(&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[1] = mat.m1; + buffer[2] = mat.m2; + buffer[3] = mat.m3; + buffer[4] = mat.m4; buffer[5] = mat.m5; - buffer[6] = mat.m9; - buffer[7] = mat.m13; - buffer[8] = mat.m2; - buffer[9] = mat.m6; + buffer[6] = mat.m6; + buffer[7] = mat.m7; + buffer[8] = mat.m8; + buffer[9] = mat.m9; buffer[10] = mat.m10; - buffer[11] = mat.m14; - buffer[12] = mat.m3; - buffer[13] = mat.m7; - buffer[14] = mat.m11; + buffer[11] = mat.m11; + buffer[12] = mat.m12; + buffer[13] = mat.m13; + buffer[14] = mat.m14; buffer[15] = mat.m15; return buffer; diff --git a/src/rlgl.c b/src/rlgl.c index 54b30b90..93612896 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -395,7 +395,7 @@ void rlLoadIdentity(void) { glLoadIdentity(); } void rlTranslatef(float x, float y, float z) { glTranslatef(x, y, z); } void rlRotatef(float angleDeg, float x, float y, float z) { glRotatef(angleDeg, x, y, z); } void rlScalef(float x, float y, float z) { glScalef(x, y, z); } -void rlMultMatrixf(float *mat) { glMultMatrixf(mat); } +void rlMultMatrixf(float *matf) { glMultMatrixf(matf); } #elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) @@ -445,7 +445,6 @@ void rlLoadIdentity(void) void rlTranslatef(float x, float y, float z) { Matrix matTranslation = MatrixTranslate(x, y, z); - MatrixTranspose(&matTranslation); *currentMatrix = MatrixMultiply(*currentMatrix, matTranslation); } @@ -458,7 +457,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); } @@ -467,28 +465,26 @@ void rlRotatef(float angleDeg, float x, float y, float z) void rlScalef(float x, float y, float z) { Matrix matScale = MatrixScale(x, y, z); - MatrixTranspose(&matScale); *currentMatrix = MatrixMultiply(*currentMatrix, matScale); } // Multiply the current matrix by another matrix -void rlMultMatrixf(float *mat) +void rlMultMatrixf(float *matf) { // Matrix creation from array - Matrix mat2 = { m[0], m[1], m[2], m[3], - m[4], m[5], m[6], m[7], - m[8], m[9], m[10], m[11], - m[12], m[13], m[14], m[15] }; + Matrix mat = { matf[0], matf[4], matf[8], matf[12], + matf[1], matf[5], matf[9], matf[13], + matf[2], matf[6], matf[10], matf[14], + matf[3], matf[7], matf[11], matf[15] }; - *currentMatrix = MatrixMultiply(*currentMatrix, mat2); + *currentMatrix = MatrixMultiply(*currentMatrix, mat); } // Multiply the current matrix by a perspective matrix generated by parameters void rlFrustum(double left, double right, double bottom, double top, double near, double far) { Matrix matPerps = MatrixFrustum(left, right, bottom, top, near, far); - MatrixTranspose(&matPerps); *currentMatrix = MatrixMultiply(*currentMatrix, matPerps); } @@ -497,7 +493,6 @@ void rlFrustum(double left, double right, double bottom, double top, double near void rlOrtho(double left, double right, double bottom, double top, double near, double far) { Matrix matOrtho = MatrixOrtho(left, right, bottom, top, near, far); - MatrixTranspose(&matOrtho); *currentMatrix = MatrixMultiply(*currentMatrix, matOrtho); } @@ -2545,7 +2540,7 @@ Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size) // Create projection (transposed) and different views for each face Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, 0.01, 1000.0); - MatrixTranspose(&fboProjection); + //MatrixTranspose(&fboProjection); Matrix fboViews[6] = { MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }), MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ -1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }), @@ -2617,7 +2612,7 @@ Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size) // Create projection (transposed) and different views for each face Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, 0.01, 1000.0); - MatrixTranspose(&fboProjection); + //MatrixTranspose(&fboProjection); Matrix fboViews[6] = { MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }), MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ -1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }), @@ -2693,7 +2688,7 @@ Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size) // Create projection (transposed) and different views for each face Matrix fboProjection = MatrixPerspective(90.0*DEG2RAD, 1.0, 0.01, 1000.0); - MatrixTranspose(&fboProjection); + //MatrixTranspose(&fboProjection); Matrix fboViews[6] = { MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ 1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }), MatrixLookAt((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector3){ -1.0f, 0.0f, 0.0f }, (Vector3){ 0.0f, -1.0f, 0.0f }), @@ -2931,7 +2926,6 @@ void ToggleVrMode(void) // Reset viewport and default projection-modelview matrices rlViewport(0, 0, screenWidth, screenHeight); projection = MatrixOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f); - MatrixTranspose(&projection); modelview = MatrixIdentity(); } else vrStereoRender = true; @@ -3034,7 +3028,6 @@ void EndVrDrawing(void) // Reset viewport and default projection-modelview matrices rlViewport(0, 0, screenWidth, screenHeight); projection = MatrixOrtho(0, screenWidth, screenHeight, 0, 0.0f, 1.0f); - MatrixTranspose(&projection); modelview = MatrixIdentity(); rlDisableDepthTest(); @@ -3977,18 +3970,14 @@ static void SetStereoConfig(VrDeviceInfo hmd) // Fovy is normally computed with: 2*atan2(hmd.vScreenSize, 2*hmd.eyeToScreenDistance)*RAD2DEG // ...but with lens distortion it is increased (see Oculus SDK Documentation) //float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance)*RAD2DEG; // Really need distortionScale? - float fovy = 2.0f*(float)atan2(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance)*RAD2DEG; + float fovy = 2.0f*(float)atan2(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance); // Compute camera projection matrices float projOffset = 4.0f*lensShift; // Scaled to projection space coordinates [-1..1] - Matrix proj = MatrixPerspective(fovy*DEG2RAD, aspect, 0.01, 1000.0); + Matrix proj = MatrixPerspective(fovy, aspect, 0.01, 1000.0); vrConfig.eyesProjection[0] = MatrixMultiply(proj, MatrixTranslate(projOffset, 0.0f, 0.0f)); vrConfig.eyesProjection[1] = MatrixMultiply(proj, MatrixTranslate(-projOffset, 0.0f, 0.0f)); - // NOTE: Projection matrices must be transposed due to raymath convention - MatrixTranspose(&vrConfig.eyesProjection[0]); - MatrixTranspose(&vrConfig.eyesProjection[1]); - // Compute camera transformation matrices // NOTE: Camera movement might seem more natural if we model the head. // Our axis of rotation is the base of our head, so we might want to add diff --git a/src/rlgl.h b/src/rlgl.h index 84ece706..b9ea0f43 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -355,7 +355,7 @@ void rlLoadIdentity(void); // Reset current matrix to ident void rlTranslatef(float x, float y, float z); // Multiply the current matrix by a translation matrix void rlRotatef(float angleDeg, float x, float y, float z); // Multiply the current matrix by a rotation matrix void rlScalef(float x, float y, float z); // Multiply the current matrix by a scaling matrix -void rlMultMatrixf(float *mat); // Multiply the current matrix by another matrix +void rlMultMatrixf(float *matf); // Multiply the current matrix by another matrix void rlFrustum(double left, double right, double bottom, double top, double near, double far); void rlOrtho(double left, double right, double bottom, double top, double near, double far); void rlViewport(int x, int y, int width, int height); // Set the viewport area -- cgit v1.2.3 From c6cd07c373541f3b112e99f924b2213196625dc7 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 21 Jul 2017 17:46:44 +0200 Subject: Some tweaks raymath related --- examples/models/models_skybox.c | 1 - src/models.c | 2 +- src/raymath.h | 12 ++---------- 3 files changed, 3 insertions(+), 12 deletions(-) (limited to 'src/raymath.h') diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index 25b01e9c..30ee8e2e 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -10,7 +10,6 @@ ********************************************************************************************/ #include "raylib.h" -#include "raymath.h" int main() { diff --git a/src/models.c b/src/models.c index cfcefc2f..7df9a10b 100644 --- a/src/models.c +++ b/src/models.c @@ -1297,8 +1297,8 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota { // Calculate transformation matrix from function parameters // Get transform matrix (rotation -> scale -> translation) - Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD); Matrix matScale = MatrixScale(scale.x, scale.y, scale.z); + Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD); Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z); Matrix matTransform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation); diff --git a/src/raymath.h b/src/raymath.h index a4f3f895..270441a5 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -1,6 +1,6 @@ /********************************************************************************************** * -* raymath v1.0 - Math functions to work with Vector3, Matrix and Quaternions +* raymath v1.1 - Math functions to work with Vector3, Matrix and Quaternions * * CONFIGURATION: * @@ -19,7 +19,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* Copyright (c) 2015-2017 Ramon Santamaria (@raysan5) * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. @@ -405,7 +405,6 @@ RMDEF void VectorNormalize(Vector3 *v) } // Transforms a Vector3 by a given Matrix -// TODO: Review math (matrix transpose required?) RMDEF void VectorTransform(Vector3 *v, Matrix mat) { float x = v->x; @@ -415,13 +414,6 @@ RMDEF void VectorTransform(Vector3 *v, Matrix 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; - - // TODO: Transposed matrix (?) - /* - v->x = mat.m0*x + mat.m1*y + mat.m2*z + mat.m3; - v->y = mat.m4*x + mat.m5*y + mat.m6*z + mat.m7; - v->z = mat.m8*x + mat.m9*y + mat.m10*z + mat.m11; - */ }; // Calculate linear interpolation between two vectors -- cgit v1.2.3 From 00d2768bc910ca0b6749878f0d142b62d30d55c1 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 22 Jul 2017 10:35:41 +0200 Subject: Corrected bug on MatrixPerspective() Some other tweaks... --- src/core.c | 2 +- src/models.c | 4 ++-- src/raymath.h | 2 +- src/rlgl.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/raymath.h') diff --git a/src/core.c b/src/core.c index 5e7cc811..028d7b14 100644 --- a/src/core.c +++ b/src/core.c @@ -885,7 +885,7 @@ void Begin3dMode(Camera camera) // Setup perspective projection float aspect = (float)screenWidth/(float)screenHeight; - double top = 0.01*tan(camera.fovy*PI/360.0); + double top = 0.01*tan(camera.fovy*0.5*DEG2RAD); double right = top*aspect; // NOTE: zNear and zFar values are important when computing depth buffer values diff --git a/src/models.c b/src/models.c index 7df9a10b..47175b2c 100644 --- a/src/models.c +++ b/src/models.c @@ -120,8 +120,8 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c rlPushMatrix(); // NOTE: Be careful! Function order matters (scale -> rotate -> translate) - rlScalef(1.0f, 3.0f, 1.0f); - rlRotatef(45, 0, 1, 0); + //rlScalef(1.0f, 3.0f, 1.0f); + //rlRotatef(45, 0, 1, 0); rlTranslatef(position.x, position.y, position.z); rlBegin(RL_TRIANGLES); diff --git a/src/raymath.h b/src/raymath.h index 270441a5..93ae90ae 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -882,7 +882,7 @@ RMDEF Matrix MatrixFrustum(double left, double right, double bottom, double top, // NOTE: Angle should be provided in radians RMDEF Matrix MatrixPerspective(double fovy, double aspect, double near, double far) { - double top = near*tan(fovy); + double top = near*tan(fovy*0.5); double right = top*aspect; return MatrixFrustum(-right, right, -top, top, near, far); diff --git a/src/rlgl.c b/src/rlgl.c index 93612896..ac4ad20d 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -3585,7 +3585,7 @@ static void UpdateBuffersDefault(void) // Draw default internal buffers vertex data // NOTE: We draw in this order: lines, triangles, quads -static void DrawBuffersDefault() +static void DrawBuffersDefault(void) { Matrix matProjection = projection; Matrix matModelView = modelview; @@ -3967,9 +3967,9 @@ static void SetStereoConfig(VrDeviceInfo hmd) SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "chromaAbParam"), hmd.chromaAbCorrection, 4); #endif - // Fovy is normally computed with: 2*atan2(hmd.vScreenSize, 2*hmd.eyeToScreenDistance)*RAD2DEG + // Fovy is normally computed with: 2*atan2(hmd.vScreenSize, 2*hmd.eyeToScreenDistance) // ...but with lens distortion it is increased (see Oculus SDK Documentation) - //float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance)*RAD2DEG; // Really need distortionScale? + //float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance); // Really need distortionScale? float fovy = 2.0f*(float)atan2(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance); // Compute camera projection matrices -- cgit v1.2.3 From 3655c6e4663d62e93099cdf4871a03a4b0944c6a Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 22 Jul 2017 22:13:26 +0200 Subject: Renamed Vector*() functions to Vector3*() For consistency! --- src/raymath.h | 125 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 57 deletions(-) (limited to 'src/raymath.h') diff --git a/src/raymath.h b/src/raymath.h index 93ae90ae..e85367c2 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -136,25 +136,26 @@ RMDEF void Vector2Normalize(Vector2 *v); // Normalize pro //------------------------------------------------------------------------------------ // Functions Declaration to work with Vector3 //------------------------------------------------------------------------------------ -RMDEF Vector3 VectorZero(void); // Vector with components value 0.0f -RMDEF Vector3 VectorOne(void); // Vector with components value 1.0f -RMDEF Vector3 VectorAdd(Vector3 v1, Vector3 v2); // Add two vectors -RMDEF Vector3 VectorSubtract(Vector3 v1, Vector3 v2); // Substract two vectors -RMDEF Vector3 VectorCrossProduct(Vector3 v1, Vector3 v2); // Calculate two vectors cross product -RMDEF Vector3 VectorPerpendicular(Vector3 v); // Calculate one vector perpendicular vector -RMDEF float VectorLength(const Vector3 v); // Calculate vector length -RMDEF float VectorDotProduct(Vector3 v1, Vector3 v2); // Calculate two vectors dot product -RMDEF float VectorDistance(Vector3 v1, Vector3 v2); // Calculate distance between two points -RMDEF void VectorScale(Vector3 *v, float scale); // Scale provided vector -RMDEF void VectorNegate(Vector3 *v); // Negate provided vector (invert direction) -RMDEF void VectorNormalize(Vector3 *v); // Normalize provided vector -RMDEF void VectorTransform(Vector3 *v, Matrix mat); // Transforms a Vector3 by a given Matrix -RMDEF Vector3 VectorLerp(Vector3 v1, Vector3 v2, float amount); // Calculate linear interpolation between two vectors -RMDEF Vector3 VectorReflect(Vector3 vector, Vector3 normal); // Calculate reflected vector to normal -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 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 +RMDEF Vector3 Vector3Zero(void); // Vector with components value 0.0f +RMDEF Vector3 Vector3One(void); // Vector with components value 1.0f +RMDEF Vector3 Vector3Add(Vector3 v1, Vector3 v2); // Add two vectors +RMDEF Vector3 Vector3Multiply(Vector3 v, float scalar); // Multiply vector by scalar +RMDEF Vector3 Vector3Subtract(Vector3 v1, Vector3 v2); // Substract two vectors +RMDEF Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2); // Calculate two vectors cross product +RMDEF Vector3 Vector3Perpendicular(Vector3 v); // Calculate one vector perpendicular vector +RMDEF float Vector3Length(const Vector3 v); // Calculate vector length +RMDEF float Vector3DotProduct(Vector3 v1, Vector3 v2); // Calculate two vectors dot product +RMDEF float Vector3Distance(Vector3 v1, Vector3 v2); // Calculate distance between two points +RMDEF void Vector3Scale(Vector3 *v, float scale); // Scale provided vector +RMDEF void Vector3Negate(Vector3 *v); // Negate provided vector (invert direction) +RMDEF void Vector3Normalize(Vector3 *v); // Normalize provided vector +RMDEF void Vector3Transform(Vector3 *v, Matrix mat); // Transforms a Vector3 by a given Matrix +RMDEF Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount); // Calculate linear interpolation between two vectors +RMDEF Vector3 Vector3Reflect(Vector3 vector, Vector3 normal); // Calculate reflected vector to normal +RMDEF Vector3 Vector3Min(Vector3 vec1, Vector3 vec2); // Return min value for each pair of components +RMDEF Vector3 Vector3Max(Vector3 vec1, Vector3 vec2); // Return max value for each pair of components +RMDEF Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c); // Barycenter coords for p in triangle abc +RMDEF float *Vector3ToFloat(Vector3 vec); // Returns Vector3 as float array //------------------------------------------------------------------------------------ // Functions Declaration to work with Matrix @@ -297,25 +298,35 @@ RMDEF void Vector2Normalize(Vector2 *v) //---------------------------------------------------------------------------------- // Vector with components value 0.0f -RMDEF Vector3 VectorZero(void) { return (Vector3){ 0.0f, 0.0f, 0.0f }; } +RMDEF Vector3 Vector3Zero(void) { return (Vector3){ 0.0f, 0.0f, 0.0f }; } // Vector with components value 1.0f -RMDEF Vector3 VectorOne(void) { return (Vector3){ 1.0f, 1.0f, 1.0f }; } +RMDEF Vector3 Vector3One(void) { return (Vector3){ 1.0f, 1.0f, 1.0f }; } // Add two vectors -RMDEF Vector3 VectorAdd(Vector3 v1, Vector3 v2) +RMDEF Vector3 Vector3Add(Vector3 v1, Vector3 v2) { return (Vector3){ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z }; } // Substract two vectors -RMDEF Vector3 VectorSubtract(Vector3 v1, Vector3 v2) +RMDEF Vector3 Vector3Subtract(Vector3 v1, Vector3 v2) { return (Vector3){ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z }; } +// Multiply vector by scalar +RMDEF Vector3 Vector3Multiply(Vector3 v, float scalar) +{ + v.x *= scalar; + v.y *= scalar; + v.z *= scalar; + + return v; +} + // Calculate two vectors cross product -RMDEF Vector3 VectorCrossProduct(Vector3 v1, Vector3 v2) +RMDEF Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2) { Vector3 result; @@ -327,7 +338,7 @@ RMDEF Vector3 VectorCrossProduct(Vector3 v1, Vector3 v2) } // Calculate one vector perpendicular vector -RMDEF Vector3 VectorPerpendicular(Vector3 v) +RMDEF Vector3 Vector3Perpendicular(Vector3 v) { Vector3 result; @@ -345,25 +356,25 @@ RMDEF Vector3 VectorPerpendicular(Vector3 v) cardinalAxis = (Vector3){0.0f, 0.0f, 1.0f}; } - result = VectorCrossProduct(v, cardinalAxis); + result = Vector3CrossProduct(v, cardinalAxis); return result; } // Calculate vector length -RMDEF float VectorLength(const Vector3 v) +RMDEF float Vector3Length(const Vector3 v) { return sqrtf(v.x*v.x + v.y*v.y + v.z*v.z); } // Calculate two vectors dot product -RMDEF float VectorDotProduct(Vector3 v1, Vector3 v2) +RMDEF float Vector3DotProduct(Vector3 v1, Vector3 v2) { return (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z); } // Calculate distance between two vectors -RMDEF float VectorDistance(Vector3 v1, Vector3 v2) +RMDEF float Vector3Distance(Vector3 v1, Vector3 v2) { float dx = v2.x - v1.x; float dy = v2.y - v1.y; @@ -373,7 +384,7 @@ RMDEF float VectorDistance(Vector3 v1, Vector3 v2) } // Scale provided vector -RMDEF void VectorScale(Vector3 *v, float scale) +RMDEF void Vector3Scale(Vector3 *v, float scale) { v->x *= scale; v->y *= scale; @@ -381,7 +392,7 @@ RMDEF void VectorScale(Vector3 *v, float scale) } // Negate provided vector (invert direction) -RMDEF void VectorNegate(Vector3 *v) +RMDEF void Vector3Negate(Vector3 *v) { v->x = -v->x; v->y = -v->y; @@ -389,11 +400,11 @@ RMDEF void VectorNegate(Vector3 *v) } // Normalize provided vector -RMDEF void VectorNormalize(Vector3 *v) +RMDEF void Vector3Normalize(Vector3 *v) { float length, ilength; - length = VectorLength(*v); + length = Vector3Length(*v); if (length == 0.0f) length = 1.0f; @@ -405,7 +416,7 @@ RMDEF void VectorNormalize(Vector3 *v) } // Transforms a Vector3 by a given Matrix -RMDEF void VectorTransform(Vector3 *v, Matrix mat) +RMDEF void Vector3Transform(Vector3 *v, Matrix mat) { float x = v->x; float y = v->y; @@ -417,7 +428,7 @@ RMDEF void VectorTransform(Vector3 *v, Matrix mat) }; // Calculate linear interpolation between two vectors -RMDEF Vector3 VectorLerp(Vector3 v1, Vector3 v2, float amount) +RMDEF Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount) { Vector3 result; @@ -429,7 +440,7 @@ RMDEF Vector3 VectorLerp(Vector3 v1, Vector3 v2, float amount) } // Calculate reflected vector to normal -RMDEF Vector3 VectorReflect(Vector3 vector, Vector3 normal) +RMDEF Vector3 Vector3Reflect(Vector3 vector, Vector3 normal) { // I is the original vector // N is the normal of the incident plane @@ -437,7 +448,7 @@ RMDEF Vector3 VectorReflect(Vector3 vector, Vector3 normal) Vector3 result; - float dotProduct = VectorDotProduct(vector, normal); + float dotProduct = Vector3DotProduct(vector, normal); result.x = vector.x - (2.0f*normal.x)*dotProduct; result.y = vector.y - (2.0f*normal.y)*dotProduct; @@ -447,7 +458,7 @@ RMDEF Vector3 VectorReflect(Vector3 vector, Vector3 normal) } // Return min value for each pair of components -RMDEF Vector3 VectorMin(Vector3 vec1, Vector3 vec2) +RMDEF Vector3 Vector3Min(Vector3 vec1, Vector3 vec2) { Vector3 result; @@ -459,7 +470,7 @@ RMDEF Vector3 VectorMin(Vector3 vec1, Vector3 vec2) } // Return max value for each pair of components -RMDEF Vector3 VectorMax(Vector3 vec1, Vector3 vec2) +RMDEF Vector3 Vector3Max(Vector3 vec1, Vector3 vec2) { Vector3 result; @@ -472,18 +483,18 @@ RMDEF Vector3 VectorMax(Vector3 vec1, Vector3 vec2) // Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c) // NOTE: Assumes P is on the plane of the triangle -RMDEF Vector3 VectorBarycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c) +RMDEF Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c) { //Vector v0 = b - a, v1 = c - a, v2 = p - a; - Vector3 v0 = VectorSubtract(b, a); - Vector3 v1 = VectorSubtract(c, a); - Vector3 v2 = VectorSubtract(p, a); - float d00 = VectorDotProduct(v0, v0); - float d01 = VectorDotProduct(v0, v1); - float d11 = VectorDotProduct(v1, v1); - float d20 = VectorDotProduct(v2, v0); - float d21 = VectorDotProduct(v2, v1); + Vector3 v0 = Vector3Subtract(b, a); + Vector3 v1 = Vector3Subtract(c, a); + Vector3 v2 = Vector3Subtract(p, a); + float d00 = Vector3DotProduct(v0, v0); + float d01 = Vector3DotProduct(v0, v1); + float d11 = Vector3DotProduct(v1, v1); + float d20 = Vector3DotProduct(v2, v0); + float d21 = Vector3DotProduct(v2, v1); float denom = d00*d11 - d01*d01; @@ -497,7 +508,7 @@ RMDEF Vector3 VectorBarycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c) } // Returns Vector3 as float array -RMDEF float *VectorToFloat(Vector3 vec) +RMDEF float *Vector3ToFloat(Vector3 vec) { static float buffer[3]; @@ -922,12 +933,12 @@ RMDEF Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up) { Matrix result; - Vector3 z = VectorSubtract(eye, target); - VectorNormalize(&z); - Vector3 x = VectorCrossProduct(up, z); - VectorNormalize(&x); - Vector3 y = VectorCrossProduct(z, x); - VectorNormalize(&y); + Vector3 z = Vector3Subtract(eye, target); + Vector3Normalize(&z); + Vector3 x = Vector3CrossProduct(up, z); + Vector3Normalize(&x); + Vector3 y = Vector3CrossProduct(z, x); + Vector3Normalize(&y); result.m0 = x.x; result.m1 = x.y; @@ -1176,11 +1187,11 @@ RMDEF Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle) { Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f }; - if (VectorLength(axis) != 0.0f) + if (Vector3Length(axis) != 0.0f) angle *= 0.5f; - VectorNormalize(&axis); + Vector3Normalize(&axis); float sinres = sinf(angle); float cosres = cosf(angle); -- cgit v1.2.3 From f57367e786089e9bb53f0b245f15e989822fcdb1 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 23 Jul 2017 13:20:35 +0200 Subject: Implemented some changes --- src/raymath.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 11 deletions(-) (limited to 'src/raymath.h') diff --git a/src/raymath.h b/src/raymath.h index e85367c2..855f97b0 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -184,11 +184,15 @@ RMDEF float *MatrixToFloat(Matrix mat); // Returns float //------------------------------------------------------------------------------------ // Functions Declaration to work with Quaternions //------------------------------------------------------------------------------------ +RMDEF Quaternion QuaternionIdentity(void); // Returns identity quaternion RMDEF float QuaternionLength(Quaternion quat); // Compute the length of a quaternion RMDEF void QuaternionNormalize(Quaternion *q); // Normalize provided quaternion RMDEF void QuaternionInvert(Quaternion *quat); // Invert provided quaternion RMDEF Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2); // Calculate two quaternion multiplication -RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float slerp); // Calculates spherical linear interpolation between two quaternions +RMDEF Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount); // Calculate linear interpolation between two quaternions +RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount); // Calculates spherical linear interpolation between two quaternions +RMDEF Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount); // Calculate slerp-optimized interpolation between two quaternions +RMDEF Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to); // Calculate quaternion based on the rotation from one vector to another RMDEF Quaternion QuaternionFromMatrix(Matrix matrix); // Returns a quaternion for a given rotation matrix RMDEF Matrix QuaternionToMatrix(Quaternion q); // Returns a matrix for a given quaternion RMDEF Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle); // Returns rotation quaternion for an angle and axis @@ -991,6 +995,12 @@ RMDEF float *MatrixToFloat(Matrix mat) // Module Functions Definition - Quaternion math //---------------------------------------------------------------------------------- +// Returns identity quaternion +RMDEF Quaternion QuaternionIdentity(void) +{ + return (Quaternion){ 0.0f, 0.0f, 0.0f, 1.0f }; +} + // Computes the length of a quaternion RMDEF float QuaternionLength(Quaternion quat) { @@ -1047,6 +1057,19 @@ RMDEF Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2) return result; } +// Calculate linear interpolation between two quaternions +RMDEF Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount) +{ + Quaternion result; + + result.x = q1.x + amount*(q2.x - q1.x); + result.y = q1.y + amount*(q2.y - q1.y); + result.z = q1.z + amount*(q2.z - q1.z); + result.w = q1.w + amount*(q2.w - q1.w); + + return result; +} + // Calculates spherical linear interpolation between two quaternions RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount) { @@ -1055,6 +1078,7 @@ RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount) float cosHalfTheta = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w; if (fabs(cosHalfTheta) >= 1.0f) result = q1; + else if (cosHalfTheta > 0.95f) result = QuaternionNlerp(q1, q2, amount); else { float halfTheta = acos(cosHalfTheta); @@ -1082,6 +1106,35 @@ RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount) return result; } +// Calculate slerp-optimized interpolation between two quaternions +RMDEF Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount) +{ + Quaternion result = QuaternionLerp(q1, q2, amount); + QuaternionNormalize(&result); + + return result; +} + +// Calculate quaternion based on the rotation from one vector to another +RMDEF Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to) +{ + Quaternion q = { 0 }; + + float cos2Theta = Vector3DotProduct(from, to); + Vector3 cross = Vector3CrossProduct(from, to); + + q.x = cross.x; + q.y = cross.y; + q.z = cross.y; + q.w = 1.0f + cos2Theta; + + QuaternionNormalize(&q); + + Quaternion result = QuaternionNlerp(q, QuaternionIdentity(), 0.5f); + + return result; +} + // Returns a quaternion for a given rotation matrix RMDEF Quaternion QuaternionFromMatrix(Matrix matrix) { @@ -1148,18 +1201,21 @@ RMDEF Matrix QuaternionToMatrix(Quaternion q) float x2 = x + x; float y2 = y + y; float z2 = z + z; + + float length = QuaternionLength(q); + float lenghtSquared = length*length; - float xx = x*x2; - float xy = x*y2; - float xz = x*z2; + float xx = x*x2/lenghtSquared; + float xy = x*y2/lenghtSquared; + float xz = x*z2/lenghtSquared; - float yy = y*y2; - float yz = y*z2; - float zz = z*z2; + float yy = y*y2/lenghtSquared; + float yz = y*z2/lenghtSquared; + float zz = z*z2/lenghtSquared; - float wx = w*x2; - float wy = w*y2; - float wz = w*z2; + float wx = w*x2/lenghtSquared; + float wy = w*y2/lenghtSquared; + float wz = w*z2/lenghtSquared; result.m0 = 1.0f - (yy + zz); result.m1 = xy - wz; @@ -1255,7 +1311,7 @@ RMDEF Quaternion QuaternionFromEuler(float roll, float pitch, float yaw) } // Return the Euler angles equivalent to quaternion (roll, pitch, yaw) -// NOTE: Angles are returned in a Vector3 struct and in degrees +// NOTE: Angles are returned in a Vector3 struct in degrees RMDEF Vector3 QuaternionToEuler(Quaternion q) { Vector3 v = { 0 }; -- cgit v1.2.3 From b2712b6db7c184aff47436f387f2012cf77f4f67 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 23 Jul 2017 17:29:51 +0200 Subject: Corrected issue on QuaternionFromVector3ToVector3() --- src/raymath.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/raymath.h') diff --git a/src/raymath.h b/src/raymath.h index 855f97b0..cd45c0b5 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -1126,13 +1126,15 @@ RMDEF Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to) q.x = cross.x; q.y = cross.y; q.z = cross.y; - q.w = 1.0f + cos2Theta; - - QuaternionNormalize(&q); + q.w = 1.0f + cos2Theta; // NOTE: Added QuaternioIdentity() + + // Normalize to essentially nlerp the original and identity to 0.5 + QuaternionNormalize(&q); - Quaternion result = QuaternionNlerp(q, QuaternionIdentity(), 0.5f); + // Above lines are equivalent to: + //Quaternion result = QuaternionNlerp(q, QuaternionIdentity(), 0.5f); - return result; + return q; } // Returns a quaternion for a given rotation matrix -- cgit v1.2.3 From d071418cba7491ce6302ba14ed84acb8cc5f2063 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 28 Jul 2017 20:58:38 +0200 Subject: Added Vector3MultiplyV() To multiply Vector3 by Vector3 --- src/raymath.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/raymath.h') diff --git a/src/raymath.h b/src/raymath.h index cd45c0b5..a06a4f9e 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -140,6 +140,7 @@ RMDEF Vector3 Vector3Zero(void); // Vector with RMDEF Vector3 Vector3One(void); // Vector with components value 1.0f RMDEF Vector3 Vector3Add(Vector3 v1, Vector3 v2); // Add two vectors RMDEF Vector3 Vector3Multiply(Vector3 v, float scalar); // Multiply vector by scalar +RMDEF Vector3 Vector3MultiplyV(Vector3 v1, Vector3 v2); // Multiply vector by vector RMDEF Vector3 Vector3Subtract(Vector3 v1, Vector3 v2); // Substract two vectors RMDEF Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2); // Calculate two vectors cross product RMDEF Vector3 Vector3Perpendicular(Vector3 v); // Calculate one vector perpendicular vector @@ -329,6 +330,18 @@ RMDEF Vector3 Vector3Multiply(Vector3 v, float scalar) return v; } +// Multiply vector by vector +RMDEF Vector3 Vector3MultiplyV(Vector3 v1, Vector3 v2) +{ + Vector3 result; + + result.x = v1.x * v2.x; + result.y = v1.y * v2.y; + result.z = v1.z * v2.z; + + return result; +} + // Calculate two vectors cross product RMDEF Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2) { -- cgit v1.2.3 From 18bf0ac044e2642ed82f226ba58b0331d0a86ba6 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Wed, 23 Aug 2017 22:55:43 -0400 Subject: Fix typo in raymath.h --- src/raymath.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/raymath.h') diff --git a/src/raymath.h b/src/raymath.h index a06a4f9e..fe0b8947 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -1218,19 +1218,19 @@ RMDEF Matrix QuaternionToMatrix(Quaternion q) float z2 = z + z; float length = QuaternionLength(q); - float lenghtSquared = length*length; + float lengthSquared = length*length; - float xx = x*x2/lenghtSquared; - float xy = x*y2/lenghtSquared; - float xz = x*z2/lenghtSquared; + float xx = x*x2/lengthSquared; + float xy = x*y2/lengthSquared; + float xz = x*z2/lengthSquared; - float yy = y*y2/lenghtSquared; - float yz = y*z2/lenghtSquared; - float zz = z*z2/lenghtSquared; + float yy = y*y2/lengthSquared; + float yz = y*z2/lengthSquared; + float zz = z*z2/lengthSquared; - float wx = w*x2/lenghtSquared; - float wy = w*y2/lenghtSquared; - float wz = w*z2/lenghtSquared; + float wx = w*x2/lengthSquared; + float wy = w*y2/lengthSquared; + float wz = w*z2/lengthSquared; result.m0 = 1.0f - (yy + zz); result.m1 = xy - wz; -- cgit v1.2.3