physics

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FilterAll = Filter{Categories: math.MaxUint64, Mask: math.MaxUint64}

Functions

func StepSystem2D

func StepSystem2D(name string) ecs.SystemConfig

func StepSystem3D

func StepSystem3D(name string) ecs.SystemConfig

func TaskCount2D

func TaskCount2D(world *ecs.World) int

TaskCount2D includes active ECS simulation bodies, manually created bodies, and pending synchronization. Idle requires all external inputs to be consumed.

func TaskCount3D

func TaskCount3D(world *ecs.World) int

TaskCount3D includes non-static bodies and pending synchronization, including removal or deactivation of the last managed body.

func ValidateBodyTransform

func ValidateBodyTransform(matrix mgl32.Mat4, planar bool) error

ValidateBodyTransform rejects transforms the rigid-body solvers cannot represent. Shape dimensions are authored in world units; scaling, reflection and shear must be baked into the collision resource instead.

Types

type Body

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

func (Body) AngularVelocity

func (body Body) AngularVelocity() float64

func (Body) ApplyForce

func (body Body) ApplyForce(force Vector)

func (Body) ApplyImpulse

func (body Body) ApplyImpulse(impulse, worldPoint Vector)

func (Body) ApplyTorque

func (body Body) ApplyTorque(torque float64)

func (Body) ClearForces

func (body Body) ClearForces()

func (Body) ID

func (body Body) ID() BodyID

func (Body) IsSleeping

func (body Body) IsSleeping() bool

IsSleeping reports whether the optional contact-island sleep policy suspended this body.

func (Body) Position

func (body Body) Position() Vector

func (Body) Rotation

func (body Body) Rotation() float64

func (Body) SetAngularVelocity

func (body Body) SetAngularVelocity(value float64)

func (Body) SetGravityScale

func (body Body) SetGravityScale(value float64)

func (Body) SetPosition

func (body Body) SetPosition(value Vector)

func (Body) SetRotation

func (body Body) SetRotation(value float64)

func (Body) SetType

func (body Body) SetType(value BodyType)

func (Body) SetVelocity

func (body Body) SetVelocity(value Vector)

func (Body) Type

func (body Body) Type() BodyType

func (Body) UserData

func (body Body) UserData() uint64

func (Body) Valid

func (body Body) Valid() bool

func (Body) Velocity

func (body Body) Velocity() Vector

func (Body) Wake

func (body Body) Wake()

Wake immediately wakes this body's contact island. A changed support wakes its neighbours, without joining separate islands across static supports. Repeated requests share the traversal until the next physics step.

type Body3D

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

func (Body3D) AngularVelocity

func (body Body3D) AngularVelocity() Vector3D

func (Body3D) ApplyForce

func (body Body3D) ApplyForce(force Vector3D)

func (Body3D) ApplyImpulse

func (body Body3D) ApplyImpulse(impulse, worldPoint Vector3D)

func (Body3D) ApplyTorque

func (body Body3D) ApplyTorque(torque Vector3D)

func (Body3D) ClearForces

func (body Body3D) ClearForces()

func (Body3D) ID

func (body Body3D) ID() BodyID3D

func (Body3D) Position

func (body Body3D) Position() Vector3D

func (Body3D) Rotation

func (body Body3D) Rotation() Quaternion

func (Body3D) SetAngularVelocity

func (body Body3D) SetAngularVelocity(value Vector3D)

func (Body3D) SetGravityScale

func (body Body3D) SetGravityScale(value float64)

func (Body3D) SetPosition

func (body Body3D) SetPosition(value Vector3D)

func (Body3D) SetRotation

func (body Body3D) SetRotation(value Quaternion)

func (Body3D) SetType

func (body Body3D) SetType(value BodyType)

func (Body3D) SetVelocity

func (body Body3D) SetVelocity(value Vector3D)

func (Body3D) Type

func (body Body3D) Type() BodyType

