physics

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ImpulseIterationCount controls the number of iterations for impulse
	// solutions by the solvers.
	ImpulseIterationCount = 8

	// NudgeIterationCount controls the number of iterations for nudge
	// solutions by the solvers.
	NudgeIterationCount = 8

	// ImpulseDriftAdjustmentRatio controls the amount by which impulses should
	// try to correct positional drift.
	//
	// This is the `beta` coefficient in the Baumgarte stabilization approach.
	ImpulseDriftAdjustmentRatio = 0.2
	// NudgeDriftAdjustmentRatio controls the amount by which nudges should
	// try to correct positional drift.
	//
	// The value here is accumulated over all iterations. In fact, the total
	// remaining error is proportional to (1.0 - ratio) ^ iterations.
	//
	// Some error should be left in order to avoid jitters due to imprecise
	// integration of the correction and to leave some drift for the
	// impulse solution.
	NudgeDriftAdjustmentRatio = 0.2
)

Functions

func HollowSphereMomentOfInertia added in v0.10.0

func HollowSphereMomentOfInertia(mass, radius float64) dprec.Mat3

HollowSphereMomentOfInertia returns the moment of inertia of a hollow sphere with the specified mass and radius.

func NewCollisionGroup added in v0.10.0

func NewCollisionGroup() int

func SolidSphereMomentOfInertia added in v0.10.0

func SolidSphereMomentOfInertia(mass, radius float64) dprec.Mat3

SolidSphereMomentOfInertia returns the moment of inertia of a solid sphere with the specified mass and radius.

func SymmetricMomentOfInertia

func SymmetricMomentOfInertia(value float64) dprec.Mat3

SymmetricMomentOfInertia returns a moment of inertia tensor that represents a symmetric object across all axis.

Types

type AccelerationContext added in v0.10.0

type AccelerationContext struct {
}

type Accelerator added in v0.10.0

type Accelerator struct {
}

type AerodynamicShape

type AerodynamicShape struct {
	Transform
	// contains filtered or unexported fields
}

func NewAerodynamicShape added in v0.10.0

func NewAerodynamicShape(transform Transform, solver AerodynamicSolver) AerodynamicShape

func (AerodynamicShape) Transformed added in v0.10.0

func (p AerodynamicShape) Transformed(parent Transform) AerodynamicShape

Transformed returns a new Placement that is based on this one but has the specified transform applied to it.

type AerodynamicSolver added in v0.10.0

type AerodynamicSolver interface {
	Force(windSpeed dprec.Vec3) dprec.Vec3
}

AerodynamicSolver represents a shape that is affected by air or liquid motion and inflicts a force on the body.

type Body

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

Body represents a physical body that has physics act upon it.

func (*Body) AerodynamicShapes

func (b *Body) AerodynamicShapes() []AerodynamicShape

AerodynamicShapes returns a slice of shapes that dictate how this body is affected by relative air motion.

func (*Body) AngularDragFactor

func (b *Body) AngularDragFactor() float64

AngularDragFactor returns the angular drag factor for this body.

func (*Body) AngularVelocity

func (b *Body) AngularVelocity() dprec.Vec3

AngularVelocity returns the angular velocity of this body.

func (*Body) CollisionGroup added in v0.10.0

func (b *Body) CollisionGroup() int

CollisionGroup returns the collision group for this body. Two bodies with the same collision group are not checked for collisions.

func (*Body) CollisionSet added in v0.10.0

func (b *Body) CollisionSet() collision.Set

CollisionSet contains the collision shapes for this body.

func (*Body) Delete

func (b *Body) Delete()

Delete removes this physical body. The object should no longer be used after calling this method.

func (*Body) DragFactor

func (b *Body) DragFactor() float64

DragCoefficient returns the drag factor of this body.

func (*Body) Mass

func (b *Body) Mass() float64

Mass returns the mass of this body in kg.

func (*Body) MomentOfInertia

func (b *Body) MomentOfInertia() dprec.Mat3

MomentOfInertia returns the moment of inertia, or rotational inertia of this body.

func (*Body) Name

func (b *Body) Name() string

Name returns the name of this body.

func (*Body) Orientation

func (b *Body) Orientation() dprec.Quat

Orientation returns the quaternion rotation of this body.

func (*Body) Position

func (b *Body) Position() dprec.Vec3

Position returns the body's position in world space.

func (*Body) RestitutionCoefficient

func (b *Body) RestitutionCoefficient() float64

