box2d

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2018 License: Zlib Imports: 5 Imported by: 0

README

Box2D.go

What is this ?

This is Go a port of Box2D (https://github.com/erincatto/Box2D), a 2D physics engine for games written in C++ by Erin Catto.

The port is complete and based on the latest Box2D commit as of 2017-09-20 (https://github.com/erincatto/Box2D/commit/f655c603ba9d83f07fc566d38d2654ba35739102)

Who did this ?

The ByteArena team did. Erin Catto, the author of the original software, was not involved in the port.

https://s3.eu-central-1.amazonaws.com/bytearena-public/ba-prod-twitter.mp4

Documentation

We kept the source code as close to the C++ as we possibly could. So the documentation you'll find on Box2D is relevant.

http://box2d.org/manual.pdf

API changes

The API had to change a tiny bit due to the fact that :

  • Go has no constructors as a language feature, thus code for constructors has been placed in Make$NAME_OF_TYPE functions
  • Go has no support for function overloading; some functions implemented multiple times for different sets of parameters under the same name in C++ are distinguished by name in the golang version; we tried to make names explicit so that should not be an issue
  • Go has no support for operator overloading; this C++ feature is used extensively throughout the C++ version of Box2D (mainly for the vector and matrix arithmethic), and has been converted to good old, albeit verbose function calls

Tests

No opengl testbed for the moment.

Our tests verify the output of position and rotation of bodies over time against those generared by the C++ reference.

Right now, there's a test (passing) checking all the supported body shape collisions in cmd/test-character-collision.

Usage example

Have a look at cpp_compliance_test.go.

License of the original Box2D (C++)

The original Box2D is developed by Erin Catto, and has the zlib license. Thank you Erin for this incredible piece of software.

License of this port (Go)

Box2D.go is developed by ByteArena (https://github.com/bytearena), and has the zlib license. While the zlib license does not require acknowledgement, we encourage you to give credit to Box2D.go in your product.

Documentation

Index

Constants

View Source
const B2DEBUG = false

@port(OK)

View Source
const B2_DEBUG_SOLVER = 0

// Solver debugging is normally disabled because the block solver sometimes has to deal with a poorly conditioned effective mass matrix.

View Source
const B2_aabbExtension = 0.1

/ This is used to fatten AABBs in the dynamic tree. This allows proxies / to move by a small amount without triggering a tree adjustment. / This is in meters.

View Source
const B2_aabbMultiplier = 2.0

/ This is used to fatten AABBs in the dynamic tree. This is used to predict / the future position based on the current displacement. / This is a dimensionless multiplier.

View Source
const B2_angularSleepTolerance = (2.0 / 180.0 * B2_pi)

/ A body cannot sleep if its angular velocity is above this tolerance.

View Source
const B2_angularSlop = (2.0 / 180.0 * B2_pi)

/ A small angle used as a collision and constraint tolerance. Usually it is / chosen to be numerically significant, but visually insignificant.

View Source
const B2_baumgarte = 0.2

/ This scale factor controls how fast overlap is resolved. Ideally this would be 1 so / that overlap is removed in one time step. However using values close to 1 often lead / to overshoot.

View Source
const B2_linearSleepTolerance = 0.01

/ A body cannot sleep if its linear velocity is above this tolerance.

View Source
const B2_linearSlop = 0.005

/ A small length used as a collision and constraint tolerance. Usually it is / chosen to be numerically significant, but visually insignificant.

View Source
const B2_maxAngularCorrection = (8.0 / 180.0 * B2_pi)

/ The maximum angular position correction used when solving constraints. This helps to / prevent overshoot.

View Source
const B2_maxFloat = math.MaxFloat64
View Source
const B2_maxLinearCorrection = 0.2

/ The maximum linear position correction used when solving constraints. This helps to / prevent overshoot.

View Source
const B2_maxManifoldPoints = 2

/ The maximum number of contact points between two convex shapes. Do / not change this value.

View Source
const B2_maxPolygonVertices = 8

/ The maximum number of vertices on a convex polygon. You cannot increase / this too much because b2BlockAllocator has a maximum object size.

View Source
const B2_maxRotation = (0.5 * B2_pi)

/ The maximum angular velocity of a body. This limit is very large and is used / to prevent numerical problems. You shouldn't need to adjust this.

View Source
const B2_maxRotationSquared = (B2_maxRotation * B2_maxRotation)
View Source
const B2_maxSubSteps = 8

/ Maximum number of sub-steps per contact in continuous physics simulation.

View Source
const B2_maxTOIContacts = 32

/ Maximum number of contacts to be handled to solve a TOI impact.

View Source
const B2_maxTranslation = 2.0

/ The maximum linear velocity of a body. This limit is very large and is used / to prevent numerical problems. You shouldn't need to adjust this.

View Source
const B2_maxTranslationSquared = (B2_maxTranslation * B2_maxTranslation)
View Source
const B2_nullFeature uint8 = math.MaxUint8
View Source
const B2_nullNode = -1
View Source
const B2_pi = math.Pi
View Source
const B2_polygonRadius = (2.0 * B2_linearSlop)

/ The radius of the polygon/edge shape skin. This should not be modified. Making / this smaller means polygons will have an insufficient buffer for continuous collision. / Making it larger may create artifacts for vertex collision.

View Source
const B2_timeToSleep = 0.5

/ The time that a body must be still before it will go to sleep.

View Source
const B2_toiBaugarte = 0.75
View Source
const B2_velocityThreshold = 1.0

/ A velocity threshold for elastic collisions. Any collision with a relative linear / velocity below this threshold will be treated as inelastic.

View Source
const E_nullProxy = -1

Variables

View Source
var B2BodyType = struct {
	B2_staticBody    uint8
	B2_kinematicBody uint8
	B2_dynamicBody   uint8
}{
	B2_staticBody:    0,
	B2_kinematicBody: 1,
	B2_dynamicBody:   2,
}
View Source
var B2Body_Flags = struct {
	E_islandFlag        uint32
	E_awakeFlag         uint32
	E_autoSleepFlag     uint32
	E_bulletFlag        uint32
	E_fixedRotationFlag uint32
	E_activeFlag        uint32
	E_toiFlag           uint32
}{
	E_islandFlag:        0x0001,
	E_awakeFlag:         0x0002,
	E_autoSleepFlag:     0x0004,
	E_bulletFlag:        0x0008,
	E_fixedRotationFlag: 0x0010,
	E_activeFlag:        0x0020,
	E_toiFlag:           0x0040,
}
View Source
var B2ContactFeature_Type = struct {
	E_vertex uint8
	E_face   uint8
}{
	E_vertex: 0,
	E_face:   1,
}
View Source
var B2Contact_Flag = struct {
	// Used when crawling contact graph when forming islands.
	E_islandFlag uint32

	// Set when the shapes are touching.
	E_touchingFlag uint32

	// This contact can be disabled (by user)
	E_enabledFlag uint32

	// This contact needs filtering because a fixture filter was changed.
	E_filterFlag uint32

	// This bullet contact had a TOI event
	E_bulletHitFlag uint32

	// This contact has a valid TOI in m_toi
	E_toiFlag uint32
}{
	E_islandFlag:    0x0001,
	E_touchingFlag:  0x0002,
	E_enabledFlag:   0x0004,
	E_filterFlag:    0x0008,
	E_bulletHitFlag: 0x0010,
	E_toiFlag:       0x0020,
}
View Source
var B2EPAxis_Type = struct {
	E_unknown uint8
	E_edgeA   uint8
	E_edgeB   uint8
}{
	E_unknown: 0,
	E_edgeA:   1,
	E_edgeB:   2,
}

This structure is used to keep track of the best separating axis.

View Source
var B2EPCollider_VertexType = struct {
	E_isolated uint8
	E_concave  uint8
	E_convex   uint8
}{
	E_isolated: 0,
	E_concave:  1,
	E_convex:   2,
}
View Source
var B2JointType = struct {
	E_unknownJoint   uint8
	E_revoluteJoint  uint8
	E_prismaticJoint uint8
	E_distanceJoint  uint8
	E_pulleyJoint    uint8
	E_mouseJoint     uint8
	E_gearJoint      uint8
	E_wheelJoint     uint8
	E_weldJoint      uint8
	E_frictionJoint  uint8
	E_ropeJoint      uint8
	E_motorJoint     uint8
}{
	E_unknownJoint:   1,
	E_revoluteJoint:  2,
	E_prismaticJoint: 3,
	E_distanceJoint:  4,
	E_pulleyJoint:    5,
	E_mouseJoint:     6,
	E_gearJoint:      7,
	E_wheelJoint:     8,
	E_weldJoint:      9,
	E_frictionJoint:  10,
	E_ropeJoint:      11,
	E_motorJoint:     12,
}
View Source
var B2LimitState = struct {
	E_inactiveLimit uint8
	E_atLowerLimit  uint8
	E_atUpperLimit  uint8
	E_equalLimits   uint8
}{
	E_inactiveLimit: 1,
	E_atLowerLimit:  2,
	E_atUpperLimit:  3,
	E_equalLimits:   4,
}
View Source
var B2Manifold_Type = struct {
	E_circles uint8
	E_faceA   uint8
	E_faceB   uint8
}{
	E_circles: 0,
	E_faceA:   1,
	E_faceB:   2,
}
View Source
var B2PointState = struct {
	B2_nullState    uint8 ///< point does not exist
	B2_addState     uint8 ///< point was added in the update
	B2_persistState uint8 ///< point persisted across the update
	B2_removeState  uint8 ///< point was removed in the update
}{
	B2_nullState:    0,
	B2_addState:     1,
	B2_persistState: 2,
	B2_removeState:  3,
}
View Source
var B2SeparationFunction_Type = struct {
	E_points uint8
	E_faceA  uint8
	E_faceB  uint8
}{
	E_points: 0,
	E_faceA:  1,
	E_faceB:  2,
}
View Source
var B2Shape_Type = struct {
	E_circle    uint8
	E_edge      uint8
	E_polygon   uint8
	E_chain     uint8
	E_typeCount uint8
}{
	E_circle:    0,
	E_edge:      1,
	E_polygon:   2,
	E_chain:     3,
	E_typeCount: 4,
}
View Source
var B2TOIOutput_State = struct {
	E_unknown    uint8
	E_failed     uint8
	E_overlapped uint8
	E_touching   uint8
	E_separated  uint8
}{
	E_unknown:    1,
	E_failed:     2,
	E_overlapped: 3,
	E_touching:   4,
	E_separated:  5,
}
View Source
var B2Vec2_zero = MakeB2Vec2(0, 0)

/ Useful constant

View Source
var B2World_Flags = struct {
	E_newFixture  int
	E_locked      int
	E_clearForces int
}{
	E_newFixture:  0x0001,
	E_locked:      0x0002,
	E_clearForces: 0x0004,
}
View Source
var B2_toiCalls, B2_toiIters, B2_toiMaxIters int
View Source
var B2_toiRootIters, B2_toiMaxRootIters int
View Source
var B2_toiTime, B2_toiMaxTime float64

Functions

func AbsInt

func AbsInt(v int) int

func AddType

func AddType(createFcn B2ContactCreateFcn, destroyFcn B2ContactDestroyFcn, type1 uint8, type2 uint8)

func B2Assert

func B2Assert(a bool)

@port(OK)

func B2ChainAndCircleContact_Destroy

func B2ChainAndCircleContact_Destroy(contact B2ContactInterface)

func B2ChainAndPolygonContact_Destroy

func B2ChainAndPolygonContact_Destroy(contact B2ContactInterface)

func B2CircleContact_Destroy

func B2CircleContact_Destroy(contact B2ContactInterface)

func B2ClipSegmentToLine

func B2ClipSegmentToLine(vOut []B2ClipVertex, vIn []B2ClipVertex, normal B2Vec2, offset float64, vertexIndexA int) int

Sutherland-Hodgman clipping.

func B2CollideCircles

func B2CollideCircles(manifold *B2Manifold, circleA *B2CircleShape, xfA B2Transform, circleB *B2CircleShape, xfB B2Transform)

func B2CollideEdgeAndCircle

func B2CollideEdgeAndCircle(manifold *B2Manifold, edgeA *B2EdgeShape, xfA B2Transform, circleB *B2CircleShape, xfB B2Transform)

Compute contact points for edge versus circle. This accounts for edge connectivity.

func B2CollideEdgeAndPolygon

func B2CollideEdgeAndPolygon(manifold *B2Manifold, edgeA *B2EdgeShape, xfA B2Transform, polygonB *B2PolygonShape, xfB B2Transform)

func B2CollidePolygonAndCircle

func B2CollidePolygonAndCircle(manifold *B2Manifold, polygonA *B2PolygonShape, xfA B2Transform, circleB *B2CircleShape, xfB B2Transform)

func B2CollidePolygons

func B2CollidePolygons(manifold *B2Manifold, polyA *B2PolygonShape, xfA B2Transform, polyB *B2PolygonShape, xfB B2Transform)

The normal points from 1 to 2

func B2ContactDestroy

func B2ContactDestroy(contact B2ContactInterface)

func B2ContactInitializeRegisters

func B2ContactInitializeRegisters()

func B2ContactUpdate

func B2ContactUpdate(contact B2ContactInterface, listener B2ContactListenerInterface)

Update the contact manifold and touching status. Note: do not assume the fixture AABBs are overlapping or are valid.

func B2Distance

func B2Distance(output *B2DistanceOutput, cache *B2SimplexCache, input *B2DistanceInput)

func B2EdgeAndCircleContact_Destroy

func B2EdgeAndCircleContact_Destroy(contact B2ContactInterface)

func B2EdgeAndPolygonContact_Destroy

func B2EdgeAndPolygonContact_Destroy(contact B2ContactInterface)

func B2FindIncidentEdge

func B2FindIncidentEdge(c []B2ClipVertex, poly1 *B2PolygonShape, xf1 B2Transform, edge1 int, poly2 *B2PolygonShape, xf2 B2Transform)

func B2FindMaxSeparation

func B2FindMaxSeparation(edgeIndex *int, poly1 *B2PolygonShape, xf1 B2Transform, poly2 *B2PolygonShape, xf2 B2Transform) float64

Find the max separation between poly1 and poly2 using edge normals from poly1.

func B2FloatClamp

func B2FloatClamp(a, low, high float64) float64

func B2GetPointStates

func B2GetPointStates(state1 *[B2_maxManifoldPoints]uint8, state2 *[B2_maxManifoldPoints]uint8, manifold1 B2Manifold, manifold2 B2Manifold)

func B2InvSqrt

func B2InvSqrt(x float64) float64

/ This is a approximate yet fast inverse square-root.

func B2IsPowerOfTwo

func B2IsPowerOfTwo(x uint32) bool

func B2IsValid

func B2IsValid(x float64) bool

/ This function is used to ensure that a floating point number is not a NaN or infinity.

func B2JointDestroy

func B2JointDestroy(joint B2JointInterface)

func B2MixFriction

func B2MixFriction(friction1, friction2 float64) float64

/ Friction mixing law. The idea is to allow either fixture to drive the friction to zero. / For example, anything slides on ice.

func B2MixRestitution

func B2MixRestitution(restitution1, restitution2 float64) float64

/ Restitution mixing law. The idea is allow for anything to bounce off an inelastic surface. / For example, a superball bounces on anything.

func B2NextPowerOfTwo

func B2NextPowerOfTwo(x uint32) uint32

/ "Next Largest Power of 2 / Given a binary integer value x, the next largest power of 2 can be computed by a SWAR algorithm / that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with / the same most significant 1 as x, but all 1's below it. Adding 1 to that value yields the next / largest power of 2. For a 32-bit value:"

func B2PairLessThan

func B2PairLessThan(pair1 B2Pair, pair2 B2Pair) bool

/ This is used to sort pairs.

func B2PolygonAndCircleContact_Destroy

func B2PolygonAndCircleContact_Destroy(contact B2ContactInterface)

func B2PolygonContact_Destroy

func B2PolygonContact_Destroy(contact B2ContactInterface)

func B2TestOverlapBoundingBoxes

func B2TestOverlapBoundingBoxes(a, b B2AABB) bool

func B2TestOverlapShapes

func B2TestOverlapShapes(shapeA B2ShapeInterface, indexA int, shapeB B2ShapeInterface, indexB int, xfA B2Transform, xfB B2Transform) bool

func B2TimeOfImpact

func B2TimeOfImpact(output *B2TOIOutput, input *B2TOIInput)

/ Compute the upper bound on time before two shapes penetrate. Time is represented as / a fraction between [0,tMax]. This uses a swept separating axis and may miss some intermediate, / non-tunneling collision. If you change the time interval, you should call this function / again. / Note: use b2Distance to compute the contact point and normal at the time of impact. CCD via the local separating axis method. This seeks progression by computing the largest time at which separation is maintained.

func B2Vec2Cross

func B2Vec2Cross(a, b B2Vec2) float64

/ Perform the cross product on two vectors. In 2D this produces a scalar.

func B2Vec2Distance

func B2Vec2Distance(a, b B2Vec2) float64

func B2Vec2DistanceSquared

func B2Vec2DistanceSquared(a, b B2Vec2) float64

func B2Vec2Dot

func B2Vec2Dot(a, b B2Vec2) float64

/ Perform the dot product on two vectors.

func B2Vec2Equals

func B2Vec2Equals(a, b B2Vec2) bool

func B2Vec2NotEquals

func B2Vec2NotEquals(a, b B2Vec2) bool

func B2Vec3Dot

func B2Vec3Dot(a, b B2Vec3) float64

/ Perform the dot product on two vectors.

func MaxInt

func MaxInt(x, y int) int

func MinInt

func MinInt(x, y int) int

Types

type B2AABB

type B2AABB struct {
	LowerBound B2Vec2 ///< the lower vertex
	UpperBound B2Vec2 ///< the upper vertex
}

/ An axis aligned bounding box.

func MakeB2AABB

func MakeB2AABB() B2AABB

func NewB2AABB

func NewB2AABB() *B2AABB

func (B2AABB) Clone

func (bb B2AABB) Clone() B2AABB

func (*B2AABB) CombineInPlace

func (bb *B2AABB) CombineInPlace(aabb B2AABB)

/ Combine an AABB into this one.

func (*B2AABB) CombineTwoInPlace

func (bb *B2AABB) CombineTwoInPlace(aabb1, aabb2 B2AABB)

/ Combine two AABBs into this one.

func (B2AABB) Contains

func (bb B2AABB) Contains(aabb B2AABB) bool

/ Does this aabb contain the provided AABB.

func (B2AABB) GetCenter

func (bb B2AABB) GetCenter() B2Vec2

/ Get the center of the AABB.

func (B2AABB) GetExtents

func (bb B2AABB) GetExtents() B2Vec2

/ Get the extents of the AABB (half-widths).

func (B2AABB) GetPerimeter

func (bb B2AABB) GetPerimeter() float64

/ Get the perimeter length

func (B2AABB) IsValid

func (bb B2AABB) IsValid() bool

func (B2AABB) RayCast

func (bb B2AABB) RayCast(output *B2RayCastOutput, input B2RayCastInput) bool

From Real-time Collision Detection, p179.

type B2Body

type B2Body struct {
	M_type uint8

	M_flags uint32

	M_islandIndex int

	M_xf    B2Transform // the body origin transform
	M_sweep B2Sweep     // the swept motion for CCD

	M_linearVelocity  B2Vec2
	M_angularVelocity float64

	M_force  B2Vec2
	M_torque float64

	M_world *B2World
	M_prev  *B2Body
	M_next  *B2Body

	M_fixtureList  *B2Fixture // linked list
	M_fixtureCount int

	M_jointList   *B2JointEdge   // linked list
	M_contactList *B2ContactEdge // linked list

	M_mass, M_invMass float64

	// Rotational inertia about the center of mass.
	M_I, M_invI float64

	M_linearDamping  float64
	M_angularDamping float64
	M_gravityScale   float64

	M_sleepTime float64

	M_userData interface{}
}

func NewB2Body

func NewB2Body(bd *B2BodyDef, world *B2World) *B2Body

func (*B2Body) Advance

func (body *B2Body) Advance(alpha float64)

func (*B2Body) ApplyAngularImpulse

func (body *B2Body) ApplyAngularImpulse(impulse float64, wake bool)

func (*B2Body) ApplyForce

func (body *B2Body) ApplyForce(force B2Vec2, point B2Vec2, wake bool)

func (*B2Body) ApplyForceToCenter

func (body *B2Body) ApplyForceToCenter(force B2Vec2, wake bool)

func (*B2Body) ApplyLinearImpulse

func (body *B2Body) ApplyLinearImpulse(impulse B2Vec2, point B2Vec2, wake bool)

func (*B2Body) ApplyLinearImpulseToCenter

func (body *B2Body) ApplyLinearImpulseToCenter(impulse B2Vec2, wake bool)

func (*B2Body) ApplyTorque

func (body *B2Body) ApplyTorque(torque float64, wake bool)

func (*B2Body) CreateFixture

func (body *B2Body) CreateFixture(shape B2ShapeInterface, density float64) *B2Fixture

func (*B2Body) CreateFixtureFromDef

func (body *B2Body) CreateFixtureFromDef(def *B2FixtureDef) *B2Fixture

func (*B2Body) DestroyFixture

func (body *B2Body) DestroyFixture(fixture *B2Fixture)

func (*B2Body) Dump

func (body *B2Body) Dump()

func (B2Body) GetAngle

func (body B2Body) GetAngle() float64

func (B2Body) GetAngularDamping

func (body B2Body) GetAngularDamping() float64

func (B2Body) GetAngularVelocity

func (body B2Body) GetAngularVelocity() float64

func (B2Body) GetContactList

func (body B2Body) GetContactList() *B2ContactEdge

func (B2Body) GetFixtureList

func (body B2Body) GetFixtureList() *B2Fixture

func (B2Body) GetGravityScale

func (body B2Body) GetGravityScale() float64

func (B2Body) GetInertia

func (body B2Body) GetInertia() float64

func (B2Body) GetJointList

func (body B2Body) GetJointList() *B2JointEdge

func (B2Body) GetLinearDamping

func (body B2Body) GetLinearDamping() float64

func (B2Body) GetLinearVelocity

func (body B2Body) GetLinearVelocity() B2Vec2

func (B2Body) GetLinearVelocityFromLocalPoint

func (body B2Body) GetLinearVelocityFromLocalPoint(localPoint B2Vec2) B2Vec2

func (B2Body) GetLinearVelocityFromWorldPoint

func (body B2Body) GetLinearVelocityFromWorldPoint(worldPoint B2Vec2) B2Vec2

func (B2Body) GetLocalCenter

func (body B2Body) GetLocalCenter() B2Vec2

func (B2Body) GetLocalPoint

func (body B2Body) GetLocalPoint(worldPoint B2Vec2) B2Vec2

func (B2Body) GetLocalVector

func (body B2Body) GetLocalVector(worldVector B2Vec2) B2Vec2

func (B2Body) GetMass

func (body B2Body) GetMass() float64

func (B2Body) GetMassData

func (body B2Body) GetMassData(data *B2MassData)

func (B2Body) GetNext

func (body B2Body) GetNext() *B2Body

func (B2Body) GetPosition

func (body B2Body) GetPosition() B2Vec2

func (B2Body) GetTransform

func (body B2Body) GetTransform() B2Transform

func (B2Body) GetType

func (body B2Body) GetType() uint8

func (B2Body) GetUserData

func (body B2Body) GetUserData() interface{}

func (B2Body) GetWorld

func (body B2Body) GetWorld() *B2World

func (B2Body) GetWorldCenter

func (body B2Body) GetWorldCenter() B2Vec2

func (B2Body) GetWorldPoint

func (body B2Body) GetWorldPoint(localPoint B2Vec2) B2Vec2

func (B2Body) GetWorldVector

func (body B2Body) GetWorldVector(localVector B2Vec2) B2Vec2

func (B2Body) IsActive

func (body B2Body) IsActive() bool

func (B2Body) IsAwake

func (body B2Body) IsAwake() bool

func (B2Body) IsBullet

func (body B2Body) IsBullet() bool

func (B2Body) IsFixedRotation

func (body B2Body) IsFixedRotation() bool

func (B2Body) IsSleepingAllowed

func (body B2Body) IsSleepingAllowed() bool

func (*B2Body) ResetMassData

func (body *B2Body) ResetMassData()

func (*B2Body) SetActive

func (body *B2Body) SetActive(flag bool)

func (*B2Body) SetAngularDamping

func (body *B2Body) SetAngularDamping(angularDamping float64)

func (*B2Body) SetAngularVelocity

func (body *B2Body) SetAngularVelocity(w float64)

func (*B2Body) SetAwake

func (body *B2Body) SetAwake(flag bool)

func (*B2Body) SetBullet

func (body *B2Body) SetBullet(flag bool)

func (*B2Body) SetFixedRotation

func (body *B2Body) SetFixedRotation(flag bool)

func (*B2Body) SetGravityScale

func (body *B2Body) SetGravityScale(scale float64)

func (*B2Body) SetLinearDamping

func (body *B2Body) SetLinearDamping(linearDamping float64)

func (*B2Body) SetLinearVelocity

func (body *B2Body) SetLinearVelocity(v B2Vec2)

func (*B2Body) SetMassData

func (body *B2Body) SetMassData(massData *B2MassData)

func (*B2Body) SetSleepingAllowed

func (body *B2Body) SetSleepingAllowed(flag bool)

func (*B2Body) SetTransform

func (body *B2Body) SetTransform(position B2Vec2, angle float64)

func (*B2Body) SetType

func (body *B2Body) SetType(bodytype uint8)

func (*B2Body) SetUserData

func (body *B2Body) SetUserData(data interface{})

func (B2Body) ShouldCollide

func (body B2Body) ShouldCollide(other *B2Body) bool

func (*B2Body) SynchronizeFixtures

func (body *B2Body) SynchronizeFixtures()

func (*B2Body) SynchronizeTransform

func (body *B2Body) SynchronizeTransform()

type B2BodyDef

type B2BodyDef struct {

	/// The body type: static, kinematic, or dynamic.
	/// Note: if a dynamic body would have zero mass, the mass is set to one.
	Type uint8

	/// The world position of the body. Avoid creating bodies at the origin
	/// since this can lead to many overlapping shapes.
	Position B2Vec2

	/// The world angle of the body in radians.
	Angle float64

	/// The linear velocity of the body's origin in world co-ordinates.
	LinearVelocity B2Vec2

	/// The angular velocity of the body.
	AngularVelocity float64

	/// Linear damping is use to reduce the linear velocity. The damping parameter
	/// can be larger than 1.0 but the damping effect becomes sensitive to the
	/// time step when the damping parameter is large.
	/// Units are 1/time
	LinearDamping float64

	/// Angular damping is use to reduce the angular velocity. The damping parameter
	/// can be larger than 1.0 but the damping effect becomes sensitive to the
	/// time step when the damping parameter is large.
	/// Units are 1/time
	AngularDamping float64

	/// Set this flag to false if this body should never fall asleep. Note that
	/// this increases CPU usage.
	AllowSleep bool

	/// Is this body initially awake or sleeping?
	Awake bool

	/// Should this body be prevented from rotating? Useful for characters.
	FixedRotation bool

	/// Is this a fast moving body that should be prevented from tunneling through
	/// other moving bodies? Note that all bodies are prevented from tunneling through
	/// kinematic and static bodies. This setting is only considered on dynamic bodies.
	/// @warning You should use this flag sparingly since it increases processing time.
	Bullet bool

	/// Does this body start out active?
	Active bool

	/// Use this to store application specific body data.
	UserData interface{}

	/// Scale the gravity applied to this body.
	GravityScale float64
}

/ A body definition holds all the data needed to construct a rigid body. / You can safely re-use body definitions. Shapes are added to a body after construction.

func MakeB2BodyDef

func MakeB2BodyDef() B2BodyDef

/ This constructor sets the body definition default values.

func NewB2BodyDef

func NewB2BodyDef() *B2BodyDef

type B2BroadPhase

type B2BroadPhase struct {
	M_tree B2DynamicTree

	M_proxyCount int

	M_moveBuffer   []int
	M_moveCapacity int
	M_moveCount    int

	M_pairBuffer   []B2Pair
	M_pairCapacity int
	M_pairCount    int

	M_queryProxyId int
}

func MakeB2BroadPhase

func MakeB2BroadPhase() B2BroadPhase

func (*B2BroadPhase) BufferMove

func (bp *B2BroadPhase) BufferMove(proxyId int)

func (*B2BroadPhase) CreateProxy

func (bp *B2BroadPhase) CreateProxy(aabb B2AABB, userData interface{}) int

func (*B2BroadPhase) DestroyProxy

func (bp *B2BroadPhase) DestroyProxy(proxyId int)

func (B2BroadPhase) GetFatAABB

func (bp B2BroadPhase) GetFatAABB(proxyId int) B2AABB

func (B2BroadPhase) GetProxyCount

func (bp B2BroadPhase) GetProxyCount() int

func (B2BroadPhase) GetTreeBalance

func (bp B2BroadPhase) GetTreeBalance() int

func (B2BroadPhase) GetTreeHeight

func (bp B2BroadPhase) GetTreeHeight() int

func (B2BroadPhase) GetTreeQuality

func (bp B2BroadPhase) GetTreeQuality() float64

func (B2BroadPhase) GetUserData

func (bp B2BroadPhase) GetUserData(proxyId int) interface{}

func (*B2BroadPhase) MoveProxy

func (bp *B2BroadPhase) MoveProxy(proxyId int, aabb B2AABB, displacement B2Vec2)

func (*B2BroadPhase) Query

func (bp *B2BroadPhase) Query(callback B2TreeQueryCallback, aabb B2AABB)

func (*B2BroadPhase) QueryCallback

func (bp *B2BroadPhase) QueryCallback(proxyId int) bool

This is called from b2DynamicTree::Query when we are gathering pairs.

func (*B2BroadPhase) RayCast

func (bp *B2BroadPhase) RayCast(callback B2TreeRayCastCallback, input B2RayCastInput)

func (*B2BroadPhase) ShiftOrigin

func (bp *B2BroadPhase) ShiftOrigin(newOrigin B2Vec2)

func (B2BroadPhase) TestOverlap

func (bp B2BroadPhase) TestOverlap(proxyIdA int, proxyIdB int) bool

func (*B2BroadPhase) TouchProxy

func (bp *B2BroadPhase) TouchProxy(proxyId int)

func (*B2BroadPhase) UnBufferMove

func (bp *B2BroadPhase) UnBufferMove(proxyId int)

func (*B2BroadPhase) UpdatePairs

func (bp *B2BroadPhase) UpdatePairs(addPairCallback B2BroadPhaseAddPairCallback)

type B2BroadPhaseAddPairCallback

type B2BroadPhaseAddPairCallback func(userDataA interface{}, userDataB interface{})

type B2BroadPhaseQueryCallback

type B2BroadPhaseQueryCallback func(fixture *B2Fixture) bool

type B2ChainAndCircleContact

type B2ChainAndCircleContact struct {
	B2Contact
}

func (*B2ChainAndCircleContact) Evaluate

func (contact *B2ChainAndCircleContact) Evaluate(manifold *B2Manifold, xfA B2Transform, xfB B2Transform)

type B2ChainAndPolygonContact

type B2ChainAndPolygonContact struct {
	B2Contact
}

func (*B2ChainAndPolygonContact) Evaluate

func (contact *B2ChainAndPolygonContact) Evaluate(manifold *B2Manifold, xfA B2Transform, xfB B2Transform)

type B2ChainShape

type B2ChainShape struct {
	B2Shape

	/// The vertices. Owned by this class.
	M_vertices []B2Vec2

	/// The vertex count.
	M_count int

	M_prevVertex    B2Vec2
	M_nextVertex    B2Vec2
	M_hasPrevVertex bool
	M_hasNextVertex bool
}

/ A circle shape.

func MakeB2ChainShape

func MakeB2ChainShape() B2ChainShape

func (*B2ChainShape) Clear

func (chain *B2ChainShape) Clear()

func (B2ChainShape) Clone

func (chain B2ChainShape) Clone() B2ShapeInterface

func (B2ChainShape) ComputeAABB

func (chain B2ChainShape) ComputeAABB(aabb *B2AABB, xf B2Transform, childIndex int)

func (B2ChainShape) ComputeMass

func (chain B2ChainShape) ComputeMass(massData *B2MassData, density float64)

func (*B2ChainShape) CreateChain

func (chain *B2ChainShape) CreateChain(vertices []B2Vec2, count int)

func (*B2ChainShape) CreateLoop

func (chain *B2ChainShape) CreateLoop(vertices []B2Vec2, count int)

func (*B2ChainShape) Destroy

func (chain *B2ChainShape) Destroy()

func (B2ChainShape) GetChildCount

func (chain B2ChainShape) GetChildCount() int

func (B2ChainShape) GetChildEdge

func (chain B2ChainShape) GetChildEdge(edge *B2EdgeShape, index int)

func (B2ChainShape) RayCast

func (chain B2ChainShape) RayCast(output *B2RayCastOutput, input B2RayCastInput, xf B2Transform, childIndex int) bool

func (*B2ChainShape) SetNextVertex

func (chain *B2ChainShape) SetNextVertex(nextVertex B2Vec2)

func (*B2ChainShape) SetPrevVertex

func (chain *B2ChainShape) SetPrevVertex(prevVertex B2Vec2)

func (B2ChainShape) TestPoint

func (chain B2ChainShape) TestPoint(xf B2Transform, p B2Vec2) bool

type B2CircleContact

type B2CircleContact struct {
	B2Contact
}

func (*B2CircleContact) Evaluate

func (contact *B2CircleContact) Evaluate(manifold *B2Manifold, xfA B2Transform, xfB B2Transform)

type B2CircleShape

type B2CircleShape struct {
	B2Shape
	/// Position
	M_p B2Vec2
}

/ A circle shape.

func MakeB2CircleShape

func MakeB2CircleShape() B2CircleShape

func NewB2CircleShape

func NewB2CircleShape() *B2CircleShape

func (B2CircleShape) Clone

func (shape B2CircleShape) Clone() B2ShapeInterface

func (B2CircleShape) ComputeAABB

func (shape B2CircleShape) ComputeAABB(aabb *B2AABB, transform B2Transform, childIndex int)

func (B2CircleShape) ComputeMass

func (shape B2CircleShape) ComputeMass(massData *B2MassData, density float64)

func (B2CircleShape) Destroy

func (shape B2CircleShape) Destroy()

func (B2CircleShape) GetChildCount

func (shape B2CircleShape) GetChildCount() int

func (B2CircleShape) RayCast

func (shape B2CircleShape) RayCast(output *B2RayCastOutput, input B2RayCastInput, transform B2Transform, childIndex int) bool

Collision Detection in Interactive 3D Environments by Gino van den Bergen From Section 3.1.2 x = s + a * r norm(x) = radius

func (B2CircleShape) TestPoint

func (shape B2CircleShape) TestPoint(transform B2Transform, p B2Vec2) bool

type B2ClipVertex

type B2ClipVertex struct {
	V  B2Vec2
	Id B2ContactID
}

/ Used for computing contact manifolds.

type B2Contact

type B2Contact struct {
	M_flags uint32

	// World pool and list pointers.
	M_prev B2ContactInterface //should be backed by a pointer
	M_next B2ContactInterface //should be backed by a pointer

	// Nodes for connecting bodies.
	M_nodeA *B2ContactEdge
	M_nodeB *B2ContactEdge

	M_fixtureA *B2Fixture
	M_fixtureB *B2Fixture

	M_indexA int
	M_indexB int

	M_manifold *B2Manifold

	M_toiCount     int
	M_toi          float64
	M_friction     float64
	M_restitution  float64
	M_tangentSpeed float64
}

func MakeB2Contact

func MakeB2Contact(fA *B2Fixture, indexA int, fB *B2Fixture, indexB int) B2Contact

func (*B2Contact) FlagForFiltering

func (contact *B2Contact) FlagForFiltering()

func (B2Contact) GetChildIndexA

func (contact B2Contact) GetChildIndexA() int

func (B2Contact) GetChildIndexB

func (contact B2Contact) GetChildIndexB() int

func (B2Contact) GetFixtureA

func (contact B2Contact) GetFixtureA() *B2Fixture

func (B2Contact) GetFixtureB

func (contact B2Contact) GetFixtureB() *B2Fixture

func (B2Contact) GetFlags

func (contact B2Contact) GetFlags() uint32

func (B2Contact) GetFriction

func (contact B2Contact) GetFriction() float64

func (B2Contact) GetManifold

func (contact B2Contact) GetManifold() *B2Manifold

func (B2Contact) GetNext

func (contact B2Contact) GetNext() B2ContactInterface

func (B2Contact) GetNodeA

func (contact B2Contact) GetNodeA() *B2ContactEdge

func (B2Contact) GetNodeB

func (contact B2Contact) GetNodeB() *B2ContactEdge

func (B2Contact) GetPrev

func (contact B2Contact) GetPrev() B2ContactInterface

func (B2Contact) GetRestitution

func (contact B2Contact) GetRestitution() float64

func (B2Contact) GetTOI

func (contact B2Contact) GetTOI() float64

func (B2Contact) GetTOICount

func (contact B2Contact) GetTOICount() int

func (B2Contact) GetTangentSpeed

func (contact B2Contact) GetTangentSpeed() float64

func (B2Contact) GetWorldManifold

func (contact B2Contact) GetWorldManifold(worldManifold *B2WorldManifold)

func (B2Contact) IsEnabled

func (contact B2Contact) IsEnabled() bool

func (B2Contact) IsTouching

func (contact B2Contact) IsTouching() bool

func (*B2Contact) ResetFriction

func (contact *B2Contact) ResetFriction()

func (*B2Contact) ResetRestitution

func (contact *B2Contact) ResetRestitution()

func (*B2Contact) SetChildIndexA

func (contact *B2Contact) SetChildIndexA(index int)

func (*B2Contact) SetChildIndexB

func (contact *B2Contact) SetChildIndexB(index int)

func (*B2Contact) SetEnabled

func (contact *B2Contact) SetEnabled(flag bool)

func (*B2Contact) SetFixtureA

func (contact *B2Contact) SetFixtureA(fixture *B2Fixture)

func (*B2Contact) SetFixtureB

func (contact *B2Contact) SetFixtureB(fixture *B2Fixture)

func (*B2Contact) SetFlags

func (contact *B2Contact) SetFlags(flags uint32)

func (*B2Contact) SetFriction

func (contact *B2Contact) SetFriction(friction float64)

func (*B2Contact) SetManifold

func (contact *B2Contact) SetManifold(manifold *B2Manifold)

func (*B2Contact) SetNext

func (contact *B2Contact) SetNext(next B2ContactInterface)

func (*B2Contact) SetNodeA

func (contact *B2Contact) SetNodeA(node *B2ContactEdge)

func (*B2Contact) SetNodeB

func (contact *B2Contact) SetNodeB(node *B2ContactEdge)

func (*B2Contact) SetPrev

func (contact *B2Contact) SetPrev(prev B2ContactInterface)

func (*B2Contact) SetRestitution

func (contact *B2Contact) SetRestitution(restitution float64)

func (*B2Contact) SetTOI

func (contact *B2Contact) SetTOI(toi float64)

func (*B2Contact) SetTOICount

func (contact *B2Contact) SetTOICount(toiCount int)

func (*B2Contact) SetTangentSpeed

func (contact *B2Contact) SetTangentSpeed(speed float64)

type B2ContactCreateFcn

type B2ContactCreateFcn func(fixtureA *B2Fixture, indexA int, fixtureB *B2Fixture, indexB int) B2ContactInterface // returned contact should be a pointer

type B2ContactDestroyFcn

type B2ContactDestroyFcn func(contact B2ContactInterface) // contact should be a pointer

type B2ContactEdge

type B2ContactEdge struct {
	Other   *B2Body            ///< provides quick access to the other body attached.
	Contact B2ContactInterface ///< the contact
	Prev    *B2ContactEdge     ///< the previous contact edge in the body's contact list
	Next    *B2ContactEdge     ///< the next contact edge in the body's contact list
}

/ A contact edge is used to connect bodies and contacts together / in a contact graph where each body is a node and each contact / is an edge. A contact edge belongs to a doubly linked list / maintained in each attached body. Each contact has two contact / nodes, one for each attached body.

func NewB2ContactEdge

func NewB2ContactEdge() *B2ContactEdge

type B2ContactFeature

type B2ContactFeature struct {
	IndexA uint8 ///< Feature index on shapeA
	IndexB uint8 ///< Feature index on shapeB
	TypeA  uint8 ///< The feature type on shapeA
	TypeB  uint8 ///< The feature type on shapeB
}

/ The features that intersect to form the contact point / This must be 4 bytes or less.

func MakeB2ContactFeature

func MakeB2ContactFeature() B2ContactFeature

type B2ContactFilter

type B2ContactFilter struct {
}

func (*B2ContactFilter) ShouldCollide

func (cf *B2ContactFilter) ShouldCollide(fixtureA *B2Fixture, fixtureB *B2Fixture) bool

Return true if contact calculations should be performed between these two shapes. If you implement your own collision filter you may want to build from this implementation.

type B2ContactFilterInterface

type B2ContactFilterInterface interface {
	ShouldCollide(fixtureA *B2Fixture, fixtureB *B2Fixture) bool
}

type B2ContactID

type B2ContactID B2ContactFeature

func (B2ContactID) Key

func (v B2ContactID) Key() uint32

/ Contact ids to facilitate warm starting. /< Used to quickly compare contact ids.

func (B2ContactID) SetKey

func (v B2ContactID) SetKey(key uint32)

type B2ContactImpulse

type B2ContactImpulse struct {
	NormalImpulses  [B2_maxManifoldPoints]float64
	TangentImpulses [B2_maxManifoldPoints]float64
	Count           int
}

/ Contact impulses for reporting. Impulses are used instead of forces because / sub-step forces may approach infinity for rigid body collisions. These / match up one-to-one with the contact points in b2Manifold.

func MakeB2ContactImpulse

func MakeB2ContactImpulse() B2ContactImpulse

type B2ContactInterface

type B2ContactInterface interface {
	GetFlags() uint32
	SetFlags(flags uint32)

	GetPrev() B2ContactInterface
	SetPrev(prev B2ContactInterface)

	GetNext() B2ContactInterface
	SetNext(prev B2ContactInterface)

	GetNodeA() *B2ContactEdge
	SetNodeA(node *B2ContactEdge)

	GetNodeB() *B2ContactEdge
	SetNodeB(node *B2ContactEdge)

	GetFixtureA() *B2Fixture
	SetFixtureA(fixture *B2Fixture)

	GetFixtureB() *B2Fixture
	SetFixtureB(fixture *B2Fixture)

	GetChildIndexA() int
	SetChildIndexA(index int)

	GetChildIndexB() int
	SetChildIndexB(index int)

	GetManifold() *B2Manifold
	SetManifold(manifold *B2Manifold)

	GetTOICount() int
	SetTOICount(toiCount int)

	GetTOI() float64
	SetTOI(toiCount float64)

	GetFriction() float64
	SetFriction(friction float64)
	ResetFriction()

	GetRestitution() float64
	SetRestitution(restitution float64)
	ResetRestitution()

	GetTangentSpeed() float64
	SetTangentSpeed(tangentSpeed float64)

	IsTouching() bool
	IsEnabled() bool
	SetEnabled(bool)

	Evaluate(manifold *B2Manifold, xfA B2Transform, xfB B2Transform)

	FlagForFiltering()

	GetWorldManifold(worldManifold *B2WorldManifold)
}

func B2ChainAndCircleContact_Create

func B2ChainAndCircleContact_Create(fixtureA *B2Fixture, indexA int, fixtureB *B2Fixture, indexB int) B2ContactInterface

func B2ChainAndPolygonContact_Create

func B2ChainAndPolygonContact_Create(fixtureA *B2Fixture, indexA int, fixtureB *B2Fixture, indexB int) B2ContactInterface

func B2CircleContact_Create

func B2CircleContact_Create(fixtureA *B2Fixture, indexA int, fixtureB *B2Fixture, indexB int) B2ContactInterface

func B2ContactFactory

func B2ContactFactory(fixtureA *B2Fixture, indexA int, fixtureB *B2Fixture, indexB int) B2ContactInterface

func B2EdgeAndCircleContact_Create

func B2EdgeAndCircleContact_Create(fixtureA *B2Fixture, indexA int, fixtureB *B2Fixture, indexB int) B2ContactInterface

func B2EdgeAndPolygonContact_Create

func B2EdgeAndPolygonContact_Create(fixtureA *B2Fixture, indexA int, fixtureB *B2Fixture, indexB int) B2ContactInterface

func B2PolygonAndCircleContact_Create

func B2PolygonAndCircleContact_Create(fixtureA *B2Fixture, indexA int, fixtureB *B2Fixture, indexB int) B2ContactInterface

func B2PolygonContact_Create

func B2PolygonContact_Create(fixtureA *B2Fixture, indexA int, fixtureB *B2Fixture, indexB int) B2ContactInterface

type B2ContactListenerInterface

type B2ContactListenerInterface interface {
	/// Called when two fixtures begin to touch.
	BeginContact(contact B2ContactInterface) // contact has to be backed by a pointer

	/// Called when two fixtures cease to touch.
	EndContact(contact B2ContactInterface) // contact has to be backed by a pointer

	/// This is called after a contact is updated. This allows you to inspect a
	/// contact before it goes to the solver. If you are careful, you can modify the
	/// contact manifold (e.g. disable contact).
	/// A copy of the old manifold is provided so that you can detect changes.
	/// Note: this is called only for awake bodies.
	/// Note: this is called even when the number of contact points is zero.
	/// Note: this is not called for sensors.
	/// Note: if you set the number of contact points to zero, you will not
	/// get an EndContact callback. However, you may get a BeginContact callback
	/// the next step.
	PreSolve(contact B2ContactInterface, oldManifold B2Manifold) // contact has to be backed by a pointer

	/// This lets you inspect a contact after the solver is finished. This is useful
	/// for inspecting impulses.
	/// Note: the contact manifold does not include time of impact impulses, which can be
	/// arbitrarily large if the sub-step is small. Hence the impulse is provided explicitly
	/// in a separate data structure.
	/// Note: this is only called for contacts that are touching, solid, and awake.
	PostSolve(contact B2ContactInterface, impulse *B2ContactImpulse) // contact has to be backed by a pointer
}

type B2ContactManager

type B2ContactManager struct {
	M_broadPhase      B2BroadPhase
	M_contactList     B2ContactInterface
	M_contactCount    int
	M_contactFilter   B2ContactFilterInterface
	M_contactListener B2ContactListenerInterface
}

func MakeB2ContactManager

func MakeB2ContactManager() B2ContactManager

func NewB2ContactManager

func NewB2ContactManager() *B2ContactManager

func (*B2ContactManager) AddPair

func (mgr *B2ContactManager) AddPair(proxyUserDataA interface{}, proxyUserDataB interface{})

func (*B2ContactManager) Collide

func (mgr *B2ContactManager) Collide()

This is the top level collision call for the time step. Here all the narrow phase collision is processed for the world contact list.

func (*B2ContactManager) Destroy

func (mgr *B2ContactManager) Destroy(c B2ContactInterface)

func (*B2ContactManager) FindNewContacts

func (mgr *B2ContactManager) FindNewContacts()

type B2ContactPositionConstraint

type B2ContactPositionConstraint struct {
	LocalPoints                [B2_maxManifoldPoints]B2Vec2
	LocalNormal                B2Vec2
	LocalPoint                 B2Vec2
	IndexA                     int
	IndexB                     int
	InvMassA, InvMassB         float64
	LocalCenterA, LocalCenterB B2Vec2
	InvIA, InvIB               float64
	Type                       uint8
	RadiusA, RadiusB           float64
	PointCount                 int
}

type B2ContactRegister

type B2ContactRegister struct {
	CreateFcn  B2ContactCreateFcn
	DestroyFcn B2ContactDestroyFcn
	Primary    bool
}

type B2ContactSolver

type B2ContactSolver struct {
	M_step                B2TimeStep
	M_positions           []B2Position
	M_velocities          []B2Velocity
	M_positionConstraints []B2ContactPositionConstraint
	M_velocityConstraints []B2ContactVelocityConstraint
	M_contacts            []B2ContactInterface // has to be backed by pointers
	M_count               int
}

func MakeB2ContactSolver

func MakeB2ContactSolver(def *B2ContactSolverDef) B2ContactSolver

func (*B2ContactSolver) Destroy

func (solver *B2ContactSolver) Destroy()

func (*B2ContactSolver) InitializeVelocityConstraints

func (solver *B2ContactSolver) InitializeVelocityConstraints()

Initialize position dependent portions of the velocity constraints.

func (*B2ContactSolver) SolvePositionConstraints

func (solver *B2ContactSolver) SolvePositionConstraints() bool

Sequential solver.

func (*B2ContactSolver) SolveTOIPositionConstraints

func (solver *B2ContactSolver) SolveTOIPositionConstraints(toiIndexA int, toiIndexB int) bool

Sequential position solver for position constraints.

func (*B2ContactSolver) SolveVelocityConstraints

func (solver *B2ContactSolver) SolveVelocityConstraints()

func (*B2ContactSolver) StoreImpulses

func (solver *B2ContactSolver) StoreImpulses()

func (*B2ContactSolver) WarmStart

func (solver *B2ContactSolver) WarmStart()

type B2ContactSolverDef

type B2ContactSolverDef struct {
	Step       B2TimeStep
	Contacts   []B2ContactInterface // has to be backed by pointers
	Count      int
	Positions  []B2Position
	Velocities []B2Velocity
}

func MakeB2ContactSolverDef

func MakeB2ContactSolverDef() B2ContactSolverDef

type B2ContactVelocityConstraint

type B2ContactVelocityConstraint struct {
	Points             [B2_maxManifoldPoints]B2VelocityConstraintPoint
	Normal             B2Vec2
	NormalMass         B2Mat22
	K                  B2Mat22
	IndexA             int
	IndexB             int
	InvMassA, InvMassB float64
	InvIA, InvIB       float64
	Friction           float64
	Restitution        float64
	TangentSpeed       float64
	PointCount         int
	ContactIndex       int
}

type B2DestructionListenerInterface

type B2DestructionListenerInterface interface {
	/// Called when any fixture is about to be destroyed due
	/// to the destruction of its parent body.
	SayGoodbyeToFixture(fixture *B2Fixture)

	SayGoodbyeToJoint(joint B2JointInterface) // backed by pointer
}

type B2DistanceInput

type B2DistanceInput struct {
	ProxyA     B2DistanceProxy
	ProxyB     B2DistanceProxy
	TransformA B2Transform
	TransformB B2Transform
	UseRadii   bool
}

/ Input for b2Distance. / You have to option to use the shape radii / in the computation. Even

func MakeB2DistanceInput

func MakeB2DistanceInput() B2DistanceInput

func NewB2DistanceInput

func NewB2DistanceInput() *B2DistanceInput

type B2DistanceJoint

type B2DistanceJoint struct {
	*B2Joint

	M_frequencyHz  float64
	M_dampingRatio float64
	M_bias         float64

	// Solver shared
	M_localAnchorA B2Vec2
	M_localAnchorB B2Vec2
	M_gamma        float64
	M_impulse      float64
	M_length       float64

	// Solver temp
	M_indexA       int
	M_indexB       int
	M_u            B2Vec2
	M_rA           B2Vec2
	M_rB           B2Vec2
	M_localCenterA B2Vec2
	M_localCenterB B2Vec2
	M_invMassA     float64
	M_invMassB     float64
	M_invIA        float64
	M_invIB        float64
	M_mass         float64
}

/ A distance joint constrains two points on two bodies / to remain at a fixed distance from each other. You can view / this as a massless, rigid rod.

func MakeB2DistanceJoint

func MakeB2DistanceJoint(def *B2DistanceJointDef) *B2DistanceJoint

func (B2DistanceJoint) Dump

func (joint B2DistanceJoint) Dump()

func (B2DistanceJoint) GetAnchorA

func (joint B2DistanceJoint) GetAnchorA() B2Vec2

func (B2DistanceJoint) GetAnchorB

func (joint B2DistanceJoint) GetAnchorB() B2Vec2

func (B2DistanceJoint) GetDampingRatio

func (joint B2DistanceJoint) GetDampingRatio() float64

func (B2DistanceJoint) GetFrequency

func (joint B2DistanceJoint) GetFrequency() float64

func (B2DistanceJoint) GetLength

func (joint B2DistanceJoint) GetLength() float64

func (B2DistanceJoint) GetLocalAnchorA

func (joint B2DistanceJoint) GetLocalAnchorA() B2Vec2

/ The local anchor point relative to bodyA's origin.

func (B2DistanceJoint) GetLocalAnchorB

func (joint B2DistanceJoint) GetLocalAnchorB() B2Vec2

/ The local anchor point relative to bodyB's origin.

func (B2DistanceJoint) GetReactionForce

func (joint B2DistanceJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2DistanceJoint) GetReactionTorque

func (joint B2DistanceJoint) GetReactionTorque(inv_dt float64) float64

func (*B2DistanceJoint) InitVelocityConstraints

func (joint *B2DistanceJoint) InitVelocityConstraints(data B2SolverData)

func (*B2DistanceJoint) SetDampingRatio

func (joint *B2DistanceJoint) SetDampingRatio(ratio float64)

func (*B2DistanceJoint) SetFrequency

func (joint *B2DistanceJoint) SetFrequency(hz float64)

func (*B2DistanceJoint) SetLength

func (joint *B2DistanceJoint) SetLength(length float64)

func (*B2DistanceJoint) SolvePositionConstraints

func (joint *B2DistanceJoint) SolvePositionConstraints(data B2SolverData) bool

func (*B2DistanceJoint) SolveVelocityConstraints

func (joint *B2DistanceJoint) SolveVelocityConstraints(data B2SolverData)

type B2DistanceJointDef

type B2DistanceJointDef struct {
	B2JointDef

	/// The local anchor point relative to bodyA's origin.
	LocalAnchorA B2Vec2

	/// The local anchor point relative to bodyB's origin.
	LocalAnchorB B2Vec2

	/// The natural length between the anchor points.
	Length float64

	/// The mass-spring-damper frequency in Hertz. A value of 0
	/// disables softness.
	FrequencyHz float64

	/// The damping ratio. 0 = no damping, 1 = critical damping.
	DampingRatio float64
}

/ Distance joint definition. This requires defining an / anchor point on both bodies and the non-zero length of the / distance joint. The definition uses local anchor points / so that the initial configuration can violate the constraint / slightly. This helps when saving and loading a game. / @warning Do not use a zero or short length.

func MakeB2DistanceJointDef

func MakeB2DistanceJointDef() B2DistanceJointDef

func (*B2DistanceJointDef) Initialize

func (joint *B2DistanceJointDef) Initialize(b1 *B2Body, b2 *B2Body, anchor1 B2Vec2, anchor2 B2Vec2)

type B2DistanceOutput

type B2DistanceOutput struct {
	PointA     B2Vec2 ///< closest point on shapeA
	PointB     B2Vec2 ///< closest point on shapeB
	Distance   float64
	Iterations int ///< number of GJK iterations used
}

/ Output for b2Distance.

func MakeB2DistanceOutput

func MakeB2DistanceOutput() B2DistanceOutput

func NewB2DistanceOutput

func NewB2DistanceOutput() *B2DistanceOutput

type B2DistanceProxy

type B2DistanceProxy struct {
	M_buffer   [2]B2Vec2
	M_vertices []B2Vec2 // is a memory blob using pointer arithmetic in original implementation
	M_count    int
	M_radius   float64
}

/ A distance proxy is used by the GJK algorithm. / It encapsulates any shape.

func MakeB2DistanceProxy

func MakeB2DistanceProxy() B2DistanceProxy

func NewB2DistanceProxy

func NewB2DistanceProxy() *B2DistanceProxy

func (B2DistanceProxy) GetSupport

func (p B2DistanceProxy) GetSupport(d B2Vec2) int

func (B2DistanceProxy) GetSupportVertex

func (p B2DistanceProxy) GetSupportVertex(d B2Vec2) B2Vec2

func (B2DistanceProxy) GetVertex

func (p B2DistanceProxy) GetVertex(index int) B2Vec2

func (B2DistanceProxy) GetVertexCount

func (p B2DistanceProxy) GetVertexCount() int

func (*B2DistanceProxy) Set

func (p *B2DistanceProxy) Set(shape B2ShapeInterface, index int)

type B2DynamicTree

type B2DynamicTree struct {

	// Private members:
	M_root int

	M_nodes        []B2TreeNode
	M_nodeCount    int
	M_nodeCapacity int

	M_freeList int

	/// This is used to incrementally traverse the tree for re-balancing.
	M_path int

	M_insertionCount int
}

/ A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt. / A dynamic tree arranges data in a binary tree to accelerate / queries such as volume queries and ray casts. Leafs are proxies / with an AABB. In the tree we expand the proxy AABB by b2_fatAABBFactor / so that the proxy AABB is bigger than the client object. This allows the client / object to move by small amounts without triggering a tree update. / / Nodes are pooled and relocatable, so we use node indices rather than pointers.

func MakeB2DynamicTree

func MakeB2DynamicTree() B2DynamicTree

func (*B2DynamicTree) AllocateNode

func (tree *B2DynamicTree) AllocateNode() int

Allocate a node from the pool. Grow the pool if necessary.

func (*B2DynamicTree) Balance

func (tree *B2DynamicTree) Balance(iA int) int

Perform a left or right rotation if node A is imbalanced. Returns the new root index.

func (B2DynamicTree) ComputeHeight

func (tree B2DynamicTree) ComputeHeight(nodeId int) int

Compute the height of a sub-tree.

func (B2DynamicTree) ComputeTotalHeight

func (tree B2DynamicTree) ComputeTotalHeight() int

func (*B2DynamicTree) CreateProxy

func (tree *B2DynamicTree) CreateProxy(aabb B2AABB, userData interface{}) int

Create a proxy in the tree as a leaf node. We return the index of the node instead of a pointer so that we can grow the node pool.

func (*B2DynamicTree) DestroyProxy

func (tree *B2DynamicTree) DestroyProxy(proxyId int)

func (*B2DynamicTree) FreeNode

func (tree *B2DynamicTree) FreeNode(nodeId int)

Return a node to the pool.

func (B2DynamicTree) GetAreaRatio

func (tree B2DynamicTree) GetAreaRatio() float64

func (B2DynamicTree) GetFatAABB

func (tree B2DynamicTree) GetFatAABB(proxyId int) B2AABB

func (B2DynamicTree) GetHeight

func (tree B2DynamicTree) GetHeight() int

func (B2DynamicTree) GetMaxBalance

func (tree B2DynamicTree) GetMaxBalance() int

func (B2DynamicTree) GetUserData

func (tree B2DynamicTree) GetUserData(proxyId int) interface{}

func (*B2DynamicTree) InsertLeaf

func (tree *B2DynamicTree) InsertLeaf(leaf int)

func (*B2DynamicTree) MoveProxy

func (tree *B2DynamicTree) MoveProxy(proxyId int, aabb B2AABB, displacement B2Vec2) bool

func (*B2DynamicTree) Query

func (tree *B2DynamicTree) Query(queryCallback B2TreeQueryCallback, aabb B2AABB)

func (B2DynamicTree) RayCast

func (tree B2DynamicTree) RayCast(rayCastCallback B2TreeRayCastCallback, input B2RayCastInput)

func (*B2DynamicTree) RebuildBottomUp

func (tree *B2DynamicTree) RebuildBottomUp()

func (*B2DynamicTree) RemoveLeaf

func (tree *B2DynamicTree) RemoveLeaf(leaf int)

func (*B2DynamicTree) ShiftOrigin

func (tree *B2DynamicTree) ShiftOrigin(newOrigin B2Vec2)

func (B2DynamicTree) Validate

func (tree B2DynamicTree) Validate()

func (B2DynamicTree) ValidateMetrics

func (tree B2DynamicTree) ValidateMetrics(index int)

func (B2DynamicTree) ValidateStructure

func (tree B2DynamicTree) ValidateStructure(index int)

type B2EPAxis

type B2EPAxis struct {
	Type       uint8
	Index      int
	Separation float64
}

func MakeB2EPAxis

func MakeB2EPAxis() B2EPAxis

type B2EPCollider

type B2EPCollider struct {
	M_polygonB B2TempPolygon

	M_xf                            B2Transform
	M_centroidB                     B2Vec2
	M_v0, M_v1, M_v2, M_v3          B2Vec2
	M_normal0, M_normal1, M_normal2 B2Vec2
	M_normal                        B2Vec2
	M_type1, M_type2                uint8
	M_lowerLimit, M_upperLimit      B2Vec2
	M_radius                        float64
	M_front                         bool
}

This class collides and edge and a polygon, taking into account edge adjacency.

func MakeB2EPCollider

func MakeB2EPCollider() B2EPCollider

func (*B2EPCollider) Collide

func (collider *B2EPCollider) Collide(manifold *B2Manifold, edgeA *B2EdgeShape, xfA B2Transform, polygonB *B2PolygonShape, xfB B2Transform)

Algorithm: 1. Classify v1 and v2 2. Classify polygon centroid as front or back 3. Flip normal if necessary 4. Initialize normal range to [-pi, pi] about face normal 5. Adjust normal range according to adjacent edges 6. Visit each separating axes, only accept axes within the range 7. Return if _any_ axis indicates separation 8. Clip

func (*B2EPCollider) ComputeEdgeSeparation

func (collider *B2EPCollider) ComputeEdgeSeparation() B2EPAxis

func (*B2EPCollider) ComputePolygonSeparation

func (collider *B2EPCollider) ComputePolygonSeparation() B2EPAxis

type B2EdgeAndCircleContact

type B2EdgeAndCircleContact struct {
	B2Contact
}

func (*B2EdgeAndCircleContact) Evaluate

func (contact *B2EdgeAndCircleContact) Evaluate(manifold *B2Manifold, xfA B2Transform, xfB B2Transform)

type B2EdgeAndPolygonContact

type B2EdgeAndPolygonContact struct {
	B2Contact
}

func (*B2EdgeAndPolygonContact) Evaluate

func (contact *B2EdgeAndPolygonContact) Evaluate(manifold *B2Manifold, xfA B2Transform, xfB B2Transform)

type B2EdgeShape

type B2EdgeShape struct {
	B2Shape
	/// These are the edge vertices
	M_vertex1, M_vertex2 B2Vec2

	/// Optional adjacent vertices. These are used for smooth collision.
	M_vertex0, M_vertex3       B2Vec2
	M_hasVertex0, M_hasVertex3 bool
}

/ A line segment (edge) shape. These can be connected in chains or loops / to other edge shapes. The connectivity information is used to ensure / correct contact normals.

func MakeB2EdgeShape

func MakeB2EdgeShape() B2EdgeShape

func NewB2EdgeShape

func NewB2EdgeShape() *B2EdgeShape

func (B2EdgeShape) Clone

func (edge B2EdgeShape) Clone() B2ShapeInterface

func (B2EdgeShape) ComputeAABB

func (edge B2EdgeShape) ComputeAABB(aabb *B2AABB, xf B2Transform, childIndex int)

func (B2EdgeShape) ComputeMass

func (edge B2EdgeShape) ComputeMass(massData *B2MassData, density float64)

func (*B2EdgeShape) Destroy

func (edge *B2EdgeShape) Destroy()

func (B2EdgeShape) GetChildCount

func (edge B2EdgeShape) GetChildCount() int

func (B2EdgeShape) RayCast

func (edge B2EdgeShape) RayCast(output *B2RayCastOutput, input B2RayCastInput, xf B2Transform, childIndex int) bool

p = p1 + t * d v = v1 + s * e p1 + t * d = v1 + s * e s * e - t * d = p1 - v1

func (*B2EdgeShape) Set

func (edge *B2EdgeShape) Set(v1 B2Vec2, v2 B2Vec2)

func (B2EdgeShape) TestPoint

func (edge B2EdgeShape) TestPoint(xf B2Transform, p B2Vec2) bool

type B2Filter

type B2Filter struct {
	/// The collision category bits. Normally you would just set one bit.
	CategoryBits uint16

	/// The collision mask bits. This states the categories that this
	/// shape would accept for collision.
	MaskBits uint16

	/// Collision groups allow a certain group of objects to never collide (negative)
	/// or always collide (positive). Zero means no collision group. Non-zero group
	/// filtering always wins against the mask bits.
	GroupIndex int16
}

/ This holds contact filtering data.

func MakeB2Filter

func MakeB2Filter() B2Filter

type B2Fixture

type B2Fixture struct {
	M_density float64

	M_next *B2Fixture
	M_body *B2Body

	M_shape B2ShapeInterface

	M_friction    float64
	M_restitution float64

	M_proxies    []B2FixtureProxy
	M_proxyCount int

	M_filter B2Filter

	M_isSensor bool

	M_userData interface{}
}

/// A fixture is used to attach a shape to a body for collision detection. A fixture /// inherits its transform from its parent. Fixtures hold additional non-geometric data /// such as friction, collision filters, etc. /// Fixtures are created via b2Body::CreateFixture. /// @warning you cannot reuse fixtures.

func MakeB2Fixture

func MakeB2Fixture() B2Fixture

func NewB2Fixture

func NewB2Fixture() *B2Fixture

func (*B2Fixture) Create

func (fix *B2Fixture) Create(body *B2Body, def *B2FixtureDef)

func (*B2Fixture) CreateProxies

func (fix *B2Fixture) CreateProxies(broadPhase *B2BroadPhase, xf B2Transform)

func (*B2Fixture) Destroy

func (fix *B2Fixture) Destroy()

func (*B2Fixture) DestroyProxies

func (fix *B2Fixture) DestroyProxies(broadPhase *B2BroadPhase)

func (*B2Fixture) Dump

func (fix *B2Fixture) Dump(bodyIndex int)

func (B2Fixture) GetAABB

func (fix B2Fixture) GetAABB(childIndex int) B2AABB

func (B2Fixture) GetBody

func (fix B2Fixture) GetBody() *B2Body

func (B2Fixture) GetDensity

func (fix B2Fixture) GetDensity() float64

func (B2Fixture) GetFilterData

func (fix B2Fixture) GetFilterData() B2Filter

func (B2Fixture) GetFriction

func (fix B2Fixture) GetFriction() float64

func (B2Fixture) GetMassData

func (fix B2Fixture) GetMassData(massData *B2MassData)

func (B2Fixture) GetNext

func (fix B2Fixture) GetNext() *B2Fixture

func (B2Fixture) GetRestitution

func (fix B2Fixture) GetRestitution() float64

func (B2Fixture) GetShape

func (fix B2Fixture) GetShape() B2ShapeInterface

func (B2Fixture) GetType

func (fix B2Fixture) GetType() uint8

func (B2Fixture) GetUserData

func (fix B2Fixture) GetUserData() interface{}

func (B2Fixture) IsSensor

func (fix B2Fixture) IsSensor() bool

func (B2Fixture) RayCast

func (fix B2Fixture) RayCast(output *B2RayCastOutput, input B2RayCastInput, childIndex int) bool

func (*B2Fixture) Refilter

func (fix *B2Fixture) Refilter()

func (*B2Fixture) SetDensity

func (fix *B2Fixture) SetDensity(density float64)

func (*B2Fixture) SetFilterData

func (fix *B2Fixture) SetFilterData(filter B2Filter)

func (*B2Fixture) SetFriction

func (fix *B2Fixture) SetFriction(friction float64)

func (*B2Fixture) SetRestitution

func (fix *B2Fixture) SetRestitution(restitution float64)

func (*B2Fixture) SetSensor

func (fix *B2Fixture) SetSensor(sensor bool)

func (*B2Fixture) SetUserData

func (fix *B2Fixture) SetUserData(data interface{})

func (*B2Fixture) Synchronize

func (fix *B2Fixture) Synchronize(broadPhase *B2BroadPhase, transform1 B2Transform, transform2 B2Transform)

func (B2Fixture) TestPoint

func (fix B2Fixture) TestPoint(p B2Vec2) bool

type B2FixtureDef

type B2FixtureDef struct {

	/// The shape, this must be set. The shape will be cloned, so you
	/// can create the shape on the stack.
	Shape B2ShapeInterface

	/// Use this to store application specific fixture data.
	UserData interface{}

	/// The friction coefficient, usually in the range [0,1].
	Friction float64

	/// The restitution (elasticity) usually in the range [0,1].
	Restitution float64

	/// The density, usually in kg/m^2.
	Density float64

	/// A sensor shape collects contact information but never generates a collision
	/// response.
	IsSensor bool

	/// Contact filtering data.
	Filter B2Filter
}

/ A fixture definition is used to create a fixture. This class defines an / abstract fixture definition. You can reuse fixture definitions safely.

func MakeB2FixtureDef

func MakeB2FixtureDef() B2FixtureDef

/ The constructor sets the default fixture definition values.

type B2FixtureProxy

type B2FixtureProxy struct {
	Aabb       B2AABB
	Fixture    *B2Fixture
	ChildIndex int
	ProxyId    int
}

/ This proxy is used internally to connect fixtures to the broad-phase.

type B2FrictionJoint

type B2FrictionJoint struct {
	*B2Joint

	M_localAnchorA B2Vec2
	M_localAnchorB B2Vec2

	// Solver shared
	M_linearImpulse  B2Vec2
	M_angularImpulse float64
	M_maxForce       float64
	M_maxTorque      float64

	// Solver temp
	M_indexA       int
	M_indexB       int
	M_rA           B2Vec2
	M_rB           B2Vec2
	M_localCenterA B2Vec2
	M_localCenterB B2Vec2
	M_invMassA     float64
	M_invMassB     float64
	M_invIA        float64
	M_invIB        float64
	M_linearMass   B2Mat22
	M_angularMass  float64
}

/ Friction joint. This is used for top-down friction. / It provides 2D translational friction and angular friction.

func MakeB2FrictionJoint

func MakeB2FrictionJoint(def *B2FrictionJointDef) *B2FrictionJoint

func (*B2FrictionJoint) Dump

func (joint *B2FrictionJoint) Dump()

func (B2FrictionJoint) GetAnchorA

func (joint B2FrictionJoint) GetAnchorA() B2Vec2

func (B2FrictionJoint) GetAnchorB

func (joint B2FrictionJoint) GetAnchorB() B2Vec2

func (B2FrictionJoint) GetLocalAnchorA

func (joint B2FrictionJoint) GetLocalAnchorA() B2Vec2

/ The local anchor point relative to bodyA's origin.

func (B2FrictionJoint) GetLocalAnchorB

func (joint B2FrictionJoint) GetLocalAnchorB() B2Vec2

/ The local anchor point relative to bodyB's origin.

func (B2FrictionJoint) GetMaxForce

func (joint B2FrictionJoint) GetMaxForce() float64

func (B2FrictionJoint) GetMaxTorque

func (joint B2FrictionJoint) GetMaxTorque() float64

func (B2FrictionJoint) GetReactionForce

func (joint B2FrictionJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2FrictionJoint) GetReactionTorque

func (joint B2FrictionJoint) GetReactionTorque(inv_dt float64) float64

func (*B2FrictionJoint) InitVelocityConstraints

func (joint *B2FrictionJoint) InitVelocityConstraints(data B2SolverData)

func (*B2FrictionJoint) SetMaxForce

func (joint *B2FrictionJoint) SetMaxForce(force float64)

func (*B2FrictionJoint) SetMaxTorque

func (joint *B2FrictionJoint) SetMaxTorque(torque float64)

func (*B2FrictionJoint) SolvePositionConstraints

func (joint *B2FrictionJoint) SolvePositionConstraints(data B2SolverData) bool

func (*B2FrictionJoint) SolveVelocityConstraints

func (joint *B2FrictionJoint) SolveVelocityConstraints(data B2SolverData)

type B2FrictionJointDef

type B2FrictionJointDef struct {
	B2JointDef

	/// The local anchor point relative to bodyA's origin.
	LocalAnchorA B2Vec2

	/// The local anchor point relative to bodyB's origin.
	LocalAnchorB B2Vec2

	/// The maximum friction force in N.
	MaxForce float64

	/// The maximum friction torque in N-m.
	MaxTorque float64
}

/ Friction joint definition.

func MakeB2FrictionJointDef

func MakeB2FrictionJointDef() B2FrictionJointDef

func (*B2FrictionJointDef) Initialize

func (joint *B2FrictionJointDef) Initialize(bA *B2Body, bB *B2Body, anchor B2Vec2)

type B2GearJoint

type B2GearJoint struct {
	*B2Joint

	M_joint1 B2JointInterface // backed by pointer
	M_joint2 B2JointInterface // backed by pointer

	M_typeA uint8
	M_typeB uint8

	// Body A is connected to body C
	// Body B is connected to body D
	M_bodyC *B2Body
	M_bodyD *B2Body

	// Solver shared
	M_localAnchorA B2Vec2
	M_localAnchorB B2Vec2
	M_localAnchorC B2Vec2
	M_localAnchorD B2Vec2

	M_localAxisC B2Vec2
	M_localAxisD B2Vec2

	M_referenceAngleA float64
	M_referenceAngleB float64

	M_constant float64
	M_ratio    float64

	M_impulse float64

	// Solver temp
	M_indexA, M_indexB, M_indexC, M_indexD int
	M_lcA, M_lcB, M_lcC, M_lcD             B2Vec2
	M_mA, M_mB, M_mC, M_mD                 float64
	M_iA, M_iB, M_iC, M_iD                 float64
	M_JvAC, M_JvBD                         B2Vec2
	M_JwA, M_JwB, M_JwC, M_JwD             float64
	M_mass                                 float64
}

/ A gear joint is used to connect two joints together. Either joint / can be a revolute or prismatic joint. You specify a gear ratio / to bind the motions together: / coordinate1 + ratio * coordinate2 = constant / The ratio can be negative or positive. If one joint is a revolute joint / and the other joint is a prismatic joint, then the ratio will have units / of length or units of 1/length. / @warning You have to manually destroy the gear joint if joint1 or joint2 / is destroyed.

func MakeB2GearJoint

func MakeB2GearJoint(def *B2GearJointDef) *B2GearJoint

func (*B2GearJoint) Dump

func (joint *B2GearJoint) Dump()

func (B2GearJoint) GetAnchorA

func (joint B2GearJoint) GetAnchorA() B2Vec2

func (B2GearJoint) GetAnchorB

func (joint B2GearJoint) GetAnchorB() B2Vec2

func (B2GearJoint) GetJoint1

func (joint B2GearJoint) GetJoint1() B2JointInterface

/ Get the first joint.

func (B2GearJoint) GetJoint2

func (joint B2GearJoint) GetJoint2() B2JointInterface

/ Get the second joint.

func (B2GearJoint) GetRatio

func (joint B2GearJoint) GetRatio() float64

func (B2GearJoint) GetReactionForce

func (joint B2GearJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2GearJoint) GetReactionTorque

func (joint B2GearJoint) GetReactionTorque(inv_dt float64) float64

func (*B2GearJoint) InitVelocityConstraints

func (joint *B2GearJoint) InitVelocityConstraints(data B2SolverData)

func (*B2GearJoint) SetRatio

func (joint *B2GearJoint) SetRatio(ratio float64)

func (*B2GearJoint) SolvePositionConstraints

func (joint *B2GearJoint) SolvePositionConstraints(data B2SolverData) bool

func (*B2GearJoint) SolveVelocityConstraints

func (joint *B2GearJoint) SolveVelocityConstraints(data B2SolverData)

type B2GearJointDef

type B2GearJointDef struct {
	B2JointDef

	/// The first revolute/prismatic joint attached to the gear joint.
	Joint1 B2JointInterface // has to be backed by pointer

	/// The second revolute/prismatic joint attached to the gear joint.
	Joint2 B2JointInterface // has to be backed by pointer

	/// The gear ratio.
	/// @see b2GearJoint for explanation.
	Ratio float64
}

/ Gear joint definition. This definition requires two existing / revolute or prismatic joints (any combination will work).

func MakeB2GearJointDef

func MakeB2GearJointDef() B2GearJointDef

type B2GrowableStack

type B2GrowableStack struct {
	// contains filtered or unexported fields
}

func NewB2GrowableStack

func NewB2GrowableStack() *B2GrowableStack

func (B2GrowableStack) GetCount

func (s B2GrowableStack) GetCount() int

Return the stack's length

func (*B2GrowableStack) Pop

func (s *B2GrowableStack) Pop() (value interface{})

Remove the top element from the stack and return it's value If the stack is empty, return nil

func (*B2GrowableStack) Push

func (s *B2GrowableStack) Push(value interface{})

Push a new element onto the stack

type B2Island

type B2Island struct {
	M_listener B2ContactListenerInterface

	M_bodies   []*B2Body
	M_contacts []B2ContactInterface // has to be backed by pointers
	M_joints   []B2JointInterface   // has to be backed by pointers

	M_positions  []B2Position
	M_velocities []B2Velocity

	M_bodyCount    int
	M_jointCount   int
	M_contactCount int

	M_bodyCapacity    int
	M_contactCapacity int
	M_jointCapacity   int
}

/ This is an internal class.

func MakeB2Island

func MakeB2Island(bodyCapacity int, contactCapacity int, jointCapacity int, listener B2ContactListenerInterface) B2Island

func (*B2Island) Add

func (island *B2Island) Add(joint B2JointInterface)

func (*B2Island) AddBody

func (island *B2Island) AddBody(body *B2Body)

func (*B2Island) AddContact

func (island *B2Island) AddContact(contact B2ContactInterface)

func (*B2Island) Clear

func (island *B2Island) Clear()

func (*B2Island) Destroy

func (island *B2Island) Destroy()

func (*B2Island) Report

func (island *B2Island) Report(constraints []B2ContactVelocityConstraint)

func (*B2Island) Solve

func (island *B2Island) Solve(profile *B2Profile, step B2TimeStep, gravity B2Vec2, allowSleep bool)

func (*B2Island) SolveTOI

func (island *B2Island) SolveTOI(subStep B2TimeStep, toiIndexA int, toiIndexB int)

type B2Jacobian

type B2Jacobian struct {
	Linear   B2Vec2
	AngularA float64
	AngularB float64
}

type B2Joint

type B2Joint struct {
	M_type             uint8
	M_prev             B2JointInterface // has to be backed by pointer
	M_next             B2JointInterface // has to be backed by pointer
	M_edgeA            *B2JointEdge
	M_edgeB            *B2JointEdge
	M_bodyA            *B2Body
	M_bodyB            *B2Body
	M_index            int
	M_islandFlag       bool
	M_collideConnected bool
	M_userData         interface{}
}

/ The base joint class. Joints are used to constraint two bodies together in / various fashions. Some joints also feature limits and motors.

func MakeB2Joint

func MakeB2Joint(def B2JointDefInterface) *B2Joint

func (*B2Joint) Destroy

func (j *B2Joint) Destroy()

@goadd

func (B2Joint) Dump

func (j B2Joint) Dump()

/ Dump this joint to the log file.

func (B2Joint) GetBodyA

func (j B2Joint) GetBodyA() *B2Body

func (B2Joint) GetBodyB

func (j B2Joint) GetBodyB() *B2Body

func (B2Joint) GetEdgeA

func (j B2Joint) GetEdgeA() *B2JointEdge

@goadd

func (B2Joint) GetEdgeB

func (j B2Joint) GetEdgeB() *B2JointEdge

@goadd

func (B2Joint) GetIndex

func (j B2Joint) GetIndex() int

@goadd

func (B2Joint) GetIslandFlag

func (j B2Joint) GetIslandFlag() bool

func (B2Joint) GetNext

func (j B2Joint) GetNext() B2JointInterface

func (B2Joint) GetPrev

func (j B2Joint) GetPrev() B2JointInterface

func (B2Joint) GetType

func (j B2Joint) GetType() uint8

func (B2Joint) GetUserData

func (j B2Joint) GetUserData() interface{}

func (*B2Joint) InitVelocityConstraints

func (j *B2Joint) InitVelocityConstraints(data B2SolverData)

func (B2Joint) IsActive

func (j B2Joint) IsActive() bool

func (B2Joint) IsCollideConnected

func (j B2Joint) IsCollideConnected() bool

func (*B2Joint) SetBodyA

func (j *B2Joint) SetBodyA(body *B2Body)

@goadd

func (*B2Joint) SetBodyB

func (j *B2Joint) SetBodyB(body *B2Body)

@goadd

func (*B2Joint) SetCollideConnected

func (j *B2Joint) SetCollideConnected(flag bool)

@goadd

func (*B2Joint) SetEdgeA

func (j *B2Joint) SetEdgeA(edge *B2JointEdge)

@goadd

func (*B2Joint) SetEdgeB

func (j *B2Joint) SetEdgeB(edge *B2JointEdge)

@goadd

func (*B2Joint) SetIndex

func (j *B2Joint) SetIndex(index int)

func (*B2Joint) SetIslandFlag

func (j *B2Joint) SetIslandFlag(flag bool)

func (*B2Joint) SetNext

func (j *B2Joint) SetNext(next B2JointInterface)

@goadd

func (*B2Joint) SetPrev

func (j *B2Joint) SetPrev(prev B2JointInterface)

@goadd

func (*B2Joint) SetType

func (j *B2Joint) SetType(t uint8)

@goadd

func (*B2Joint) SetUserData

func (j *B2Joint) SetUserData(data interface{})

func (B2Joint) ShiftOrigin

func (j B2Joint) ShiftOrigin(newOrigin B2Vec2)

/ Shift the origin for any points stored in world coordinates.

func (*B2Joint) SolvePositionConstraints

func (j *B2Joint) SolvePositionConstraints(data B2SolverData) bool

func (*B2Joint) SolveVelocityConstraints

func (j *B2Joint) SolveVelocityConstraints(data B2SolverData)

type B2JointDef

type B2JointDef struct {

	/// The joint type is set automatically for concrete joint types.
	Type uint8

	/// Use this to attach application specific data to your joints.
	UserData interface{}

	/// The first attached body.
	BodyA *B2Body

	/// The second attached body.
	BodyB *B2Body

	/// Set this flag to true if the attached bodies should collide.
	CollideConnected bool
}

/ Joint definitions are used to construct joints.

func MakeB2JointDef

func MakeB2JointDef() B2JointDef

func (B2JointDef) GetBodyA

func (def B2JointDef) GetBodyA() *B2Body

func (B2JointDef) GetBodyB

func (def B2JointDef) GetBodyB() *B2Body

func (B2JointDef) GetType

func (def B2JointDef) GetType() uint8

Implementing B2JointDefInterface on B2Joint (used as a base struct)

func (B2JointDef) GetUserData

func (def B2JointDef) GetUserData() interface{}

func (B2JointDef) IsCollideConnected

func (def B2JointDef) IsCollideConnected() bool

func (*B2JointDef) SetBodyA

func (def *B2JointDef) SetBodyA(body *B2Body)

func (*B2JointDef) SetBodyB

func (def *B2JointDef) SetBodyB(body *B2Body)

func (*B2JointDef) SetCollideConnected

func (def *B2JointDef) SetCollideConnected(flag bool)

func (*B2JointDef) SetType

func (def *B2JointDef) SetType(t uint8)

func (*B2JointDef) SetUserData

func (def *B2JointDef) SetUserData(userdata interface{})

type B2JointDefInterface

type B2JointDefInterface interface {
	GetType() uint8
	SetType(t uint8)
	GetUserData() interface{}
	SetUserData(userdata interface{})
	GetBodyA() *B2Body
	SetBodyA(body *B2Body)
	GetBodyB() *B2Body
	SetBodyB(body *B2Body)
	IsCollideConnected() bool
	SetCollideConnected(flag bool)
}

type B2JointEdge

type B2JointEdge struct {
	Other *B2Body          ///< provides quick access to the other body attached.
	Joint B2JointInterface ///< the joint; backed by pointer
	Prev  *B2JointEdge     ///< the previous joint edge in the body's joint list
	Next  *B2JointEdge     ///< the next joint edge in the body's joint list
}

/ A joint edge is used to connect bodies and joints together / in a joint graph where each body is a node and each joint / is an edge. A joint edge belongs to a doubly linked list / maintained in each attached body. Each joint has two joint / nodes, one for each attached body.

type B2JointInterface

type B2JointInterface interface {
	/// Dump this joint to the log file.
	Dump()

	/// Shift the origin for any points stored in world coordinates.
	ShiftOrigin(newOrigin B2Vec2)

	GetType() uint8
	SetType(t uint8)

	GetBodyA() *B2Body
	SetBodyA(body *B2Body)

	GetBodyB() *B2Body
	SetBodyB(body *B2Body)

	GetIndex() int
	SetIndex(index int)

	GetNext() B2JointInterface     // backed by pointer
	SetNext(next B2JointInterface) // backed by pointer

	GetPrev() B2JointInterface     // backed by pointer
	SetPrev(prev B2JointInterface) // backed by pointer

	GetEdgeA() *B2JointEdge
	SetEdgeA(edge *B2JointEdge)

	GetEdgeB() *B2JointEdge
	SetEdgeB(edge *B2JointEdge)

	GetUserData() interface{}
	SetUserData(data interface{})

	IsCollideConnected() bool
	SetCollideConnected(flag bool)

	IsActive() bool

	//@goadd
	Destroy()

	InitVelocityConstraints(data B2SolverData)

	SolveVelocityConstraints(data B2SolverData)

	SolvePositionConstraints(data B2SolverData) bool

	GetIslandFlag() bool
	SetIslandFlag(flag bool)
}

func B2JointCreate

func B2JointCreate(def B2JointDefInterface) B2JointInterface

type B2Manifold

type B2Manifold struct {
	Points      [B2_maxManifoldPoints]B2ManifoldPoint ///< the points of contact
	LocalNormal B2Vec2                                ///< not use for Type::e_points
	LocalPoint  B2Vec2                                ///< usage depends on manifold type
	Type        uint8                                 // B2Manifold_Type
	PointCount  int                                   ///< the number of manifold points
}

func NewB2Manifold

func NewB2Manifold() *B2Manifold

type B2ManifoldPoint

type B2ManifoldPoint struct {
	LocalPoint     B2Vec2      ///< usage depends on manifold type
	NormalImpulse  float64     ///< the non-penetration impulse
	TangentImpulse float64     ///< the friction impulse
	Id             B2ContactID ///< uniquely identifies a contact point between two shapes
}

/ A manifold point is a contact point belonging to a contact / manifold. It holds details related to the geometry and dynamics / of the contact points. / The local point usage depends on the manifold type: / -e_circles: the local center of circleB / -e_faceA: the local center of cirlceB or the clip point of polygonB / -e_faceB: the clip point of polygonA / This structure is stored across time steps, so we keep it small. / Note: the impulses are used for internal caching and may not / provide reliable contact forces, especially for high speed collisions.

type B2MassData

type B2MassData struct {
	/// The mass of the shape, usually in kilograms.
	Mass float64

	/// The position of the shape's centroid relative to the shape's origin.
	Center B2Vec2

	/// The rotational inertia of the shape about the local origin.
	I float64
}

/ This holds the mass data computed for a shape.

func MakeMassData

func MakeMassData() B2MassData

func NewMassData

func NewMassData() *B2MassData

type B2Mat22

type B2Mat22 struct {
	Ex, Ey B2Vec2
}

///////////////////////////////////////////////////////////////////////////// / A 2-by-2 matrix. Stored in column-major order. /////////////////////////////////////////////////////////////////////////////

func B2Mat22Abs

func B2Mat22Abs(A B2Mat22) B2Mat22

func B2Mat22Add

func B2Mat22Add(A, B B2Mat22) B2Mat22

func B2Mat22Mul

func B2Mat22Mul(A, B B2Mat22) B2Mat22

A * B

func B2Mat22MulT

func B2Mat22MulT(A, B B2Mat22) B2Mat22

A^T * B

func MakeB2Mat22

func MakeB2Mat22() B2Mat22

/ The default constructor does nothing

func MakeB2Mat22FromColumns

func MakeB2Mat22FromColumns(c1, c2 B2Vec2) B2Mat22

/ Construct this matrix using columns.

func MakeB2Mat22FromScalars

func MakeB2Mat22FromScalars(a11, a12, a21, a22 float64) B2Mat22

/ Construct this matrix using scalars.

func NewB2Mat22

func NewB2Mat22() *B2Mat22

func NewB2Mat22FromColumns

func NewB2Mat22FromColumns(c1, c2 B2Vec2) *B2Mat22

func NewB2Mat22FromScalars

func NewB2Mat22FromScalars(a11, a12, a21, a22 float64) *B2Mat22

func (B2Mat22) GetInverse

func (m B2Mat22) GetInverse() B2Mat22

func (*B2Mat22) Set

func (m *B2Mat22) Set(c1 B2Vec2, c2 B2Vec2)

/ Initialize this matrix using columns.

func (*B2Mat22) SetIdentity

func (m *B2Mat22) SetIdentity()

/ Set this to the identity matrix.

func (*B2Mat22) SetZero

func (m *B2Mat22) SetZero()

/ Set this matrix to all zeros.

func (B2Mat22) Solve

func (m B2Mat22) Solve(b B2Vec2) B2Vec2

/ Solve A * x = b, where b is a column vector. This is more efficient / than computing the inverse in one-shot cases.

type B2Mat33

type B2Mat33 struct {
	Ex, Ey, Ez B2Vec3
}

///////////////////////////////////////////////////////////////////////////// / A 3-by-3 matrix. Stored in column-major order. /////////////////////////////////////////////////////////////////////////////

func MakeB2Mat33

func MakeB2Mat33() B2Mat33

/ The default constructor does nothing (for performance).

func MakeB2Mat33FromColumns

func MakeB2Mat33FromColumns(c1, c2, c3 B2Vec3) B2Mat33

/ Construct this matrix using columns.

func NewB2Mat33

func NewB2Mat33() *B2Mat33

func NewB2Mat33FromColumns

func NewB2Mat33FromColumns(c1, c2, c3 B2Vec3) *B2Mat33

func (B2Mat33) GetInverse22

func (mat B2Mat33) GetInverse22(M *B2Mat33)

/

func (B2Mat33) GetSymInverse33

func (mat B2Mat33) GetSymInverse33(M *B2Mat33)

/ Returns the zero matrix if singular.

func (*B2Mat33) SetZero

func (m *B2Mat33) SetZero()

/ Set this matrix to all zeros.

func (B2Mat33) Solve22

func (mat B2Mat33) Solve22(b B2Vec2) B2Vec2

/ Solve A * x = b, where b is a column vector. This is more efficient / than computing the inverse in one-shot cases.

func (B2Mat33) Solve33

func (mat B2Mat33) Solve33(b B2Vec3) B2Vec3

/ Solve A * x = b, where b is a column vector. This is more efficient / than computing the inverse in one-shot cases.

type B2MotorJoint

type B2MotorJoint struct {
	*B2Joint

	// Solver shared
	M_linearOffset     B2Vec2
	M_angularOffset    float64
	M_linearImpulse    B2Vec2
	M_angularImpulse   float64
	M_maxForce         float64
	M_maxTorque        float64
	M_correctionFactor float64

	// Solver temp
	M_indexA       int
	M_indexB       int
	M_rA           B2Vec2
	M_rB           B2Vec2
	M_localCenterA B2Vec2
	M_localCenterB B2Vec2
	M_linearError  B2Vec2
	M_angularError float64
	M_invMassA     float64
	M_invMassB     float64
	M_invIA        float64
	M_invIB        float64
	M_linearMass   B2Mat22
	M_angularMass  float64
}

/ A motor joint is used to control the relative motion / between two bodies. A typical usage is to control the movement / of a dynamic body with respect to the ground.

func MakeB2MotorJoint

func MakeB2MotorJoint(def *B2MotorJointDef) *B2MotorJoint

func (*B2MotorJoint) Dump

func (joint *B2MotorJoint) Dump()

func (B2MotorJoint) GetAnchorA

func (joint B2MotorJoint) GetAnchorA() B2Vec2

func (B2MotorJoint) GetAnchorB

func (joint B2MotorJoint) GetAnchorB() B2Vec2

func (B2MotorJoint) GetAngularOffset

func (joint B2MotorJoint) GetAngularOffset() float64

func (B2MotorJoint) GetCorrectionFactor

func (joint B2MotorJoint) GetCorrectionFactor() float64

func (B2MotorJoint) GetLinearOffset

func (joint B2MotorJoint) GetLinearOffset() B2Vec2

func (B2MotorJoint) GetMaxForce

func (joint B2MotorJoint) GetMaxForce() float64

func (B2MotorJoint) GetMaxTorque

func (joint B2MotorJoint) GetMaxTorque() float64

func (B2MotorJoint) GetReactionForce

func (joint B2MotorJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2MotorJoint) GetReactionTorque

func (joint B2MotorJoint) GetReactionTorque(inv_dt float64) float64

func (*B2MotorJoint) InitVelocityConstraints

func (joint *B2MotorJoint) InitVelocityConstraints(data B2SolverData)

func (*B2MotorJoint) SetAngularOffset

func (joint *B2MotorJoint) SetAngularOffset(angularOffset float64)

func (*B2MotorJoint) SetCorrectionFactor

func (joint *B2MotorJoint) SetCorrectionFactor(factor float64)

func (*B2MotorJoint) SetLinearOffset

func (joint *B2MotorJoint) SetLinearOffset(linearOffset B2Vec2)

func (*B2MotorJoint) SetMaxForce

func (joint *B2MotorJoint) SetMaxForce(force float64)

func (*B2MotorJoint) SetMaxTorque

func (joint *B2MotorJoint) SetMaxTorque(torque float64)

func (*B2MotorJoint) SolvePositionConstraints

func (joint *B2MotorJoint) SolvePositionConstraints(data B2SolverData) bool

func (*B2MotorJoint) SolveVelocityConstraints

func (joint *B2MotorJoint) SolveVelocityConstraints(data B2SolverData)

type B2MotorJointDef

type B2MotorJointDef struct {
	B2JointDef

	/// Position of bodyB minus the position of bodyA, in bodyA's frame, in meters.
	LinearOffset B2Vec2

	/// The bodyB angle minus bodyA angle in radians.
	AngularOffset float64

	/// The maximum motor force in N.
	MaxForce float64

	/// The maximum motor torque in N-m.
	MaxTorque float64

	/// Position correction factor in the range [0,1].
	CorrectionFactor float64
}

/ Motor joint definition.

func MakeB2MotorJointDef

func MakeB2MotorJointDef() B2MotorJointDef

func (*B2MotorJointDef) Initialize

func (def *B2MotorJointDef) Initialize(bA *B2Body, bB *B2Body)

type B2MouseJoint

type B2MouseJoint struct {
	*B2Joint

	M_localAnchorB B2Vec2
	M_targetA      B2Vec2
	M_frequencyHz  float64
	M_dampingRatio float64
	M_beta         float64

	// Solver shared
	M_impulse  B2Vec2
	M_maxForce float64
	M_gamma    float64

	// Solver temp
	M_indexA       int
	M_indexB       int
	M_rB           B2Vec2
	M_localCenterB B2Vec2
	M_invMassB     float64
	M_invIB        float64
	M_mass         B2Mat22
	M_C            B2Vec2
}

/ A mouse joint is used to make a point on a body track a / specified world point. This a soft constraint with a maximum / force. This allows the constraint to stretch and without / applying huge forces. / NOTE: this joint is not documented in the manual because it was / developed to be used in the testbed. If you want to learn how to / use the mouse joint, look at the testbed.

func MakeB2MouseJoint

func MakeB2MouseJoint(def *B2MouseJointDef) *B2MouseJoint

func (*B2MouseJoint) Dump

func (def *B2MouseJoint) Dump()

/ The mouse joint does not support dumping.

func (B2MouseJoint) GetAnchorA

func (joint B2MouseJoint) GetAnchorA() B2Vec2

func (B2MouseJoint) GetAnchorB

func (joint B2MouseJoint) GetAnchorB() B2Vec2

func (B2MouseJoint) GetDampingRatio

func (joint B2MouseJoint) GetDampingRatio() float64

func (B2MouseJoint) GetFrequency

func (joint B2MouseJoint) GetFrequency() float64

func (B2MouseJoint) GetMaxForce

func (joint B2MouseJoint) GetMaxForce() float64

func (B2MouseJoint) GetReactionForce

func (joint B2MouseJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2MouseJoint) GetReactionTorque

func (joint B2MouseJoint) GetReactionTorque(inv_dt float64) float64

func (B2MouseJoint) GetTarget

func (joint B2MouseJoint) GetTarget() B2Vec2

func (*B2MouseJoint) InitVelocityConstraints

func (joint *B2MouseJoint) InitVelocityConstraints(data B2SolverData)

func (*B2MouseJoint) SetDampingRatio

func (joint *B2MouseJoint) SetDampingRatio(ratio float64)

func (*B2MouseJoint) SetFrequency

func (joint *B2MouseJoint) SetFrequency(hz float64)

func (*B2MouseJoint) SetMaxForce

func (joint *B2MouseJoint) SetMaxForce(force float64)

func (*B2MouseJoint) SetTarget

func (joint *B2MouseJoint) SetTarget(target B2Vec2)

func (*B2MouseJoint) ShiftOrigin

func (joint *B2MouseJoint) ShiftOrigin(newOrigin B2Vec2)

func (*B2MouseJoint) SolvePositionConstraints

func (joint *B2MouseJoint) SolvePositionConstraints(data B2SolverData) bool

func (*B2MouseJoint) SolveVelocityConstraints

func (joint *B2MouseJoint) SolveVelocityConstraints(data B2SolverData)

type B2MouseJointDef

type B2MouseJointDef struct {
	B2JointDef

	/// The initial world target point. This is assumed
	/// to coincide with the body anchor initially.
	Target B2Vec2

	/// The maximum constraint force that can be exerted
	/// to move the candidate body. Usually you will express
	/// as some multiple of the weight (multiplier * mass * gravity).
	MaxForce float64

	/// The response speed.
	FrequencyHz float64

	/// The damping ratio. 0 = no damping, 1 = critical damping.
	DampingRatio float64
}

/ Mouse joint definition. This requires a world target point, / tuning parameters, and the time step.

func MakeB2MouseJointDef

func MakeB2MouseJointDef() B2MouseJointDef

type B2Pair

type B2Pair struct {
	ProxyIdA int
	ProxyIdB int
}

type B2PolygonAndCircleContact

type B2PolygonAndCircleContact struct {
	B2Contact
}

func (*B2PolygonAndCircleContact) Evaluate

func (contact *B2PolygonAndCircleContact) Evaluate(manifold *B2Manifold, xfA B2Transform, xfB B2Transform)

type B2PolygonContact

type B2PolygonContact struct {
	B2Contact
}

func (*B2PolygonContact) Evaluate

func (contact *B2PolygonContact) Evaluate(manifold *B2Manifold, xfA B2Transform, xfB B2Transform)

type B2PolygonShape

type B2PolygonShape struct {
	B2Shape

	M_centroid B2Vec2
	M_vertices [B2_maxPolygonVertices]B2Vec2
	M_normals  [B2_maxPolygonVertices]B2Vec2
	M_count    int
}

func MakeB2PolygonShape

func MakeB2PolygonShape() B2PolygonShape

func NewB2PolygonShape

func NewB2PolygonShape() *B2PolygonShape

func (B2PolygonShape) Clone

func (poly B2PolygonShape) Clone() B2ShapeInterface

func (B2PolygonShape) ComputeAABB

func (poly B2PolygonShape) ComputeAABB(aabb *B2AABB, xf B2Transform, childIndex int)

func (B2PolygonShape) ComputeMass

func (poly B2PolygonShape) ComputeMass(massData *B2MassData, density float64)

func (*B2PolygonShape) Destroy

func (edge *B2PolygonShape) Destroy()

func (B2PolygonShape) GetChildCount

func (poly B2PolygonShape) GetChildCount() int

func (B2PolygonShape) RayCast

func (poly B2PolygonShape) RayCast(output *B2RayCastOutput, input B2RayCastInput, xf B2Transform, childIndex int) bool

func (*B2PolygonShape) Set

func (poly *B2PolygonShape) Set(vertices []B2Vec2, count int)

func (*B2PolygonShape) SetAsBox

func (poly *B2PolygonShape) SetAsBox(hx float64, hy float64)

func (*B2PolygonShape) SetAsBoxFromCenterAndAngle

func (poly *B2PolygonShape) SetAsBoxFromCenterAndAngle(hx float64, hy float64, center B2Vec2, angle float64)

func (B2PolygonShape) TestPoint

func (poly B2PolygonShape) TestPoint(xf B2Transform, p B2Vec2) bool

func (B2PolygonShape) Validate

func (poly B2PolygonShape) Validate() bool

type B2Position

type B2Position struct {
	C B2Vec2
	A float64
}

/ This is an internal structure.

type B2PositionSolverManifold

type B2PositionSolverManifold struct {
	Normal     B2Vec2
	Point      B2Vec2
	Separation float64
}

func MakeB2PositionSolverManifold

func MakeB2PositionSolverManifold() B2PositionSolverManifold

func (*B2PositionSolverManifold) Initialize

func (solvermanifold *B2PositionSolverManifold) Initialize(pc *B2ContactPositionConstraint, xfA B2Transform, xfB B2Transform, index int)

type B2PrismaticJoint

type B2PrismaticJoint struct {
	*B2Joint

	// Solver shared
	M_localAnchorA     B2Vec2
	M_localAnchorB     B2Vec2
	M_localXAxisA      B2Vec2
	M_localYAxisA      B2Vec2
	M_referenceAngle   float64
	M_impulse          B2Vec3
	M_motorImpulse     float64
	M_lowerTranslation float64
	M_upperTranslation float64
	M_maxMotorForce    float64
	M_motorSpeed       float64
	M_enableLimit      bool
	M_enableMotor      bool
	M_limitState       uint8

	// Solver temp
	M_indexA       int
	M_indexB       int
	M_localCenterA B2Vec2
	M_localCenterB B2Vec2
	M_invMassA     float64
	M_invMassB     float64
	M_invIA        float64
	M_invIB        float64
	M_axis, M_perp B2Vec2
	M_s1, M_s2     float64
	M_a1, M_a2     float64
	M_K            B2Mat33
	M_motorMass    float64
}

/ A prismatic joint. This joint provides one degree of freedom: translation / along an axis fixed in bodyA. Relative rotation is prevented. You can / use a joint limit to restrict the range of motion and a joint motor to / drive the motion or to model joint friction.

func MakeB2PrismaticJoint

func MakeB2PrismaticJoint(def *B2PrismaticJointDef) *B2PrismaticJoint

func (*B2PrismaticJoint) Dump

func (joint *B2PrismaticJoint) Dump()

func (*B2PrismaticJoint) EnableLimit

func (joint *B2PrismaticJoint) EnableLimit(flag bool)

func (*B2PrismaticJoint) EnableMotor

func (joint *B2PrismaticJoint) EnableMotor(flag bool)

func (B2PrismaticJoint) GetAnchorA

func (joint B2PrismaticJoint) GetAnchorA() B2Vec2

func (B2PrismaticJoint) GetAnchorB

func (joint B2PrismaticJoint) GetAnchorB() B2Vec2

func (B2PrismaticJoint) GetJointSpeed

func (joint B2PrismaticJoint) GetJointSpeed() float64

func (B2PrismaticJoint) GetJointTranslation

func (joint B2PrismaticJoint) GetJointTranslation() float64

func (B2PrismaticJoint) GetLocalAnchorA

func (joint B2PrismaticJoint) GetLocalAnchorA() B2Vec2

/ The local anchor point relative to bodyA's origin.

func (B2PrismaticJoint) GetLocalAnchorB

func (joint B2PrismaticJoint) GetLocalAnchorB() B2Vec2

/ The local anchor point relative to bodyB's origin.

func (B2PrismaticJoint) GetLocalAxisA

func (joint B2PrismaticJoint) GetLocalAxisA() B2Vec2

/ The local joint axis relative to bodyA.

func (B2PrismaticJoint) GetLowerLimit

func (joint B2PrismaticJoint) GetLowerLimit() float64

func (B2PrismaticJoint) GetMaxMotorForce

func (joint B2PrismaticJoint) GetMaxMotorForce() float64

func (B2PrismaticJoint) GetMotorForce

func (joint B2PrismaticJoint) GetMotorForce(inv_dt float64) float64

func (B2PrismaticJoint) GetMotorSpeed

func (joint B2PrismaticJoint) GetMotorSpeed() float64

func (B2PrismaticJoint) GetReactionForce

func (joint B2PrismaticJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2PrismaticJoint) GetReactionTorque

func (joint B2PrismaticJoint) GetReactionTorque(inv_dt float64) float64

func (B2PrismaticJoint) GetReferenceAngle

func (joint B2PrismaticJoint) GetReferenceAngle() float64

/ Get the reference angle.

func (B2PrismaticJoint) GetUpperLimit

func (joint B2PrismaticJoint) GetUpperLimit() float64

func (*B2PrismaticJoint) InitVelocityConstraints

func (joint *B2PrismaticJoint) InitVelocityConstraints(data B2SolverData)

func (B2PrismaticJoint) IsLimitEnabled

func (joint B2PrismaticJoint) IsLimitEnabled() bool

func (B2PrismaticJoint) IsMotorEnabled

func (joint B2PrismaticJoint) IsMotorEnabled() bool

func (*B2PrismaticJoint) SetLimits

func (joint *B2PrismaticJoint) SetLimits(lower float64, upper float64)

func (*B2PrismaticJoint) SetMaxMotorForce

func (joint *B2PrismaticJoint) SetMaxMotorForce(force float64)

func (*B2PrismaticJoint) SetMotorSpeed

func (joint *B2PrismaticJoint) SetMotorSpeed(speed float64)

func (*B2PrismaticJoint) SolvePositionConstraints

func (joint *B2PrismaticJoint) SolvePositionConstraints(data B2SolverData) bool

A velocity based solver computes reaction forces(impulses) using the velocity constraint solver.Under this context, the position solver is not there to resolve forces.It is only there to cope with integration error.

Therefore, the pseudo impulses in the position solver do not have any physical meaning.Thus it is okay if they suck.

We could take the active state from the velocity solver.However, the joint might push past the limit when the velocity solver indicates the limit is inactive.

func (*B2PrismaticJoint) SolveVelocityConstraints

func (joint *B2PrismaticJoint) SolveVelocityConstraints(data B2SolverData)

type B2PrismaticJointDef

type B2PrismaticJointDef struct {
	B2JointDef

	/// The local anchor point relative to bodyA's origin.
	LocalAnchorA B2Vec2

	/// The local anchor point relative to bodyB's origin.
	LocalAnchorB B2Vec2

	/// The local translation unit axis in bodyA.
	LocalAxisA B2Vec2

	/// The constrained angle between the bodies: bodyB_angle - bodyA_angle.
	ReferenceAngle float64

	/// Enable/disable the joint limit.
	EnableLimit bool

	/// The lower translation limit, usually in meters.
	LowerTranslation float64

	/// The upper translation limit, usually in meters.
	UpperTranslation float64

	/// Enable/disable the joint motor.
	EnableMotor bool

	/// The maximum motor torque, usually in N-m.
	MaxMotorForce float64

	/// The desired motor speed in radians per second.
	MotorSpeed float64
}

/ Prismatic joint definition. This requires defining a line of / motion using an axis and an anchor point. The definition uses local / anchor points and a local axis so that the initial configuration / can violate the constraint slightly. The joint translation is zero / when the local anchor points coincide in world space. Using local / anchors and a local axis helps when saving and loading a game.

func MakeB2PrismaticJointDef

func MakeB2PrismaticJointDef() B2PrismaticJointDef

func (*B2PrismaticJointDef) Initialize

func (joint *B2PrismaticJointDef) Initialize(bA *B2Body, bB *B2Body, anchor B2Vec2, axis B2Vec2)

type B2Profile

type B2Profile struct {
	Step          float64
	Collide       float64
	Solve         float64
	SolveInit     float64
	SolveVelocity float64
	SolvePosition float64
	Broadphase    float64
	SolveTOI      float64
}

/ Profiling data. Times are in milliseconds.

func MakeB2Profile

func MakeB2Profile() B2Profile

type B2PulleyJoint

type B2PulleyJoint struct {
	*B2Joint

	M_groundAnchorA B2Vec2
	M_groundAnchorB B2Vec2
	M_lengthA       float64
	M_lengthB       float64

	// Solver shared
	M_localAnchorA B2Vec2
	M_localAnchorB B2Vec2
	M_constant     float64
	M_ratio        float64
	M_impulse      float64

	// Solver temp
	M_indexA       int
	M_indexB       int
	M_uA           B2Vec2
	M_uB           B2Vec2
	M_rA           B2Vec2
	M_rB           B2Vec2
	M_localCenterA B2Vec2
	M_localCenterB B2Vec2
	M_invMassA     float64
	M_invMassB     float64
	M_invIA        float64
	M_invIB        float64
	M_mass         float64
}

/ The pulley joint is connected to two bodies and two fixed ground points. / The pulley supports a ratio such that: / length1 + ratio * length2 <= constant / Yes, the force transmitted is scaled by the ratio. / Warning: the pulley joint can get a bit squirrelly by itself. They often / work better when combined with prismatic joints. You should also cover the / the anchor points with static shapes to prevent one side from going to / zero length.

func MakeB2PulleyJoint

func MakeB2PulleyJoint(def *B2PulleyJointDef) *B2PulleyJoint

func (*B2PulleyJoint) Dump

func (joint *B2PulleyJoint) Dump()

func (B2PulleyJoint) GetAnchorA

func (joint B2PulleyJoint) GetAnchorA() B2Vec2

func (B2PulleyJoint) GetAnchorB

func (joint B2PulleyJoint) GetAnchorB() B2Vec2

func (B2PulleyJoint) GetCurrentLengthA

func (joint B2PulleyJoint) GetCurrentLengthA() float64

func (B2PulleyJoint) GetCurrentLengthB

func (joint B2PulleyJoint) GetCurrentLengthB() float64

func (B2PulleyJoint) GetGroundAnchorA

func (joint B2PulleyJoint) GetGroundAnchorA() B2Vec2

func (B2PulleyJoint) GetGroundAnchorB

func (joint B2PulleyJoint) GetGroundAnchorB() B2Vec2

func (B2PulleyJoint) GetLengthA

func (joint B2PulleyJoint) GetLengthA() float64

func (B2PulleyJoint) GetLengthB

func (joint B2PulleyJoint) GetLengthB() float64

func (B2PulleyJoint) GetRatio

func (joint B2PulleyJoint) GetRatio() float64

func (B2PulleyJoint) GetReactionForce

func (joint B2PulleyJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2PulleyJoint) GetReactionTorque

func (joint B2PulleyJoint) GetReactionTorque(inv_dt float64) float64

func (*B2PulleyJoint) InitVelocityConstraints

func (joint *B2PulleyJoint) InitVelocityConstraints(data B2SolverData)

func (*B2PulleyJoint) ShiftOrigin

func (joint *B2PulleyJoint) ShiftOrigin(newOrigin B2Vec2)

func (*B2PulleyJoint) SolvePositionConstraints

func (joint *B2PulleyJoint) SolvePositionConstraints(data B2SolverData) bool

func (*B2PulleyJoint) SolveVelocityConstraints

func (joint *B2PulleyJoint) SolveVelocityConstraints(data B2SolverData)

type B2PulleyJointDef

type B2PulleyJointDef struct {
	B2JointDef

	/// The first ground anchor in world coordinates. This point never moves.
	GroundAnchorA B2Vec2

	/// The second ground anchor in world coordinates. This point never moves.
	GroundAnchorB B2Vec2

	/// The local anchor point relative to bodyA's origin.
	LocalAnchorA B2Vec2

	/// The local anchor point relative to bodyB's origin.
	LocalAnchorB B2Vec2

	/// The a reference length for the segment attached to bodyA.
	LengthA float64

	/// The a reference length for the segment attached to bodyB.
	LengthB float64

	/// The pulley ratio, used to simulate a block-and-tackle.
	Ratio float64
}

/ Pulley joint definition. This requires two ground anchors, / two dynamic body anchor points, and a pulley ratio.

func MakeB2PulleyJointDef

func MakeB2PulleyJointDef() B2PulleyJointDef

func (*B2PulleyJointDef) Initialize

func (def *B2PulleyJointDef) Initialize(bA *B2Body, bB *B2Body, groundA B2Vec2, groundB B2Vec2, anchorA B2Vec2, anchorB B2Vec2, r float64)

type B2RayCastInput

type B2RayCastInput struct {
	P1, P2      B2Vec2
	MaxFraction float64
}

/ Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).

func MakeB2RayCastInput

func MakeB2RayCastInput() B2RayCastInput

func NewB2RayCastInput

func NewB2RayCastInput() *B2RayCastInput

type B2RayCastOutput

type B2RayCastOutput struct {
	Normal   B2Vec2
	Fraction float64
}

/ Ray-cast output data. The ray hits at p1 + fraction * (p2 - p1), where p1 and p2 / come from b2RayCastInput.

func MakeB2RayCastOutput

func MakeB2RayCastOutput() B2RayCastOutput

type B2RaycastCallback

type B2RaycastCallback func(fixture *B2Fixture, point B2Vec2, normal B2Vec2, fraction float64) float64

/ Called for each fixture found in the query. You control how the ray cast / proceeds by returning a float: / return -1: ignore this fixture and continue / return 0: terminate the ray cast / return fraction: clip the ray to this point / return 1: don't clip the ray and continue / @param fixture the fixture hit by the ray / @param point the point of initial intersection / @param normal the normal vector at the point of intersection / @return -1 to filter, 0 to terminate, fraction to clip the ray for / closest hit, 1 to continue

type B2ReferenceFace

type B2ReferenceFace struct {
	I1, I2 int

	V1, V2 B2Vec2

	Normal B2Vec2

	SideNormal1 B2Vec2
	SideOffset1 float64

	SideNormal2 B2Vec2
	SideOffset2 float64
}

Reference face used for clipping

func MakeB2ReferenceFace

func MakeB2ReferenceFace() B2ReferenceFace

type B2RevoluteJoint

type B2RevoluteJoint struct {
	*B2Joint

	// Solver shared
	M_localAnchorA B2Vec2
	M_localAnchorB B2Vec2
	M_impulse      B2Vec3
	M_motorImpulse float64

	M_enableMotor    bool
	M_maxMotorTorque float64
	M_motorSpeed     float64

	M_enableLimit    bool
	M_referenceAngle float64
	M_lowerAngle     float64
	M_upperAngle     float64

	// Solver temp
	M_indexA       int
	M_indexB       int
	M_rA           B2Vec2
	M_rB           B2Vec2
	M_localCenterA B2Vec2
	M_localCenterB B2Vec2
	M_invMassA     float64
	M_invMassB     float64
	M_invIA        float64
	M_invIB        float64
	M_mass         B2Mat33 // effective mass for point-to-point constraint.
	M_motorMass    float64 // effective mass for motor/limit angular constraint.
	M_limitState   uint8
}

/ A revolute joint constrains two bodies to share a common point while they / are free to rotate about the point. The relative rotation about the shared / point is the joint angle. You can limit the relative rotation with / a joint limit that specifies a lower and upper angle. You can use a motor / to drive the relative rotation about the shared point. A maximum motor torque / is provided so that infinite forces are not generated.

func MakeB2RevoluteJoint

func MakeB2RevoluteJoint(def *B2RevoluteJointDef) *B2RevoluteJoint

func (*B2RevoluteJoint) Dump

func (joint *B2RevoluteJoint) Dump()

func (*B2RevoluteJoint) EnableLimit

func (joint *B2RevoluteJoint) EnableLimit(flag bool)

func (*B2RevoluteJoint) EnableMotor

func (joint *B2RevoluteJoint) EnableMotor(flag bool)

func (B2RevoluteJoint) GetAnchorA

func (joint B2RevoluteJoint) GetAnchorA() B2Vec2

func (B2RevoluteJoint) GetAnchorB

func (joint B2RevoluteJoint) GetAnchorB() B2Vec2

func (B2RevoluteJoint) GetJointAngle

func (joint B2RevoluteJoint) GetJointAngle() float64

func (*B2RevoluteJoint) GetJointSpeed

func (joint *B2RevoluteJoint) GetJointSpeed() float64

func (B2RevoluteJoint) GetLocalAnchorA

func (joint B2RevoluteJoint) GetLocalAnchorA() B2Vec2

/ The local anchor point relative to bodyA's origin.

func (B2RevoluteJoint) GetLocalAnchorB

func (joint B2RevoluteJoint) GetLocalAnchorB() B2Vec2

/ The local anchor point relative to bodyB's origin.

func (B2RevoluteJoint) GetLowerLimit

func (joint B2RevoluteJoint) GetLowerLimit() float64

func (B2RevoluteJoint) GetMaxMotorTorque

func (joint B2RevoluteJoint) GetMaxMotorTorque() float64

func (B2RevoluteJoint) GetMotorSpeed

func (joint B2RevoluteJoint) GetMotorSpeed() float64

func (B2RevoluteJoint) GetMotorTorque

func (joint B2RevoluteJoint) GetMotorTorque(inv_dt float64) float64

func (B2RevoluteJoint) GetReactionForce

func (joint B2RevoluteJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2RevoluteJoint) GetReactionTorque

func (joint B2RevoluteJoint) GetReactionTorque(inv_dt float64) float64

func (B2RevoluteJoint) GetReferenceAngle

func (joint B2RevoluteJoint) GetReferenceAngle() float64

/ Get the reference angle.

func (B2RevoluteJoint) GetUpperLimit

func (joint B2RevoluteJoint) GetUpperLimit() float64

func (*B2RevoluteJoint) InitVelocityConstraints

func (joint *B2RevoluteJoint) InitVelocityConstraints(data B2SolverData)

func (B2RevoluteJoint) IsLimitEnabled

func (joint B2RevoluteJoint) IsLimitEnabled() bool

func (B2RevoluteJoint) IsMotorEnabled

func (joint B2RevoluteJoint) IsMotorEnabled() bool

func (*B2RevoluteJoint) SetLimits

func (joint *B2RevoluteJoint) SetLimits(lower float64, upper float64)

func (*B2RevoluteJoint) SetMaxMotorTorque

func (joint *B2RevoluteJoint) SetMaxMotorTorque(torque float64)

func (*B2RevoluteJoint) SetMotorSpeed

func (joint *B2RevoluteJoint) SetMotorSpeed(speed float64)

func (*B2RevoluteJoint) SolvePositionConstraints

func (joint *B2RevoluteJoint) SolvePositionConstraints(data B2SolverData) bool

func (*B2RevoluteJoint) SolveVelocityConstraints

func (joint *B2RevoluteJoint) SolveVelocityConstraints(data B2SolverData)

type B2RevoluteJointDef

type B2RevoluteJointDef struct {
	B2JointDef

	/// The local anchor point relative to bodyA's origin.
	LocalAnchorA B2Vec2

	/// The local anchor point relative to bodyB's origin.
	LocalAnchorB B2Vec2

	/// The bodyB angle minus bodyA angle in the reference state (radians).
	ReferenceAngle float64

	/// A flag to enable joint limits.
	EnableLimit bool

	/// The lower angle for the joint limit (radians).
	LowerAngle float64

	/// The upper angle for the joint limit (radians).
	UpperAngle float64

	/// A flag to enable the joint motor.
	EnableMotor bool

	/// The desired motor speed. Usually in radians per second.
	MotorSpeed float64

	/// The maximum motor torque used to achieve the desired motor speed.
	/// Usually in N-m.
	MaxMotorTorque float64
}

/ Revolute joint definition. This requires defining an / anchor point where the bodies are joined. The definition / uses local anchor points so that the initial configuration / can violate the constraint slightly. You also need to / specify the initial relative angle for joint limits. This / helps when saving and loading a game. / The local anchor points are measured from the body's origin / rather than the center of mass because: / 1. you might not know where the center of mass will be. / 2. if you add/remove shapes from a body and recompute the mass, / the joints will be broken.

func MakeB2RevoluteJointDef

func MakeB2RevoluteJointDef() B2RevoluteJointDef

func (*B2RevoluteJointDef) Initialize

func (def *B2RevoluteJointDef) Initialize(bA *B2Body, bB *B2Body, anchor B2Vec2)

type B2Rope

type B2Rope struct {
	M_count int
	M_ps    []B2Vec2
	M_p0s   []B2Vec2
	M_vs    []B2Vec2

	M_ims []float64

	M_Ls []float64
	M_as []float64

	M_gravity B2Vec2
	M_damping float64

	M_k2 float64
	M_k3 float64
}

/

func MakeB2Rope

func MakeB2Rope() B2Rope

func (*B2Rope) Destroy

func (rope *B2Rope) Destroy()

func (B2Rope) GetVertexCount

func (rope B2Rope) GetVertexCount() int

/

func (B2Rope) GetVertices

func (rope B2Rope) GetVertices() []B2Vec2

/

func (*B2Rope) Initialize

func (rope *B2Rope) Initialize(def *B2RopeDef)

func (*B2Rope) SetAngle

func (rope *B2Rope) SetAngle(angle float64)

func (*B2Rope) SolveC2

func (rope *B2Rope) SolveC2()

func (*B2Rope) SolveC3

func (rope *B2Rope) SolveC3()

func (*B2Rope) Step

func (rope *B2Rope) Step(h float64, iterations int)

type B2RopeDef

type B2RopeDef struct {

	///
	Vertices []B2Vec2

	///
	Count int

	///
	Masses []float64

	///
	Gravity B2Vec2

	///
	Damping float64

	/// Stretching stiffness
	K2 float64

	/// Bending stiffness. Values above 0.5 can make the simulation blow up.
	K3 float64
}

/

func MakeB2RopeDef

func MakeB2RopeDef() B2RopeDef

type B2RopeJoint

type B2RopeJoint struct {
	*B2Joint

	// Solver shared
	M_localAnchorA B2Vec2
	M_localAnchorB B2Vec2
	M_maxLength    float64
	M_length       float64
	M_impulse      float64

	// Solver temp
	M_indexA       int
	M_indexB       int
	M_u            B2Vec2
	M_rA           B2Vec2
	M_rB           B2Vec2
	M_localCenterA B2Vec2
	M_localCenterB B2Vec2
	M_invMassA     float64
	M_invMassB     float64
	M_invIA        float64
	M_invIB        float64
	M_mass         float64
	M_state        uint8
}

/ A rope joint enforces a maximum distance between two points / on two bodies. It has no other effect. / Warning: if you attempt to change the maximum length during / the simulation you will get some non-physical behavior. / A model that would allow you to dynamically modify the length / would have some sponginess, so I chose not to implement it / that way. See b2DistanceJoint if you want to dynamically / control length.

func MakeB2RopeJoint

func MakeB2RopeJoint(def *B2RopeJointDef) *B2RopeJoint

func (*B2RopeJoint) Dump

func (joint *B2RopeJoint) Dump()

func (B2RopeJoint) GetAnchorA

func (joint B2RopeJoint) GetAnchorA() B2Vec2

func (B2RopeJoint) GetAnchorB

func (joint B2RopeJoint) GetAnchorB() B2Vec2

func (B2RopeJoint) GetLimitState

func (joint B2RopeJoint) GetLimitState() uint8

func (B2RopeJoint) GetLocalAnchorA

func (joint B2RopeJoint) GetLocalAnchorA() B2Vec2

/ The local anchor point relative to bodyA's origin.

func (B2RopeJoint) GetLocalAnchorB

func (joint B2RopeJoint) GetLocalAnchorB() B2Vec2

/ The local anchor point relative to bodyB's origin.

func (B2RopeJoint) GetMaxLength

func (joint B2RopeJoint) GetMaxLength() float64

func (B2RopeJoint) GetReactionForce

func (joint B2RopeJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2RopeJoint) GetReactionTorque

func (joint B2RopeJoint) GetReactionTorque(inv_dt float64) float64

func (*B2RopeJoint) InitVelocityConstraints

func (joint *B2RopeJoint) InitVelocityConstraints(data B2SolverData)

func (*B2RopeJoint) SetMaxLength

func (joint *B2RopeJoint) SetMaxLength(length float64)

/ Set/Get the maximum length of the rope.

func (*B2RopeJoint) SolvePositionConstraints

func (joint *B2RopeJoint) SolvePositionConstraints(data B2SolverData) bool

func (*B2RopeJoint) SolveVelocityConstraints

func (joint *B2RopeJoint) SolveVelocityConstraints(data B2SolverData)

type B2RopeJointDef

type B2RopeJointDef struct {
	B2JointDef

	/// The local anchor point relative to bodyA's origin.
	LocalAnchorA B2Vec2

	/// The local anchor point relative to bodyB's origin.
	LocalAnchorB B2Vec2

	/// The maximum length of the rope.
	/// Warning: this must be larger than b2_linearSlop or
	/// the joint will have no effect.
	MaxLength float64
}

/ Rope joint definition. This requires two body anchor points and / a maximum lengths. / Note: by default the connected objects will not collide. / see collideConnected in b2JointDef.

func MakeB2RopeJointDef

func MakeB2RopeJointDef() B2RopeJointDef

type B2Rot

type B2Rot struct {
	/// Sine and cosine
	S, C float64
}

///////////////////////////////////////////////////////////////////////////// / Rotation /////////////////////////////////////////////////////////////////////////////

func B2RotMul

func B2RotMul(q, r B2Rot) B2Rot

/ Multiply two rotations: q * r

func B2RotMulT

func B2RotMulT(q, r B2Rot) B2Rot

/ Transpose multiply two rotations: qT * r

func MakeB2Rot

func MakeB2Rot() B2Rot

func MakeB2RotFromAngle

func MakeB2RotFromAngle(anglerad float64) B2Rot

/ Initialize from an angle in radians

func NewB2Rot

func NewB2Rot() *B2Rot

func NewB2RotFromAngle

func NewB2RotFromAngle(anglerad float64) *B2Rot

func (B2Rot) GetAngle

func (r B2Rot) GetAngle() float64

/ Get the angle in radians

func (B2Rot) GetXAxis

func (r B2Rot) GetXAxis() B2Vec2

/ Get the x-axis

func (B2Rot) GetYAxis

func (r B2Rot) GetYAxis() B2Vec2

/ Get the u-axis

func (*B2Rot) Set

func (r *B2Rot) Set(anglerad float64)

/ Set using an angle in radians.

func (*B2Rot) SetIdentity

func (r *B2Rot) SetIdentity()

/ Set to the identity rotation

type B2SeparationFunction

type B2SeparationFunction struct {
	M_proxyA           *B2DistanceProxy
	M_proxyB           *B2DistanceProxy
	M_sweepA, M_sweepB B2Sweep
	M_type             uint8
	M_localPoint       B2Vec2
	M_axis             B2Vec2
}

func (*B2SeparationFunction) Evaluate

func (sepfunc *B2SeparationFunction) Evaluate(indexA int, indexB int, t float64) float64

func (*B2SeparationFunction) FindMinSeparation

func (sepfunc *B2SeparationFunction) FindMinSeparation(indexA *int, indexB *int, t float64) float64

func (*B2SeparationFunction) Initialize

func (sepfunc *B2SeparationFunction) Initialize(cache *B2SimplexCache, proxyA *B2DistanceProxy, sweepA B2Sweep, proxyB *B2DistanceProxy, sweepB B2Sweep, t1 float64) float64

TODO_ERIN might not need to return the separation

type B2Shape

type B2Shape struct {
	M_type uint8

	/// Radius of a shape. For polygonal shapes this must be b2_polygonRadius. There is no support for
	/// making rounded polygons.
	M_radius float64
}

func (B2Shape) GetRadius

func (shape B2Shape) GetRadius() float64

func (B2Shape) GetType

func (shape B2Shape) GetType() uint8

func (*B2Shape) SetRadius

func (shape *B2Shape) SetRadius(r float64)

@addedgo

type B2ShapeInterface

type B2ShapeInterface interface {
	Destroy()

	/// Clone the concrete shape using the provided allocator.
	Clone() B2ShapeInterface

	/// Get the type of this shape. You can use this to down cast to the concrete shape.
	/// @return the shape type.
	GetType() uint8

	/// Get the type of this shape. You can use this to down cast to the concrete shape.
	/// @return the shape type.
	GetRadius() float64

	/// Get the number of child primitives.
	GetChildCount() int

	/// Test a point for containment in this shape. This only works for convex shapes.
	/// @param xf the shape world transform.
	/// @param p a point in world coordinates.
	TestPoint(xf B2Transform, p B2Vec2) bool

	/// Cast a ray against a child shape.
	/// @param output the ray-cast results.
	/// @param input the ray-cast input parameters.
	/// @param transform the transform to be applied to the shape.
	/// @param childIndex the child shape index
	RayCast(output *B2RayCastOutput, input B2RayCastInput, transform B2Transform, childIndex int) bool

	/// Given a transform, compute the associated axis aligned bounding box for a child shape.
	/// @param aabb returns the axis aligned box.
	/// @param xf the world transform of the shape.
	/// @param childIndex the child shape
	ComputeAABB(aabb *B2AABB, xf B2Transform, childIndex int)

	/// Compute the mass properties of this shape using its dimensions and density.
	/// The inertia tensor is computed about the local origin.
	/// @param massData returns the mass data for this shape.
	/// @param density the density in kilograms per meter squared.
	ComputeMass(massData *B2MassData, density float64)
}

type B2Simplex

type B2Simplex struct {
	//M_v1, M_v2, M_v3 *B2SimplexVertex
	M_vs    [3]B2SimplexVertex
	M_count int
}

func MakeB2Simplex

func MakeB2Simplex() B2Simplex

func NewB2Simplex

func NewB2Simplex() *B2Simplex

func (B2Simplex) GetClosestPoint

func (simplex B2Simplex) GetClosestPoint() B2Vec2

func (B2Simplex) GetMetric

func (simplex B2Simplex) GetMetric() float64

func (B2Simplex) GetSearchDirection

func (simplex B2Simplex) GetSearchDirection() B2Vec2

func (B2Simplex) GetWitnessPoints

func (simplex B2Simplex) GetWitnessPoints(pA *B2Vec2, pB *B2Vec2)

func (*B2Simplex) ReadCache

func (simplex *B2Simplex) ReadCache(cache *B2SimplexCache, proxyA *B2DistanceProxy, transformA B2Transform, proxyB *B2DistanceProxy, transformB B2Transform)

func (*B2Simplex) Solve2

func (simplex *B2Simplex) Solve2()

Solve a line segment using barycentric coordinates.

func (*B2Simplex) Solve3

func (simplex *B2Simplex) Solve3()

// Possible regions: // - points[2] // - edge points[0]-points[2] // - edge points[1]-points[2] // - inside the triangle

func (B2Simplex) WriteCache

func (simplex B2Simplex) WriteCache(cache *B2SimplexCache)

type B2SimplexCache

type B2SimplexCache struct {
	Metric float64 ///< length or area
	Count  int
	IndexA [3]int ///< vertices on shape A
	IndexB [3]int ///< vertices on shape B
}

/ Used to warm start b2Distance. / Set count to zero on first call.

func MakeB2SimplexCache

func MakeB2SimplexCache() B2SimplexCache

func NewB2SimplexCache

func NewB2SimplexCache() *B2SimplexCache

type B2SimplexVertex

type B2SimplexVertex struct {
	WA     B2Vec2  // support point in proxyA
	WB     B2Vec2  // support point in proxyB
	W      B2Vec2  // wB - wA
	A      float64 // barycentric coordinate for closest point
	IndexA int     // wA index
	IndexB int     // wB index
}

func MakeB2SimplexVertex

func MakeB2SimplexVertex() B2SimplexVertex

func NewB2SimplexVertex

func NewB2SimplexVertex() *B2SimplexVertex

type B2SolverData

type B2SolverData struct {
	Step       B2TimeStep
	Positions  []B2Position
	Velocities []B2Velocity
}

/ Solver Data

func MakeB2SolverData

func MakeB2SolverData() B2SolverData

type B2Sweep

type B2Sweep struct {
	LocalCenter B2Vec2  ///< local center of mass position
	C0, C       B2Vec2  ///< center world positions
	A0, A       float64 ///< world angles

	/// Fraction of the current time step in the range [0,1]
	/// c0 and a0 are the positions at alpha0.
	Alpha0 float64
}

func (*B2Sweep) Advance

func (sweep *B2Sweep) Advance(alpha float64)

func (B2Sweep) GetTransform

func (sweep B2Sweep) GetTransform(xf *B2Transform, beta float64)

func (*B2Sweep) Normalize

func (sweep *B2Sweep) Normalize()

/ Normalize an angle in radians to be between -pi and pi

type B2TOIInput

type B2TOIInput struct {
	ProxyA B2DistanceProxy
	ProxyB B2DistanceProxy
	SweepA B2Sweep
	SweepB B2Sweep
	TMax   float64 // defines sweep interval [0, tMax]
}

/ Input parameters for b2TimeOfImpact

func MakeB2TOIInput

func MakeB2TOIInput() B2TOIInput

type B2TOIOutput

type B2TOIOutput struct {
	State uint8
	T     float64
}

func MakeB2TOIOutput

func MakeB2TOIOutput() B2TOIOutput

type B2TempPolygon

type B2TempPolygon struct {
	Vertices [B2_maxPolygonVertices]B2Vec2
	Normals  [B2_maxPolygonVertices]B2Vec2
	Count    int
}

This holds polygon B expressed in frame A.

type B2TimeStep

type B2TimeStep struct {
	Dt                 float64 // time step
	Inv_dt             float64 // inverse time step (0 if dt == 0).
	DtRatio            float64 // dt * inv_dt0
	VelocityIterations int
	PositionIterations int
	WarmStarting       bool
}

/ This is an internal structure.

func MakeB2TimeStep

func MakeB2TimeStep() B2TimeStep

type B2Timer

type B2Timer struct {
	// contains filtered or unexported fields
}

/ Timer for profiling. This has platform specific code and may / not work on every platform.

func MakeB2Timer

func MakeB2Timer() B2Timer

func (B2Timer) GetMilliseconds

func (timer B2Timer) GetMilliseconds() float64

func (*B2Timer) Reset

func (timer *B2Timer) Reset()

type B2Transform

type B2Transform struct {
	P B2Vec2
	Q B2Rot
}

///////////////////////////////////////////////////////////////////////////// / A transform contains translation and rotation. It is used to represent / the position and orientation of rigid frames. /////////////////////////////////////////////////////////////////////////////

func B2TransformMul

func B2TransformMul(A, B B2Transform) B2Transform

func B2TransformMulT

func B2TransformMulT(A, B B2Transform) B2Transform

func MakeB2Transform

func MakeB2Transform() B2Transform

/ The default constructor does nothing.

func MakeB2TransformByPositionAndRotation

func MakeB2TransformByPositionAndRotation(position B2Vec2, rotation B2Rot) B2Transform

/ Initialize using a position vector and a rotation.

func NewB2Transform

func NewB2Transform() *B2Transform

func NewB2TransformByPositionAndRotation

func NewB2TransformByPositionAndRotation(position B2Vec2, rotation B2Rot) *B2Transform

func (*B2Transform) Set

func (t *B2Transform) Set(position B2Vec2, anglerad float64)

/ Set this based on the position and angle.

func (*B2Transform) SetIdentity

func (t *B2Transform) SetIdentity()

/ Set this to the identity transform.

type B2TreeNode

type B2TreeNode struct {

	/// Enlarged AABB
	Aabb B2AABB

	UserData interface{}

	// union
	// {
	Parent int
	Next   int

	Child1 int
	Child2 int

	// leaf = 0, free node = -1
	Height int
}

func (B2TreeNode) IsLeaf

func (node B2TreeNode) IsLeaf() bool

type B2TreeQueryCallback

type B2TreeQueryCallback func(nodeId int) bool

type B2TreeRayCastCallback

type B2TreeRayCastCallback func(input B2RayCastInput, nodeId int) float64

type B2Vec2

type B2Vec2 struct {
	X, Y float64
}

///////////////////////////////////////////////////////////////////////////// / A 2D column vector. /////////////////////////////////////////////////////////////////////////////

func B2RotVec2Mul

func B2RotVec2Mul(q B2Rot, v B2Vec2) B2Vec2

/ Rotate a vector

func B2RotVec2MulT

func B2RotVec2MulT(q B2Rot, v B2Vec2) B2Vec2

/ Inverse rotate a vector

func B2TransformVec2Mul

func B2TransformVec2Mul(T B2Transform, v B2Vec2) B2Vec2

func B2TransformVec2MulT

func B2TransformVec2MulT(T B2Transform, v B2Vec2) B2Vec2

func B2Vec2Abs

func B2Vec2Abs(a B2Vec2) B2Vec2

func B2Vec2Add

func B2Vec2Add(a, b B2Vec2) B2Vec2

/ Add two vectors component-wise.

func B2Vec2Clamp

func B2Vec2Clamp(a, low, high B2Vec2) B2Vec2

func B2Vec2CrossScalarVector

func B2Vec2CrossScalarVector(s float64, a B2Vec2) B2Vec2

/ Perform the cross product on a scalar and a vector. In 2D this produces / a vector.

func B2Vec2CrossVectorScalar

func B2Vec2CrossVectorScalar(a B2Vec2, s float64) B2Vec2

/ Perform the cross product on a vector and a scalar. In 2D this produces / a vector.

func B2Vec2Mat22Mul

func B2Vec2Mat22Mul(A B2Mat22, v B2Vec2) B2Vec2

/ Multiply a matrix times a vector. If a rotation matrix is provided, / then this transforms the vector from one frame to another.

func B2Vec2Mat22MulT

func B2Vec2Mat22MulT(A B2Mat22, v B2Vec2) B2Vec2

/ Multiply a matrix transpose times a vector. If a rotation matrix is provided, / then this transforms the vector from one frame to another (inverse transform).

func B2Vec2Max

func B2Vec2Max(a, b B2Vec2) B2Vec2

func B2Vec2Min

func B2Vec2Min(a, b B2Vec2) B2Vec2

func B2Vec2Mul22

func B2Vec2Mul22(A B2Mat33, v B2Vec2) B2Vec2

/ Multiply a matrix times a vector.

func B2Vec2MulScalar

func B2Vec2MulScalar(s float64, a B2Vec2) B2Vec2

func B2Vec2Sub

func B2Vec2Sub(a, b B2Vec2) B2Vec2

/// Subtract two vectors component-wise.

func ComputeCentroid

func ComputeCentroid(vs []B2Vec2, count int) B2Vec2

func MakeB2Vec2

func MakeB2Vec2(xIn, yIn float64) B2Vec2

func NewB2Vec2

func NewB2Vec2(xIn, yIn float64) *B2Vec2

/ Construct using coordinates.

func (B2Vec2) Clone

func (v B2Vec2) Clone() B2Vec2

func (B2Vec2) IsValid

func (v B2Vec2) IsValid() bool

/ Does this vector contain finite coordinates?

func (B2Vec2) Length

func (v B2Vec2) Length() float64

/ Get the length of this vector (the norm).

func (B2Vec2) LengthSquared

func (v B2Vec2) LengthSquared() float64

/ Get the length squared. For performance, use this instead of / b2Vec2::Length (if possible).

func (*B2Vec2) Normalize

func (v *B2Vec2) Normalize() float64

/ Convert this vector into a unit vector. Returns the length.

func (B2Vec2) OperatorIndexGet

func (v B2Vec2) OperatorIndexGet(i int) float64

/ Read from and indexed element.

func (*B2Vec2) OperatorIndexSet

func (v *B2Vec2) OperatorIndexSet(i int, value float64)

/ Write to an indexed element.

func (*B2Vec2) OperatorMinusInplace

func (v *B2Vec2) OperatorMinusInplace(other B2Vec2)

/ Subtract a vector from this vector.

func (B2Vec2) OperatorNegate

func (v B2Vec2) OperatorNegate() B2Vec2

/ Negate this vector.

func (*B2Vec2) OperatorPlusInplace

func (v *B2Vec2) OperatorPlusInplace(other B2Vec2)

/ Add a vector to this vector.

func (*B2Vec2) OperatorScalarMulInplace

func (v *B2Vec2) OperatorScalarMulInplace(a float64)

/ Multiply this vector by a scalar.

func (*B2Vec2) Set

func (v *B2Vec2) Set(x, y float64)

/ Set this vector to some specified coordinates.

func (*B2Vec2) SetZero

func (v *B2Vec2) SetZero()

/ Set this vector to all zeros.

func (B2Vec2) Skew

func (v B2Vec2) Skew() B2Vec2

/ Get the skew vector such that dot(skew_vec, other) == cross(vec, other)

type B2Vec3

type B2Vec3 struct {
	X, Y, Z float64
}

///////////////////////////////////////////////////////////////////////////// / A 2D column vector with 3 elements. /////////////////////////////////////////////////////////////////////////////

func B2Vec3Add

func B2Vec3Add(a, b B2Vec3) B2Vec3

/ Add two vectors component-wise.

func B2Vec3Cross

func B2Vec3Cross(a, b B2Vec3) B2Vec3

/ Perform the cross product on two vectors.

func B2Vec3Mat33Mul

func B2Vec3Mat33Mul(A B2Mat33, v B2Vec3) B2Vec3

/ Multiply a matrix times a vector.

func B2Vec3MultScalar

func B2Vec3MultScalar(s float64, a B2Vec3) B2Vec3

func B2Vec3Sub

func B2Vec3Sub(a, b B2Vec3) B2Vec3

/ Subtract two vectors component-wise.

func MakeB2Vec3

func MakeB2Vec3(xIn, yIn, zIn float64) B2Vec3

/ Construct using coordinates.

func NewB2Vec3

func NewB2Vec3(xIn, yIn, zIn float64) *B2Vec3

func (*B2Vec3) OperatorMinusInplace

func (v *B2Vec3) OperatorMinusInplace(other B2Vec3)

/ Subtract a vector from this vector.

func (B2Vec3) OperatorNegate

func (v B2Vec3) OperatorNegate() B2Vec3

/ Negate this vector.

func (*B2Vec3) OperatorPlusInplace

func (v *B2Vec3) OperatorPlusInplace(other B2Vec3)

/ Add a vector to this vector.

func (*B2Vec3) OperatorScalarMultInplace

func (v *B2Vec3) OperatorScalarMultInplace(a float64)

/ Multiply this vector by a scalar.

func (*B2Vec3) Set

func (v *B2Vec3) Set(x, y, z float64)

/ Set this vector to some specified coordinates.

func (*B2Vec3) SetZero

func (v *B2Vec3) SetZero()

/ Set this vector to all zeros.

type B2Velocity

type B2Velocity struct {
	V B2Vec2
	W float64
}

/ This is an internal structure.

type B2VelocityConstraintPoint

type B2VelocityConstraintPoint struct {
	RA             B2Vec2
	RB             B2Vec2
	NormalImpulse  float64
	TangentImpulse float64
	NormalMass     float64
	TangentMass    float64
	VelocityBias   float64
}

type B2WeldJoint

type B2WeldJoint struct {
	*B2Joint

	M_frequencyHz  float64
	M_dampingRatio float64
	M_bias         float64

	// Solver shared
	M_localAnchorA   B2Vec2
	M_localAnchorB   B2Vec2
	M_referenceAngle float64
	M_gamma          float64
	M_impulse        B2Vec3

	// Solver temp
	M_indexA       int
	M_indexB       int
	M_rA           B2Vec2
	M_rB           B2Vec2
	M_localCenterA B2Vec2
	M_localCenterB B2Vec2
	M_invMassA     float64
	M_invMassB     float64
	M_invIA        float64
	M_invIB        float64
	M_mass         B2Mat33
}

/ A weld joint essentially glues two bodies together. A weld joint may / distort somewhat because the island constraint solver is approximate.

func MakeB2WeldJoint

func MakeB2WeldJoint(def *B2WeldJointDef) *B2WeldJoint

func (*B2WeldJoint) Dump

func (joint *B2WeldJoint) Dump()

func (B2WeldJoint) GetAnchorA

func (joint B2WeldJoint) GetAnchorA() B2Vec2

func (B2WeldJoint) GetAnchorB

func (joint B2WeldJoint) GetAnchorB() B2Vec2

func (B2WeldJoint) GetDampingRatio

func (joint B2WeldJoint) GetDampingRatio() float64

func (B2WeldJoint) GetFrequency

func (joint B2WeldJoint) GetFrequency() float64

func (B2WeldJoint) GetLocalAnchorA

func (joint B2WeldJoint) GetLocalAnchorA() B2Vec2

/ The local anchor point relative to bodyA's origin.

func (B2WeldJoint) GetLocalAnchorB

func (joint B2WeldJoint) GetLocalAnchorB() B2Vec2

/ The local anchor point relative to bodyB's origin.

func (B2WeldJoint) GetReactionForce

func (joint B2WeldJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2WeldJoint) GetReactionTorque

func (joint B2WeldJoint) GetReactionTorque(inv_dt float64) float64

func (B2WeldJoint) GetReferenceAngle

func (joint B2WeldJoint) GetReferenceAngle() float64

/ Get the reference angle.

func (*B2WeldJoint) InitVelocityConstraints

func (joint *B2WeldJoint) InitVelocityConstraints(data B2SolverData)

func (*B2WeldJoint) SetDampingRatio

func (joint *B2WeldJoint) SetDampingRatio(ratio float64)

/ Set/get damping ratio.

func (*B2WeldJoint) SetFrequency

func (joint *B2WeldJoint) SetFrequency(hz float64)

/ Set/get frequency in Hz.

func (*B2WeldJoint) SolvePositionConstraints

func (joint *B2WeldJoint) SolvePositionConstraints(data B2SolverData) bool

func (*B2WeldJoint) SolveVelocityConstraints

func (joint *B2WeldJoint) SolveVelocityConstraints(data B2SolverData)

type B2WeldJointDef

type B2WeldJointDef struct {
	B2JointDef

	/// The local anchor point relative to bodyA's origin.
	LocalAnchorA B2Vec2

	/// The local anchor point relative to bodyB's origin.
	LocalAnchorB B2Vec2

	/// The bodyB angle minus bodyA angle in the reference state (radians).
	ReferenceAngle float64

	/// The mass-spring-damper frequency in Hertz. Rotation only.
	/// Disable softness with a value of 0.
	FrequencyHz float64

	/// The damping ratio. 0 = no damping, 1 = critical damping.
	DampingRatio float64
}

/ Weld joint definition. You need to specify local anchor points / where they are attached and the relative body angle. The position / of the anchor points is important for computing the reaction torque.

func MakeB2WeldJointDef

func MakeB2WeldJointDef() B2WeldJointDef

func (*B2WeldJointDef) Initialize

func (def *B2WeldJointDef) Initialize(bA *B2Body, bB *B2Body, anchor B2Vec2)

type B2WheelJoint

type B2WheelJoint struct {
	*B2Joint

	M_frequencyHz  float64
	M_dampingRatio float64

	// Solver shared
	M_localAnchorA B2Vec2
	M_localAnchorB B2Vec2
	M_localXAxisA  B2Vec2
	M_localYAxisA  B2Vec2

	M_impulse       float64
	M_motorImpulse  float64
	M_springImpulse float64

	M_maxMotorTorque float64
	M_motorSpeed     float64
	M_enableMotor    bool

	// Solver temp
	M_indexA       int
	M_indexB       int
	M_localCenterA B2Vec2
	M_localCenterB B2Vec2
	M_invMassA     float64
	M_invMassB     float64
	M_invIA        float64
	M_invIB        float64

	M_ax  B2Vec2
	M_ay  B2Vec2
	M_sAx float64
	M_sBx float64
	M_sAy float64
	M_sBy float64

	M_mass       float64
	M_motorMass  float64
	M_springMass float64

	M_bias  float64
	M_gamma float64
}

/ A wheel joint. This joint provides two degrees of freedom: translation / along an axis fixed in bodyA and rotation in the plane. In other words, it is a point to / line constraint with a rotational motor and a linear spring/damper. / This joint is designed for vehicle suspensions.

func MakeB2WheelJoint

func MakeB2WheelJoint(def *B2WheelJointDef) *B2WheelJoint

func (*B2WheelJoint) Dump

func (joint *B2WheelJoint) Dump()

func (*B2WheelJoint) EnableMotor

func (joint *B2WheelJoint) EnableMotor(flag bool)

func (B2WheelJoint) GetAnchorA

func (joint B2WheelJoint) GetAnchorA() B2Vec2

func (B2WheelJoint) GetAnchorB

func (joint B2WheelJoint) GetAnchorB() B2Vec2

func (B2WheelJoint) GetJointAngle

func (joint B2WheelJoint) GetJointAngle() float64

func (B2WheelJoint) GetJointAngularSpeed

func (joint B2WheelJoint) GetJointAngularSpeed() float64

func (B2WheelJoint) GetJointLinearSpeed

func (joint B2WheelJoint) GetJointLinearSpeed() float64

func (B2WheelJoint) GetJointTranslation

func (joint B2WheelJoint) GetJointTranslation() float64

func (B2WheelJoint) GetLocalAnchorA

func (joint B2WheelJoint) GetLocalAnchorA() B2Vec2

/ The local anchor point relative to bodyA's origin.

func (B2WheelJoint) GetLocalAnchorB

func (joint B2WheelJoint) GetLocalAnchorB() B2Vec2

/ The local anchor point relative to bodyB's origin.

func (B2WheelJoint) GetLocalAxisA

func (joint B2WheelJoint) GetLocalAxisA() B2Vec2

/ The local joint axis relative to bodyA.

func (B2WheelJoint) GetMaxMotorTorque

func (joint B2WheelJoint) GetMaxMotorTorque() float64

func (B2WheelJoint) GetMotorSpeed

func (joint B2WheelJoint) GetMotorSpeed() float64

func (B2WheelJoint) GetMotorTorque

func (joint B2WheelJoint) GetMotorTorque(inv_dt float64) float64

func (B2WheelJoint) GetReactionForce

func (joint B2WheelJoint) GetReactionForce(inv_dt float64) B2Vec2

func (B2WheelJoint) GetReactionTorque

func (joint B2WheelJoint) GetReactionTorque(inv_dt float64) float64

func (B2WheelJoint) GetSpringDampingRatio

func (joint B2WheelJoint) GetSpringDampingRatio() float64

func (B2WheelJoint) GetSpringFrequencyHz

func (joint B2WheelJoint) GetSpringFrequencyHz() float64

func (*B2WheelJoint) InitVelocityConstraints

func (joint *B2WheelJoint) InitVelocityConstraints(data B2SolverData)

func (B2WheelJoint) IsMotorEnabled

func (joint B2WheelJoint) IsMotorEnabled() bool

func (*B2WheelJoint) SetMaxMotorTorque

func (joint *B2WheelJoint) SetMaxMotorTorque(torque float64)

func (*B2WheelJoint) SetMotorSpeed

func (joint *B2WheelJoint) SetMotorSpeed(speed float64)

func (*B2WheelJoint) SetSpringDampingRatio

func (joint *B2WheelJoint) SetSpringDampingRatio(ratio float64)

func (*B2WheelJoint) SetSpringFrequencyHz

func (joint *B2WheelJoint) SetSpringFrequencyHz(hz float64)

func (*B2WheelJoint) SolvePositionConstraints

func (joint *B2WheelJoint) SolvePositionConstraints(data B2SolverData) bool

func (*B2WheelJoint) SolveVelocityConstraints

func (joint *B2WheelJoint) SolveVelocityConstraints(data B2SolverData)

type B2WheelJointDef

type B2WheelJointDef struct {
	B2JointDef

	/// The local anchor point relative to bodyA's origin.
	LocalAnchorA B2Vec2

	/// The local anchor point relative to bodyB's origin.
	LocalAnchorB B2Vec2

	/// The local translation axis in bodyA.
	LocalAxisA B2Vec2

	/// Enable/disable the joint motor.
	EnableMotor bool

	/// The maximum motor torque, usually in N-m.
	MaxMotorTorque float64

	/// The desired motor speed in radians per second.
	MotorSpeed float64

	/// Suspension frequency, zero indicates no suspension
	FrequencyHz float64

	/// Suspension damping ratio, one indicates critical damping
	DampingRatio float64
}

/ Wheel joint definition. This requires defining a line of / motion using an axis and an anchor point. The definition uses local / anchor points and a local axis so that the initial configuration / can violate the constraint slightly. The joint translation is zero / when the local anchor points coincide in world space. Using local / anchors and a local axis helps when saving and loading a game.

func MakeB2WheelJointDef

func MakeB2WheelJointDef() B2WheelJointDef

func (*B2WheelJointDef) Initialize

func (def *B2WheelJointDef) Initialize(bA *B2Body, bB *B2Body, anchor B2Vec2, axis B2Vec2)

type B2World

type B2World struct {
	M_flags int

	M_contactManager B2ContactManager

	M_bodyList  *B2Body          // linked list
	M_jointList B2JointInterface // has to be backed by pointer

	M_bodyCount  int
	M_jointCount int

	M_gravity    B2Vec2
	M_allowSleep bool

	M_destructionListener B2DestructionListenerInterface

	// This is used to compute the time step ratio to
	// support a variable time step.
	M_inv_dt0 float64

	// These are for debugging the solver.
	M_warmStarting      bool
	M_continuousPhysics bool
	M_subStepping       bool

	M_stepComplete bool

	M_profile B2Profile
}

/// The world class manages all physics entities, dynamic simulation, /// and asynchronous queries. The world also contains efficient memory /// management facilities.

func MakeB2World

func MakeB2World(gravity B2Vec2) B2World

func (*B2World) ClearForces

func (world *B2World) ClearForces()

func (*B2World) CreateBody

func (world *B2World) CreateBody(def *B2BodyDef) *B2Body

func (*B2World) CreateJoint

func (world *B2World) CreateJoint(def B2JointDefInterface) B2JointInterface

func (*B2World) Destroy

func (world *B2World) Destroy()

func (*B2World) DestroyBody

func (world *B2World) DestroyBody(b *B2Body)

func (*B2World) DestroyJoint

func (world *B2World) DestroyJoint(j B2JointInterface)

func (*B2World) Dump

func (world *B2World) Dump()

func (B2World) GetAutoClearForces

func (world B2World) GetAutoClearForces() bool

/ Get the flag that controls automatic clearing of forces after each time step.

func (B2World) GetBodyCount

func (world B2World) GetBodyCount() int

func (B2World) GetBodyList

func (world B2World) GetBodyList() *B2Body

func (B2World) GetContactCount

func (world B2World) GetContactCount() int

func (B2World) GetContactList

func (world B2World) GetContactList() B2ContactInterface

func (B2World) GetContactManager

func (world B2World) GetContactManager() B2ContactManager

func (B2World) GetGravity

func (world B2World) GetGravity() B2Vec2

func (B2World) GetJointCount

func (world B2World) GetJointCount() int

func (B2World) GetJointList

func (world B2World) GetJointList() B2JointInterface

func (B2World) GetProfile

func (world B2World) GetProfile() B2Profile

func (B2World) GetProxyCount

func (world B2World) GetProxyCount() int

func (B2World) GetTreeBalance

func (world B2World) GetTreeBalance() int

func (B2World) GetTreeHeight

func (world B2World) GetTreeHeight() int

func (B2World) GetTreeQuality

func (world B2World) GetTreeQuality() float64

func (B2World) IsLocked

func (world B2World) IsLocked() bool

func (*B2World) QueryAABB

func (world *B2World) QueryAABB(callback B2BroadPhaseQueryCallback, aabb B2AABB)

func (*B2World) RayCast

func (world *B2World) RayCast(callback B2RaycastCallback, point1 B2Vec2, point2 B2Vec2)

func (*B2World) SetAllowSleeping

func (world *B2World) SetAllowSleeping(flag bool)

func (*B2World) SetAutoClearForces

func (world *B2World) SetAutoClearForces(flag bool)

func (*B2World) SetContactFilter

func (world *B2World) SetContactFilter(filter B2ContactFilterInterface)

func (*B2World) SetContactListener

func (world *B2World) SetContactListener(listener B2ContactListenerInterface)

func (*B2World) SetDestructionListener

func (world *B2World) SetDestructionListener(listener B2DestructionListenerInterface)

func (*B2World) SetGravity

func (world *B2World) SetGravity(gravity B2Vec2)

func (*B2World) ShiftOrigin

func (world *B2World) ShiftOrigin(newOrigin B2Vec2)

func (*B2World) Solve

func (world *B2World) Solve(step B2TimeStep)

Find islands, integrate and solve constraints, solve position constraints

func (*B2World) SolveTOI

func (world *B2World) SolveTOI(step B2TimeStep)

Find TOI contacts and solve them.

func (*B2World) Step

func (world *B2World) Step(dt float64, velocityIterations int, positionIterations int)

type B2WorldManifold

type B2WorldManifold struct {
	Normal      B2Vec2                        ///< world vector pointing from A to B
	Points      [B2_maxManifoldPoints]B2Vec2  ///< world contact point (point of intersection)
	Separations [B2_maxManifoldPoints]float64 ///< a negative value indicates overlap, in meters
}

/ This is used to compute the current state of a contact manifold.

func MakeB2WorldManifold

func MakeB2WorldManifold() B2WorldManifold

func (*B2WorldManifold) Initialize

func (wm *B2WorldManifold) Initialize(manifold *B2Manifold, xfA B2Transform, radiusA float64, xfB B2Transform, radiusB float64)

type B2WorldQueryWrapper

type B2WorldQueryWrapper struct {
	BroadPhase *B2BroadPhase
	Callback   B2BroadPhaseQueryCallback
}

func MakeB2WorldQueryWrapper

func MakeB2WorldQueryWrapper() B2WorldQueryWrapper

func (*B2WorldQueryWrapper) QueryCallback

func (query *B2WorldQueryWrapper) QueryCallback(proxyId int) bool

type PairByLessThan

type PairByLessThan []B2Pair

func (PairByLessThan) Len

func (a PairByLessThan) Len() int

func (PairByLessThan) Less

func (a PairByLessThan) Less(i, j int) bool

func (PairByLessThan) Swap

func (a PairByLessThan) Swap(i, j int)

type StackElement

type StackElement struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL