Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

camera: update check for sphereInFrustum and boudnsInFrustum to default to 0f for the z-axes, if not specified #295

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 27 additions & 31 deletions core/src/commonMain/kotlin/com/littlekt/graphics/Camera.kt
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ abstract class Camera {

/** Determines if the given center point and [radius] are within the camera frustum. */
fun sphereInFrustum(cx: Float, cy: Float, radius: Float): Boolean =
sphereInFrustum(cx, cy, 1f, radius)
sphereInFrustum(cx, cy, 0f, radius)

/** Determines if the given point and size are within the camera frustum. */
fun boundsInFrustum(px: Float, py: Float, width: Float, height: Float): Boolean =
boundsInFrustum(px, py, 1f, width, height, 0f)
boundsInFrustum(px, py, 0f, width, height, 0f)

/** Determines if the given center point and [radius] are within the camera frustum. */
abstract fun sphereInFrustum(cx: Float, cy: Float, cz: Float, radius: Float): Boolean
Expand All @@ -208,7 +208,7 @@ abstract class Camera {
pz: Float,
width: Float,
height: Float,
length: Float
length: Float,
): Boolean

fun project(world: Vec2f, result: MutableVec2f): Boolean {
Expand Down Expand Up @@ -246,7 +246,7 @@ abstract class Camera {
viewport.x.toFloat(),
viewport.y.toFloat(),
viewport.width.toFloat(),
viewport.height.toFloat()
viewport.height.toFloat(),
)

/**
Expand Down Expand Up @@ -276,7 +276,7 @@ abstract class Camera {
context: Context,
world: Vec2f,
viewport: Viewport,
result: MutableVec2f
result: MutableVec2f,
): Boolean =
worldToScreen(
context,
Expand All @@ -285,7 +285,7 @@ abstract class Camera {
viewport.y.toFloat(),
viewport.width.toFloat(),
viewport.height.toFloat(),
result
result,
)

/**
Expand All @@ -308,7 +308,7 @@ abstract class Camera {
viewport.y.toFloat(),
viewport.width.toFloat(),
viewport.height.toFloat(),
result
result,
)

/**
Expand All @@ -333,7 +333,7 @@ abstract class Camera {
viewportY,
viewportWidth,
viewportHeight,
result
result,
)
return result
}
Expand All @@ -360,7 +360,7 @@ abstract class Camera {
viewportY,
viewportWidth,
viewportHeight,
result
result,
)

/**
Expand Down Expand Up @@ -396,7 +396,7 @@ abstract class Camera {
context: Context,
world: Vec3f,
viewport: Viewport,
result: MutableVec3f
result: MutableVec3f,
): Boolean =
worldToScreen(
context,
Expand All @@ -405,7 +405,7 @@ abstract class Camera {
viewport.y.toFloat(),
viewport.width.toFloat(),
viewport.height.toFloat(),
result
result,
)

/**
Expand Down Expand Up @@ -449,7 +449,7 @@ abstract class Camera {
viewportY,
viewportWidth,
viewportHeight,
result
result,
)
return result
}
Expand Down Expand Up @@ -477,7 +477,7 @@ abstract class Camera {
viewportY,
viewportWidth,
viewportHeight,
result
result,
)

/**
Expand Down Expand Up @@ -534,7 +534,7 @@ abstract class Camera {
viewport.x.toFloat(),
viewport.y.toFloat(),
viewport.width.toFloat(),
viewport.height.toFloat()
viewport.height.toFloat(),
)

/**
Expand All @@ -559,7 +559,7 @@ abstract class Camera {
viewportY,
viewportWidth,
viewportHeight,
result
result,
)
return result
}
Expand Down Expand Up @@ -587,7 +587,7 @@ abstract class Camera {
viewportY,
viewportWidth,
viewportHeight,
result
result,
)

/**
Expand All @@ -601,7 +601,7 @@ abstract class Camera {
x: Float,
y: Float,
viewport: Viewport,
result: MutableVec2f
result: MutableVec2f,
): Boolean = screenToWorld(context, tempVec2.set(x, y), viewport, result)

/**
Expand All @@ -614,7 +614,7 @@ abstract class Camera {
context: Context,
screen: MutableVec2f,
viewport: Viewport,
result: MutableVec2f
result: MutableVec2f,
): Boolean =
screenToWorld(
context,
Expand All @@ -623,7 +623,7 @@ abstract class Camera {
viewport.y.toFloat(),
viewport.width.toFloat(),
viewport.height.toFloat(),
result
result,
)

/**
Expand Down Expand Up @@ -656,18 +656,14 @@ abstract class Camera {
*
* @return a newly create [MutableVec3f] containing the calculated world coordinates.
*/
fun screenToWorld(
context: Context,
screen: Vec3f,
viewport: Viewport,
): MutableVec3f =
fun screenToWorld(context: Context, screen: Vec3f, viewport: Viewport): MutableVec3f =
screenToWorld(
context,
screen,
viewport.x.toFloat(),
viewport.y.toFloat(),
viewport.width.toFloat(),
viewport.height.toFloat()
viewport.height.toFloat(),
)

/**
Expand Down Expand Up @@ -711,7 +707,7 @@ abstract class Camera {
viewportY,
viewportWidth,
viewportHeight,
result
result,
)
return result
}
Expand Down Expand Up @@ -740,7 +736,7 @@ abstract class Camera {
viewportY,
viewportWidth,
viewportHeight,
result
result,
)

/**
Expand All @@ -762,7 +758,7 @@ abstract class Camera {
viewport.y.toFloat(),
viewport.width.toFloat(),
viewport.height.toFloat(),
result
result,
)

/**
Expand All @@ -787,7 +783,7 @@ abstract class Camera {
2f * x / viewportWidth - 1f,
2f * y / viewportHeight - 1f,
2f * screen.z - 1f,
1f
1f,
)
invViewProjection.transform(tempVec4)
val s = 1f / tempVec4.w
Expand Down Expand Up @@ -819,7 +815,7 @@ abstract class Camera {
viewportY,
viewportWidth,
viewportHeight,
pickRay.origin
pickRay.origin,
)
valid =
valid &&
Expand All @@ -830,7 +826,7 @@ abstract class Camera {
viewportY,
viewportWidth,
viewportHeight,
pickRay.direction
pickRay.direction,
)

if (valid) {
Expand Down
Loading