func (Body3D) UserData

func (body Body3D) UserData() uint64

func (Body3D) Valid

func (body Body3D) Valid() bool

func (Body3D) Velocity

func (body Body3D) Velocity() Vector3D

type BodyDef

type BodyDef struct {
	Velocity        Vector
	Position        Vector
	Inertia         float64
	Rotation        float64
	AngularVelocity float64
	Mass            float64
	GravityScale    float64
	LinearDamping   float64
	AngularDamping  float64
	UserData        uint64
	Type            BodyType
	FixedRotation   bool
	// contains filtered or unexported fields
}

func NewBodyDef

func NewBodyDef(bodyType BodyType) BodyDef

type BodyDef3D

type BodyDef3D struct {
	Rotation        Quaternion
	AngularVelocity Vector3D
	Position        Vector3D
	Velocity        Vector3D
	Inertia         float64
	Mass            float64
	GravityScale    float64
	LinearDamping   float64
	AngularDamping  float64
	UserData        uint64
	Type            BodyType
	FixedRotation   bool
	// contains filtered or unexported fields
}

func NewBodyDef3D

func NewBodyDef3D(bodyType BodyType) BodyDef3D

type BodyID

type BodyID uint64

type BodyID3D

type BodyID3D uint64

type BodyType

type BodyType uint8
const (
	BodyDynamic BodyType = iota
	BodyStatic
	BodyKinematic
)

type Bounds3D

type Bounds3D struct {
	Min Vector3D
	Max Vector3D
}

Bounds3D is an axis-aligned box used by cooked collision resources. Bounds are expressed in the resource's local space.

func (Bounds3D) Center

func (bounds Bounds3D) Center() Vector3D

func (Bounds3D) Size

func (bounds Bounds3D) Size() Vector3D

func (Bounds3D) Valid

func (bounds Bounds3D) Valid() bool

type Box

type Box struct {
	Center      Vector
	HalfExtents Vector
	Rotation    float64
}

func NewBox

func NewBox(width, height float64) Box

type Box3D

type Box3D struct {
	Center      Vector3D
	HalfExtents Vector3D
	Rotation    Quaternion
}

func NewBox3D

func NewBox3D(width, height, depth float64) Box3D

type BoxCollider2D

type BoxCollider2D = Collider2D[Box]

type BoxCollider3D

type BoxCollider3D = Collider3D[Box3D]

type Capsule

type Capsule struct {
	Center     Vector3D
	Rotation   Quaternion
	HalfHeight float64
	Radius     float64
}

Capsule is aligned to its local Y axis. HalfHeight excludes the round caps.

func NewCapsule

func NewCapsule(height, radius float64) Capsule

type CapsuleCollider3D

type CapsuleCollider3D = Collider3D[Capsule]

type Circle

type Circle struct {
	Center Vector
	Radius float64
}

type CircleCollider2D

type CircleCollider2D = Collider2D[Circle]

type Collider2D

type Collider2D[S Shape2D] struct {
	Shape S

	Filter        Filter
	Friction      float64
	Restitution   float64
	CollisionType uint32
	Sensor        bool
	// contains filtered or unexported fields
}

func NewCollider2D

func NewCollider2D[S Shape2D](shape S) Collider2D[S]

func (*Collider2D[S]) Handle

func (collider *Collider2D[S]) Handle() ColliderHandle[S]

type Collider3D

type Collider3D[S Shape3D] struct {
	Shape S

	Filter        Filter
	Friction      float64
	Restitution   float64
	CollisionType uint32
	Sensor        bool
	// contains filtered or unexported fields
}

func NewCollider3D

func NewCollider3D[S Shape3D](shape S) Collider3D[S]

func (*Collider3D[S]) Handle

func (collider *Collider3D[S]) Handle() ColliderHandle3D[S]

type ColliderDef

type ColliderDef[S Shape] struct {
	Shape         S
	Filter        Filter
	Friction      float64
	Restitution   float64
	CollisionType uint32
	Sensor        bool
}

func NewColliderDef

func NewColliderDef[S Shape](shape S) ColliderDef[S]

type ColliderHandle

type ColliderHandle[S Shape2D] struct {
	// contains filtered or unexported fields
}

func (ColliderHandle[S]) CollisionType

func (collider ColliderHandle[S]) CollisionType() uint32

func (ColliderHandle[S]) Filter

func (collider ColliderHandle[S]) Filter() Filter

func (ColliderHandle[S]) ID

func (collider ColliderHandle[S]) ID() ColliderID

func (ColliderHandle[S]) Sensor

func (collider ColliderHandle[S]) Sensor() bool

func (ColliderHandle[S]) SetCollisionType

func (collider ColliderHandle[S]) SetCollisionType(value uint32)

func (ColliderHandle[S]) SetFilter

func (collider ColliderHandle[S]) SetFilter(value Filter)

func (ColliderHandle[S]) SetMaterial

func (collider ColliderHandle[S]) SetMaterial(friction, restitution float64)

func (ColliderHandle[S]) SetSensor

func (collider ColliderHandle[S]) SetSensor(value bool)

func (ColliderHandle[S]) SetShape

func (collider ColliderHandle[S]) SetShape(shape S)

func (ColliderHandle[S]) Shape

func (collider ColliderHandle[S]) Shape() S

func (ColliderHandle[S]) Valid

func (collider ColliderHandle[S]) Valid() bool

type ColliderHandle3D

type ColliderHandle3D[S Shape3D] struct {
	// contains filtered or unexported fields
}

func (ColliderHandle3D[S]) CollisionType

func (collider ColliderHandle3D[S]) CollisionType() uint32

func (ColliderHandle3D[S]) Filter

func (collider ColliderHandle3D[S]) Filter() Filter

func (ColliderHandle3D[S]) ID

func (collider ColliderHandle3D[S]) ID() ColliderID3D

func (ColliderHandle3D[S]) Sensor

func (collider ColliderHandle3D[S]) Sensor() bool

func (ColliderHandle3D[S]) SetCollisionType

func (collider ColliderHandle3D[S]) SetCollisionType(value uint32)

func (ColliderHandle3D[S]) SetFilter

func (collider ColliderHandle3D[S]) SetFilter(value Filter)

func (ColliderHandle3D[S]) SetMaterial

func (collider ColliderHandle3D[S]) SetMaterial(friction, restitution float64)

func (ColliderHandle3D[S]) SetSensor

func (collider ColliderHandle3D[S]) SetSensor(value bool)

func (ColliderHandle3D[S]) SetShape

func (collider ColliderHandle3D[S]) SetShape(shape S)

func (ColliderHandle3D[S]) Shape

func (collider ColliderHandle3D[S]) Shape() S

func (ColliderHandle3D[S]) Valid

func (collider ColliderHandle3D[S]) Valid() bool

type ColliderID

type ColliderID uint64

type ColliderID3D

type ColliderID3D uint64

type CollisionEvent

type CollisionEvent struct {
	Phase          CollisionPhase
	BodyA          BodyID
	BodyB          BodyID
	ColliderA      ColliderID
	ColliderB      ColliderID
	CollisionTypeA uint32
	CollisionTypeB uint32
	UserDataA      uint64
	UserDataB      uint64
	Normal         Vector
	Point          Vector
	Penetration    float64
}

type CollisionEvent3D

type CollisionEvent3D struct {
	Phase          CollisionPhase
	BodyA          BodyID3D
	BodyB          BodyID3D
	ColliderA      ColliderID3D
	ColliderB      ColliderID3D
	CollisionTypeA uint32
	CollisionTypeB uint32
	UserDataA      uint64
	UserDataB      uint64
	Normal         Vector3D
	Point          Vector3D
	Penetration    float64
}

type CollisionMessage2D

