Skip to content

package graviton

import "kaijuengine.com/engine/graviton"

Constants

DefaultCollisionGroup

0

DefaultCollisionMask

1 << DefaultCollisionGroup

DefaultSleepThreshold

matrix.[Float(0](../matrix#Float(0)

Variables

NullAABB

AABB{Type: ShapeTypeAABB}

Functions

AngularAxisEffectiveMass

func AngularAxisEffectiveMass(body *RigidBody, axis matrix.Vec3) matrix.Float

AngularConstraintEffectiveMass

func AngularConstraintEffectiveMass(bodyA, bodyB *RigidBody, axis matrix.Vec3) matrix.Float

AngularConstraintImpulseDenominator

func AngularConstraintImpulseDenominator(bodyA, bodyB *RigidBody, axis matrix.Vec3) matrix.Float

AngularEffectiveMass

func AngularEffectiveMass(body *RigidBody, relativeAnchor, axis matrix.Vec3) matrix.Float

CalculateLocalInertia

func CalculateLocalInertia(shape Shape, mass matrix.Float) matrix.Vec3

ConstraintEffectiveMass

func ConstraintEffectiveMass(bodyA, bodyB *RigidBody, ra, rb, axis matrix.Vec3) matrix.Float

ConstraintImpulseDenominator

func ConstraintImpulseDenominator(bodyA, bodyB *RigidBody, ra, rb, axis matrix.Vec3) matrix.Float

LocalAnchor

func LocalAnchor(body *RigidBody, worldAnchor matrix.Vec3) matrix.Vec3

LocalAxis

func LocalAxis(body *RigidBody, worldAxis matrix.Vec3) matrix.Vec3

PointOutsideOfPlane

func PointOutsideOfPlane(p, a, b, c, d matrix.Vec3) bool

PointOutsideOfPlane returns true if the given point is outside of the plane

RelativeAnchorOffset

func RelativeAnchorOffset(body *RigidBody, worldAnchor matrix.Vec3) matrix.Vec3

RemoveAllLeavesMatchingTransform

func RemoveAllLeavesMatchingTransform(world **BVH, transform *matrix.Transform)

RemoveBVHNode

func RemoveBVHNode(root **BVH, node *BVH)

RemoveSubBVH

func RemoveSubBVH(world **BVH, sub *BVH)

VelocityAtAnchor

func VelocityAtAnchor(body *RigidBody, relativeAnchor matrix.Vec3) matrix.Vec3

WakeConstrainedBodies

func WakeConstrainedBodies(bodyA, bodyB *RigidBody)

WorldAnchor

func WorldAnchor(body *RigidBody, localAnchor matrix.Vec3) matrix.Vec3

WorldAxis

func WorldAxis(body *RigidBody, localAxis matrix.Vec3) matrix.Vec3

Types

AABB

Shape

type AABB Shape

AABBFromCorners

func AABBFromCorners(corners [8]matrix.Vec3) AABB

AABBFromCorners creates an AABB from 8 corner points

AABBFromMinMax

func AABBFromMinMax(min, max matrix.Vec3) AABB

AABBFromMinMax creates an AABB from the minimum and maximum points

AABBFromPoints

func AABBFromPoints(points []matrix.Vec3) AABB

AABBFromTransform

func AABBFromTransform(transform *matrix.Transform) AABB

AABBFromTriangles

func AABBFromTriangles(triangles []DetailedTriangle) AABB

AABBFromWidth

func AABBFromWidth(center matrix.Vec3, halfWidth matrix.Float) AABB

AABBFromWidth creates an AABB from the center and half-width

AABBUnion

func AABBUnion(a, b AABB) AABB

Union returns the union of two AABBs

NewAABB

func NewAABB(center, extent matrix.Vec3) AABB

AABB.AABBIntersect

func (a *AABB) AABBIntersect(b AABB) bool

AABBIntersect returns whether the AABB intersects another AABB

AABB.Bounds

func (box AABB) Bounds() AABB

Satisfying BVH HitObject interface

AABB.ClosestDistance

func (a AABB) ClosestDistance(b AABB) matrix.Float

ClosestDistance returns the closest distance between two AABBs

AABB.Contains

func (box *AABB) Contains(point matrix.Vec3) bool

Contains returns whether the AABB contains the point

AABB.ContainsAABB

func (box *AABB) ContainsAABB(b AABB) bool

ContainsAABB returns whether the AABB contains another AABB

AABB.Corners

func (box AABB) Corners() [8]matrix.Vec3

AABB.FromTriangle

func (box *AABB) FromTriangle(triangle DetailedTriangle) AABB

FromTriangle returns an AABB that contains the triangle

AABB.IntersectsFrustum

func (box *AABB) IntersectsFrustum(frustum Frustum) bool

IntersectsFrustum returns whether the AABB is in the frustum

AABB.LongestAxis

func (box *AABB) LongestAxis() int

LongestAxis returns the longest axis of the AABB (0 = X, 1 = Y, 2 = Z)

AABB.Max

func (box *AABB) Max() matrix.Vec3

Max returns the maximum point of the AABB

AABB.Min

func (box *AABB) Min() matrix.Vec3

Min returns the minimum point of the AABB

AABB.PlaneIntersect

func (box *AABB) PlaneIntersect(plane Plane) bool

PlaneIntersect returns whether the AABB intersects a plane

AABB.RayHit

func (box *AABB) RayHit(ray Ray) (matrix.Vec3, bool)

RayHit returns the point of intersection and whether the ray hit the AABB

AABB.RayIntersectTest

func (box AABB) RayIntersectTest(ray Ray, length float32, transform *matrix.Transform) (matrix.Vec3, bool)

AABB.Size

func (box AABB) Size() matrix.Vec3

Size returns the size of the AABB

AABB.SurfaceArea

func (box AABB) SurfaceArea() matrix.Float

AABB.Transform

func (a AABB) Transform(m matrix.Mat4) AABB

AABB.TriangleIntersect

func (box *AABB) TriangleIntersect(tri DetailedTriangle) bool

TriangleIntersect returns whether the AABB intersects a triangle

ActivePair

struct

type ActivePair struct {
    BodyA *RigidBody
    BodyB *RigidBody
}

ActivePair represents a potential collision pair found by SAP

AngularConstraintSolverRow

struct

type AngularConstraintSolverRow struct {
    BodyA              *RigidBody
    BodyB              *RigidBody
    Axis               matrix.Vec3
    EffectiveMass      matrix.Float
    Bias               matrix.Float
    AccumulatedImpulse matrix.Float
    MinImpulse         matrix.Float
    MaxImpulse         matrix.Float
}

AngularConstraintSolverRow stores a scalar angular-only Jacobian row. It is used by constraints that must remove relative angular velocity around a world-space axis without applying any linear impulse.

AngularConstraintSolverRow.ApplyImpulse

func (r *AngularConstraintSolverRow) ApplyImpulse(impulse matrix.Float)

AngularConstraintSolverRow.RelativeVelocity

func (r *AngularConstraintSolverRow) RelativeVelocity() matrix.Float

AngularConstraintSolverRow.SetImpulseLimits

func (r *AngularConstraintSolverRow) SetImpulseLimits(minimum, maximum matrix.Float)

AngularConstraintSolverRow.SetWorldAxis

func (r *AngularConstraintSolverRow) SetWorldAxis(bodyA, bodyB *RigidBody, axis matrix.Vec3)

AngularConstraintSolverRow.Solve

func (r *AngularConstraintSolverRow) Solve() matrix.Float

Axis

uint

type Axis = uint

const ( AxisX Axis = iota AxisY AxisZ )

BVH

struct

type BVH struct {
    Left   *BVH
    Right  *BVH
    Parent *BVH
    Item   BVHItem
    // Has unexported fields.
}

AddSubBVH

func AddSubBVH(world **BVH, sub *BVH, transform *matrix.Transform) *BVH

CloneBVH

func CloneBVH(bvh *BVH) *BVH

InsertBVH

func InsertBVH(root **BVH, hitCheck HitObject, transform *matrix.Transform, data any) *BVH

NewBVH

func NewBVH(entries []HitObject, transform *matrix.Transform, data any) *BVH

BVH.Bounds

func (b *BVH) Bounds() AABB

BVH.IsLeaf

func (b *BVH) IsLeaf() bool

BVH.RayIntersect

func (b *BVH) RayIntersect(ray Ray, length float32) (any, matrix.Vec3, bool)

BVH.RayIntersectTest

func (b *BVH) RayIntersectTest(ray Ray, length float32, transform *matrix.Transform) (matrix.Vec3, bool)

BVH.Refit

func (b *BVH) Refit()

BVH.RefitUpwards

func (b *BVH) RefitUpwards()

BVHItem

struct

type BVHItem struct {
    Transform *matrix.Transform
    HitCheck  HitObject
    Data      any
}

BVHItem.Bounds

func (item BVHItem) Bounds() AABB

BVHItem.IsValid

func (item BVHItem) IsValid() bool

BVHItem.RayIntersect

func (item BVHItem) RayIntersect(ray Ray, length float32, transform *matrix.Transform) (matrix.Vec3, bool)

BroadPhaseFilter

func

type BroadPhaseFilter func(a, b *RigidBody) bool

Capsule

Shape

type Capsule Shape

NewCapsule

func NewCapsule(center matrix.Vec3, radius matrix.Float, height matrix.Float, direction matrix.Vec3) Capsule

Capsule.IntersectsAABB

func (s Capsule) IntersectsAABB(b AABB) bool

Capsule.IntersectsCapsule

func (s Capsule) IntersectsCapsule(b Capsule) bool

Capsule.IntersectsCone

func (s Capsule) IntersectsCone(c Cone) bool

Capsule.IntersectsCylinder

func (s Capsule) IntersectsCylinder(c Cylinder) bool

Capsule.IntersectsFrustum

func (s Capsule) IntersectsFrustum(f Frustum) bool

Capsule.IntersectsOOBB

func (s Capsule) IntersectsOOBB(b OOBB) bool

Capsule.IntersectsPlane

func (s Capsule) IntersectsPlane(p Plane) (bool, float32)

Capsule.IntersectsRay

func (s Capsule) IntersectsRay(r Ray) (bool, float32)

Capsule.IntersectsSphere

func (s Capsule) IntersectsSphere(c Sphere) bool

Circle

struct

type Circle struct {
    Point  matrix.Vec3
    Radius matrix.Float
    Axis   Axis
}

Circle.RayHit

func (c Circle) RayHit(ray Ray) (matrix.Vec3, bool)

CollisionInfo

struct

type CollisionInfo struct {
    Shape     Shape
    Mesh      *MeshCollision
    Terrain   *TerrainCollision
    LocalAABB AABB
    Group     int
    Mask      int
    IsTrigger bool
}

CollisionSolver

struct

type CollisionSolver struct {
    VelocityIterations int
    PositionIterations int
    DeltaTime          matrix.Float
    Restitution        matrix.Float
    StaticFriction     matrix.Float
    DynamicFriction    matrix.Float
    Baumgarte          matrix.Float
    PenetrationSlop    matrix.Float
    MaxCorrection      matrix.Float

    // Has unexported fields.
}

CollisionSolver resolves narrow-phase contacts with an iterative impulse solver. Contacts are grouped into independent dynamic islands so islands can be solved in parallel without concurrent writes to the same body.

CollisionSolver.Initialize

func (s *CollisionSolver) Initialize()

CollisionSolver.Reset

func (s *CollisionSolver) Reset()

CollisionSolver.Solve

func (s *CollisionSolver) Solve(manifolds []ContactManifold, threads *concurrent.Threads)

CollisionSolver.SolveWithConstraints

func (s *CollisionSolver) SolveWithConstraints(manifolds []ContactManifold, constraints []*Constraint, threads *concurrent.Threads)

Cone

Shape

type Cone Shape

NewCone

func NewCone(center matrix.Vec3, radius matrix.Float, height matrix.Float, direction matrix.Vec3) Cone

Cone.IntersectCone

func (a *Cone) IntersectCone(b Cone) bool

Cone.IntersectsAABB

func (s Cone) IntersectsAABB(b AABB) bool

Cone.IntersectsCapsule

func (s Cone) IntersectsCapsule(c Capsule) bool

Cone.IntersectsCylinder

func (s Cone) IntersectsCylinder(c Cylinder) bool

Cone.IntersectsFrustum

func (s Cone) IntersectsFrustum(f Frustum) bool

Cone.IntersectsOOBB

func (s Cone) IntersectsOOBB(b OOBB) bool

Cone.IntersectsPlane

func (s Cone) IntersectsPlane(p Plane) (bool, float32)

Cone.IntersectsRay

func (s Cone) IntersectsRay(r Ray) (bool, float32)

Cone.IntersectsSphere

func (s Cone) IntersectsSphere(c Sphere) bool

Constraint

struct

type Constraint struct {
    Type     ConstraintType
    BodyA    *RigidBody
    BodyB    *RigidBody
    Rows     []ConstraintSolverRow
    Distance *DistanceJoint
    Rope     *RopeJoint
    Point    *PointJoint
    Hinge    *HingeJoint
    Active   bool
    Enabled  bool
    // BreakForce and BreakTorque are optional impulse thresholds. Values <= 0
    // leave that break mode disabled.
    BreakForce  matrix.Float
    BreakTorque matrix.Float
    Broken      bool

    // Has unexported fields.
}

Constraint stores the lifecycle and endpoints for a future Graviton constraint solver. BodyA and BodyB form a body-body constraint; either body may be nil to represent a body-world constraint.

Constraint.AccumulatedAngularImpulse

func (c *Constraint) AccumulatedAngularImpulse() matrix.Float

Constraint.AccumulatedLinearImpulse

func (c *Constraint) AccumulatedLinearImpulse() matrix.Float

Constraint.BodiesValid

func (c *Constraint) BodiesValid() bool

Constraint.BreakIfNeeded

func (c *Constraint) BreakIfNeeded() bool

Constraint.IsBodyBody

func (c *Constraint) IsBodyBody() bool

Constraint.IsBodyWorld

func (c *Constraint) IsBodyWorld() bool

Constraint.IsStretched

func (c *Constraint) IsStretched() bool

Constraint.IsValid

func (c *Constraint) IsValid() bool

Constraint.SetActive

func (c *Constraint) SetActive(active bool)

Constraint.SetBodies

func (c *Constraint) SetBodies(bodyA, bodyB *RigidBody)

Constraint.SetBreakForce

func (c *Constraint) SetBreakForce(threshold matrix.Float)

Constraint.SetBreakTorque

func (c *Constraint) SetBreakTorque(threshold matrix.Float)

Constraint.SetEnabled

func (c *Constraint) SetEnabled(enabled bool)

Constraint.WakeBodies

func (c *Constraint) WakeBodies()

ConstraintSolverRow

struct

type ConstraintSolverRow struct {
    BodyA              *RigidBody
    BodyB              *RigidBody
    Axis               matrix.Vec3
    JacobianLinearA    matrix.Vec3
    JacobianAngularA   matrix.Vec3
    JacobianLinearB    matrix.Vec3
    JacobianAngularB   matrix.Vec3
    AnchorA            matrix.Vec3
    AnchorB            matrix.Vec3
    RelativeAnchorA    matrix.Vec3
    RelativeAnchorB    matrix.Vec3
    EffectiveMass      matrix.Float
    Bias               matrix.Float
    AccumulatedImpulse matrix.Float
    MinImpulse         matrix.Float
    MaxImpulse         matrix.Float
}

ConstraintSolverRow stores a single scalar Jacobian row for iterative constraint solving. The row applies impulses along Axis at both anchors, where BodyA receives the negative impulse and BodyB receives the positive impulse.

NewConstraintSolverRow

func NewConstraintSolverRow(bodyA, bodyB *RigidBody, anchorA, anchorB, axis matrix.Vec3) ConstraintSolverRow

ConstraintSolverRow.ApplyImpulse

func (r *ConstraintSolverRow) ApplyImpulse(impulse matrix.Float)

ConstraintSolverRow.RelativeVelocity

func (r *ConstraintSolverRow) RelativeVelocity() matrix.Float

ConstraintSolverRow.SetImpulseLimits

func (r *ConstraintSolverRow) SetImpulseLimits(minimum, maximum matrix.Float)

ConstraintSolverRow.SetLocalAnchors

func (r *ConstraintSolverRow) SetLocalAnchors(bodyA, bodyB *RigidBody, anchorA, anchorB, axis matrix.Vec3)

ConstraintSolverRow.SetWorldAnchors

func (r *ConstraintSolverRow) SetWorldAnchors(bodyA, bodyB *RigidBody, anchorA, anchorB, axis matrix.Vec3)

ConstraintSolverRow.Solve

func (r *ConstraintSolverRow) Solve() matrix.Float

ConstraintType

uint8

type ConstraintType uint8

const ( ConstraintTypeUnknown ConstraintType = iota ConstraintTypeGeneric ConstraintTypeDistance ConstraintTypeRope ConstraintTypePoint ConstraintTypeHinge )

Contact

struct

type Contact struct {
    BodyA       *RigidBody
    BodyB       *RigidBody
    Point       matrix.Vec3
    PointA      matrix.Vec3
    PointB      matrix.Vec3
    Normal      matrix.Vec3
    Penetration matrix.Float
}

Contact contains one world-space contact point generated by the narrow phase. Normal always points from BodyA toward BodyB.

ContactManifold

struct

type ContactManifold struct {
    BodyA    *RigidBody
    BodyB    *RigidBody
    Normal   matrix.Vec3
    Contacts [maxManifoldContacts]Contact
    Count    int
}

ContactManifold groups contacts for a colliding body pair.

CollideBodies

func CollideBodies(a, b *RigidBody) (ContactManifold, bool)

Cylinder

Shape

type Cylinder Shape

NewCylinder

func NewCylinder(center matrix.Vec3, radius matrix.Float, height matrix.Float, direction matrix.Vec3) Cylinder

Cylinder.IntersectsAABB

func (s Cylinder) IntersectsAABB(b AABB) bool

Cylinder.IntersectsCapsule

func (s Cylinder) IntersectsCapsule(c Capsule) bool

Cylinder.IntersectsCone

func (s Cylinder) IntersectsCone(c Cone) bool

Cylinder.IntersectsCylinder

func (a Cylinder) IntersectsCylinder(b Cylinder) bool

Cylinder.IntersectsFrustum

func (s Cylinder) IntersectsFrustum(f Frustum) bool

Cylinder.IntersectsOOBB

func (s Cylinder) IntersectsOOBB(b OOBB) bool

Cylinder.IntersectsPlane

func (s Cylinder) IntersectsPlane(p Plane) (bool, float32)

Cylinder.IntersectsRay

func (s Cylinder) IntersectsRay(r Ray) (bool, float32)

Cylinder.IntersectsSphere

func (s Cylinder) IntersectsSphere(c Sphere) bool

DetailedTriangle

struct

type DetailedTriangle struct {
    Points   [3]matrix.Vec3
    Normal   matrix.Vec3
    Centroid matrix.Vec3
    Radius   matrix.Float
}

DetailedTriangleFromPoints

func DetailedTriangleFromPoints(points [3]matrix.Vec3) DetailedTriangle

DetailedTriangleFromPoints creates a detailed triangle from three points, a detailed triangle is different from a regular triangle in that it contains additional information such as the centroid and radius

DetailedTriangle.Bounds

func (t DetailedTriangle) Bounds() AABB

DetailedTriangle.RayIntersectTest

func (t DetailedTriangle) RayIntersectTest(ray Ray, length float32, transform *matrix.Transform) (matrix.Vec3, bool)

DistanceJoint

struct

type DistanceJoint struct {
    BodyA                    *RigidBody
    BodyB                    *RigidBody
    LocalAnchorA             matrix.Vec3
    LocalAnchorB             matrix.Vec3
    RestLength               matrix.Float
    Stiffness                matrix.Float
    BiasFactor               matrix.Float
    PositionCorrectionFactor matrix.Float
    Slop                     matrix.Float
    MaxCorrection            matrix.Float
    WarmStarting             bool
    AccumulatedImpulse       matrix.Float

    // Has unexported fields.
}

DistanceJoint keeps two body anchors, or one body anchor and one fixed world anchor, at a target distance. Nil bodies are treated as fixed world anchors.

NewDistanceJoint

func NewDistanceJoint(bodyA, bodyB *RigidBody, localAnchorA, localAnchorB matrix.Vec3) *DistanceJoint

NewDistanceJointAtWorldAnchors

func NewDistanceJointAtWorldAnchors(bodyA, bodyB *RigidBody, worldAnchorA, worldAnchorB matrix.Vec3) *DistanceJoint

NewDistanceJointToWorld

func NewDistanceJointToWorld(body *RigidBody, localAnchor, worldAnchor matrix.Vec3) *DistanceJoint

DistanceJoint.Constraint

func (j *DistanceJoint) Constraint() *Constraint

DistanceJoint.CurrentLength

func (j *DistanceJoint) CurrentLength() matrix.Float

DistanceJoint.IsStretched

func (j *DistanceJoint) IsStretched() bool

DistanceJoint.SetRestLength

func (j *DistanceJoint) SetRestLength(restLength matrix.Float)

DistanceJoint.SetWorldAnchors

func (j *DistanceJoint) SetWorldAnchors(worldAnchorA, worldAnchorB matrix.Vec3)

DistanceJoint.WorldAnchorA

func (j *DistanceJoint) WorldAnchorA() matrix.Vec3

DistanceJoint.WorldAnchorB

func (j *DistanceJoint) WorldAnchorB() matrix.Vec3

Frustum

struct

type Frustum struct {
    Planes [6]Plane
}

Frustum.ExtractPlanes

func (f *Frustum) ExtractPlanes(vp matrix.Mat4)

FrustumCorners

[8]matrix.Vec4

type FrustumCorners [8]matrix.Vec4

FrustumExtractCorners

func FrustumExtractCorners(view, projection matrix.Mat4) FrustumCorners

FrustumCorners.Center

func (c FrustumCorners) Center() matrix.Vec3

HingeJoint

struct

type HingeJoint struct {
    BodyA                     *RigidBody
    BodyB                     *RigidBody
    LocalAnchorA              matrix.Vec3
    LocalAnchorB              matrix.Vec3
    LocalAxisA                matrix.Vec3
    LocalAxisB                matrix.Vec3
    LocalRefA                 matrix.Vec3
    LocalRefB                 matrix.Vec3
    Stiffness                 matrix.Float
    BiasFactor                matrix.Float
    PositionCorrectionFactor  matrix.Float
    Slop                      matrix.Float
    MaxCorrection             matrix.Float
    WarmStarting              bool
    EnableLimits              bool
    MinAngle                  matrix.Float
    MaxAngle                  matrix.Float
    EnableMotor               bool
    MotorTargetSpeed          matrix.Float
    MaxMotorImpulse           matrix.Float
    MaxMotorTorque            matrix.Float
    AccumulatedAnchorImpulse  matrix.Vec3
    AccumulatedAngularImpulse matrix.Vec2
    AccumulatedLimitImpulse   matrix.Float
    AccumulatedMotorImpulse   matrix.Float

    // Has unexported fields.
}

HingeJoint keeps two anchors coincident and aligns each body's hinge axis. Relative rotation is constrained around the two axes perpendicular to the hinge, leaving rotation around the hinge axis free.

NewHingeJoint

func NewHingeJoint(bodyA, bodyB *RigidBody, localAnchorA, localAnchorB, localAxisA, localAxisB matrix.Vec3) *HingeJoint

NewHingeJointAtWorldAnchor

func NewHingeJointAtWorldAnchor(bodyA, bodyB *RigidBody, worldAnchor, worldAxis matrix.Vec3) *HingeJoint

NewHingeJointToWorld

func NewHingeJointToWorld(body *RigidBody, localAnchor, worldAnchor, localAxis, worldAxis matrix.Vec3) *HingeJoint

HingeJoint.AccumulatedAngularImpulseMagnitude

func (j *HingeJoint) AccumulatedAngularImpulseMagnitude() matrix.Float

HingeJoint.Constraint

func (j *HingeJoint) Constraint() *Constraint

HingeJoint.CurrentAnchorError

func (j *HingeJoint) CurrentAnchorError() matrix.Vec3

HingeJoint.CurrentAngle

func (j *HingeJoint) CurrentAngle() matrix.Float

HingeJoint.CurrentAngularError

func (j *HingeJoint) CurrentAngularError() matrix.Vec3

HingeJoint.CurrentAngularVelocity

func (j *HingeJoint) CurrentAngularVelocity() matrix.Float

HingeJoint.DisableAngularLimits

func (j *HingeJoint) DisableAngularLimits()

HingeJoint.DisableMotor

func (j *HingeJoint) DisableMotor()

HingeJoint.IsStretched

func (j *HingeJoint) IsStretched() bool

HingeJoint.SetAngularLimits

func (j *HingeJoint) SetAngularLimits(minAngle, maxAngle matrix.Float)

HingeJoint.SetMotor

func (j *HingeJoint) SetMotor(targetSpeed, maxMotorImpulse matrix.Float)

HingeJoint.SetMotorTorque

func (j *HingeJoint) SetMotorTorque(targetSpeed, maxMotorTorque matrix.Float)

HingeJoint.SetWorldAnchors

func (j *HingeJoint) SetWorldAnchors(worldAnchorA, worldAnchorB matrix.Vec3)

HingeJoint.SetWorldAxis

func (j *HingeJoint) SetWorldAxis(worldAxis matrix.Vec3)

HingeJoint.WorldAnchorA

func (j *HingeJoint) WorldAnchorA() matrix.Vec3

HingeJoint.WorldAnchorB

func (j *HingeJoint) WorldAnchorB() matrix.Vec3

HingeJoint.WorldAxisA

func (j *HingeJoint) WorldAxisA() matrix.Vec3

HingeJoint.WorldAxisB

func (j *HingeJoint) WorldAxisB() matrix.Vec3

HingeJoint.WorldReferenceA

func (j *HingeJoint) WorldReferenceA() matrix.Vec3

HingeJoint.WorldReferenceB

func (j *HingeJoint) WorldReferenceB() matrix.Vec3

Hit

struct

type Hit struct {
    Body     *RigidBody
    Point    matrix.Vec3
    Normal   matrix.Vec3
    Distance matrix.Float
}

HitObject

interface

type HitObject interface {
    Bounds() AABB
    RayIntersectTest(ray Ray, length float32, transform *matrix.Transform) (matrix.Vec3, bool)
}

Interval

struct

type Interval struct {
    Min  matrix.Float
    Max  matrix.Float
    Body *RigidBody
    // Has unexported fields.
}

Interval represents a projected AABB onto one axis

Mass

struct

type Mass struct {
    Inertia matrix.Vec3

    Mass matrix.Float
    // Has unexported fields.
}

MeshCollision

struct

type MeshCollision struct {
    Triangles []DetailedTriangle
    BVH       *BVH
    Bounds    AABB
}

MeshCollision stores the heavy collision data for triangle meshes. The flat Shape keeps only type and bounds so primitive shape data stays compact.

NewMeshCollision

func NewMeshCollision(triangles []DetailedTriangle) *MeshCollision

NewMeshCollisionFromVertices

func NewMeshCollisionFromVertices(vertices []matrix.Vec3, indexes []uint32) *MeshCollision

MeshCollision.ForEachWorldTriangle

func (m *MeshCollision) ForEachWorldTriangle(transform *matrix.Transform, visit func(DetailedTriangle) bool)

MeshCollision.Raycast

func (m *MeshCollision) Raycast(ray Ray, length matrix.Float, transform *matrix.Transform) (Hit, bool)

MotionState

struct

type MotionState struct {
    Acceleration        matrix.Vec3
    AngularAcceleration matrix.Vec3
    LinearVelocity      matrix.Vec3
    AngularVelocity     matrix.Vec3
}

NarrowPhase

struct

type NarrowPhase struct {
    // Has unexported fields.
}

NarrowPhase performs exact pair tests after the broad phase has produced candidate pairs. It owns reusable buffers so a physics step can run without per-pair allocations.

NarrowPhase.Collide

func (n *NarrowPhase) Collide(pairs []ActivePair, threads *concurrent.Threads) []ContactManifold

NarrowPhase.Manifolds

func (n *NarrowPhase) Manifolds() []ContactManifold

NarrowPhase.Reset

func (n *NarrowPhase) Reset()

OOBB

Shape

type OOBB Shape

NewOOBB

func NewOOBB(center, extent matrix.Vec3, orientation matrix.Mat3) OOBB

OOBBFromAABB

func OOBBFromAABB(aabb AABB) OOBB

OOBBFromTransform

func OOBBFromTransform(baseAABB AABB, transform *matrix.Transform) OOBB

OOBB.Bounds

func (o OOBB) Bounds() AABB

OOBB.ContainsPoint

func (o OOBB) ContainsPoint(point matrix.Vec3) bool

OOBB.Corners

func (o OOBB) Corners() [8]matrix.Vec3

OOBB.Intersect

func (o OOBB) Intersect(other OOBB) bool

OOBB.RayIntersect

func (o OOBB) RayIntersect(ray Ray, length float32) bool

Octree

struct

type Octree struct {
    Center    matrix.Vec3
    HalfWidth matrix.Float
    Children  [8]*Octree
    Objects   []HitObject
}

NewOctree

func NewOctree(center matrix.Vec3, halfWidth matrix.Float, maxDepth int) *Octree

OctreeForMesh

func OctreeForMesh(mesh []matrix.Vec3) *Octree

Octree.AsAABB

func (o *Octree) AsAABB() AABB

Octree.Insert

func (node *Octree) Insert(obj HitObject)

Plane

struct

type Plane struct {
    Normal matrix.Vec3
    Dot    matrix.Float
}

PlaneCCW

func PlaneCCW(a, b, c matrix.Vec3) Plane

PlaneCCW creates a plane from three points in counter clockwise order

Plane.ClosestPoint

func (p Plane) ClosestPoint(point matrix.Vec3) matrix.Vec3

ClosestPoint returns the closest point on the plane to the given point

Plane.Distance

func (p Plane) Distance(point matrix.Vec3) float32

Distance returns the distance from the plane to the given point

Plane.SetFloatValue

func (p *Plane) SetFloatValue(value float32, index int)

SetFloatValue sets the value of the plane at the given index (X, Y, Z, Dot)

Plane.ToArray

func (p Plane) ToArray() [4]float32

ToArray converts the plane to an array of 4 floats

Plane.ToVec4

func (p Plane) ToVec4() matrix.Vec4

ToVec4 converts the plane to a Vec4 (analogous to ToArray)

PointJoint

struct

type PointJoint struct {
    BodyA                    *RigidBody
    BodyB                    *RigidBody
    LocalAnchorA             matrix.Vec3
    LocalAnchorB             matrix.Vec3
    Stiffness                matrix.Float
    BiasFactor               matrix.Float
    PositionCorrectionFactor matrix.Float
    Slop                     matrix.Float
    MaxCorrection            matrix.Float
    WarmStarting             bool
    AccumulatedImpulse       matrix.Vec3

    // Has unexported fields.
}

PointJoint keeps two local anchors coincident while leaving relative orientation unconstrained. Nil bodies are treated as fixed world anchors.

NewPointJoint

func NewPointJoint(bodyA, bodyB *RigidBody, localAnchorA, localAnchorB matrix.Vec3) *PointJoint

NewPointJointAtWorldAnchors

func NewPointJointAtWorldAnchors(bodyA, bodyB *RigidBody, worldAnchorA, worldAnchorB matrix.Vec3) *PointJoint

NewPointJointToWorld

func NewPointJointToWorld(body *RigidBody, localAnchor, worldAnchor matrix.Vec3) *PointJoint

PointJoint.Constraint

func (j *PointJoint) Constraint() *Constraint

PointJoint.CurrentError

func (j *PointJoint) CurrentError() matrix.Vec3

PointJoint.IsStretched

func (j *PointJoint) IsStretched() bool

PointJoint.SetWorldAnchors

func (j *PointJoint) SetWorldAnchors(worldAnchorA, worldAnchorB matrix.Vec3)

PointJoint.WorldAnchorA

func (j *PointJoint) WorldAnchorA() matrix.Vec3

PointJoint.WorldAnchorB

func (j *PointJoint) WorldAnchorB() matrix.Vec3

Ray

struct

type Ray struct {
    Origin    matrix.Vec3
    Direction matrix.Vec3
}

Ray.PlaneHit

func (r Ray) PlaneHit(planePosition, planeNormal matrix.Vec3) (hit matrix.Vec3, success bool)

PlaneHit returns the point of intersection with the plane and true if the ray hits the plane

Ray.Point

func (r Ray) Point(distance float32) matrix.Vec3

Point returns the point at the given distance along the ray

Ray.SphereHit

func (r Ray) SphereHit(center matrix.Vec3, radius, maxLen float32) bool

SphereHit returns true if the ray hits the sphere

Ray.TriangleHit

func (r Ray) TriangleHit(rayLen float32, a, b, c matrix.Vec3) (matrix.Vec3, bool)

TriangleHit returns true if the ray hits the triangle defined by the three points

RigidBody

struct

type RigidBody struct {
    Transform   matrix.Transform
    MotionState MotionState
    Mass        Mass
    Collision   CollisionInfo
    Simulation  SimulationState
    Active      bool

    // Has unexported fields.
}

RigidBody.ApplyForce

func (r *RigidBody) ApplyForce(force matrix.Vec3)

ApplyForce applies a continuous world-space force at the body's center of mass.

RigidBody.ApplyForceAtPoint

func (r *RigidBody) ApplyForceAtPoint(force, point matrix.Vec3)

ApplyForceAtPoint applies a continuous world-space force at a world-space point.

RigidBody.ApplyImpulse

func (r *RigidBody) ApplyImpulse(impulse matrix.Vec3)

ApplyImpulse applies an immediate world-space impulse at the body's center of mass.

RigidBody.ApplyImpulseAtPoint

func (r *RigidBody) ApplyImpulseAtPoint(impulse, point matrix.Vec3)

ApplyImpulseAtPoint applies an immediate world-space impulse at a world-space point.

RigidBody.CollisionFilter

func (r *RigidBody) CollisionFilter() (int, int)

RigidBody.IsDynamic

func (r *RigidBody) IsDynamic() bool

RigidBody.IsKinematic

func (r *RigidBody) IsKinematic() bool

RigidBody.IsStatic

func (r *RigidBody) IsStatic() bool

RigidBody.IsTrigger

func (r *RigidBody) IsTrigger() bool

RigidBody.Position

func (r *RigidBody) Position() matrix.Vec3

RigidBody.Rotation

func (r *RigidBody) Rotation() matrix.Quaternion

RigidBody.SetCollisionFilter

func (r *RigidBody) SetCollisionFilter(group, mask int)

RigidBody.SetDynamic

func (r *RigidBody) SetDynamic(mass matrix.Float, inertia matrix.Vec3)

RigidBody.SetKinematic

func (r *RigidBody) SetKinematic()

SetKinematic makes this body entity-driven: the stage sync copies the entity transform into the body before collision detection, and the solver treats it as immovable because kinematic bodies have no inverse mass.

RigidBody.SetMass

func (r *RigidBody) SetMass(mass matrix.Float, inertia matrix.Vec3)

RigidBody.SetShape

func (r *RigidBody) SetShape(shape Shape)

RigidBody.SetStatic

func (r *RigidBody) SetStatic()

RigidBody.SetStaticMesh

func (r *RigidBody) SetStaticMesh(mesh *MeshCollision)

RigidBody.SetStaticTerrain

func (r *RigidBody) SetStaticTerrain(terrain *TerrainCollision)

RigidBody.SetTrigger

func (r *RigidBody) SetTrigger(isTrigger bool)

RigidBody.Shape

func (r *RigidBody) Shape() Shape

RigidBody.Sleep

func (r *RigidBody) Sleep()

RigidBody.Wake

func (r *RigidBody) Wake()

RigidBody.WorldAABB

func (r *RigidBody) WorldAABB() AABB

RigidBodyType

uint8

type RigidBodyType uint8

const ( RigidBodyTypeStatic RigidBodyType = iota RigidBodyTypeKinematic RigidBodyTypeDynamic )

RopeJoint

struct

type RopeJoint struct {
    BodyA                    *RigidBody
    BodyB                    *RigidBody
    LocalAnchorA             matrix.Vec3
    LocalAnchorB             matrix.Vec3
    MaxLength                matrix.Float
    Stiffness                matrix.Float
    BiasFactor               matrix.Float
    PositionCorrectionFactor matrix.Float
    Slop                     matrix.Float
    MaxCorrection            matrix.Float
    WarmStarting             bool
    AccumulatedImpulse       matrix.Float

    // Has unexported fields.
}

RopeJoint keeps two anchors from separating beyond MaxLength. Unlike a DistanceJoint, it is inactive while the anchors are within the limit.

NewRopeJoint

func NewRopeJoint(bodyA, bodyB *RigidBody, localAnchorA, localAnchorB matrix.Vec3) *RopeJoint

NewRopeJointAtWorldAnchors

func NewRopeJointAtWorldAnchors(bodyA, bodyB *RigidBody, worldAnchorA, worldAnchorB matrix.Vec3) *RopeJoint

NewRopeJointToWorld

func NewRopeJointToWorld(body *RigidBody, localAnchor, worldAnchor matrix.Vec3) *RopeJoint

RopeJoint.Constraint

func (j *RopeJoint) Constraint() *Constraint

RopeJoint.CurrentLength

func (j *RopeJoint) CurrentLength() matrix.Float

RopeJoint.IsSlack

func (j *RopeJoint) IsSlack() bool

RopeJoint.IsStretched

func (j *RopeJoint) IsStretched() bool

RopeJoint.SetMaxLength

func (j *RopeJoint) SetMaxLength(maxLength matrix.Float)

RopeJoint.SetWorldAnchors

func (j *RopeJoint) SetWorldAnchors(worldAnchorA, worldAnchorB matrix.Vec3)

RopeJoint.WorldAnchorA

func (j *RopeJoint) WorldAnchorA() matrix.Vec3

RopeJoint.WorldAnchorB

func (j *RopeJoint) WorldAnchorB() matrix.Vec3

Segment

struct

type Segment struct {
    A matrix.Vec3
    B matrix.Vec3
}

LineSegmentFromRay

func LineSegmentFromRay(ray Ray, length float32) Segment

LineSegmentFromRay creates a line segment from a ray

Segment.TriangleHit

func (l Segment) TriangleHit(a, b, c matrix.Vec3) (matrix.Vec3, bool)

TriangleHit returns true if the segment hits the triangle defined by the three points

Shape

struct

type Shape struct {
    Center      matrix.Vec3  // Circle, AABB, OOBB, Capsule, Cylinder, Cone
    Radius      matrix.Float // Circle, Capsule, Cylinder, Cone
    Extent      matrix.Vec3  // AABB, OOBB
    Orientation matrix.Mat3  // OOBB
    Height      matrix.Float // Capsule, Cylinder, Cone
    Direction   matrix.Vec3  // Capsule, Cylinder, Cone
    Type        ShapeType
}

NewAABBShape

func NewAABBShape(extent matrix.Vec3) Shape

NewBoxShape

func NewBoxShape(extent matrix.Vec3) Shape

NewCapsuleShape

func NewCapsuleShape(radius, height matrix.Float) Shape

NewConeShape

func NewConeShape(radius, height matrix.Float) Shape

NewCylinderShape

func NewCylinderShape(radius, height matrix.Float) Shape

NewMeshShape

func NewMeshShape(bounds AABB) Shape

NewOOBBShape

func NewOOBBShape(extent matrix.Vec3) Shape

NewSphereShape

func NewSphereShape(radius matrix.Float) Shape

NewTerrainShape

func NewTerrainShape(bounds AABB) Shape

Shape.SetAABB

func (s *Shape) SetAABB(center, extent matrix.Vec3)

Shape.SetAABBShape

func (s *Shape) SetAABBShape(extent matrix.Vec3)

Shape.SetBoxShape

func (s *Shape) SetBoxShape(extent matrix.Vec3)

Shape.SetCapsule

func (s *Shape) SetCapsule(center matrix.Vec3, radius matrix.Float, height matrix.Float, direction matrix.Vec3)

Shape.SetCapsuleShape

func (s *Shape) SetCapsuleShape(radius, height matrix.Float)

Shape.SetCone

func (s *Shape) SetCone(center matrix.Vec3, radius matrix.Float, height matrix.Float, direction matrix.Vec3)

Shape.SetConeShape

func (s *Shape) SetConeShape(radius, height matrix.Float)

Shape.SetCylinder

func (s *Shape) SetCylinder(center matrix.Vec3, radius matrix.Float, height matrix.Float, direction matrix.Vec3)

Shape.SetCylinderShape

func (s *Shape) SetCylinderShape(radius, height matrix.Float)

Shape.SetMesh

func (s *Shape) SetMesh(bounds AABB)

Shape.SetOOBB

func (s *Shape) SetOOBB(center, extent matrix.Vec3, orientation matrix.Mat3)

Shape.SetOOBBShape

func (s *Shape) SetOOBBShape(extent matrix.Vec3)

Shape.SetSphere

func (s *Shape) SetSphere(center matrix.Vec3, radius matrix.Float)

Shape.SetSphereShape

func (s *Shape) SetSphereShape(radius matrix.Float)

Shape.SetTerrain

func (s *Shape) SetTerrain(bounds AABB)

ShapeType

uint8

type ShapeType uint8

const ( ShapeTypeSphere ShapeType = iota ShapeTypeAABB ShapeTypeOOBB ShapeTypeCapsule ShapeTypeCylinder ShapeTypeCone ShapeTypeMesh ShapeTypeTerrain )

SimulationState

struct

type SimulationState struct {
    Type            RigidBodyType
    SleepThreshold  matrix.Float
    SleepTimer      matrix.Float
    IsSleeping      bool
    IsFixedRotation bool
    IsFixedPosition bool

    // Has unexported fields.
}

Sphere

Shape

type Sphere Shape

NewSphere

func NewSphere(center matrix.Vec3, radius matrix.Float) Sphere

Sphere.IntersectsAABB

func (s Sphere) IntersectsAABB(b AABB) bool

Sphere.IntersectsCapsule

func (s Sphere) IntersectsCapsule(c Capsule) bool

Sphere.IntersectsCone

func (s Sphere) IntersectsCone(c Cone) bool

Sphere.IntersectsCylinder

func (s Sphere) IntersectsCylinder(c Cylinder) bool

Sphere.IntersectsFrustum

func (s Sphere) IntersectsFrustum(f Frustum) bool

Sphere.IntersectsOOBB

func (s Sphere) IntersectsOOBB(b OOBB) bool

Sphere.IntersectsPlane

func (s Sphere) IntersectsPlane(p Plane) (bool, float32)

Sphere.IntersectsRay

func (s Sphere) IntersectsRay(r Ray) (bool, float32)

Sphere.IntersectsSphere

func (a Sphere) IntersectsSphere(b Sphere) bool

SweepPrune

struct

type SweepPrune struct {
    // Has unexported fields.
}

SweepPrune.Initialize

func (s *SweepPrune) Initialize(initialBodyCount int)

SweepPrune.Rebuild

func (s *SweepPrune) Rebuild(bodies *pooling.PoolGroup[RigidBody])

SweepPrune.RebuildParallel

func (s *SweepPrune) RebuildParallel(bodies *pooling.PoolGroup[RigidBody], threads *concurrent.Threads)

SweepPrune.Sweep

func (s *SweepPrune) Sweep() []ActivePair

SweepPrune.SweepParallel

func (s *SweepPrune) SweepParallel(threads *concurrent.Threads, filter BroadPhaseFilter) []ActivePair

System

struct

type System struct {

    // Constraint iteration counts are shared by contact and constraint solving
    // because System.Step solves them together in the same islands.
    ConstraintVelocityIterations int
    ConstraintPositionIterations int

    // Has unexported fields.
}

System.AddBody

func (s *System) AddBody(body *RigidBody) *RigidBody

System.AddConstraint

func (s *System) AddConstraint(constraint *Constraint) *Constraint

System.AddConstraintWithBodies

func (s *System) AddConstraintWithBodies(constraint *Constraint, bodyA, bodyB *RigidBody) *Constraint

System.AddDistanceJoint

func (s *System) AddDistanceJoint(joint *DistanceJoint) *DistanceJoint

System.AddHingeJoint

func (s *System) AddHingeJoint(joint *HingeJoint) *HingeJoint

System.AddPointJoint

func (s *System) AddPointJoint(joint *PointJoint) *PointJoint

System.AddRopeJoint

func (s *System) AddRopeJoint(joint *RopeJoint) *RopeJoint

System.Clear

func (s *System) Clear()

System.ClearConstraints

func (s *System) ClearConstraints()

System.Constraints

func (s *System) Constraints() []*Constraint

Constraints returns the constraints currently stored in the System. The returned slice is owned by the System and is reused on the next constraints query or Step.

System.Contacts

func (s *System) Contacts() []ContactManifold

Contacts returns the contact manifolds generated during the most recent Step. The returned slice is owned by the System and is reused on the next Step.

System.Initialize

func (s *System) Initialize()

System.NewBody

func (s *System) NewBody() *RigidBody

System.NewConstraint

func (s *System) NewConstraint(constraintType ConstraintType, bodyA, bodyB *RigidBody) *Constraint

System.NewDistanceJoint

func (s *System) NewDistanceJoint(bodyA, bodyB *RigidBody, localAnchorA, localAnchorB matrix.Vec3) *DistanceJoint

System.NewDistanceJointAtWorldAnchors

func (s *System) NewDistanceJointAtWorldAnchors(bodyA, bodyB *RigidBody, worldAnchorA, worldAnchorB matrix.Vec3) *DistanceJoint

System.NewDistanceJointToWorld

func (s *System) NewDistanceJointToWorld(body *RigidBody, localAnchor, worldAnchor matrix.Vec3) *DistanceJoint

System.NewHingeJoint

func (s *System) NewHingeJoint(bodyA, bodyB *RigidBody, localAnchorA, localAnchorB, localAxisA, localAxisB matrix.Vec3) *HingeJoint

System.NewHingeJointAtWorldAnchor

func (s *System) NewHingeJointAtWorldAnchor(bodyA, bodyB *RigidBody, worldAnchor, worldAxis matrix.Vec3) *HingeJoint

System.NewHingeJointToWorld

func (s *System) NewHingeJointToWorld(body *RigidBody, localAnchor, worldAnchor, localAxis, worldAxis matrix.Vec3) *HingeJoint

System.NewPointJoint

func (s *System) NewPointJoint(bodyA, bodyB *RigidBody, localAnchorA, localAnchorB matrix.Vec3) *PointJoint

System.NewPointJointAtWorldAnchors

func (s *System) NewPointJointAtWorldAnchors(bodyA, bodyB *RigidBody, worldAnchorA, worldAnchorB matrix.Vec3) *PointJoint

System.NewPointJointToWorld

func (s *System) NewPointJointToWorld(body *RigidBody, localAnchor, worldAnchor matrix.Vec3) *PointJoint

System.NewRopeJoint

func (s *System) NewRopeJoint(bodyA, bodyB *RigidBody, localAnchorA, localAnchorB matrix.Vec3) *RopeJoint

System.NewRopeJointAtWorldAnchors

func (s *System) NewRopeJointAtWorldAnchors(bodyA, bodyB *RigidBody, worldAnchorA, worldAnchorB matrix.Vec3) *RopeJoint

System.NewRopeJointToWorld

func (s *System) NewRopeJointToWorld(body *RigidBody, localAnchor, worldAnchor matrix.Vec3) *RopeJoint

System.Raycast

func (s *System) Raycast(from, to matrix.Vec3) (Hit, bool)

System.RemoveBody

func (s *System) RemoveBody(body *RigidBody)

RemoveBody releases a body and disables any constraints attached to it. The disabled constraints remain in constraint storage until explicitly removed or cleared, with the removed body endpoint set to nil.

System.RemoveConstraint

func (s *System) RemoveConstraint(constraint *Constraint)

System.RemoveDistanceJoint

func (s *System) RemoveDistanceJoint(joint *DistanceJoint)

System.RemoveHingeJoint

func (s *System) RemoveHingeJoint(joint *HingeJoint)

System.RemovePointJoint

func (s *System) RemovePointJoint(joint *PointJoint)

System.RemoveRopeJoint

func (s *System) RemoveRopeJoint(joint *RopeJoint)

System.SetGravity

func (s *System) SetGravity(gravity matrix.Vec3)

System.SphereSweep

func (s *System) SphereSweep(from, to matrix.Vec3, radius matrix.Float) (Hit, bool)

System.Step

func (s *System) Step(workGroup *concurrent.WorkGroup, threads *concurrent.Threads, deltaTime float64)

TerrainCollision

struct

type TerrainCollision struct {
    Resolution int
    WorldSize  matrix.Vec2
    Heights    []matrix.Float
    MinHeight  matrix.Float
    MaxHeight  matrix.Float
    Bounds     AABB
}

NewTerrainCollision

func NewTerrainCollision(resolution int, worldSize matrix.Vec2, heights []matrix.Float, minHeight, maxHeight matrix.Float) (*TerrainCollision, error)

NewTerrainCollisionCopy

func NewTerrainCollisionCopy(resolution int, worldSize matrix.Vec2, heights []matrix.Float, minHeight, maxHeight matrix.Float) (*TerrainCollision, error)

TerrainCollision.CellRangeForLocalAABB

func (c *TerrainCollision) CellRangeForLocalAABB(bounds AABB) (minX, minZ, maxX, maxZ int, ok bool)

TerrainCollision.ForEachTriangleInLocalAABB

func (c *TerrainCollision) ForEachTriangleInLocalAABB(bounds AABB, visit func(DetailedTriangle) bool)

TerrainCollision.GridToLocal

func (c *TerrainCollision) GridToLocal(x, z matrix.Float) matrix.Vec3

TerrainCollision.Height

func (c *TerrainCollision) Height(x, z int) matrix.Float

TerrainCollision.HeightAtLocal

func (c *TerrainCollision) HeightAtLocal(localXZ matrix.Vec2) matrix.Float

TerrainCollision.LocalBounds

func (c *TerrainCollision) LocalBounds() AABB

TerrainCollision.LocalToGrid

func (c *TerrainCollision) LocalToGrid(localXZ matrix.Vec2) (matrix.Float, matrix.Float)

TerrainCollision.NormalAtLocal

func (c *TerrainCollision) NormalAtLocal(localXZ matrix.Vec2) matrix.Vec3

TerrainCollision.Raycast

func (c *TerrainCollision) Raycast(ray Ray, length matrix.Float, transform *matrix.Transform) (Hit, bool)

TerrainCollision.RefreshBounds

func (c *TerrainCollision) RefreshBounds() AABB

TerrainCollision.SampleGrid

func (c *TerrainCollision) SampleGrid(x, z matrix.Float) matrix.Float

Triangle

struct

type Triangle struct {
    P           Plane
    EdgePlaneBC Plane
    EdgePlaneCA Plane
}

TriangleBVH

struct

type TriangleBVH struct {
    Bounds      AABB
    Left        *TriangleBVH
    Right       *TriangleBVH
    Triangle    DetailedTriangle
    HasTriangle bool
}

NewTriangleBVH

func NewTriangleBVH(bvh *BVH) *TriangleBVH

TriangleBVH.ToBVH

func (b *TriangleBVH) ToBVH(transform *matrix.Transform, data any) *BVH