mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-12 14:28:15 +00:00
18
src/core.c
18
src/core.c
@@ -1521,6 +1521,14 @@ Matrix GetCameraMatrix2D(Camera2D camera)
|
|||||||
|
|
||||||
// Returns the screen space position from a 3d world space position
|
// Returns the screen space position from a 3d world space position
|
||||||
Vector2 GetWorldToScreen(Vector3 position, Camera camera)
|
Vector2 GetWorldToScreen(Vector3 position, Camera camera)
|
||||||
|
{
|
||||||
|
Vector2 screenPosition = GetWorldToScreenEx(position, camera, GetScreenWidth(), GetScreenHeight());
|
||||||
|
|
||||||
|
return screenPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns size position for a 3d world space position (useful for texture drawing)
|
||||||
|
Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int height)
|
||||||
{
|
{
|
||||||
// Calculate projection matrix (from perspective instead of frustum
|
// Calculate projection matrix (from perspective instead of frustum
|
||||||
Matrix matProj = MatrixIdentity();
|
Matrix matProj = MatrixIdentity();
|
||||||
@@ -1528,16 +1536,16 @@ Vector2 GetWorldToScreen(Vector3 position, Camera camera)
|
|||||||
if (camera.type == CAMERA_PERSPECTIVE)
|
if (camera.type == CAMERA_PERSPECTIVE)
|
||||||
{
|
{
|
||||||
// Calculate projection matrix from perspective
|
// Calculate projection matrix from perspective
|
||||||
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), DEFAULT_NEAR_CULL_DISTANCE, DEFAULT_FAR_CULL_DISTANCE);
|
matProj = MatrixPerspective(camera.fovy * DEG2RAD, ((double)width/(double)height), DEFAULT_NEAR_CULL_DISTANCE, DEFAULT_FAR_CULL_DISTANCE);
|
||||||
}
|
}
|
||||||
else if (camera.type == CAMERA_ORTHOGRAPHIC)
|
else if (camera.type == CAMERA_ORTHOGRAPHIC)
|
||||||
{
|
{
|
||||||
float aspect = (float)screenWidth/(float)screenHeight;
|
float aspect = (float)width/(float)height;
|
||||||
double top = camera.fovy/2.0;
|
double top = camera.fovy/2.0;
|
||||||
double right = top*aspect;
|
double right = top*aspect;
|
||||||
|
|
||||||
// Calculate projection matrix from orthographic
|
// Calculate projection matrix from orthographic
|
||||||
matProj = MatrixOrtho(-right, right, -top, top, 0.01, 1000.0);
|
matProj = MatrixOrtho(-right, right, -top, top, DEFAULT_NEAR_CULL_DISTANCE, DEFAULT_FAR_CULL_DISTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate view matrix from camera look at (and transpose it)
|
// Calculate view matrix from camera look at (and transpose it)
|
||||||
@@ -1556,9 +1564,9 @@ Vector2 GetWorldToScreen(Vector3 position, Camera camera)
|
|||||||
Vector3 ndcPos = { worldPos.x/worldPos.w, -worldPos.y/worldPos.w, worldPos.z/worldPos.w };
|
Vector3 ndcPos = { worldPos.x/worldPos.w, -worldPos.y/worldPos.w, worldPos.z/worldPos.w };
|
||||||
|
|
||||||
// Calculate 2d screen position vector
|
// Calculate 2d screen position vector
|
||||||
Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)GetScreenWidth(), (ndcPos.y + 1.0f)/2.0f*(float)GetScreenHeight() };
|
Vector2 sizePosition = { (ndcPos.x + 1.0f)/2.0f*(float)width, (ndcPos.y + 1.0f)/2.0f*(float)height };
|
||||||
|
|
||||||
return screenPosition;
|
return sizePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the screen space position for a 2d camera world space position
|
// Returns the screen space position for a 2d camera world space position
|
||||||
|
@@ -920,6 +920,7 @@ RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Returns a r
|
|||||||
RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix)
|
RLAPI Matrix GetCameraMatrix(Camera camera); // Returns camera transform matrix (view matrix)
|
||||||
RLAPI Matrix GetCameraMatrix2D(Camera2D camera); // Returns camera 2d transform matrix
|
RLAPI Matrix GetCameraMatrix2D(Camera2D camera); // Returns camera 2d transform matrix
|
||||||
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position for a 3d world space position
|
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Returns the screen space position for a 3d world space position
|
||||||
|
RLAPI Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int height); // Returns size position for a 3d world space position
|
||||||
RLAPI Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera); // Returns the screen space position for a 2d camera world space position
|
RLAPI Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera); // Returns the screen space position for a 2d camera world space position
|
||||||
RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Returns the world space position for a 2d camera screen space position
|
RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Returns the world space position for a 2d camera screen space position
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user