type CollisionMessage2D struct {
	Phase         CollisionPhase
	Entity        ecs.Entity
	Other         ecs.Entity
	Collider      ColliderID
	OtherCollider ColliderID
	CollisionType uint32
	OtherType     uint32
	Normal        Vector
	Point         Vector
	Penetration   float64
}

type CollisionMessage3D

type CollisionMessage3D struct {
	Phase         CollisionPhase
	Entity        ecs.Entity
	Other         ecs.Entity
	Collider      ColliderID3D
	OtherCollider ColliderID3D
	CollisionType uint32
	OtherType     uint32
	Normal        Vector3D
	Point         Vector3D
	Penetration   float64
}

type CollisionMode

type CollisionMode string

CollisionMode selects the shape produced by model import baking.

const (
	CollisionModeTriangleMesh        CollisionMode = "trimesh"
	CollisionModeSingleConvex        CollisionMode = "singleConvex"
	CollisionModeConvexDecomposition CollisionMode = "convexDecomposition"
)

func ParseCollisionMode

func ParseCollisionMode(value string) (CollisionMode, error)

func (CollisionMode) String

func (mode CollisionMode) String() string

type CollisionPhase

type CollisionPhase uint8
const (
	CollisionBegin CollisionPhase = iota
	CollisionStay
	CollisionEnd
)

type Compound

type Compound struct {
	Children []CompoundChild
	Bounds   Bounds3D
}

Compound is an immutable collection of convex hulls for dynamic concave models. Children are never decomposed or allocated during simulation.

func ConvexDecomposition

func ConvexDecomposition(pieces []ConvexHull) (Compound, error)

ConvexDecomposition creates the runtime compound from importer-produced convex pieces. CoACD/V-HACD integration belongs to the asset pipeline; this API keeps the runtime format independent of whichever offline tool produced the pieces.

func NewCompound

func NewCompound(children []CompoundChild) (Compound, error)

func NewCompoundFromHulls

func NewCompoundFromHulls(pieces []ConvexHull) (Compound, error)

func (Compound) ChildCount

func (compound Compound) ChildCount() int

func (Compound) Cooked

func (compound Compound) Cooked() bool

type CompoundChild

type CompoundChild struct {
	Shape    ConvexHull
	Position Vector3D
	Rotation Quaternion
}

CompoundChild is a locally transformed, already-cooked convex hull.

type CompoundCollider3D

type CompoundCollider3D = Collider3D[Compound]

type ConvexFace

type ConvexFace struct {
	Indices [3]uint32
	Normal  Vector3D
}

ConvexFace is one outward-oriented triangle of a cooked convex hull.

type ConvexHull

type ConvexHull struct {
	Vertices []Vector3D
	Faces    []ConvexFace
	Edges    [][2]uint32
	Bounds   Bounds3D
}

ConvexHull is an immutable convex collision resource. It contains the original support vertices and the baked surface faces used for contacts.

func NewConvexHull

func NewConvexHull(vertices []Vector3D) (ConvexHull, error)

NewConvexHull builds a convex hull during asset baking with an incremental QuickHull pass. The expensive visibility and horizon work stays out of the simulation and scales quadratically for typical imported meshes.

func QuickHull

func QuickHull(vertices []Vector3D) (ConvexHull, error)

QuickHull is the importer-facing name for convex hull cooking.

func (ConvexHull) Cooked

func (hull ConvexHull) Cooked() bool

func (ConvexHull) FaceCount

func (hull ConvexHull) FaceCount() int

func (ConvexHull) VertexCount

func (hull ConvexHull) VertexCount() int

type ConvexHullCollider3D

type ConvexHullCollider3D = Collider3D[ConvexHull]

type CookedCollision

type CookedCollision struct {
	Mode         CollisionMode
	TriangleMesh TriangleMesh
	ConvexHull   ConvexHull
	Compound     Compound
}

