summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.c6
-rw-r--r--src/raymath.h23
-rw-r--r--src/rlgl.h24
3 files changed, 26 insertions, 27 deletions
diff --git a/src/core.c b/src/core.c
index f40e487e..32eaa70f 100644
--- a/src/core.c
+++ b/src/core.c
@@ -1633,13 +1633,13 @@ Ray GetMouseRay(Vector2 mouse, Camera camera)
}
// Unproject far/near points
- Vector3 nearPoint = rlUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 0.0f }, matProj, matView);
- Vector3 farPoint = rlUnproject((Vector3){ deviceCoords.x, deviceCoords.y, 1.0f }, matProj, matView);
+ Vector3 nearPoint = Vector3Unproject((Vector3){ deviceCoords.x, deviceCoords.y, 0.0f }, matProj, matView);
+ Vector3 farPoint = Vector3Unproject((Vector3){ deviceCoords.x, deviceCoords.y, 1.0f }, matProj, matView);
// Unproject the mouse cursor in the near plane.
// We need this as the source position because orthographic projects, compared to perspect doesn't have a
// convergence point, meaning that the "eye" of the camera is more like a plane than a point.
- Vector3 cameraPlanePointerPos = rlUnproject((Vector3){ deviceCoords.x, deviceCoords.y, -1.0f }, matProj, matView);
+ Vector3 cameraPlanePointerPos = Vector3Unproject((Vector3){ deviceCoords.x, deviceCoords.y, -1.0f }, matProj, matView);
// Calculate normalized direction vector
Vector3 direction = Vector3Normalize(Vector3Subtract(farPoint, nearPoint));
diff --git a/src/raymath.h b/src/raymath.h
index 3faa1d25..3e5e1973 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -1477,4 +1477,27 @@ RMDEF Quaternion QuaternionTransform(Quaternion q, Matrix mat)
return result;
}
+// Projects a Vector3 from screen space into object space
+RMDEF Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view)
+{
+ Vector3 result = { 0.0f, 0.0f, 0.0f };
+
+ // Calculate unproject matrix (multiply view patrix by projection matrix) and invert it
+ Matrix matViewProj = MatrixMultiply(view, projection);
+ matViewProj = MatrixInvert(matViewProj);
+
+ // Create quaternion from source point
+ Quaternion quat = { source.x, source.y, source.z, 1.0f };
+
+ // Multiply quat point by unproject matrix
+ quat = QuaternionTransform(quat, matViewProj);
+
+ // Normalized world points in vectors
+ result.x = quat.x/quat.w;
+ result.y = quat.y/quat.w;
+ result.z = quat.z/quat.w;
+
+ return result;
+}
+
#endif // RAYMATH_H
diff --git a/src/rlgl.h b/src/rlgl.h
index 26701b0c..e508ebf8 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -526,7 +526,6 @@ RLAPI bool rlCheckBufferLimit(int vCount); // Check internal buffer o
RLAPI void rlSetDebugMarker(const char *text); // Set debug marker for analysis
RLAPI void rlSetBlendMode(int glSrcFactor, int glDstFactor, int glEquation); // // Set blending mode factor and equation (using OpenGL factors)
RLAPI void rlLoadExtensions(void *loader); // Load OpenGL extensions
-RLAPI Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view); // Get world coordinates from screen coordinates
// Textures data management
RLAPI unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount); // Load texture in GPU
@@ -1907,29 +1906,6 @@ void rlLoadExtensions(void *loader)
#endif
}
-// Get world coordinates from screen coordinates
-Vector3 rlUnproject(Vector3 source, Matrix proj, Matrix view)
-{
- Vector3 result = { 0.0f, 0.0f, 0.0f };
-
- // Calculate unproject matrix (multiply view patrix by projection matrix) and invert it
- Matrix matViewProj = MatrixMultiply(view, proj);
- matViewProj = MatrixInvert(matViewProj);
-
- // Create quaternion from source point
- Quaternion quat = { source.x, source.y, source.z, 1.0f };
-
- // Multiply quat point by unproject matrix
- quat = QuaternionTransform(quat, matViewProj);
-
- // Normalized world points in vectors
- result.x = quat.x/quat.w;
- result.y = quat.y/quat.w;
- result.z = quat.z/quat.w;
-
- return result;
-}
-
// Convert image data to OpenGL texture (returns OpenGL valid Id)
unsigned int rlLoadTexture(void *data, int width, int height, int format, int mipmapCount)
{