RestitutionCoefficient returns the restitution coefficient of this body. Valid values are in the range [0.0 - 1.0], where 0.0 means that the body does not bounce and 1.0 means that it bounds back with the same velocity. In reality the amount that the body will bounce depends on the restitution coefficients of both bodies colliding. Furthermore, due to computational errors, the bounce will eventually stop.

func (*Body) SetAerodynamicShapes

func (b *Body) SetAerodynamicShapes(shapes []AerodynamicShape)

SetAerodynamicShapes sets the aerodynamics shapes to be used when calculating wind drag and lift.

func (*Body) SetAngularDragFactor

func (b *Body) SetAngularDragFactor(factor float64)

SetAngularDragFactor sets the angular factor for this body. The angular factor is similar to the drag factor, except that it deals with the drag induced by the rotation of the body.

func (*Body) SetAngularVelocity

func (b *Body) SetAngularVelocity(angularVelocity dprec.Vec3)

SetAngularVelocity changes the angular velocity of this body.

func (*Body) SetCollisionGroup added in v0.10.0

func (b *Body) SetCollisionGroup(group int)

SetCollisionGroup changes the collision group for this body.

A value of 0 disables the collision group.

func (*Body) SetDragFactor

func (b *Body) SetDragFactor(factor float64)

SetDragFactor sets the drag factor for this body. The drag factor is the drag coefficient multiplied by the area and divided in half.

func (*Body) SetMass

func (b *Body) SetMass(mass float64)

SetMass changes the mass of this body.

func (*Body) SetMomentOfInertia

func (b *Body) SetMomentOfInertia(inertia dprec.Mat3)

SetMomentOfInertia changes the moment of inertia of this body.

func (*Body) SetName

func (b *Body) SetName(name string)

SetName sets a new name for this body.

func (*Body) SetOrientation

func (b *Body) SetOrientation(orientation dprec.Quat)

SetOrientation changes the quaterntion rotation of this body.

func (*Body) SetPosition

func (b *Body) SetPosition(position dprec.Vec3)

SetPosition changes the position of this body.

func (*Body) SetRestitutionCoefficient

func (b *Body) SetRestitutionCoefficient(coefficient float64)

SetRestitutionCoefficient changes the restitution coefficient for this body.

func (*Body) SetVelocity

func (b *Body) SetVelocity(velocity dprec.Vec3)

SetVelocity changes the velocity of this body.

func (*Body) Velocity

func (b *Body) Velocity() dprec.Vec3

Velocity returns the velocity of this body.

func (*Body) VisualOrientation added in v0.10.0

func (b *Body) VisualOrientation() dprec.Quat

VisualOrientation returns the orientation of the Body as would be seen by the current frame.

NOTE: The physics engine can advance past the current frame, which is the reason for this method.

func (*Body) VisualPosition added in v0.10.0

func (b *Body) VisualPosition() dprec.Vec3

VisualPosition returns the position of the Body as would be seen by the current frame.

NOTE: The physics engine can advance past the current frame, which is the reason for this method.

type BodyDefinition added in v0.9.0

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

func (*BodyDefinition) CollisionSet added in v0.10.0

func (d *BodyDefinition) CollisionSet() collision.Set

type BodyDefinitionInfo added in v0.9.0

type BodyDefinitionInfo struct {
	Mass                   float64
	MomentOfInertia        dprec.Mat3
	FrictionCoefficient    float64
	RestitutionCoefficient float64
	DragFactor             float64
	AngularDragFactor      float64
	CollisionGroup         int
	CollisionSpheres       []collision.Sphere
	CollisionBoxes         []collision.Box
	CollisionMeshes        []collision.Mesh
	AerodynamicShapes      []AerodynamicShape
}

type BodyInfo added in v0.9.0

type BodyInfo struct {
	Name       string
	Definition *BodyDefinition
	Position   dprec.Vec3
	Rotation   dprec.Quat
}

type ConstraintSet

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

ConstraintSet represents a set of constraints. This type is useful when multiple constraints need to be managed (enabled,disabled,deleted) in parallel.

func (*ConstraintSet) CreateDoubleBodyConstraint

func (s *ConstraintSet) CreateDoubleBodyConstraint(primary, secondary *Body, solver solver.PairConstraint) *DBConstraint

CreateDoubleBodyConstraint creates a new physics constraint that acts on two bodies and enables it for this scene.

Note: Constraints creates as part of this set should not be deleted individually.

func (*ConstraintSet) CreateSingleBodyConstraint

func (s *ConstraintSet) CreateSingleBodyConstraint(body *Body, solver solver.Constraint) *SBConstraint