CookedCollision keeps all mode-specific outputs in one immutable resource. Only the selected field is populated by CookCollision.

func CookCollision

func CookCollision(vertices []Vector3D, indices []uint32, mode CollisionMode) (CookedCollision, error)

CookCollision performs the importer-side cooking step. Convex decomposition accepts a single convex fallback here; asset importers that use CoACD should pass all generated pieces to ConvexDecomposition and store the resulting Compound directly.

type Filter

type Filter struct {
	Group      int32
	Categories uint64
	Mask       uint64
}

func NewFilter

func NewFilter(group int32, categories, mask uint64) Filter

func (Filter) Reject

func (filter Filter) Reject(other Filter) bool

type MeshRayHit

type MeshRayHit struct {
	Distance      float64
	Point, Normal Vector3D
	Triangle      uint32
}

MeshRayHit is a hit in the triangle mesh's local coordinate system.

type Quaternion

type Quaternion struct {
	X float64
	Y float64
	Z float64
	W float64
}

Quaternion stores an orientation as an (x, y, z, w) unit quaternion.

func Q

func Q(x, y, z, w float64) Quaternion

func QuaternionFromAxisAngle

func QuaternionFromAxisAngle(axis Vector3D, angle float64) Quaternion

func QuaternionIdentity

func QuaternionIdentity() Quaternion

func (Quaternion) Conjugate

func (q Quaternion) Conjugate() Quaternion

func (Quaternion) Mul

func (q Quaternion) Mul(other Quaternion) Quaternion

func (Quaternion) Normalize

func (q Quaternion) Normalize() Quaternion

func (Quaternion) Rotate

func (q Quaternion) Rotate(vector Vector3D) Vector3D

type RigidBody2D

type RigidBody2D struct {
	Force    Vector
	Velocity Vector

	Impulse         Vector
	AngularDamping  float64
	AngularVelocity float64
	Inertia         float64
	LinearDamping   float64
	Torque          float64
	Mass            float64
	GravityScale    float64

	Type          BodyType
	FixedRotation bool
	// contains filtered or unexported fields
}

RigidBody2D turns a world-space scene node into a simulated body. Dynamic bodies write their pose back to Transform; static and kinematic bodies read their pose from Transform before each fixed step.

func NewRigidBody2D

func NewRigidBody2D(bodyType BodyType) RigidBody2D

func (*RigidBody2D) ApplyForce

func (body *RigidBody2D) ApplyForce(force Vector)

func (*RigidBody2D) ApplyImpulse

func (body *RigidBody2D) ApplyImpulse(impulse Vector)

func (*RigidBody2D) ApplyTorque

func (body *RigidBody2D) ApplyTorque(torque float64)

func (*RigidBody2D) Handle

func (body *RigidBody2D) Handle() Body

type RigidBody3D

type RigidBody3D struct {
	Force  Vector3D
	Torque Vector3D

	Impulse         Vector3D
	Velocity        Vector3D
	AngularVelocity Vector3D
	GravityScale    float64
	AngularDamping  float64
	Inertia         float64
	LinearDamping   float64
	Mass            float64
	Type            BodyType
	FixedRotation   bool
	// contains filtered or unexported fields
}

RigidBody3D binds a world-space transform to a simulated body.

func NewRigidBody3D

func NewRigidBody3D(bodyType BodyType) RigidBody3D

func (*RigidBody3D) ApplyForce

func (body *RigidBody3D) ApplyForce(force Vector3D)

func (*RigidBody3D) ApplyImpulse

func (body *RigidBody3D) ApplyImpulse(impulse Vector3D)

func (*RigidBody3D) ApplyTorque

func (body *RigidBody3D) ApplyTorque(torque Vector3D)

func (*RigidBody3D) Handle

func (body *RigidBody3D) Handle() Body3D

type Runtime2D

type Runtime2D struct {
	Simulation *World
	// contains filtered or unexported fields
}

