Skip to content

Commit

Permalink
camera: update check for sphereInFrustum and boudnsInFrustum to defau…
Browse files Browse the repository at this point in the history
…lt to 0f for the z-axes, if not specified (#295)
  • Loading branch information
LeHaine authored Dec 20, 2024
1 parent b3cb028 commit eb6213c
Showing 1 changed file with 27 additions and 31 deletions.
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

0 comments on commit eb6213c

Please sign in to comment.