Rename Body to B2Body and Fixture to B2Fixture
This commit is contained in:
parent
27a870fcf0
commit
6b32d0f0c4
@ -1,6 +1,6 @@
|
|||||||
package ru.dbotthepony.kbox2d.api
|
package ru.dbotthepony.kbox2d.api
|
||||||
|
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Body
|
import ru.dbotthepony.kbox2d.dynamics.B2Body
|
||||||
import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact
|
import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact
|
||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ data class ContactRegister(
|
|||||||
* nodes, one for each attached body.
|
* nodes, one for each attached body.
|
||||||
*/
|
*/
|
||||||
data class ContactEdge(
|
data class ContactEdge(
|
||||||
val other: Body, ///< provides quick access to the other body attached.
|
val other: B2Body, ///< provides quick access to the other body attached.
|
||||||
val contact: AbstractContact, ///< the contact
|
val contact: AbstractContact, ///< the contact
|
||||||
var prev: ContactEdge? = null, ///< the previous contact edge in the body's contact list
|
var prev: ContactEdge? = null, ///< the previous contact edge in the body's contact list
|
||||||
var next: ContactEdge? = null, ///< the next contact edge in the body's contact list
|
var next: ContactEdge? = null, ///< the next contact edge in the body's contact list
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package ru.dbotthepony.kbox2d.api
|
package ru.dbotthepony.kbox2d.api
|
||||||
|
|
||||||
import ru.dbotthepony.kbox2d.collision.e_nullProxy
|
import ru.dbotthepony.kbox2d.collision.e_nullProxy
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Fixture
|
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
||||||
import ru.dbotthepony.kvector.util2d.AABB
|
import ru.dbotthepony.kvector.util2d.AABB
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
|
||||||
|
|
||||||
sealed interface IFilter {
|
sealed interface IFilter {
|
||||||
/**
|
/**
|
||||||
@ -81,7 +80,7 @@ data class FixtureDef(
|
|||||||
|
|
||||||
data class FixtureProxy(
|
data class FixtureProxy(
|
||||||
var aabb: AABB,
|
var aabb: AABB,
|
||||||
val fixture: Fixture,
|
val fixture: B2Fixture,
|
||||||
val childIndex: Int,
|
val childIndex: Int,
|
||||||
) {
|
) {
|
||||||
private var setProxyID = false
|
private var setProxyID = false
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package ru.dbotthepony.kbox2d.api
|
package ru.dbotthepony.kbox2d.api
|
||||||
|
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Body
|
import ru.dbotthepony.kbox2d.dynamics.B2Body
|
||||||
import ru.dbotthepony.kbox2d.dynamics.joint.AbstractJoint
|
import ru.dbotthepony.kbox2d.dynamics.joint.AbstractJoint
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
@ -13,8 +13,8 @@ data class StiffnessResult(val stiffness: Double, val damping: Double)
|
|||||||
fun b2LinearStiffness(
|
fun b2LinearStiffness(
|
||||||
frequencyHertz: Double,
|
frequencyHertz: Double,
|
||||||
dampingRatio: Double,
|
dampingRatio: Double,
|
||||||
bodyA: Body?,
|
bodyA: B2Body?,
|
||||||
bodyB: Body?,
|
bodyB: B2Body?,
|
||||||
): StiffnessResult {
|
): StiffnessResult {
|
||||||
val massA = bodyA?.mass ?: 0.0
|
val massA = bodyA?.mass ?: 0.0
|
||||||
val massB = bodyB?.mass ?: 0.0
|
val massB = bodyB?.mass ?: 0.0
|
||||||
@ -42,8 +42,8 @@ fun b2LinearStiffness(
|
|||||||
fun b2AngularStiffness(
|
fun b2AngularStiffness(
|
||||||
frequencyHertz: Double,
|
frequencyHertz: Double,
|
||||||
dampingRatio: Double,
|
dampingRatio: Double,
|
||||||
bodyA: Body?,
|
bodyA: B2Body?,
|
||||||
bodyB: Body?,
|
bodyB: B2Body?,
|
||||||
): StiffnessResult {
|
): StiffnessResult {
|
||||||
val inertiaA = bodyA?.inertia ?: 0.0
|
val inertiaA = bodyA?.inertia ?: 0.0
|
||||||
val inertiaB = bodyB?.inertia ?: 0.0
|
val inertiaB = bodyB?.inertia ?: 0.0
|
||||||
@ -92,13 +92,13 @@ data class Jacobian(
|
|||||||
* nodes, one for each attached body.
|
* nodes, one for each attached body.
|
||||||
*/
|
*/
|
||||||
class JointEdge(
|
class JointEdge(
|
||||||
other: Body?, ///< provides quick access to the other body attached.
|
other: B2Body?, ///< provides quick access to the other body attached.
|
||||||
val joint: AbstractJoint, ///< the joint
|
val joint: AbstractJoint, ///< the joint
|
||||||
var prev: JointEdge? = null, ///< the previous joint edge in the body's joint list
|
var prev: JointEdge? = null, ///< the previous joint edge in the body's joint list
|
||||||
var next: JointEdge? = null ///< the next joint edge in the body's joint list
|
var next: JointEdge? = null ///< the next joint edge in the body's joint list
|
||||||
) {
|
) {
|
||||||
val otherNullable: Body? = other
|
val otherNullable: B2Body? = other
|
||||||
val other: Body get() = checkNotNull(otherNullable) { "Other body is not present" }
|
val other: B2Body get() = checkNotNull(otherNullable) { "Other body is not present" }
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed interface IJointDef {
|
sealed interface IJointDef {
|
||||||
@ -110,12 +110,12 @@ sealed interface IJointDef {
|
|||||||
/**
|
/**
|
||||||
* The first attached body.
|
* The first attached body.
|
||||||
*/
|
*/
|
||||||
val bodyA: Body?
|
val bodyA: B2Body?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The second attached body.
|
* The second attached body.
|
||||||
*/
|
*/
|
||||||
val bodyB: Body?
|
val bodyB: B2Body?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set this flag to true if the attached bodies should collide.
|
* Set this flag to true if the attached bodies should collide.
|
||||||
@ -129,8 +129,8 @@ sealed interface IJointDef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DistanceJointDef(
|
class DistanceJointDef(
|
||||||
b1: Body,
|
b1: B2Body,
|
||||||
b2: Body,
|
b2: B2Body,
|
||||||
anchor1: Vector2d,
|
anchor1: Vector2d,
|
||||||
anchor2: Vector2d
|
anchor2: Vector2d
|
||||||
) : IJointDef {
|
) : IJointDef {
|
||||||
@ -161,8 +161,8 @@ class DistanceJointDef(
|
|||||||
*/
|
*/
|
||||||
val damping: Double = 0.0
|
val damping: Double = 0.0
|
||||||
|
|
||||||
override var bodyA: Body = b1
|
override var bodyA: B2Body = b1
|
||||||
override var bodyB: Body = b2
|
override var bodyB: B2Body = b2
|
||||||
|
|
||||||
override var collideConnected: Boolean = false
|
override var collideConnected: Boolean = false
|
||||||
override var userData: Any? = null
|
override var userData: Any? = null
|
||||||
@ -186,13 +186,13 @@ class DistanceJointDef(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RevoluteJointDef(
|
class RevoluteJointDef(
|
||||||
b1: Body,
|
b1: B2Body,
|
||||||
b2: Body,
|
b2: B2Body,
|
||||||
anchor: Vector2d,
|
anchor: Vector2d,
|
||||||
) : IJointDef {
|
) : IJointDef {
|
||||||
override val type: JointType = JointType.REVOLUTE
|
override val type: JointType = JointType.REVOLUTE
|
||||||
override var bodyA: Body = b1
|
override var bodyA: B2Body = b1
|
||||||
override var bodyB: Body = b2
|
override var bodyB: B2Body = b2
|
||||||
override var collideConnected: Boolean = false
|
override var collideConnected: Boolean = false
|
||||||
override var userData: Any? = null
|
override var userData: Any? = null
|
||||||
|
|
||||||
@ -245,14 +245,14 @@ class RevoluteJointDef(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PrismaticJointDef(
|
class PrismaticJointDef(
|
||||||
b1: Body,
|
b1: B2Body,
|
||||||
b2: Body,
|
b2: B2Body,
|
||||||
anchor: Vector2d,
|
anchor: Vector2d,
|
||||||
axis: Vector2d,
|
axis: Vector2d,
|
||||||
) : IJointDef {
|
) : IJointDef {
|
||||||
override val type: JointType = JointType.PRISMATIC
|
override val type: JointType = JointType.PRISMATIC
|
||||||
override var bodyA: Body = b1
|
override var bodyA: B2Body = b1
|
||||||
override var bodyB: Body = b2
|
override var bodyB: B2Body = b2
|
||||||
override var collideConnected: Boolean = false
|
override var collideConnected: Boolean = false
|
||||||
override var userData: Any? = null
|
override var userData: Any? = null
|
||||||
|
|
||||||
@ -312,8 +312,8 @@ class PrismaticJointDef(
|
|||||||
* two dynamic body anchor points, and a pulley ratio.
|
* two dynamic body anchor points, and a pulley ratio.
|
||||||
*/
|
*/
|
||||||
class PulleyJointDef(
|
class PulleyJointDef(
|
||||||
b1: Body,
|
b1: B2Body,
|
||||||
b2: Body,
|
b2: B2Body,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The first ground anchor in world coordinates. This point never moves.
|
* The first ground anchor in world coordinates. This point never moves.
|
||||||
@ -330,8 +330,8 @@ class PulleyJointDef(
|
|||||||
ratio: Double,
|
ratio: Double,
|
||||||
) : IJointDef {
|
) : IJointDef {
|
||||||
override val type: JointType = JointType.PULLEY
|
override val type: JointType = JointType.PULLEY
|
||||||
override var bodyA: Body = b1
|
override var bodyA: B2Body = b1
|
||||||
override var bodyB: Body = b2
|
override var bodyB: B2Body = b2
|
||||||
override var collideConnected: Boolean = false
|
override var collideConnected: Boolean = false
|
||||||
override var userData: Any? = null
|
override var userData: Any? = null
|
||||||
|
|
||||||
@ -376,8 +376,8 @@ class PulleyJointDef(
|
|||||||
* @warning bodyB on the input joints must both be dynamic
|
* @warning bodyB on the input joints must both be dynamic
|
||||||
*/
|
*/
|
||||||
class GearJointDef(
|
class GearJointDef(
|
||||||
override var bodyA: Body,
|
override var bodyA: B2Body,
|
||||||
override var bodyB: Body,
|
override var bodyB: B2Body,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The first revolute/prismatic joint attached to the gear joint.
|
* The first revolute/prismatic joint attached to the gear joint.
|
||||||
@ -417,8 +417,8 @@ class MouseJointDef(
|
|||||||
*/
|
*/
|
||||||
var target: Vector2d,
|
var target: Vector2d,
|
||||||
|
|
||||||
override var bodyB: Body,
|
override var bodyB: B2Body,
|
||||||
override val bodyA: Body? = null,
|
override val bodyA: B2Body? = null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum constraint force that can be exerted
|
* The maximum constraint force that can be exerted
|
||||||
@ -437,8 +437,8 @@ class MouseJointDef(
|
|||||||
fun linearStiffness(
|
fun linearStiffness(
|
||||||
frequencyHertz: Double,
|
frequencyHertz: Double,
|
||||||
dampingRatio: Double,
|
dampingRatio: Double,
|
||||||
bodyA: Body?,
|
bodyA: B2Body?,
|
||||||
bodyB: Body?
|
bodyB: B2Body?
|
||||||
): MouseJointDef {
|
): MouseJointDef {
|
||||||
val (stiffness, damping) = b2LinearStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
val (stiffness, damping) = b2LinearStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
||||||
this.stiffness = stiffness
|
this.stiffness = stiffness
|
||||||
@ -449,8 +449,8 @@ class MouseJointDef(
|
|||||||
fun angularStiffness(
|
fun angularStiffness(
|
||||||
frequencyHertz: Double,
|
frequencyHertz: Double,
|
||||||
dampingRatio: Double,
|
dampingRatio: Double,
|
||||||
bodyA: Body?,
|
bodyA: B2Body?,
|
||||||
bodyB: Body?
|
bodyB: B2Body?
|
||||||
): MouseJointDef {
|
): MouseJointDef {
|
||||||
val (stiffness, damping) = b2AngularStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
val (stiffness, damping) = b2AngularStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
||||||
this.stiffness = stiffness
|
this.stiffness = stiffness
|
||||||
@ -468,8 +468,8 @@ class MouseJointDef(
|
|||||||
* anchors and a local axis helps when saving and loading a game.
|
* anchors and a local axis helps when saving and loading a game.
|
||||||
*/
|
*/
|
||||||
class WheelJointDef(
|
class WheelJointDef(
|
||||||
override var bodyA: Body,
|
override var bodyA: B2Body,
|
||||||
override var bodyB: Body,
|
override var bodyB: B2Body,
|
||||||
anchor: Vector2d,
|
anchor: Vector2d,
|
||||||
axis: Vector2d,
|
axis: Vector2d,
|
||||||
|
|
||||||
@ -535,8 +535,8 @@ class WheelJointDef(
|
|||||||
fun linearStiffness(
|
fun linearStiffness(
|
||||||
frequencyHertz: Double,
|
frequencyHertz: Double,
|
||||||
dampingRatio: Double,
|
dampingRatio: Double,
|
||||||
bodyA: Body = this.bodyA,
|
bodyA: B2Body = this.bodyA,
|
||||||
bodyB: Body = this.bodyB
|
bodyB: B2Body = this.bodyB
|
||||||
): WheelJointDef {
|
): WheelJointDef {
|
||||||
val (stiffness, damping) = b2LinearStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
val (stiffness, damping) = b2LinearStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
||||||
this.stiffness = stiffness
|
this.stiffness = stiffness
|
||||||
@ -547,8 +547,8 @@ class WheelJointDef(
|
|||||||
fun angularStiffness(
|
fun angularStiffness(
|
||||||
frequencyHertz: Double,
|
frequencyHertz: Double,
|
||||||
dampingRatio: Double,
|
dampingRatio: Double,
|
||||||
bodyA: Body = this.bodyA,
|
bodyA: B2Body = this.bodyA,
|
||||||
bodyB: Body = this.bodyB
|
bodyB: B2Body = this.bodyB
|
||||||
): WheelJointDef {
|
): WheelJointDef {
|
||||||
val (stiffness, damping) = b2AngularStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
val (stiffness, damping) = b2AngularStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
||||||
this.stiffness = stiffness
|
this.stiffness = stiffness
|
||||||
@ -563,8 +563,8 @@ class WheelJointDef(
|
|||||||
* of the anchor points is important for computing the reaction torque.
|
* of the anchor points is important for computing the reaction torque.
|
||||||
*/
|
*/
|
||||||
class WeldJointDef(
|
class WeldJointDef(
|
||||||
override var bodyA: Body,
|
override var bodyA: B2Body,
|
||||||
override var bodyB: Body,
|
override var bodyB: B2Body,
|
||||||
anchor: Vector2d,
|
anchor: Vector2d,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -599,8 +599,8 @@ class WeldJointDef(
|
|||||||
fun linearStiffness(
|
fun linearStiffness(
|
||||||
frequencyHertz: Double,
|
frequencyHertz: Double,
|
||||||
dampingRatio: Double,
|
dampingRatio: Double,
|
||||||
bodyA: Body = this.bodyA,
|
bodyA: B2Body = this.bodyA,
|
||||||
bodyB: Body = this.bodyB
|
bodyB: B2Body = this.bodyB
|
||||||
): WeldJointDef {
|
): WeldJointDef {
|
||||||
val (stiffness, damping) = b2LinearStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
val (stiffness, damping) = b2LinearStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
||||||
this.stiffness = stiffness
|
this.stiffness = stiffness
|
||||||
@ -611,8 +611,8 @@ class WeldJointDef(
|
|||||||
fun angularStiffness(
|
fun angularStiffness(
|
||||||
frequencyHertz: Double,
|
frequencyHertz: Double,
|
||||||
dampingRatio: Double,
|
dampingRatio: Double,
|
||||||
bodyA: Body = this.bodyA,
|
bodyA: B2Body = this.bodyA,
|
||||||
bodyB: Body = this.bodyB
|
bodyB: B2Body = this.bodyB
|
||||||
): WeldJointDef {
|
): WeldJointDef {
|
||||||
val (stiffness, damping) = b2AngularStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
val (stiffness, damping) = b2AngularStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
|
||||||
this.stiffness = stiffness
|
this.stiffness = stiffness
|
||||||
@ -625,8 +625,8 @@ class WeldJointDef(
|
|||||||
* Friction joint definition.
|
* Friction joint definition.
|
||||||
*/
|
*/
|
||||||
class FrictionJointDef(
|
class FrictionJointDef(
|
||||||
override var bodyA: Body,
|
override var bodyA: B2Body,
|
||||||
override var bodyB: Body,
|
override var bodyB: B2Body,
|
||||||
anchor: Vector2d,
|
anchor: Vector2d,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -656,8 +656,8 @@ class FrictionJointDef(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MotorJointDef(
|
class MotorJointDef(
|
||||||
override var bodyA: Body,
|
override var bodyA: B2Body,
|
||||||
override var bodyB: Body,
|
override var bodyB: B2Body,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum motor force in N.
|
* The maximum motor force in N.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package ru.dbotthepony.kbox2d.api
|
package ru.dbotthepony.kbox2d.api
|
||||||
|
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Fixture
|
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
||||||
import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact
|
import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact
|
||||||
import ru.dbotthepony.kbox2d.dynamics.joint.AbstractJoint
|
import ru.dbotthepony.kbox2d.dynamics.joint.AbstractJoint
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
@ -14,7 +14,7 @@ interface IContactFilter {
|
|||||||
* Return true if contact calculations should be performed between these two shapes.
|
* Return true if contact calculations should be performed between these two shapes.
|
||||||
* @warning for performance reasons this is only called when the AABBs begin to overlap.
|
* @warning for performance reasons this is only called when the AABBs begin to overlap.
|
||||||
*/
|
*/
|
||||||
fun shouldCollide(fixtureA: Fixture, fixtureB: Fixture): Boolean
|
fun shouldCollide(fixtureA: B2Fixture, fixtureB: B2Fixture): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +33,7 @@ interface IDestructionListener {
|
|||||||
* Called when any fixture is about to be destroyed due
|
* Called when any fixture is about to be destroyed due
|
||||||
* to the destruction of its parent body.
|
* to the destruction of its parent body.
|
||||||
*/
|
*/
|
||||||
fun sayGoodbye(fixture: Fixture)
|
fun sayGoodbye(fixture: B2Fixture)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,7 +111,7 @@ fun interface IQueryCallback {
|
|||||||
* Called for each fixture found in the query AABB.
|
* Called for each fixture found in the query AABB.
|
||||||
* @return false to terminate the query.
|
* @return false to terminate the query.
|
||||||
*/
|
*/
|
||||||
fun reportFixture(fixture: Fixture): Boolean
|
fun reportFixture(fixture: B2Fixture): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,5 +138,5 @@ fun interface IRayCastCallback {
|
|||||||
* @return -1 to filter, 0 to terminate, fraction to clip the ray for
|
* @return -1 to filter, 0 to terminate, fraction to clip the ray for
|
||||||
* closest hit, 1 to continue
|
* closest hit, 1 to continue
|
||||||
*/
|
*/
|
||||||
fun reportFixture(fixture: Fixture, point: Vector2d, normal: Vector2d, fraction: Double): Double
|
fun reportFixture(fixture: B2Fixture, point: Vector2d, normal: Vector2d, fraction: Double): Double
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package ru.dbotthepony.kbox2d.dynamics
|
|||||||
import ru.dbotthepony.kbox2d.api.*
|
import ru.dbotthepony.kbox2d.api.*
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
|
|
||||||
class Body(def: BodyDef, world: B2World) {
|
class B2Body(def: BodyDef, world: B2World) {
|
||||||
private var _world: B2World? = world
|
private var _world: B2World? = world
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,7 +101,7 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
var fixtureList: Fixture? = null
|
var fixtureList: B2Fixture? = null
|
||||||
protected set
|
protected set
|
||||||
|
|
||||||
var fixtureCount: Int = 0
|
var fixtureCount: Int = 0
|
||||||
@ -159,20 +159,20 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var next: Body? = null
|
var next: B2Body? = null
|
||||||
internal set
|
internal set
|
||||||
var prev: Body? = null
|
var prev: B2Body? = null
|
||||||
internal set
|
internal set
|
||||||
|
|
||||||
val fixtureIterator: Iterator<Fixture> get() {
|
val fixtureIterator: Iterator<B2Fixture> get() {
|
||||||
return object : Iterator<Fixture> {
|
return object : Iterator<B2Fixture> {
|
||||||
private var node = fixtureList
|
private var node = fixtureList
|
||||||
|
|
||||||
override fun hasNext(): Boolean {
|
override fun hasNext(): Boolean {
|
||||||
return node != null
|
return node != null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun next(): Fixture {
|
override fun next(): B2Fixture {
|
||||||
val old = node!!
|
val old = node!!
|
||||||
node = old.next
|
node = old.next
|
||||||
return old
|
return old
|
||||||
@ -273,7 +273,7 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
val broadPhase = world.contactManager.broadPhase
|
val broadPhase = world.contactManager.broadPhase
|
||||||
|
|
||||||
for (fixture in fixtureIterator) {
|
for (fixture in fixtureIterator) {
|
||||||
(fixture as Fixture).createProxies(broadPhase, transform)
|
(fixture as B2Fixture).createProxies(broadPhase, transform)
|
||||||
}
|
}
|
||||||
|
|
||||||
world.notifyNewContacts()
|
world.notifyNewContacts()
|
||||||
@ -284,7 +284,7 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
val broadPhase = world.contactManager.broadPhase
|
val broadPhase = world.contactManager.broadPhase
|
||||||
|
|
||||||
for (fixture in fixtureIterator) {
|
for (fixture in fixtureIterator) {
|
||||||
(fixture as Fixture).destroyProxies(broadPhase)
|
(fixture as B2Fixture).destroyProxies(broadPhase)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the attached contacts.
|
// Destroy the attached contacts.
|
||||||
@ -362,7 +362,7 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
contactEdge = null
|
contactEdge = null
|
||||||
|
|
||||||
val broadPhase = world.contactManager.broadPhase
|
val broadPhase = world.contactManager.broadPhase
|
||||||
var f: Fixture? = fixtureList
|
var f: B2Fixture? = fixtureList
|
||||||
|
|
||||||
while (f != null) {
|
while (f != null) {
|
||||||
for (proxy in f.proxies) {
|
for (proxy in f.proxies) {
|
||||||
@ -381,11 +381,11 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
* @param def the fixture definition.
|
* @param def the fixture definition.
|
||||||
* @warning This function is locked during callbacks.
|
* @warning This function is locked during callbacks.
|
||||||
*/
|
*/
|
||||||
fun createFixture(def: FixtureDef): Fixture {
|
fun createFixture(def: FixtureDef): B2Fixture {
|
||||||
if (world.isLocked)
|
if (world.isLocked)
|
||||||
throw ConcurrentModificationException()
|
throw ConcurrentModificationException()
|
||||||
|
|
||||||
val fixture = Fixture(this, def)
|
val fixture = B2Fixture(this, def)
|
||||||
|
|
||||||
if (isEnabled) {
|
if (isEnabled) {
|
||||||
fixture.createProxies(world.contactManager.broadPhase, transform)
|
fixture.createProxies(world.contactManager.broadPhase, transform)
|
||||||
@ -416,7 +416,7 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
* @param density the shape density (set to zero for static bodies).
|
* @param density the shape density (set to zero for static bodies).
|
||||||
* @warning This function is locked during callbacks.
|
* @warning This function is locked during callbacks.
|
||||||
*/
|
*/
|
||||||
fun createFixture(shape: IShape<*>, density: Double): Fixture {
|
fun createFixture(shape: IShape<*>, density: Double): B2Fixture {
|
||||||
return createFixture(
|
return createFixture(
|
||||||
FixtureDef(
|
FixtureDef(
|
||||||
shape = shape,
|
shape = shape,
|
||||||
@ -434,16 +434,16 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
* @param fixture the fixture to be removed.
|
* @param fixture the fixture to be removed.
|
||||||
* @warning This function is locked during callbacks.
|
* @warning This function is locked during callbacks.
|
||||||
*/
|
*/
|
||||||
fun destroyFixture(fixture: Fixture) {
|
fun destroyFixture(fixture: B2Fixture) {
|
||||||
if (world.isLocked)
|
if (world.isLocked)
|
||||||
throw ConcurrentModificationException()
|
throw ConcurrentModificationException()
|
||||||
|
|
||||||
require(fixture.body == this) { "$fixture does not belong to $this (belongs to ${fixture.body})" }
|
require(fixture.body == this) { "$fixture does not belong to $this (belongs to ${fixture.body})" }
|
||||||
check(fixtureCount > 0) { "Having no tracked fixtures, but $fixture belongs to us" }
|
check(fixtureCount > 0) { "Having no tracked fixtures, but $fixture belongs to us" }
|
||||||
|
|
||||||
var node: Fixture? = fixtureList
|
var node: B2Fixture? = fixtureList
|
||||||
var found = false
|
var found = false
|
||||||
var previous: Fixture? = null
|
var previous: B2Fixture? = null
|
||||||
|
|
||||||
while (node != null) {
|
while (node != null) {
|
||||||
if (node == fixture) {
|
if (node == fixture) {
|
||||||
@ -478,7 +478,7 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fixture as Fixture
|
fixture as B2Fixture
|
||||||
|
|
||||||
if (isEnabled) {
|
if (isEnabled) {
|
||||||
fixture.destroyProxies(world.contactManager.broadPhase)
|
fixture.destroyProxies(world.contactManager.broadPhase)
|
||||||
@ -605,7 +605,7 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
linearVelocity += b2Cross(angularVelocity, sweep.c - oldCenter)
|
linearVelocity += b2Cross(angularVelocity, sweep.c - oldCenter)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun shouldCollide(other: Body): Boolean {
|
internal fun shouldCollide(other: B2Body): Boolean {
|
||||||
// At least one body should be dynamic.
|
// At least one body should be dynamic.
|
||||||
if (type != BodyType.DYNAMIC && other.type != BodyType.DYNAMIC)
|
if (type != BodyType.DYNAMIC && other.type != BodyType.DYNAMIC)
|
||||||
return false
|
return false
|
||||||
@ -654,7 +654,7 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
val broadPhase = world.contactManager.broadPhase
|
val broadPhase = world.contactManager.broadPhase
|
||||||
|
|
||||||
for (fixture in fixtureIterator) {
|
for (fixture in fixtureIterator) {
|
||||||
(fixture as Fixture?)?.synchronize(broadPhase, transform, transform)
|
(fixture as B2Fixture?)?.synchronize(broadPhase, transform, transform)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for new contacts the next step
|
// Check for new contacts the next step
|
||||||
@ -868,11 +868,11 @@ class Body(def: BodyDef, world: B2World) {
|
|||||||
transform1.position = sweep.c0 - transform1.rotation.times(sweep.localCenter)
|
transform1.position = sweep.c0 - transform1.rotation.times(sweep.localCenter)
|
||||||
|
|
||||||
for (fixture in fixtureIterator) {
|
for (fixture in fixtureIterator) {
|
||||||
(fixture as Fixture).synchronize(broadPhase, transform1, transform)
|
(fixture as B2Fixture).synchronize(broadPhase, transform1, transform)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (fixture in fixtureIterator) {
|
for (fixture in fixtureIterator) {
|
||||||
(fixture as Fixture).synchronize(broadPhase, transform, transform)
|
(fixture as B2Fixture).synchronize(broadPhase, transform, transform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,6 @@ package ru.dbotthepony.kbox2d.dynamics
|
|||||||
|
|
||||||
import ru.dbotthepony.kbox2d.api.*
|
import ru.dbotthepony.kbox2d.api.*
|
||||||
import ru.dbotthepony.kbox2d.collision.BroadPhase
|
import ru.dbotthepony.kbox2d.collision.BroadPhase
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.ChainShape
|
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
||||||
import ru.dbotthepony.kvector.util2d.AABB
|
import ru.dbotthepony.kvector.util2d.AABB
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
@ -16,22 +15,22 @@ import kotlin.collections.ArrayList
|
|||||||
* Fixtures are created via b2Body::CreateFixture.
|
* Fixtures are created via b2Body::CreateFixture.
|
||||||
* @warning you cannot reuse fixtures.
|
* @warning you cannot reuse fixtures.
|
||||||
*/
|
*/
|
||||||
class Fixture(
|
class B2Fixture(
|
||||||
body: Body,
|
body: B2Body,
|
||||||
def: FixtureDef
|
def: FixtureDef
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* Get the parent body of this fixture. This is nullptr if the fixture is not attached.
|
* Get the parent body of this fixture. This is nullptr if the fixture is not attached.
|
||||||
* @return the parent body.
|
* @return the parent body.
|
||||||
*/
|
*/
|
||||||
var body: Body? = body
|
var body: B2Body? = body
|
||||||
private set
|
private set
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next fixture in the parent body's fixture list.
|
* Get the next fixture in the parent body's fixture list.
|
||||||
* @return the next shape.
|
* @return the next shape.
|
||||||
*/
|
*/
|
||||||
var next: Fixture? = null
|
var next: B2Fixture? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the user data that was assigned in the fixture definition. Use this to
|
* Get the user data that was assigned in the fixture definition. Use this to
|
@ -78,7 +78,7 @@ class B2World(
|
|||||||
* the next body in the world list. A nullptr body indicates the end of the list.
|
* the next body in the world list. A nullptr body indicates the end of the list.
|
||||||
* @return the head of the world body list.
|
* @return the head of the world body list.
|
||||||
*/
|
*/
|
||||||
var bodyList: Body? = null
|
var bodyList: B2Body? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,15 +89,15 @@ class B2World(
|
|||||||
var jointList: AbstractJoint? = null
|
var jointList: AbstractJoint? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
val bodyListIterator: Iterator<Body> get() {
|
val bodyListIterator: Iterator<B2Body> get() {
|
||||||
return object : Iterator<Body> {
|
return object : Iterator<B2Body> {
|
||||||
private var node = bodyList
|
private var node = bodyList
|
||||||
|
|
||||||
override fun hasNext(): Boolean {
|
override fun hasNext(): Boolean {
|
||||||
return node != null
|
return node != null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun next(): Body {
|
override fun next(): B2Body {
|
||||||
val old = node!!
|
val old = node!!
|
||||||
node = old.next
|
node = old.next
|
||||||
check(node != old) { "Hard loop detected at $old" }
|
check(node != old) { "Hard loop detected at $old" }
|
||||||
@ -191,11 +191,11 @@ class B2World(
|
|||||||
* is retained.
|
* is retained.
|
||||||
* @warning This function is locked during callbacks.
|
* @warning This function is locked during callbacks.
|
||||||
*/
|
*/
|
||||||
fun createBody(bodyDef: BodyDef): Body {
|
fun createBody(bodyDef: BodyDef): B2Body {
|
||||||
if (isLocked)
|
if (isLocked)
|
||||||
throw ConcurrentModificationException()
|
throw ConcurrentModificationException()
|
||||||
|
|
||||||
val body = Body(bodyDef, this)
|
val body = B2Body(bodyDef, this)
|
||||||
|
|
||||||
body.next = bodyList
|
body.next = bodyList
|
||||||
bodyList?.prev = body
|
bodyList?.prev = body
|
||||||
@ -211,7 +211,7 @@ class B2World(
|
|||||||
* @warning This automatically deletes all associated shapes and joints.
|
* @warning This automatically deletes all associated shapes and joints.
|
||||||
* @warning This function is locked during callbacks.
|
* @warning This function is locked during callbacks.
|
||||||
*/
|
*/
|
||||||
fun destroyBody(body: Body) {
|
fun destroyBody(body: B2Body) {
|
||||||
if (isLocked)
|
if (isLocked)
|
||||||
throw ConcurrentModificationException()
|
throw ConcurrentModificationException()
|
||||||
|
|
||||||
@ -400,7 +400,7 @@ class B2World(
|
|||||||
|
|
||||||
// Reset island and stack.
|
// Reset island and stack.
|
||||||
island.clear()
|
island.clear()
|
||||||
val stack = ArrayDeque<Body>(32)
|
val stack = ArrayDeque<B2Body>(32)
|
||||||
stack.add(seed)
|
stack.add(seed)
|
||||||
seed.isOnIsland = true
|
seed.isOnIsland = true
|
||||||
|
|
||||||
@ -554,8 +554,8 @@ class B2World(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val bA = fA.body as Body
|
val bA = fA.body as B2Body
|
||||||
val bB = fB.body as Body
|
val bB = fB.body as B2Body
|
||||||
|
|
||||||
val typeA = bA.type
|
val typeA = bA.type
|
||||||
val typeB = bB.type
|
val typeB = bB.type
|
||||||
@ -633,8 +633,8 @@ class B2World(
|
|||||||
// Advance the bodies to the TOI.
|
// Advance the bodies to the TOI.
|
||||||
val fA = minContact.fixtureA
|
val fA = minContact.fixtureA
|
||||||
val fB = minContact.fixtureB
|
val fB = minContact.fixtureB
|
||||||
val bA = fA.body as Body
|
val bA = fA.body as B2Body
|
||||||
val bB = fB.body as Body
|
val bB = fB.body as B2Body
|
||||||
|
|
||||||
val backup1 = bA.sweep.copy()
|
val backup1 = bA.sweep.copy()
|
||||||
val backup2 = bB.sweep.copy()
|
val backup2 = bB.sweep.copy()
|
||||||
@ -911,7 +911,7 @@ class B2World(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawShape(fixture: Fixture, xf: Transform, color: Color) {
|
private fun drawShape(fixture: B2Fixture, xf: Transform, color: Color) {
|
||||||
when (fixture.type) {
|
when (fixture.type) {
|
||||||
IShape.Type.CIRCLE -> {
|
IShape.Type.CIRCLE -> {
|
||||||
val circle = fixture.shape as CircleShape
|
val circle = fixture.shape as CircleShape
|
||||||
|
@ -35,8 +35,8 @@ class ContactManager {
|
|||||||
fun destroy(contact: AbstractContact) {
|
fun destroy(contact: AbstractContact) {
|
||||||
val fixtureA = contact.fixtureA
|
val fixtureA = contact.fixtureA
|
||||||
val fixtureB = contact.fixtureB
|
val fixtureB = contact.fixtureB
|
||||||
val bodyA = fixtureA.body as Body
|
val bodyA = fixtureA.body as B2Body
|
||||||
val bodyB = fixtureB.body as Body
|
val bodyB = fixtureB.body as B2Body
|
||||||
|
|
||||||
if (contact.isTouching) {
|
if (contact.isTouching) {
|
||||||
contactListener?.endContact(contact)
|
contactListener?.endContact(contact)
|
||||||
@ -98,8 +98,8 @@ class ContactManager {
|
|||||||
val fixtureB = c.fixtureB
|
val fixtureB = c.fixtureB
|
||||||
val indexA = c.childIndexA
|
val indexA = c.childIndexA
|
||||||
val indexB = c.childIndexB
|
val indexB = c.childIndexB
|
||||||
val bodyA = fixtureA.body as Body
|
val bodyA = fixtureA.body as B2Body
|
||||||
val bodyB = fixtureB.body as Body
|
val bodyB = fixtureB.body as B2Body
|
||||||
|
|
||||||
// Is this contact flagged for filtering?
|
// Is this contact flagged for filtering?
|
||||||
if (c.isFlaggedForFiltering) {
|
if (c.isFlaggedForFiltering) {
|
||||||
@ -154,8 +154,8 @@ class ContactManager {
|
|||||||
val indexA = proxyA.childIndex
|
val indexA = proxyA.childIndex
|
||||||
val indexB = proxyB.childIndex
|
val indexB = proxyB.childIndex
|
||||||
|
|
||||||
val bodyA = fixtureA.body as Body
|
val bodyA = fixtureA.body as B2Body
|
||||||
val bodyB = fixtureB.body as Body
|
val bodyB = fixtureB.body as B2Body
|
||||||
|
|
||||||
// Are the fixtures on the same body?
|
// Are the fixtures on the same body?
|
||||||
if (bodyA === bodyB) {
|
if (bodyA === bodyB) {
|
||||||
|
@ -3,13 +3,12 @@ package ru.dbotthepony.kbox2d.dynamics.contact
|
|||||||
import ru.dbotthepony.kbox2d.api.*
|
import ru.dbotthepony.kbox2d.api.*
|
||||||
import ru.dbotthepony.kbox2d.collision.WorldManifold
|
import ru.dbotthepony.kbox2d.collision.WorldManifold
|
||||||
import ru.dbotthepony.kbox2d.collision.b2TestOverlap
|
import ru.dbotthepony.kbox2d.collision.b2TestOverlap
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Body
|
import ru.dbotthepony.kbox2d.dynamics.B2Body
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Fixture
|
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.HashMap
|
|
||||||
|
|
||||||
fun interface ContactFactory {
|
fun interface ContactFactory {
|
||||||
fun factorize(fixtureA: Fixture, childIndexA: Int, fixtureB: Fixture, childIndexB: Int): AbstractContact
|
fun factorize(fixtureA: B2Fixture, childIndexA: Int, fixtureB: B2Fixture, childIndexB: Int): AbstractContact
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,7 +20,7 @@ sealed class AbstractContact(
|
|||||||
/**
|
/**
|
||||||
* Get fixture A in this contact.
|
* Get fixture A in this contact.
|
||||||
*/
|
*/
|
||||||
val fixtureA: Fixture,
|
val fixtureA: B2Fixture,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the child primitive index for fixture A.
|
* Get the child primitive index for fixture A.
|
||||||
@ -31,7 +30,7 @@ sealed class AbstractContact(
|
|||||||
/**
|
/**
|
||||||
* Get fixture B in this contact.
|
* Get fixture B in this contact.
|
||||||
*/
|
*/
|
||||||
val fixtureB: Fixture,
|
val fixtureB: B2Fixture,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the child primitive index for fixture B.
|
* Get the child primitive index for fixture B.
|
||||||
@ -69,8 +68,8 @@ sealed class AbstractContact(
|
|||||||
internal val nodeB: ContactEdge = ContactEdge(contact = this, other = fixtureA.body!!)
|
internal val nodeB: ContactEdge = ContactEdge(contact = this, other = fixtureA.body!!)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val bodyA = fixtureA.body as Body
|
val bodyA = fixtureA.body as B2Body
|
||||||
val bodyB = fixtureB.body as Body
|
val bodyB = fixtureB.body as B2Body
|
||||||
|
|
||||||
nodeA.next = bodyA.contactEdge
|
nodeA.next = bodyA.contactEdge
|
||||||
nodeB.next = bodyB.contactEdge
|
nodeB.next = bodyB.contactEdge
|
||||||
@ -174,8 +173,8 @@ sealed class AbstractContact(
|
|||||||
|
|
||||||
val sensor = fixtureA.isSensor || fixtureB.isSensor
|
val sensor = fixtureA.isSensor || fixtureB.isSensor
|
||||||
|
|
||||||
val bodyA = fixtureA.body as Body
|
val bodyA = fixtureA.body as B2Body
|
||||||
val bodyB = fixtureB.body as Body
|
val bodyB = fixtureB.body as B2Body
|
||||||
|
|
||||||
val xfA = bodyA.transform
|
val xfA = bodyA.transform
|
||||||
val xfB = bodyB.transform
|
val xfB = bodyB.transform
|
||||||
@ -257,9 +256,9 @@ sealed class AbstractContact(
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun create(
|
internal fun create(
|
||||||
fixtureA: Fixture,
|
fixtureA: B2Fixture,
|
||||||
indexA: Int,
|
indexA: Int,
|
||||||
fixtureB: Fixture,
|
fixtureB: B2Fixture,
|
||||||
indexB: Int,
|
indexB: Int,
|
||||||
): AbstractContact {
|
): AbstractContact {
|
||||||
val type1 = fixtureA.type
|
val type1 = fixtureA.type
|
||||||
@ -271,31 +270,31 @@ sealed class AbstractContact(
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
register(IShape.Type.POLYGON, IShape.Type.POLYGON) { fixtureA: Fixture, _: Int, fixtureB: Fixture, _: Int ->
|
register(IShape.Type.POLYGON, IShape.Type.POLYGON) { fixtureA: B2Fixture, _: Int, fixtureB: B2Fixture, _: Int ->
|
||||||
return@register PolygonContact(fixtureA, fixtureB)
|
return@register PolygonContact(fixtureA, fixtureB)
|
||||||
}
|
}
|
||||||
|
|
||||||
register(IShape.Type.POLYGON, IShape.Type.CIRCLE) { fixtureA: Fixture, _: Int, fixtureB: Fixture, _: Int ->
|
register(IShape.Type.POLYGON, IShape.Type.CIRCLE) { fixtureA: B2Fixture, _: Int, fixtureB: B2Fixture, _: Int ->
|
||||||
return@register PolygonCircleContact(fixtureA, fixtureB)
|
return@register PolygonCircleContact(fixtureA, fixtureB)
|
||||||
}
|
}
|
||||||
|
|
||||||
register(IShape.Type.CIRCLE, IShape.Type.CIRCLE) { fixtureA: Fixture, _: Int, fixtureB: Fixture, _: Int ->
|
register(IShape.Type.CIRCLE, IShape.Type.CIRCLE) { fixtureA: B2Fixture, _: Int, fixtureB: B2Fixture, _: Int ->
|
||||||
return@register CircleContact(fixtureA, fixtureB)
|
return@register CircleContact(fixtureA, fixtureB)
|
||||||
}
|
}
|
||||||
|
|
||||||
register(IShape.Type.EDGE, IShape.Type.CIRCLE) { fixtureA: Fixture, _: Int, fixtureB: Fixture, _: Int ->
|
register(IShape.Type.EDGE, IShape.Type.CIRCLE) { fixtureA: B2Fixture, _: Int, fixtureB: B2Fixture, _: Int ->
|
||||||
return@register EdgeCircleContact(fixtureA, fixtureB)
|
return@register EdgeCircleContact(fixtureA, fixtureB)
|
||||||
}
|
}
|
||||||
|
|
||||||
register(IShape.Type.EDGE, IShape.Type.POLYGON) { fixtureA: Fixture, _: Int, fixtureB: Fixture, _: Int ->
|
register(IShape.Type.EDGE, IShape.Type.POLYGON) { fixtureA: B2Fixture, _: Int, fixtureB: B2Fixture, _: Int ->
|
||||||
return@register EdgePolygonContact(fixtureA, fixtureB)
|
return@register EdgePolygonContact(fixtureA, fixtureB)
|
||||||
}
|
}
|
||||||
|
|
||||||
register(IShape.Type.CHAIN, IShape.Type.POLYGON) { fixtureA: Fixture, indexA: Int, fixtureB: Fixture, indexB: Int ->
|
register(IShape.Type.CHAIN, IShape.Type.POLYGON) { fixtureA: B2Fixture, indexA: Int, fixtureB: B2Fixture, indexB: Int ->
|
||||||
return@register ChainPolygonContact(fixtureA, indexA, fixtureB, indexB)
|
return@register ChainPolygonContact(fixtureA, indexA, fixtureB, indexB)
|
||||||
}
|
}
|
||||||
|
|
||||||
register(IShape.Type.CHAIN, IShape.Type.CIRCLE) { fixtureA: Fixture, indexA: Int, fixtureB: Fixture, indexB: Int ->
|
register(IShape.Type.CHAIN, IShape.Type.CIRCLE) { fixtureA: B2Fixture, indexA: Int, fixtureB: B2Fixture, indexB: Int ->
|
||||||
return@register ChainCircleContact(fixtureA, indexA, fixtureB, indexB)
|
return@register ChainCircleContact(fixtureA, indexA, fixtureB, indexB)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,12 @@ import ru.dbotthepony.kbox2d.api.Transform
|
|||||||
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndCircle
|
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndCircle
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.ChainShape
|
import ru.dbotthepony.kbox2d.collision.shapes.ChainShape
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
|
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Fixture
|
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
||||||
|
|
||||||
class ChainCircleContact(
|
class ChainCircleContact(
|
||||||
fixtureA: Fixture,
|
fixtureA: B2Fixture,
|
||||||
childIndexA: Int,
|
childIndexA: Int,
|
||||||
fixtureB: Fixture,
|
fixtureB: B2Fixture,
|
||||||
childIndexB: Int,
|
childIndexB: Int,
|
||||||
) : AbstractContact(fixtureA, childIndexA, fixtureB, childIndexB) {
|
) : AbstractContact(fixtureA, childIndexA, fixtureB, childIndexB) {
|
||||||
init {
|
init {
|
||||||
|
@ -6,12 +6,12 @@ import ru.dbotthepony.kbox2d.api.Transform
|
|||||||
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndPolygon
|
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndPolygon
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.ChainShape
|
import ru.dbotthepony.kbox2d.collision.shapes.ChainShape
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Fixture
|
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
||||||
|
|
||||||
class ChainPolygonContact(
|
class ChainPolygonContact(
|
||||||
fixtureA: Fixture,
|
fixtureA: B2Fixture,
|
||||||
childIndexA: Int,
|
childIndexA: Int,
|
||||||
fixtureB: Fixture,
|
fixtureB: B2Fixture,
|
||||||
childIndexB: Int,
|
childIndexB: Int,
|
||||||
) : AbstractContact(fixtureA, childIndexA, fixtureB, childIndexB) {
|
) : AbstractContact(fixtureA, childIndexA, fixtureB, childIndexB) {
|
||||||
init {
|
init {
|
||||||
|
@ -5,11 +5,11 @@ import ru.dbotthepony.kbox2d.api.Manifold
|
|||||||
import ru.dbotthepony.kbox2d.api.Transform
|
import ru.dbotthepony.kbox2d.api.Transform
|
||||||
import ru.dbotthepony.kbox2d.collision.handler.b2CollideCircles
|
import ru.dbotthepony.kbox2d.collision.handler.b2CollideCircles
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
|
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Fixture
|
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
||||||
|
|
||||||
class CircleContact(
|
class CircleContact(
|
||||||
fixtureA: Fixture,
|
fixtureA: B2Fixture,
|
||||||
fixtureB: Fixture,
|
fixtureB: B2Fixture,
|
||||||
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
|
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
|
||||||
init {
|
init {
|
||||||
require(fixtureA.type == IShape.Type.CIRCLE) { "Fixture A is of type ${fixtureA.type}" }
|
require(fixtureA.type == IShape.Type.CIRCLE) { "Fixture A is of type ${fixtureA.type}" }
|
||||||
|
@ -6,11 +6,11 @@ import ru.dbotthepony.kbox2d.api.Transform
|
|||||||
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndCircle
|
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndCircle
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
|
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.EdgeShape
|
import ru.dbotthepony.kbox2d.collision.shapes.EdgeShape
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Fixture
|
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
||||||
|
|
||||||
class EdgeCircleContact(
|
class EdgeCircleContact(
|
||||||
fixtureA: Fixture,
|
fixtureA: B2Fixture,
|
||||||
fixtureB: Fixture,
|
fixtureB: B2Fixture,
|
||||||
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
|
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
|
||||||
init {
|
init {
|
||||||
require(fixtureA.type == IShape.Type.EDGE) { "Fixture A is of type ${fixtureA.type}, expected EDGE" }
|
require(fixtureA.type == IShape.Type.EDGE) { "Fixture A is of type ${fixtureA.type}, expected EDGE" }
|
||||||
|
@ -6,11 +6,11 @@ import ru.dbotthepony.kbox2d.api.Transform
|
|||||||
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndPolygon
|
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndPolygon
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.EdgeShape
|
import ru.dbotthepony.kbox2d.collision.shapes.EdgeShape
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Fixture
|
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
||||||
|
|
||||||
class EdgePolygonContact(
|
class EdgePolygonContact(
|
||||||
fixtureA: Fixture,
|
fixtureA: B2Fixture,
|
||||||
fixtureB: Fixture,
|
fixtureB: B2Fixture,
|
||||||
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
|
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
|
||||||
init {
|
init {
|
||||||
require(fixtureA.type == IShape.Type.EDGE) { "Fixture A is of type ${fixtureA.type}, expected EDGE" }
|
require(fixtureA.type == IShape.Type.EDGE) { "Fixture A is of type ${fixtureA.type}, expected EDGE" }
|
||||||
|
@ -6,11 +6,11 @@ import ru.dbotthepony.kbox2d.api.Transform
|
|||||||
import ru.dbotthepony.kbox2d.collision.handler.b2CollidePolygonAndCircle
|
import ru.dbotthepony.kbox2d.collision.handler.b2CollidePolygonAndCircle
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
|
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Fixture
|
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
||||||
|
|
||||||
class PolygonCircleContact(
|
class PolygonCircleContact(
|
||||||
fixtureA: Fixture,
|
fixtureA: B2Fixture,
|
||||||
fixtureB: Fixture,
|
fixtureB: B2Fixture,
|
||||||
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
|
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
|
||||||
init {
|
init {
|
||||||
require(fixtureA.type == IShape.Type.POLYGON) { "Fixture A is of type ${fixtureA.type}, expected POLYGON" }
|
require(fixtureA.type == IShape.Type.POLYGON) { "Fixture A is of type ${fixtureA.type}, expected POLYGON" }
|
||||||
|
@ -5,11 +5,11 @@ import ru.dbotthepony.kbox2d.api.Manifold
|
|||||||
import ru.dbotthepony.kbox2d.api.Transform
|
import ru.dbotthepony.kbox2d.api.Transform
|
||||||
import ru.dbotthepony.kbox2d.collision.handler.b2CollidePolygons
|
import ru.dbotthepony.kbox2d.collision.handler.b2CollidePolygons
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Fixture
|
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
|
||||||
|
|
||||||
class PolygonContact(
|
class PolygonContact(
|
||||||
fixtureA: Fixture,
|
fixtureA: B2Fixture,
|
||||||
fixtureB: Fixture,
|
fixtureB: B2Fixture,
|
||||||
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
|
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
|
||||||
init {
|
init {
|
||||||
require(fixtureA.type == IShape.Type.POLYGON) { "Fixture A has type of ${fixtureA.type}" }
|
require(fixtureA.type == IShape.Type.POLYGON) { "Fixture A has type of ${fixtureA.type}" }
|
||||||
|
@ -3,7 +3,7 @@ package ru.dbotthepony.kbox2d.dynamics.internal
|
|||||||
import ru.dbotthepony.kbox2d.api.*
|
import ru.dbotthepony.kbox2d.api.*
|
||||||
import ru.dbotthepony.kbox2d.collision.WorldManifold
|
import ru.dbotthepony.kbox2d.collision.WorldManifold
|
||||||
import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact
|
import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Body
|
import ru.dbotthepony.kbox2d.dynamics.B2Body
|
||||||
import ru.dbotthepony.kvector.matrix.ndouble.Matrix2d
|
import ru.dbotthepony.kvector.matrix.ndouble.Matrix2d
|
||||||
import ru.dbotthepony.kvector.matrix.ndouble.MutableMatrix2d
|
import ru.dbotthepony.kvector.matrix.ndouble.MutableMatrix2d
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
@ -144,8 +144,8 @@ internal class ContactSolver(
|
|||||||
val shapeB = fixtureB.shape
|
val shapeB = fixtureB.shape
|
||||||
val radiusA = shapeA.radius
|
val radiusA = shapeA.radius
|
||||||
val radiusB = shapeB.radius
|
val radiusB = shapeB.radius
|
||||||
val bodyA = fixtureA.body as Body
|
val bodyA = fixtureA.body as B2Body
|
||||||
val bodyB = fixtureB.body as Body
|
val bodyB = fixtureB.body as B2Body
|
||||||
val manifold = contact.manifold
|
val manifold = contact.manifold
|
||||||
|
|
||||||
check(manifold.points.isNotEmpty()) { "Manifold points at $i are empty" }
|
check(manifold.points.isNotEmpty()) { "Manifold points at $i are empty" }
|
||||||
|
@ -5,7 +5,7 @@ import ru.dbotthepony.kbox2d.collision.DistanceProxy
|
|||||||
import ru.dbotthepony.kbox2d.collision.b2Distance
|
import ru.dbotthepony.kbox2d.collision.b2Distance
|
||||||
import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact
|
import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact
|
||||||
import ru.dbotthepony.kbox2d.dynamics.joint.AbstractJoint
|
import ru.dbotthepony.kbox2d.dynamics.joint.AbstractJoint
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Body
|
import ru.dbotthepony.kbox2d.dynamics.B2Body
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.times
|
import ru.dbotthepony.kvector.vector.ndouble.times
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -144,14 +144,14 @@ internal class Island(
|
|||||||
initialJointCapacity: Int = 0,
|
initialJointCapacity: Int = 0,
|
||||||
val listener: IContactListener? = null
|
val listener: IContactListener? = null
|
||||||
) {
|
) {
|
||||||
private val bodies = ArrayList<Body>(initialBodyCapacity)
|
private val bodies = ArrayList<B2Body>(initialBodyCapacity)
|
||||||
private val contacts = ArrayList<AbstractContact>(initialContactCapacity)
|
private val contacts = ArrayList<AbstractContact>(initialContactCapacity)
|
||||||
private val joints = ArrayList<AbstractJoint>(initialJointCapacity)
|
private val joints = ArrayList<AbstractJoint>(initialJointCapacity)
|
||||||
|
|
||||||
private val velocities = ArrayList<ru.dbotthepony.kbox2d.api.B2Velocity>(initialBodyCapacity)
|
private val velocities = ArrayList<ru.dbotthepony.kbox2d.api.B2Velocity>(initialBodyCapacity)
|
||||||
private val positions = ArrayList<ru.dbotthepony.kbox2d.api.B2Position>(initialBodyCapacity)
|
private val positions = ArrayList<ru.dbotthepony.kbox2d.api.B2Position>(initialBodyCapacity)
|
||||||
|
|
||||||
val bodiesAccess: List<Body> = Collections.unmodifiableList(bodies)
|
val bodiesAccess: List<B2Body> = Collections.unmodifiableList(bodies)
|
||||||
|
|
||||||
fun clear() {
|
fun clear() {
|
||||||
bodies.clear()
|
bodies.clear()
|
||||||
@ -162,7 +162,7 @@ internal class Island(
|
|||||||
positions.clear()
|
positions.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun add(body: Body) {
|
fun add(body: B2Body) {
|
||||||
body.islandIndex = bodies.size
|
body.islandIndex = bodies.size
|
||||||
bodies.add(body)
|
bodies.add(body)
|
||||||
velocities.add(ru.dbotthepony.kbox2d.api.B2Velocity())
|
velocities.add(ru.dbotthepony.kbox2d.api.B2Velocity())
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package ru.dbotthepony.kbox2d.dynamics.joint
|
package ru.dbotthepony.kbox2d.dynamics.joint
|
||||||
|
|
||||||
import ru.dbotthepony.kbox2d.api.*
|
import ru.dbotthepony.kbox2d.api.*
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Body
|
import ru.dbotthepony.kbox2d.dynamics.B2Body
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
import java.util.EnumMap
|
import java.util.EnumMap
|
||||||
|
|
||||||
@ -47,18 +47,18 @@ sealed class AbstractJoint(def: IJointDef) : IMovable {
|
|||||||
// joint have only one body, and to avoid null assertions in all places
|
// joint have only one body, and to avoid null assertions in all places
|
||||||
// possible, bodyA and bodyB getters assert for null by themselves
|
// possible, bodyA and bodyB getters assert for null by themselves
|
||||||
// However, there is nullable getter for bodies: nullableBodyA and nullableBodyB
|
// However, there is nullable getter for bodies: nullableBodyA and nullableBodyB
|
||||||
protected var _bodyA: Body? = def.bodyA as Body?
|
protected var _bodyA: B2Body? = def.bodyA as B2Body?
|
||||||
protected var _bodyB: Body? = def.bodyB as Body?
|
protected var _bodyB: B2Body? = def.bodyB as B2Body?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the first body attached to this joint.
|
* Get the first body attached to this joint.
|
||||||
*/
|
*/
|
||||||
val bodyA: Body get() = checkNotNull(_bodyA) { "Body A is not present" }
|
val bodyA: B2Body get() = checkNotNull(_bodyA) { "Body A is not present" }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the second body attached to this joint.
|
* Get the second body attached to this joint.
|
||||||
*/
|
*/
|
||||||
val bodyB: Body get() = checkNotNull(_bodyB) { "Body B is not present" }
|
val bodyB: B2Body get() = checkNotNull(_bodyB) { "Body B is not present" }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the anchor point on bodyA in world coordinates.
|
* Get the anchor point on bodyA in world coordinates.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package ru.dbotthepony.kbox2d.dynamics.joint
|
package ru.dbotthepony.kbox2d.dynamics.joint
|
||||||
|
|
||||||
import ru.dbotthepony.kbox2d.api.*
|
import ru.dbotthepony.kbox2d.api.*
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Body
|
import ru.dbotthepony.kbox2d.dynamics.B2Body
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
|
||||||
import ru.dbotthepony.kvector.vector.ndouble.times
|
import ru.dbotthepony.kvector.vector.ndouble.times
|
||||||
|
|
||||||
@ -126,8 +126,8 @@ class GearJoint(def: GearJointDef) : AbstractJoint(def) {
|
|||||||
|
|
||||||
// Body A is connected to body C
|
// Body A is connected to body C
|
||||||
// Body B is connected to body D
|
// Body B is connected to body D
|
||||||
private var _bodyC: Body? = joint1.bodyA
|
private var _bodyC: B2Body? = joint1.bodyA
|
||||||
private var _bodyD: Body?
|
private var _bodyD: B2Body?
|
||||||
|
|
||||||
override fun unlink() {
|
override fun unlink() {
|
||||||
super.unlink()
|
super.unlink()
|
||||||
@ -135,8 +135,8 @@ class GearJoint(def: GearJointDef) : AbstractJoint(def) {
|
|||||||
_bodyD = null
|
_bodyD = null
|
||||||
}
|
}
|
||||||
|
|
||||||
val bodyC: Body get() = checkNotNull(_bodyC) { "Body C is not present" }
|
val bodyC: B2Body get() = checkNotNull(_bodyC) { "Body C is not present" }
|
||||||
val bodyD: Body get() = checkNotNull(_bodyD) { "Body D is not present" }
|
val bodyD: B2Body get() = checkNotNull(_bodyD) { "Body D is not present" }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
_bodyA = joint1.bodyB
|
_bodyA = joint1.bodyB
|
||||||
|
@ -8,7 +8,7 @@ import ru.dbotthepony.kbox2d.collision.shapes.ChainShape
|
|||||||
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
|
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
|
||||||
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
|
||||||
import ru.dbotthepony.kbox2d.dynamics.B2World
|
import ru.dbotthepony.kbox2d.dynamics.B2World
|
||||||
import ru.dbotthepony.kbox2d.dynamics.Body
|
import ru.dbotthepony.kbox2d.dynamics.B2Body
|
||||||
import ru.dbotthepony.kbox2d.dynamics.joint.MouseJoint
|
import ru.dbotthepony.kbox2d.dynamics.joint.MouseJoint
|
||||||
import ru.dbotthepony.kstarbound.client.StarboundClient
|
import ru.dbotthepony.kstarbound.client.StarboundClient
|
||||||
import ru.dbotthepony.kstarbound.world.Chunk
|
import ru.dbotthepony.kstarbound.world.Chunk
|
||||||
@ -54,7 +54,7 @@ fun main() {
|
|||||||
|
|
||||||
ground.createFixture(groundPoly, 0.0)
|
ground.createFixture(groundPoly, 0.0)
|
||||||
|
|
||||||
val boxes = ArrayList<Body>()
|
val boxes = ArrayList<B2Body>()
|
||||||
|
|
||||||
/*run {
|
/*run {
|
||||||
val movingDef = BodyDef(
|
val movingDef = BodyDef(
|
||||||
|
Loading…
Reference in New Issue
Block a user