Rename Body to B2Body and Fixture to B2Fixture

This commit is contained in:
DBotThePony 2022-02-20 14:33:35 +07:00
parent 27a870fcf0
commit 6b32d0f0c4
Signed by: DBot
GPG Key ID: DCC23B5715498507
21 changed files with 161 additions and 164 deletions

View File

@ -1,6 +1,6 @@
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 kotlin.math.sqrt
@ -33,7 +33,7 @@ data class ContactRegister(
* nodes, one for each attached body.
*/
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
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

View File

@ -1,9 +1,8 @@
package ru.dbotthepony.kbox2d.api
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.vector.ndouble.Vector2d
sealed interface IFilter {
/**
@ -81,7 +80,7 @@ data class FixtureDef(
data class FixtureProxy(
var aabb: AABB,
val fixture: Fixture,
val fixture: B2Fixture,
val childIndex: Int,
) {
private var setProxyID = false

View File

@ -1,6 +1,6 @@
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.kvector.vector.ndouble.Vector2d
import kotlin.math.PI
@ -13,8 +13,8 @@ data class StiffnessResult(val stiffness: Double, val damping: Double)
fun b2LinearStiffness(
frequencyHertz: Double,
dampingRatio: Double,
bodyA: Body?,
bodyB: Body?,
bodyA: B2Body?,
bodyB: B2Body?,
): StiffnessResult {
val massA = bodyA?.mass ?: 0.0
val massB = bodyB?.mass ?: 0.0
@ -42,8 +42,8 @@ fun b2LinearStiffness(
fun b2AngularStiffness(
frequencyHertz: Double,
dampingRatio: Double,
bodyA: Body?,
bodyB: Body?,
bodyA: B2Body?,
bodyB: B2Body?,
): StiffnessResult {
val inertiaA = bodyA?.inertia ?: 0.0
val inertiaB = bodyB?.inertia ?: 0.0
@ -92,13 +92,13 @@ data class Jacobian(
* nodes, one for each attached body.
*/
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
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
) {
val otherNullable: Body? = other
val other: Body get() = checkNotNull(otherNullable) { "Other body is not present" }
val otherNullable: B2Body? = other
val other: B2Body get() = checkNotNull(otherNullable) { "Other body is not present" }
}
sealed interface IJointDef {
@ -110,12 +110,12 @@ sealed interface IJointDef {
/**
* The first attached body.
*/
val bodyA: Body?
val bodyA: B2Body?
/**
* The second attached body.
*/
val bodyB: Body?
val bodyB: B2Body?
/**
* Set this flag to true if the attached bodies should collide.
@ -129,8 +129,8 @@ sealed interface IJointDef {
}
class DistanceJointDef(
b1: Body,
b2: Body,
b1: B2Body,
b2: B2Body,
anchor1: Vector2d,
anchor2: Vector2d
) : IJointDef {
@ -161,8 +161,8 @@ class DistanceJointDef(
*/
val damping: Double = 0.0
override var bodyA: Body = b1
override var bodyB: Body = b2
override var bodyA: B2Body = b1
override var bodyB: B2Body = b2
override var collideConnected: Boolean = false
override var userData: Any? = null
@ -186,13 +186,13 @@ class DistanceJointDef(
}
class RevoluteJointDef(
b1: Body,
b2: Body,
b1: B2Body,
b2: B2Body,
anchor: Vector2d,
) : IJointDef {
override val type: JointType = JointType.REVOLUTE
override var bodyA: Body = b1
override var bodyB: Body = b2
override var bodyA: B2Body = b1
override var bodyB: B2Body = b2
override var collideConnected: Boolean = false
override var userData: Any? = null
@ -245,14 +245,14 @@ class RevoluteJointDef(
}
class PrismaticJointDef(
b1: Body,
b2: Body,
b1: B2Body,
b2: B2Body,
anchor: Vector2d,
axis: Vector2d,
) : IJointDef {
override val type: JointType = JointType.PRISMATIC
override var bodyA: Body = b1
override var bodyB: Body = b2
override var bodyA: B2Body = b1
override var bodyB: B2Body = b2
override var collideConnected: Boolean = false
override var userData: Any? = null
@ -312,8 +312,8 @@ class PrismaticJointDef(
* two dynamic body anchor points, and a pulley ratio.
*/
class PulleyJointDef(
b1: Body,
b2: Body,
b1: B2Body,
b2: B2Body,
/**
* The first ground anchor in world coordinates. This point never moves.
@ -330,8 +330,8 @@ class PulleyJointDef(
ratio: Double,
) : IJointDef {
override val type: JointType = JointType.PULLEY
override var bodyA: Body = b1
override var bodyB: Body = b2
override var bodyA: B2Body = b1
override var bodyB: B2Body = b2
override var collideConnected: Boolean = false
override var userData: Any? = null
@ -376,8 +376,8 @@ class PulleyJointDef(
* @warning bodyB on the input joints must both be dynamic
*/
class GearJointDef(
override var bodyA: Body,
override var bodyB: Body,
override var bodyA: B2Body,
override var bodyB: B2Body,
/**
* The first revolute/prismatic joint attached to the gear joint.
@ -417,8 +417,8 @@ class MouseJointDef(
*/
var target: Vector2d,
override var bodyB: Body,
override val bodyA: Body? = null,
override var bodyB: B2Body,
override val bodyA: B2Body? = null,
/**
* The maximum constraint force that can be exerted
@ -437,8 +437,8 @@ class MouseJointDef(
fun linearStiffness(
frequencyHertz: Double,
dampingRatio: Double,
bodyA: Body?,
bodyB: Body?
bodyA: B2Body?,
bodyB: B2Body?
): MouseJointDef {
val (stiffness, damping) = b2LinearStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
this.stiffness = stiffness
@ -449,8 +449,8 @@ class MouseJointDef(
fun angularStiffness(
frequencyHertz: Double,
dampingRatio: Double,
bodyA: Body?,
bodyB: Body?
bodyA: B2Body?,
bodyB: B2Body?
): MouseJointDef {
val (stiffness, damping) = b2AngularStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
this.stiffness = stiffness
@ -468,8 +468,8 @@ class MouseJointDef(
* anchors and a local axis helps when saving and loading a game.
*/
class WheelJointDef(
override var bodyA: Body,
override var bodyB: Body,
override var bodyA: B2Body,
override var bodyB: B2Body,
anchor: Vector2d,
axis: Vector2d,
@ -535,8 +535,8 @@ class WheelJointDef(
fun linearStiffness(
frequencyHertz: Double,
dampingRatio: Double,
bodyA: Body = this.bodyA,
bodyB: Body = this.bodyB
bodyA: B2Body = this.bodyA,
bodyB: B2Body = this.bodyB
): WheelJointDef {
val (stiffness, damping) = b2LinearStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
this.stiffness = stiffness
@ -547,8 +547,8 @@ class WheelJointDef(
fun angularStiffness(
frequencyHertz: Double,
dampingRatio: Double,
bodyA: Body = this.bodyA,
bodyB: Body = this.bodyB
bodyA: B2Body = this.bodyA,
bodyB: B2Body = this.bodyB
): WheelJointDef {
val (stiffness, damping) = b2AngularStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
this.stiffness = stiffness
@ -563,8 +563,8 @@ class WheelJointDef(
* of the anchor points is important for computing the reaction torque.
*/
class WeldJointDef(
override var bodyA: Body,
override var bodyB: Body,
override var bodyA: B2Body,
override var bodyB: B2Body,
anchor: Vector2d,
/**
@ -599,8 +599,8 @@ class WeldJointDef(
fun linearStiffness(
frequencyHertz: Double,
dampingRatio: Double,
bodyA: Body = this.bodyA,
bodyB: Body = this.bodyB
bodyA: B2Body = this.bodyA,
bodyB: B2Body = this.bodyB
): WeldJointDef {
val (stiffness, damping) = b2LinearStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
this.stiffness = stiffness
@ -611,8 +611,8 @@ class WeldJointDef(
fun angularStiffness(
frequencyHertz: Double,
dampingRatio: Double,
bodyA: Body = this.bodyA,
bodyB: Body = this.bodyB
bodyA: B2Body = this.bodyA,
bodyB: B2Body = this.bodyB
): WeldJointDef {
val (stiffness, damping) = b2AngularStiffness(frequencyHertz, dampingRatio, bodyA, bodyB)
this.stiffness = stiffness
@ -625,8 +625,8 @@ class WeldJointDef(
* Friction joint definition.
*/
class FrictionJointDef(
override var bodyA: Body,
override var bodyB: Body,
override var bodyA: B2Body,
override var bodyB: B2Body,
anchor: Vector2d,
/**
@ -656,8 +656,8 @@ class FrictionJointDef(
}
class MotorJointDef(
override var bodyA: Body,
override var bodyB: Body,
override var bodyA: B2Body,
override var bodyB: B2Body,
/**
* The maximum motor force in N.

View File

@ -1,6 +1,6 @@
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.joint.AbstractJoint
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.
* @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
* 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.
* @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
* 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
}

View File

@ -3,7 +3,7 @@ package ru.dbotthepony.kbox2d.dynamics
import ru.dbotthepony.kbox2d.api.*
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
class Body(def: BodyDef, world: B2World) {
class B2Body(def: BodyDef, world: B2World) {
private var _world: B2World? = world
/**
@ -101,7 +101,7 @@ class Body(def: BodyDef, world: B2World) {
field = value
}
var fixtureList: Fixture? = null
var fixtureList: B2Fixture? = null
protected set
var fixtureCount: Int = 0
@ -159,20 +159,20 @@ class Body(def: BodyDef, world: B2World) {
}
}
var next: Body? = null
var next: B2Body? = null
internal set
var prev: Body? = null
var prev: B2Body? = null
internal set
val fixtureIterator: Iterator<Fixture> get() {
return object : Iterator<Fixture> {
val fixtureIterator: Iterator<B2Fixture> get() {
return object : Iterator<B2Fixture> {
private var node = fixtureList
override fun hasNext(): Boolean {
return node != null
}
override fun next(): Fixture {
override fun next(): B2Fixture {
val old = node!!
node = old.next
return old
@ -273,7 +273,7 @@ class Body(def: BodyDef, world: B2World) {
val broadPhase = world.contactManager.broadPhase
for (fixture in fixtureIterator) {
(fixture as Fixture).createProxies(broadPhase, transform)
(fixture as B2Fixture).createProxies(broadPhase, transform)
}
world.notifyNewContacts()
@ -284,7 +284,7 @@ class Body(def: BodyDef, world: B2World) {
val broadPhase = world.contactManager.broadPhase
for (fixture in fixtureIterator) {
(fixture as Fixture).destroyProxies(broadPhase)
(fixture as B2Fixture).destroyProxies(broadPhase)
}
// Destroy the attached contacts.
@ -362,7 +362,7 @@ class Body(def: BodyDef, world: B2World) {
contactEdge = null
val broadPhase = world.contactManager.broadPhase
var f: Fixture? = fixtureList
var f: B2Fixture? = fixtureList
while (f != null) {
for (proxy in f.proxies) {
@ -381,11 +381,11 @@ class Body(def: BodyDef, world: B2World) {
* @param def the fixture definition.
* @warning This function is locked during callbacks.
*/
fun createFixture(def: FixtureDef): Fixture {
fun createFixture(def: FixtureDef): B2Fixture {
if (world.isLocked)
throw ConcurrentModificationException()
val fixture = Fixture(this, def)
val fixture = B2Fixture(this, def)
if (isEnabled) {
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).
* @warning This function is locked during callbacks.
*/
fun createFixture(shape: IShape<*>, density: Double): Fixture {
fun createFixture(shape: IShape<*>, density: Double): B2Fixture {
return createFixture(
FixtureDef(
shape = shape,
@ -434,16 +434,16 @@ class Body(def: BodyDef, world: B2World) {
* @param fixture the fixture to be removed.
* @warning This function is locked during callbacks.
*/
fun destroyFixture(fixture: Fixture) {
fun destroyFixture(fixture: B2Fixture) {
if (world.isLocked)
throw ConcurrentModificationException()
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" }
var node: Fixture? = fixtureList
var node: B2Fixture? = fixtureList
var found = false
var previous: Fixture? = null
var previous: B2Fixture? = null
while (node != null) {
if (node == fixture) {
@ -478,7 +478,7 @@ class Body(def: BodyDef, world: B2World) {
}
}
fixture as Fixture
fixture as B2Fixture
if (isEnabled) {
fixture.destroyProxies(world.contactManager.broadPhase)
@ -605,7 +605,7 @@ class Body(def: BodyDef, world: B2World) {
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.
if (type != BodyType.DYNAMIC && other.type != BodyType.DYNAMIC)
return false
@ -654,7 +654,7 @@ class Body(def: BodyDef, world: B2World) {
val broadPhase = world.contactManager.broadPhase
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
@ -868,11 +868,11 @@ class Body(def: BodyDef, world: B2World) {
transform1.position = sweep.c0 - transform1.rotation.times(sweep.localCenter)
for (fixture in fixtureIterator) {
(fixture as Fixture).synchronize(broadPhase, transform1, transform)
(fixture as B2Fixture).synchronize(broadPhase, transform1, transform)
}
} else {
for (fixture in fixtureIterator) {
(fixture as Fixture).synchronize(broadPhase, transform, transform)
(fixture as B2Fixture).synchronize(broadPhase, transform, transform)
}
}
}

View File

@ -2,7 +2,6 @@ package ru.dbotthepony.kbox2d.dynamics
import ru.dbotthepony.kbox2d.api.*
import ru.dbotthepony.kbox2d.collision.BroadPhase
import ru.dbotthepony.kbox2d.collision.shapes.ChainShape
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
import ru.dbotthepony.kvector.util2d.AABB
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
@ -16,22 +15,22 @@ import kotlin.collections.ArrayList
* Fixtures are created via b2Body::CreateFixture.
* @warning you cannot reuse fixtures.
*/
class Fixture(
body: Body,
class B2Fixture(
body: B2Body,
def: FixtureDef
) {
/**
* Get the parent body of this fixture. This is nullptr if the fixture is not attached.
* @return the parent body.
*/
var body: Body? = body
var body: B2Body? = body
private set
/**
* Get the next fixture in the parent body's fixture list.
* @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

View File

@ -78,7 +78,7 @@ class B2World(
* the next body in the world list. A nullptr body indicates the end of the list.
* @return the head of the world body list.
*/
var bodyList: Body? = null
var bodyList: B2Body? = null
private set
/**
@ -89,15 +89,15 @@ class B2World(
var jointList: AbstractJoint? = null
private set
val bodyListIterator: Iterator<Body> get() {
return object : Iterator<Body> {
val bodyListIterator: Iterator<B2Body> get() {
return object : Iterator<B2Body> {
private var node = bodyList
override fun hasNext(): Boolean {
return node != null
}
override fun next(): Body {
override fun next(): B2Body {
val old = node!!
node = old.next
check(node != old) { "Hard loop detected at $old" }
@ -191,11 +191,11 @@ class B2World(
* is retained.
* @warning This function is locked during callbacks.
*/
fun createBody(bodyDef: BodyDef): Body {
fun createBody(bodyDef: BodyDef): B2Body {
if (isLocked)
throw ConcurrentModificationException()
val body = Body(bodyDef, this)
val body = B2Body(bodyDef, this)
body.next = bodyList
bodyList?.prev = body
@ -211,7 +211,7 @@ class B2World(
* @warning This automatically deletes all associated shapes and joints.
* @warning This function is locked during callbacks.
*/
fun destroyBody(body: Body) {
fun destroyBody(body: B2Body) {
if (isLocked)
throw ConcurrentModificationException()
@ -400,7 +400,7 @@ class B2World(
// Reset island and stack.
island.clear()
val stack = ArrayDeque<Body>(32)
val stack = ArrayDeque<B2Body>(32)
stack.add(seed)
seed.isOnIsland = true
@ -554,8 +554,8 @@ class B2World(
continue
}
val bA = fA.body as Body
val bB = fB.body as Body
val bA = fA.body as B2Body
val bB = fB.body as B2Body
val typeA = bA.type
val typeB = bB.type
@ -633,8 +633,8 @@ class B2World(
// Advance the bodies to the TOI.
val fA = minContact.fixtureA
val fB = minContact.fixtureB
val bA = fA.body as Body
val bB = fB.body as Body
val bA = fA.body as B2Body
val bB = fB.body as B2Body
val backup1 = bA.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) {
IShape.Type.CIRCLE -> {
val circle = fixture.shape as CircleShape

View File

@ -35,8 +35,8 @@ class ContactManager {
fun destroy(contact: AbstractContact) {
val fixtureA = contact.fixtureA
val fixtureB = contact.fixtureB
val bodyA = fixtureA.body as Body
val bodyB = fixtureB.body as Body
val bodyA = fixtureA.body as B2Body
val bodyB = fixtureB.body as B2Body
if (contact.isTouching) {
contactListener?.endContact(contact)
@ -98,8 +98,8 @@ class ContactManager {
val fixtureB = c.fixtureB
val indexA = c.childIndexA
val indexB = c.childIndexB
val bodyA = fixtureA.body as Body
val bodyB = fixtureB.body as Body
val bodyA = fixtureA.body as B2Body
val bodyB = fixtureB.body as B2Body
// Is this contact flagged for filtering?
if (c.isFlaggedForFiltering) {
@ -154,8 +154,8 @@ class ContactManager {
val indexA = proxyA.childIndex
val indexB = proxyB.childIndex
val bodyA = fixtureA.body as Body
val bodyB = fixtureB.body as Body
val bodyA = fixtureA.body as B2Body
val bodyB = fixtureB.body as B2Body
// Are the fixtures on the same body?
if (bodyA === bodyB) {

View File

@ -3,13 +3,12 @@ package ru.dbotthepony.kbox2d.dynamics.contact
import ru.dbotthepony.kbox2d.api.*
import ru.dbotthepony.kbox2d.collision.WorldManifold
import ru.dbotthepony.kbox2d.collision.b2TestOverlap
import ru.dbotthepony.kbox2d.dynamics.Body
import ru.dbotthepony.kbox2d.dynamics.Fixture
import ru.dbotthepony.kbox2d.dynamics.B2Body
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
import java.util.*
import kotlin.collections.HashMap
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.
*/
val fixtureA: Fixture,
val fixtureA: B2Fixture,
/**
* Get the child primitive index for fixture A.
@ -31,7 +30,7 @@ sealed class AbstractContact(
/**
* Get fixture B in this contact.
*/
val fixtureB: Fixture,
val fixtureB: B2Fixture,
/**
* 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!!)
init {
val bodyA = fixtureA.body as Body
val bodyB = fixtureB.body as Body
val bodyA = fixtureA.body as B2Body
val bodyB = fixtureB.body as B2Body
nodeA.next = bodyA.contactEdge
nodeB.next = bodyB.contactEdge
@ -174,8 +173,8 @@ sealed class AbstractContact(
val sensor = fixtureA.isSensor || fixtureB.isSensor
val bodyA = fixtureA.body as Body
val bodyB = fixtureB.body as Body
val bodyA = fixtureA.body as B2Body
val bodyB = fixtureB.body as B2Body
val xfA = bodyA.transform
val xfB = bodyB.transform
@ -257,9 +256,9 @@ sealed class AbstractContact(
}
internal fun create(
fixtureA: Fixture,
fixtureA: B2Fixture,
indexA: Int,
fixtureB: Fixture,
fixtureB: B2Fixture,
indexB: Int,
): AbstractContact {
val type1 = fixtureA.type
@ -271,31 +270,31 @@ sealed class AbstractContact(
}
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)
}
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)
}
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)
}
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)
}
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)
}
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)
}
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)
}
}

View File

@ -6,12 +6,12 @@ import ru.dbotthepony.kbox2d.api.Transform
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndCircle
import ru.dbotthepony.kbox2d.collision.shapes.ChainShape
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
import ru.dbotthepony.kbox2d.dynamics.Fixture
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
class ChainCircleContact(
fixtureA: Fixture,
fixtureA: B2Fixture,
childIndexA: Int,
fixtureB: Fixture,
fixtureB: B2Fixture,
childIndexB: Int,
) : AbstractContact(fixtureA, childIndexA, fixtureB, childIndexB) {
init {

View File

@ -6,12 +6,12 @@ import ru.dbotthepony.kbox2d.api.Transform
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndPolygon
import ru.dbotthepony.kbox2d.collision.shapes.ChainShape
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
import ru.dbotthepony.kbox2d.dynamics.Fixture
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
class ChainPolygonContact(
fixtureA: Fixture,
fixtureA: B2Fixture,
childIndexA: Int,
fixtureB: Fixture,
fixtureB: B2Fixture,
childIndexB: Int,
) : AbstractContact(fixtureA, childIndexA, fixtureB, childIndexB) {
init {

View File

@ -5,11 +5,11 @@ import ru.dbotthepony.kbox2d.api.Manifold
import ru.dbotthepony.kbox2d.api.Transform
import ru.dbotthepony.kbox2d.collision.handler.b2CollideCircles
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
import ru.dbotthepony.kbox2d.dynamics.Fixture
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
class CircleContact(
fixtureA: Fixture,
fixtureB: Fixture,
fixtureA: B2Fixture,
fixtureB: B2Fixture,
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
init {
require(fixtureA.type == IShape.Type.CIRCLE) { "Fixture A is of type ${fixtureA.type}" }

View File

@ -6,11 +6,11 @@ import ru.dbotthepony.kbox2d.api.Transform
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndCircle
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
import ru.dbotthepony.kbox2d.collision.shapes.EdgeShape
import ru.dbotthepony.kbox2d.dynamics.Fixture
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
class EdgeCircleContact(
fixtureA: Fixture,
fixtureB: Fixture,
fixtureA: B2Fixture,
fixtureB: B2Fixture,
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
init {
require(fixtureA.type == IShape.Type.EDGE) { "Fixture A is of type ${fixtureA.type}, expected EDGE" }

View File

@ -6,11 +6,11 @@ import ru.dbotthepony.kbox2d.api.Transform
import ru.dbotthepony.kbox2d.collision.handler.b2CollideEdgeAndPolygon
import ru.dbotthepony.kbox2d.collision.shapes.EdgeShape
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
import ru.dbotthepony.kbox2d.dynamics.Fixture
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
class EdgePolygonContact(
fixtureA: Fixture,
fixtureB: Fixture,
fixtureA: B2Fixture,
fixtureB: B2Fixture,
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
init {
require(fixtureA.type == IShape.Type.EDGE) { "Fixture A is of type ${fixtureA.type}, expected EDGE" }

View File

@ -6,11 +6,11 @@ import ru.dbotthepony.kbox2d.api.Transform
import ru.dbotthepony.kbox2d.collision.handler.b2CollidePolygonAndCircle
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
import ru.dbotthepony.kbox2d.dynamics.Fixture
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
class PolygonCircleContact(
fixtureA: Fixture,
fixtureB: Fixture,
fixtureA: B2Fixture,
fixtureB: B2Fixture,
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
init {
require(fixtureA.type == IShape.Type.POLYGON) { "Fixture A is of type ${fixtureA.type}, expected POLYGON" }

View File

@ -5,11 +5,11 @@ import ru.dbotthepony.kbox2d.api.Manifold
import ru.dbotthepony.kbox2d.api.Transform
import ru.dbotthepony.kbox2d.collision.handler.b2CollidePolygons
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
import ru.dbotthepony.kbox2d.dynamics.Fixture
import ru.dbotthepony.kbox2d.dynamics.B2Fixture
class PolygonContact(
fixtureA: Fixture,
fixtureB: Fixture,
fixtureA: B2Fixture,
fixtureB: B2Fixture,
) : AbstractContact(fixtureA, 0, fixtureB, 0) {
init {
require(fixtureA.type == IShape.Type.POLYGON) { "Fixture A has type of ${fixtureA.type}" }

View File

@ -3,7 +3,7 @@ package ru.dbotthepony.kbox2d.dynamics.internal
import ru.dbotthepony.kbox2d.api.*
import ru.dbotthepony.kbox2d.collision.WorldManifold
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.MutableMatrix2d
import ru.dbotthepony.kvector.vector.ndouble.Vector2d
@ -144,8 +144,8 @@ internal class ContactSolver(
val shapeB = fixtureB.shape
val radiusA = shapeA.radius
val radiusB = shapeB.radius
val bodyA = fixtureA.body as Body
val bodyB = fixtureB.body as Body
val bodyA = fixtureA.body as B2Body
val bodyB = fixtureB.body as B2Body
val manifold = contact.manifold
check(manifold.points.isNotEmpty()) { "Manifold points at $i are empty" }

View File

@ -5,7 +5,7 @@ import ru.dbotthepony.kbox2d.collision.DistanceProxy
import ru.dbotthepony.kbox2d.collision.b2Distance
import ru.dbotthepony.kbox2d.dynamics.contact.AbstractContact
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.times
import java.util.*
@ -144,14 +144,14 @@ internal class Island(
initialJointCapacity: Int = 0,
val listener: IContactListener? = null
) {
private val bodies = ArrayList<Body>(initialBodyCapacity)
private val bodies = ArrayList<B2Body>(initialBodyCapacity)
private val contacts = ArrayList<AbstractContact>(initialContactCapacity)
private val joints = ArrayList<AbstractJoint>(initialJointCapacity)
private val velocities = ArrayList<ru.dbotthepony.kbox2d.api.B2Velocity>(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() {
bodies.clear()
@ -162,7 +162,7 @@ internal class Island(
positions.clear()
}
fun add(body: Body) {
fun add(body: B2Body) {
body.islandIndex = bodies.size
bodies.add(body)
velocities.add(ru.dbotthepony.kbox2d.api.B2Velocity())

View File

@ -1,7 +1,7 @@
package ru.dbotthepony.kbox2d.dynamics.joint
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 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
// possible, bodyA and bodyB getters assert for null by themselves
// However, there is nullable getter for bodies: nullableBodyA and nullableBodyB
protected var _bodyA: Body? = def.bodyA as Body?
protected var _bodyB: Body? = def.bodyB as Body?
protected var _bodyA: B2Body? = def.bodyA as B2Body?
protected var _bodyB: B2Body? = def.bodyB as B2Body?
/**
* 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.
*/
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.

View File

@ -1,7 +1,7 @@
package ru.dbotthepony.kbox2d.dynamics.joint
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.times
@ -126,8 +126,8 @@ class GearJoint(def: GearJointDef) : AbstractJoint(def) {
// Body A is connected to body C
// Body B is connected to body D
private var _bodyC: Body? = joint1.bodyA
private var _bodyD: Body?
private var _bodyC: B2Body? = joint1.bodyA
private var _bodyD: B2Body?
override fun unlink() {
super.unlink()
@ -135,8 +135,8 @@ class GearJoint(def: GearJointDef) : AbstractJoint(def) {
_bodyD = null
}
val bodyC: Body get() = checkNotNull(_bodyC) { "Body C is not present" }
val bodyD: Body get() = checkNotNull(_bodyD) { "Body D is not present" }
val bodyC: B2Body get() = checkNotNull(_bodyC) { "Body C is not present" }
val bodyD: B2Body get() = checkNotNull(_bodyD) { "Body D is not present" }
init {
_bodyA = joint1.bodyB

View File

@ -8,7 +8,7 @@ import ru.dbotthepony.kbox2d.collision.shapes.ChainShape
import ru.dbotthepony.kbox2d.collision.shapes.CircleShape
import ru.dbotthepony.kbox2d.collision.shapes.PolygonShape
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.kstarbound.client.StarboundClient
import ru.dbotthepony.kstarbound.world.Chunk
@ -54,7 +54,7 @@ fun main() {
ground.createFixture(groundPoly, 0.0)
val boxes = ArrayList<Body>()
val boxes = ArrayList<B2Body>()
/*run {
val movingDef = BodyDef(