func NewRuntime2D

func NewRuntime2D() *Runtime2D

type Runtime3D

type Runtime3D struct {
	Simulation *World3D
	// contains filtered or unexported fields
}

func NewRuntime3D

func NewRuntime3D() *Runtime3D

type Segment

type Segment struct {
	Start  Vector
	End    Vector
	Radius float64
}

type SegmentCollider2D

type SegmentCollider2D = Collider2D[Segment]

type Shape

type Shape interface {
	// contains filtered or unexported methods
}

Shape is closed to this package so every generic collider can be lowered to an allocation-free internal representation.

type Shape2D

type Shape2D interface {
	Shape
	// contains filtered or unexported methods
}

Shape2D accepts shapes supported by the 2D solver.

type Shape3D

type Shape3D interface {
	Shape
	// contains filtered or unexported methods
}

Shape3D is closed so generic colliders lower to an allocation-free internal value.

type SleepConfig

type SleepConfig struct {
	Enabled                                          bool
	LinearThreshold, AngularThreshold, TimeThreshold float64
}

SleepConfig enables whole contact-island sleeping. The zero value disables sleeping; nonpositive thresholds use the defaults below (world units/second, radians/second, and seconds respectively).

type Sphere

type Sphere struct {
	Center Vector3D
	Radius float64
}

type SphereCollider3D

type SphereCollider3D = Collider3D[Sphere]

type StepStatistics

type StepStatistics struct {
	BoundsUpdates, IndexUpdates, PairQueries, ContactBuilds int
	SleepingBodies                                          int
}

StepStatistics reports work performed by the last Step, without allocating.

type TriangleMesh

type TriangleMesh struct {
	Vertices        []Vector3D
	Indices         []uint32
	TriangleIndices []uint32
	BVH             []TriangleMeshNode
	Bounds          Bounds3D
}

TriangleMesh is an immutable, cooked static collision resource. The slices are owned by the value returned from NewTriangleMesh and must not be edited after construction.

func CookTriangleMesh

func CookTriangleMesh(vertices []Vector3D, indices []uint32) (TriangleMesh, error)

CookTriangleMesh is an explicit name for callers that keep authored mesh data separate from its immutable runtime representation.

func NewTriangleMesh

func NewTriangleMesh(vertices []Vector3D, indices []uint32) (TriangleMesh, error)

NewTriangleMesh validates and cooks a triangle mesh once. Invalid index references are rejected; repeated vertices and zero-area triangles are removed from the cooked copy.

func (TriangleMesh) Cooked

func (mesh TriangleMesh) Cooked() bool

func (TriangleMesh) OverlapsCapsule

func (mesh TriangleMesh) OverlapsCapsule(start, end Vector3D, radius float64) bool

OverlapsCapsule tests a capsule given its segment endpoints and radius in mesh-local space. It tests actual triangles, including edges and vertices.

func (TriangleMesh) Raycast

func (mesh TriangleMesh) Raycast(origin, direction Vector3D, limit float64) (MeshRayHit, bool)

Raycast returns the closest two-sided triangle hit. Direction must be unit length. The cooked BVH and traversal stack are reused without allocation.

func (TriangleMesh) TriangleCount

func (mesh TriangleMesh) TriangleCount() int

type TriangleMeshCollider3D

type TriangleMeshCollider3D = Collider3D[TriangleMesh]

type TriangleMeshNode

type TriangleMeshNode struct {
	Bounds       Bounds3D
	Left, Right  int32
	First, Count uint32
}

TriangleMeshNode is a node in a cooked triangle mesh BVH. A node with Count greater than zero is a leaf and indexes TriangleIndices[First:First+Count].

type Vector

type Vector struct {
	X float64
	Y float64
}

Vector is the scalar-independent two-dimensional value used by the physics runtime. The solver uses float64 so long simulations do not accumulate the visible drift caused by render-space float32 transforms.

func V

func V(x, y float64) Vector