CreateSingleBodyConstraint creates a new physics constraint that acts on a single body and stores it in this set.

Note: Constraints creates as part of this set should not be deleted individually.

func (*ConstraintSet) Delete

func (s *ConstraintSet) Delete()

Delete deletes all contained constraints and this set.

func (*ConstraintSet) Enabled

func (s *ConstraintSet) Enabled() bool

Enabled returns whether at least one of the constraints in this set is enabled.

func (*ConstraintSet) SetEnabled

func (s *ConstraintSet) SetEnabled(enabled bool)

SetEnabled changes the enabled state of all constraints in this set.

type DBConstraint

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

DBConstraint represents a restriction enforced two bodies in conjunction.

func (*DBConstraint) Delete

func (c *DBConstraint) Delete()

Delete removes this constraint.

func (*DBConstraint) Enabled

func (c *DBConstraint) Enabled() bool

Enabled returns whether this constraint will be enforced. By default a constraint is enabled.

func (*DBConstraint) PrimaryBody

func (c *DBConstraint) PrimaryBody() *Body

Primary returns the primary body on which this constraint acts.

func (*DBConstraint) SecondaryBody

func (c *DBConstraint) SecondaryBody() *Body

SecondaryBody returns the secondary body on which this constraint acts. If this is a single-body constraint, then this will be nil.

func (*DBConstraint) SetEnabled

func (c *DBConstraint) SetEnabled(enabled bool)

SetEnabled changes whether this constraint will be enforced.

func (*DBConstraint) Solution added in v0.10.0

func (c *DBConstraint) Solution() solver.PairConstraint

Solution returns the constraint solver that will be used to enforce mathematically this constraint.

type Engine

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

Engine is the entrypoint to working with a physics simulation.

func NewEngine

func NewEngine(timestep time.Duration) *Engine

NewEngine creates a new physics engine.

func (*Engine) CreateBodyDefinition added in v0.9.0

func (e *Engine) CreateBodyDefinition(info BodyDefinitionInfo) *BodyDefinition

CreateBodyDefinition creates a new BodyDefinition that can be used to create Body instances.

func (*Engine) CreateMaterial added in v0.10.0

func (e *Engine) CreateMaterial(info MaterialInfo) *Material

CreateMaterial creates a new Material that can be used to describe an object's behavior.

func (*Engine) CreateScene

func (e *Engine) CreateScene() *Scene

CreateScene creates a new Scene and configures the simulation for it to run at maximum stepSeconds intervals.

type Material added in v0.10.0

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

Material represents the surface properties of an object.

func (*Material) FrictionCoefficient added in v0.10.0

func (m *Material) FrictionCoefficient() float64

FrictionCoefficient returns the friction coefficient of this material.

func (*Material) RestitutionCoefficient added in v0.10.0

func (m *Material) RestitutionCoefficient() float64

RestitutionCoefficient returns the coefficient of restitution of this material.

func (*Material) SetFrictionCoefficient added in v0.10.0

func (m *Material) SetFrictionCoefficient(coefficient float64)

SetFrictionCoefficient changes the friction coefficient of this material.

func (*Material) SetRestitutionCoefficient added in v0.10.0

func (m *Material) SetRestitutionCoefficient(coefficient float64)

SetRestitutionCoefficient changes the coefficient of restitution of this material.

type MaterialInfo added in v0.10.0

type MaterialInfo struct {
	FrictionCoefficient    float64
	RestitutionCoefficient float64
}

MaterialInfo contains the data necessary to create a Material.

type Prop added in v0.10.0

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

type PropInfo added in v0.10.0

type PropInfo struct {
	CollisionSet collision.Set
}

type SBConstraint

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

SBConstraint represents a restriction enforced on one body.

func (*SBConstraint) Body

func (c *SBConstraint) Body() *Body

Body returns the body on which this constraint acts.

func (*SBConstraint) Delete

func (c *SBConstraint) Delete()

Delete removes this constraint.

func (*SBConstraint) Enabled

func (c *SBConstraint) Enabled() bool

Enabled returns whether this constraint will be enforced. By default a constraint is enabled.

func (*SBConstraint) SetEnabled

func (c *SBConstraint) SetEnabled(enabled bool)

SetEnabled changes whether this constraint will be enforced.

func (*SBConstraint) Solution added in v0.10.0

func (c *SBConstraint) Solution() solver.Constraint

Solution returns the constraint solver that will be used to enforce mathematically this constraint.

type Scene

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

Scene represents a physics scene that contains a number of bodies that are independent on any bodies managed by other scene objects.

