This commit is contained in:
Ray 2024-02-04 11:53:04 +01:00
commit d34956b197
6 changed files with 536 additions and 481 deletions

View file

@ -3886,6 +3886,29 @@
}
]
},
{
"name": "GetViewRay",
"description": "Get a ray trace from mouse position in a viewport",
"returnType": "Ray",
"params": [
{
"type": "Vector2",
"name": "mousePosition"
},
{
"type": "Camera",
"name": "camera"
},
{
"type": "float",
"name": "width"
},
{
"type": "float",
"name": "height"
}
]
},
{
"name": "GetCameraMatrix",
"description": "Get camera transform matrix (view matrix)",

View file

@ -3643,6 +3643,17 @@ return {
{type = "Camera", name = "camera"}
}
},
{
name = "GetViewRay",
description = "Get a ray trace from mouse position in a viewport",
returnType = "Ray",
params = {
{type = "Vector2", name = "mousePosition"},
{type = "Camera", name = "camera"},
{type = "float", name = "width"},
{type = "float", name = "height"}
}
},
{
name = "GetCameraMatrix",
description = "Get camera transform matrix (view matrix)",

File diff suppressed because it is too large Load diff

View file

@ -669,7 +669,7 @@
<Param type="unsigned int" name="frames" desc="" />
</Callback>
</Callbacks>
<Functions count="558">
<Functions count="559">
<Function name="InitWindow" retType="void" paramCount="3" desc="Initialize window and OpenGL context">
<Param type="int" name="width" desc="" />
<Param type="int" name="height" desc="" />
@ -906,6 +906,12 @@
<Param type="Vector2" name="mousePosition" desc="" />
<Param type="Camera" name="camera" desc="" />
</Function>
<Function name="GetViewRay" retType="Ray" paramCount="4" desc="Get a ray trace from mouse position in a viewport">
<Param type="Vector2" name="mousePosition" desc="" />
<Param type="Camera" name="camera" desc="" />
<Param type="float" name="width" desc="" />
<Param type="float" name="height" desc="" />
</Function>
<Function name="GetCameraMatrix" retType="Matrix" paramCount="1" desc="Get camera transform matrix (view matrix)">
<Param type="Camera" name="camera" desc="" />
</Function>

View file

@ -1050,6 +1050,7 @@ RLAPI void UnloadShader(Shader shader); // Un
// Screen-space-related functions
RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Get a ray trace from mouse position
RLAPI Ray GetViewRay(Vector2 mousePosition, Camera camera, float width, float height); // Get a ray trace from mouse position in a viewport
RLAPI Matrix GetCameraMatrix(Camera camera); // Get camera transform matrix (view matrix)
RLAPI Matrix GetCameraMatrix2D(Camera2D camera); // Get camera 2d transform matrix
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Get the screen space position for a 3d world space position

View file

@ -1404,14 +1404,20 @@ void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
//----------------------------------------------------------------------------------
// Get a ray trace from mouse position
Ray GetMouseRay(Vector2 mouse, Camera camera)
Ray GetMouseRay(Vector2 mousePosition, Camera camera)
{
return GetViewRay(mousePosition, camera, GetScreenWidth(), GetScreenHeight());
}
// Get a ray trace from the mouse position within a specific section of the screen
Ray GetViewRay(Vector2 mousePosition, Camera camera, float width, float height)
{
Ray ray = { 0 };
// Calculate normalized device coordinates
// NOTE: y value is negative
float x = (2.0f*mouse.x)/(float)GetScreenWidth() - 1.0f;
float y = 1.0f - (2.0f*mouse.y)/(float)GetScreenHeight();
float x = (2.0f*mousePosition.x)/width - 1.0f;
float y = 1.0f - (2.0f*mousePosition.y)/height;
float z = 1.0f;
// Store values in a vector
@ -1425,11 +1431,11 @@ Ray GetMouseRay(Vector2 mouse, Camera camera)
if (camera.projection == CAMERA_PERSPECTIVE)
{
// Calculate projection matrix from perspective
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)width/(double)height), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
}
else if (camera.projection == CAMERA_ORTHOGRAPHIC)
{
double aspect = (double)CORE.Window.screen.width/(double)CORE.Window.screen.height;
double aspect = (double)width/(double)height;
double top = camera.fovy/2.0;
double right = top*aspect;