func (Vector) Add

func (v Vector) Add(other Vector) Vector

func (Vector) Dot

func (v Vector) Dot(other Vector) float64

func (Vector) Length

func (v Vector) Length() float64

func (Vector) LengthSquared

func (v Vector) LengthSquared() float64

func (Vector) Mul

func (v Vector) Mul(scalar float64) Vector

func (Vector) Normalize

func (v Vector) Normalize() Vector

func (Vector) Perpendicular

func (v Vector) Perpendicular() Vector

func (Vector) Sub

func (v Vector) Sub(other Vector) Vector

type Vector3D

type Vector3D struct {
	X float64
	Y float64
	Z float64
}

Vector3D is the float64 simulation-space vector used by the 3D solver.

func V3

func V3(x, y, z float64) Vector3D

func (Vector3D) Add

func (v Vector3D) Add(other Vector3D) Vector3D

func (Vector3D) Cross

func (v Vector3D) Cross(other Vector3D) Vector3D

func (Vector3D) Dot

func (v Vector3D) Dot(other Vector3D) float64

func (Vector3D) Length

func (v Vector3D) Length() float64

func (Vector3D) LengthSquared

func (v Vector3D) LengthSquared() float64

func (Vector3D) Mul

func (v Vector3D) Mul(scalar float64) Vector3D

func (Vector3D) Normalize

func (v Vector3D) Normalize() Vector3D

func (Vector3D) Sub

func (v Vector3D) Sub(other Vector3D) Vector3D

type World

type World struct {
	Sleep   SleepConfig
	Gravity Vector

	Iterations    int
	CellSize      float64
	CollisionSlop float64
	Damping       float64
	// contains filtered or unexported fields
}

func NewWorld

func NewWorld() *World

func (*World) AddCollider

func (world *World) AddCollider[S Shape2D](body Body, def ColliderDef[S]) ColliderHandle[S]

func (*World) Body

func (world *World) Body(id BodyID) Body

func (*World) CreateBody

func (world *World) CreateBody(def BodyDef) Body

func (*World) Events

func (world *World) Events() []CollisionEvent

func (*World) RemoveBody

func (world *World) RemoveBody(body Body) bool

func (*World) RemoveCollider

func (world *World) RemoveCollider[S Shape2D](collider ColliderHandle[S]) bool

func (*World) Reserve

func (world *World) Reserve(bodyCount, colliderCount int)

Reserve preserves existing bodies and contacts while reserving pools and estimated scratch capacity. Dense contacts or small cells can require more scratch; once warmed up, Step reuses that storage without allocations.

func (*World) Statistics

func (world *World) Statistics() StepStatistics

func (*World) Step

func (world *World) Step(delta float64)

type World3D

type World3D struct {
	Gravity    Vector3D
	Iterations int

	CellSize      float64
	CollisionSlop float64
	Damping       float64
	// contains filtered or unexported fields
}

func NewWorld3D

func NewWorld3D() *World3D

func (*World3D) AddCollider

func (world *World3D) AddCollider[S Shape3D](body Body3D, def ColliderDef[S]) ColliderHandle3D[S]

func (*World3D) Body3D

func (world *World3D) Body3D(id BodyID3D) Body3D

func (*World3D) CreateBody

func (world *World3D) CreateBody(def BodyDef3D) Body3D

func (*World3D) Events

func (world *World3D) Events() []CollisionEvent3D

func (*World3D) RemoveBody

func (world *World3D) RemoveBody(body Body3D) bool

func (*World3D) RemoveCollider

func (world *World3D) RemoveCollider[S Shape3D](collider ColliderHandle3D[S]) bool

func (*World3D) Reserve

func (world *World3D) Reserve(bodyCount, colliderCount int)

Reserve moves pool and scratch growth to setup time.

func (*World3D) Step

func (world *World3D) Step(delta float64)

Jump to

Keyboard shortcuts

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