func (*Scene) CreateBody

func (s *Scene) CreateBody(info BodyInfo) *Body

CreateBody creates a new physics body and places it within this scene.

func (*Scene) CreateConstraintSet

func (s *Scene) CreateConstraintSet() *ConstraintSet

CreateConstraintSet creates a new ConstraintSet.

func (*Scene) CreateDoubleBodyConstraint

func (s *Scene) CreateDoubleBodyConstraint(primary, secondary *Body, solver solver.PairConstraint) *DBConstraint

CreateDoubleBodyConstraint2 creates a new physics constraint that acts on two bodies and enables it for this scene.

func (*Scene) CreateProp added in v0.10.0

func (s *Scene) CreateProp(info PropInfo)

CreateProp creates a new static Prop. A prop is an object that is static and rarely removed.

func (*Scene) CreateSingleBodyConstraint

func (s *Scene) CreateSingleBodyConstraint(body *Body, solver solver.Constraint) *SBConstraint

CreateSingleBodyConstraint2 creates a new physics constraint that acts on a single body and enables it for this scene.

func (*Scene) Delete

func (s *Scene) Delete()

Delete releases resources allocated by this scene. Users should not call any further methods on this object.

func (*Scene) Each added in v0.10.0

func (s *Scene) Each(cb func(b *Body))

func (*Scene) Engine added in v0.9.0

func (s *Scene) Engine() *Engine

Engine returns the physics Engine that owns this Scene.

func (*Scene) Gravity

func (s *Scene) Gravity() dprec.Vec3

Gravity returns the gravity acceleration.

func (*Scene) Nearby added in v0.10.0

func (s *Scene) Nearby(body *Body, distance float64, cb func(b *Body))

func (*Scene) OnUpdate added in v0.14.0

func (s *Scene) OnUpdate(elapsedTime time.Duration)

TODO: Rename to Update and get rid of the old Update

func (*Scene) SetGravity

func (s *Scene) SetGravity(gravity dprec.Vec3)

SetGravity changes the gravity acceleration.

func (*Scene) SetTimeSpeed added in v0.10.0

func (s *Scene) SetTimeSpeed(timeSpeed float64)

SetTimeSpeed changes the rate at which time runs.

func (*Scene) SetWindDensity

func (s *Scene) SetWindDensity(density float64)

SetWindDensity changes the wind density.

func (*Scene) SetWindVelocity

func (s *Scene) SetWindVelocity(velocity dprec.Vec3)

SetWindVelocity sets the wind speed.

func (*Scene) TimeSpeed added in v0.10.0

func (s *Scene) TimeSpeed() float64

TimeSpeed returns the speed at which time runs, where 1.0 is the default and 0.0 is stopped.

func (*Scene) Update

func (s *Scene) Update(elapsedSeconds float64)

Update runs a number of physics iterations until the specified number of seconds worth of simulation have passed.

func (*Scene) WindDensity

func (s *Scene) WindDensity() float64

WindDensity returns the wind density.

func (*Scene) WindVelocity

func (s *Scene) WindVelocity() dprec.Vec3

WindVelocity returns the wind speed.

type SurfaceAerodynamicShape added in v0.10.0

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

func NewSurfaceAerodynamicShape added in v0.10.0

func NewSurfaceAerodynamicShape(width, height, length float64) *SurfaceAerodynamicShape

func (*SurfaceAerodynamicShape) BoundingSphereRadius added in v0.10.0

func (s *SurfaceAerodynamicShape) BoundingSphereRadius() float64

func (*SurfaceAerodynamicShape) Force added in v0.10.0

func (s *SurfaceAerodynamicShape) Force(windSpeed dprec.Vec3) dprec.Vec3

type Transform added in v0.10.0

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

Transform represents a shape transformation - translation and rotation.

func IdentityTransform added in v0.10.0

func IdentityTransform() Transform

IdentityTransform returns a new Transform that represents the origin.

func NewTransform added in v0.10.0

func NewTransform(position dprec.Vec3, rotation dprec.Quat) Transform

NewTransform creates a new Transform with the specified position and rotation.

func (Transform) Position added in v0.10.0

func (t Transform) Position() dprec.Vec3

Position returns the translation of this Transform.

func (Transform) Rotation added in v0.10.0

func (t Transform) Rotation() dprec.Quat

Rotation returns the orientation of this Transform.

func (Transform) Transformed added in v0.10.0

func (t Transform) Transformed(transform Transform) Transform

Transformed returns a new Transform that is based on this one but has the specified Transform applied to it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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