@@ -1404,14 +1404,20 @@ void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
1404
1404
//----------------------------------------------------------------------------------
1405
1405
1406
1406
// Get a ray trace from mouse position
1407
- Ray GetMouseRay (Vector2 mouse , Camera camera )
1407
+ Ray GetMouseRay (Vector2 mousePosition , Camera camera )
1408
+ {
1409
+ return GetViewRay (mousePosition , camera , GetScreenWidth (), GetScreenHeight ());
1410
+ }
1411
+
1412
+ // Get a ray trace from the mouse position within a specific section of the screen
1413
+ Ray GetViewRay (Vector2 mousePosition , Camera camera , float width , float height )
1408
1414
{
1409
1415
Ray ray = { 0 };
1410
1416
1411
1417
// Calculate normalized device coordinates
1412
1418
// NOTE: y value is negative
1413
- float x = (2.0f * mouse .x )/( float ) GetScreenWidth () - 1.0f ;
1414
- float y = 1.0f - (2.0f * mouse .y )/( float ) GetScreenHeight () ;
1419
+ float x = (2.0f * mousePosition .x )/width - 1.0f ;
1420
+ float y = 1.0f - (2.0f * mousePosition .y )/height ;
1415
1421
float z = 1.0f ;
1416
1422
1417
1423
// Store values in a vector
@@ -1425,11 +1431,11 @@ Ray GetMouseRay(Vector2 mouse, Camera camera)
1425
1431
if (camera .projection == CAMERA_PERSPECTIVE )
1426
1432
{
1427
1433
// Calculate projection matrix from perspective
1428
- matProj = MatrixPerspective (camera .fovy * DEG2RAD , ((double )GetScreenWidth () /(double )GetScreenHeight () ), RL_CULL_DISTANCE_NEAR , RL_CULL_DISTANCE_FAR );
1434
+ matProj = MatrixPerspective (camera .fovy * DEG2RAD , ((double )width /(double )height ), RL_CULL_DISTANCE_NEAR , RL_CULL_DISTANCE_FAR );
1429
1435
}
1430
1436
else if (camera .projection == CAMERA_ORTHOGRAPHIC )
1431
1437
{
1432
- double aspect = (double )CORE . Window . screen . width /(double )CORE . Window . screen . height ;
1438
+ double aspect = (double )width /(double )height ;
1433
1439
double top = camera .fovy /2.0 ;
1434
1440
double right = top * aspect ;
1435
1441
0 commit comments