KStarbound/src/main/kotlin/ru/dbotthepony/kbox2d/api/Distance.kt
2022-02-17 11:49:50 +07:00

73 lines
1.6 KiB
Kotlin

package ru.dbotthepony.kbox2d.api
import ru.dbotthepony.kstarbound.math.Vector2d
/**
* A distance proxy is used by the GJK algorithm.
* It encapsulates any shape.
*/
interface IDistanceProxy {
val vertices: List<Vector2d>
val radius: Double
/**
* Get the supporting vertex index in the given direction.
*/
fun getSupport(d: Vector2d): Int
/**
* Get the supporting vertex in the given direction.
*/
fun getSupportVertex(d: Vector2d): Vector2d
}
/**
* Used to warm start b2Distance.
* Set count to zero on first call.
*/
data class SimplexCache(
val metric: Double = 0.0, ///< length or area
val count: Int = 0,
val indexA: IntArray = IntArray(0), ///< vertices on shape A
val indexB: IntArray = IntArray(0), ///< vertices on shape B
)
/**
* Input for b2Distance.
* You have to option to use the shape radii
* in the computation. Even
*/
data class DistanceInput(
var proxyA: IDistanceProxy,
var proxyB: IDistanceProxy,
var transformA: Transform = Transform(),
var transformB: Transform = Transform(),
var useRadii: Boolean = false
)
/**
* Output for b2Distance.
*/
data class DistanceOutput(
val pointA: Vector2d, ///< closest point on shapeA
val pointB: Vector2d, ///< closest point on shapeB
val distance: Double,
val iterations: Int, ///< number of GJK iterations used
val newCache: SimplexCache
)
data class ShapeCastInput(
var proxyA: IDistanceProxy,
var proxyB: IDistanceProxy,
var transformA: Transform,
var transformB: Transform,
var translationB: Vector2d,
)
data class ShapeCastOutput(
var point: Vector2d = Vector2d.ZERO,
var normal: Vector2d = Vector2d.ZERO,
var lambda: Double = 1.0,
var iterations: Int = 0,
)