Documentation ¶
Index ¶
- Variables
- func HollowSphereMomentOfInertia(mass, radius float64) dprec.Mat3
- func NewCollisionGroup() int
- func SolidSphereMomentOfInertia(mass, radius float64) dprec.Mat3
- func SymmetricMomentOfInertia(value float64) dprec.Mat3
- type AerodynamicShape
- type AerodynamicSolver
- type Body
- func (b Body) AngularVelocity() dprec.Vec3
- func (b Body) CollisionGroup() int
- func (b Body) CollisionSet() collision.Set
- func (b Body) Delete()
- func (b Body) IntermediatePosition() dprec.Vec3
- func (b Body) IntermediateRotation() dprec.Quat
- func (b Body) Mass() float64
- func (b Body) MomentOfInertia() dprec.Mat3
- func (b Body) Name() string
- func (b Body) Position() dprec.Vec3
- func (b Body) Rotation() dprec.Quat
- func (b Body) SetAngularVelocity(angularVelocity dprec.Vec3)
- func (b Body) SetCollisionGroup(group int)
- func (b Body) SetMass(mass float64)
- func (b Body) SetMomentOfInertia(inertia dprec.Mat3)
- func (b Body) SetName(name string)
- func (b Body) SetPosition(position dprec.Vec3)
- func (b Body) SetRotation(rotation dprec.Quat)
- func (b Body) SetVelocity(velocity dprec.Vec3)
- func (b Body) Velocity() dprec.Vec3
- type BodyDefinition
- type BodyDefinitionInfo
- type BodyInfo
- type ConstraintSet
- func (s *ConstraintSet) CreateDoubleBodyConstraint(primary, secondary Body, solver solver.PairConstraint) DBConstraint
- func (s *ConstraintSet) CreateSingleBodyConstraint(body Body, solver solver.Constraint) SBConstraint
- func (s *ConstraintSet) Delete()
- func (s *ConstraintSet) Enabled() bool
- func (s *ConstraintSet) SetEnabled(enabled bool)
- type DBConstraint
- type DoubleBodyCollisionCallback
- type DoubleBodyCollisionSubscription
- type DoubleBodyCollisionSubscriptionSet
- type Engine
- type GlobalAccelerator
- type Material
- type MaterialInfo
- type Option
- type Prop
- type PropInfo
- type SBConstraint
- type Scene
- func (s *Scene) CreateBody(info BodyInfo) Body
- func (s *Scene) CreateConstraintSet() *ConstraintSet
- func (s *Scene) CreateDoubleBodyConstraint(primary, secondary Body, logic solver.PairConstraint) DBConstraint
- func (s *Scene) CreateGlobalAccelerator(logic solver.Acceleration) GlobalAccelerator
- func (s *Scene) CreateProp(info PropInfo)
- func (s *Scene) CreateSingleBodyConstraint(body Body, logic solver.Constraint) SBConstraint
- func (s *Scene) Delete()
- func (s *Scene) Each(cb func(b Body))
- func (s *Scene) Engine() *Engine
- func (s *Scene) MaxAngularAcceleration() float64
- func (s *Scene) MaxLinearAcceleration() float64
- func (s *Scene) MediumSolver() solver.Medium
- func (s *Scene) Nearby(body Body, distance float64, cb func(b Body))
- func (s *Scene) SetMaxAngularAcceleration(acceleration float64)
- func (s *Scene) SetMaxLinearAcceleration(acceleration float64)
- func (s *Scene) SetMediumSolver(solver solver.Medium)
- func (s *Scene) SetTimeSpeed(timeSpeed float64)
- func (s *Scene) SubscribeDoubleBodyCollision(callback DoubleBodyCollisionCallback) *DoubleBodyCollisionSubscription
- func (s *Scene) SubscribePostUpdate(callback UpdateCallback) *UpdateSubscription
- func (s *Scene) SubscribePreUpdate(callback UpdateCallback) *UpdateSubscription
- func (s *Scene) SubscribeSingleBodyCollision(callback SingleBodyCollisionCallback) *SingleBodyCollisionSubscription
- func (s *Scene) TimeSpeed() float64
- func (s *Scene) Update(elapsedTime time.Duration)
- type SingleBodyCollisionCallback
- type SingleBodyCollisionSubscription
- type SingleBodyCollisionSubscriptionSet
- type SurfaceAerodynamicShape
- func (s *SurfaceAerodynamicShape) BoundingSphereRadius() float64
- func (s *SurfaceAerodynamicShape) Force(windSpeed dprec.Vec3, density float64) dprec.Vec3
- func (s *SurfaceAerodynamicShape) SetDragCoefficient(coefficient float64) *SurfaceAerodynamicShape
- func (s *SurfaceAerodynamicShape) SetLiftCoefficient(coefficient float64) *SurfaceAerodynamicShape
- type Transform
- type UpdateCallback
- type UpdateSubscription
- type UpdateSubscriptionSet
Constants ¶
This section is empty.
Variables ¶
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
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
SolidSphereMomentOfInertia returns the moment of inertia of a solid sphere with the specified mass and radius.
func SymmetricMomentOfInertia ¶
SymmetricMomentOfInertia returns a moment of inertia tensor that represents a symmetric object across all axis.
Types ¶
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
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) AngularVelocity ¶
AngularVelocity returns the angular velocity of this body.
func (Body) CollisionGroup ¶ added in v0.10.0
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
CollisionSet contains the collision shapes for this body.
func (Body) IntermediatePosition ¶ added in v0.18.0
IntermediatePosition 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.
func (Body) IntermediateRotation ¶ added in v0.18.0
IntermediateRotation returns the rotation 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) MomentOfInertia ¶
MomentOfInertia returns the moment of inertia, or rotational inertia of this body.
func (Body) SetAngularVelocity ¶
SetAngularVelocity changes the angular velocity of this body.
func (Body) SetCollisionGroup ¶ added in v0.10.0
SetCollisionGroup changes the collision group for this body.
A value of 0 disables the collision group.
func (Body) SetMomentOfInertia ¶
SetMomentOfInertia changes the moment of inertia of this body.
func (Body) SetPosition ¶
SetPosition changes the position of this body.
func (Body) SetRotation ¶ added in v0.18.0
SetRotation changes the quaterntion rotation of this body.
func (Body) SetVelocity ¶
SetVelocity changes the velocity of this body.
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 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) as a single unit.
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 on two bodies in conjunction.
func (DBConstraint) Enabled ¶
func (c DBConstraint) Enabled() bool
Enabled returns whether this constraint will be enforced.
func (DBConstraint) Logic ¶ added in v0.18.0
func (c DBConstraint) Logic() solver.PairConstraint
Logic returns the constraint solver that will be used to enforce mathematically this constraint.
func (DBConstraint) PrimaryBody ¶
func (c DBConstraint) PrimaryBody() Body
PrimaryBody 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.
func (DBConstraint) SetEnabled ¶
func (c DBConstraint) SetEnabled(enabled bool)
SetEnabled changes whether this constraint will be enforced.
type DoubleBodyCollisionCallback ¶ added in v0.18.0
DoubleBodyCollisionCallback is a mechanism to receive notifications about collisions between two bodies.
type DoubleBodyCollisionSubscription ¶ added in v0.18.0
type DoubleBodyCollisionSubscription = observer.Subscription[DoubleBodyCollisionCallback]
DoubleBodyCollisionSubscription represents a notification subscription for double body collisions.
type DoubleBodyCollisionSubscriptionSet ¶ added in v0.18.0
type DoubleBodyCollisionSubscriptionSet = observer.SubscriptionSet[DoubleBodyCollisionCallback]
DoubleBodyCollisionSubscriptionSet represents a set of double body collision subscriptions.
func NewDoubleBodyCollisionSubscriptionSet ¶ added in v0.18.0
func NewDoubleBodyCollisionSubscriptionSet() *DoubleBodyCollisionSubscriptionSet
NewDoubleBodyCollisionSubscriptionSet creates a new DoubleBodyCollisionSubscriptionSet.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the entrypoint to working with a physics simulation.
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 ¶
CreateScene creates a new Scene and configures the simulation for it to run at maximum stepSeconds intervals.
type GlobalAccelerator ¶ added in v0.18.0
type GlobalAccelerator struct {
// contains filtered or unexported fields
}
GlobalAccelerator represents a force that is applied to all bodies in the scene.
func (GlobalAccelerator) Delete ¶ added in v0.18.0
func (a GlobalAccelerator) Delete()
Delete removes this global accelerator.
func (GlobalAccelerator) Enabled ¶ added in v0.18.0
func (a GlobalAccelerator) Enabled() bool
Enabled returns whether this global accelerator will be applied.
func (GlobalAccelerator) Logic ¶ added in v0.18.0
func (a GlobalAccelerator) Logic() solver.Acceleration
Logic returns the acceleration solver that will be used to apply this global accelerator.
func (GlobalAccelerator) SetEnabled ¶ added in v0.18.0
func (a GlobalAccelerator) SetEnabled(enabled bool)
SetEnabled changes whether this global accelerator will be applied.
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
FrictionCoefficient returns the friction coefficient of this material.
func (*Material) RestitutionCoefficient ¶ added in v0.10.0
RestitutionCoefficient returns the coefficient of restitution of this material.
func (*Material) SetFrictionCoefficient ¶ added in v0.10.0
SetFrictionCoefficient changes the friction coefficient of this material.
func (*Material) SetRestitutionCoefficient ¶ added in v0.10.0
SetRestitutionCoefficient changes the coefficient of restitution of this material.
type MaterialInfo ¶ added in v0.10.0
MaterialInfo contains the data necessary to create a Material.
type Option ¶ added in v0.20.0
type Option func(c *config)
Option is a configuration function that can be used to customize the behavior of a physics engine.
func WithTimestep ¶ added in v0.20.0
WithTimestep configures the physics engine to use the provided timestep.
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) Enabled ¶
func (c SBConstraint) Enabled() bool
Enabled returns whether this constraint will be enforced. By default a constraint is enabled.
func (SBConstraint) Logic ¶ added in v0.18.0
func (c SBConstraint) Logic() solver.Constraint
Logic returns the constraint solver that will be used to enforce mathematically this constraint.
func (SBConstraint) SetEnabled ¶
func (c SBConstraint) SetEnabled(enabled bool)
SetEnabled changes whether this constraint will be enforced.
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 ¶
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, logic solver.PairConstraint) DBConstraint
CreateDoubleBodyConstraint creates a new physics constraint that acts on two bodies and enables it for this scene.
func (*Scene) CreateGlobalAccelerator ¶ added in v0.18.0
func (s *Scene) CreateGlobalAccelerator(logic solver.Acceleration) GlobalAccelerator
CreateGlobalAccelerator creates a new accelerator that affects the whole scene.
func (*Scene) CreateProp ¶ added in v0.10.0
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, logic solver.Constraint) SBConstraint
CreateSingleBodyConstraint 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) MaxAngularAcceleration ¶ added in v0.18.0
MaxAngularAcceleration returns the maximum angular acceleration that a body can have.
func (*Scene) MaxLinearAcceleration ¶ added in v0.18.0
MaxLinearAcceleration returns the maximum linear acceleration that a body can have.
func (*Scene) MediumSolver ¶ added in v0.18.0
MediumSolver returns the solver that is used to calculate the medium properties of the scene.
func (*Scene) SetMaxAngularAcceleration ¶ added in v0.18.0
SetMaxAngularAcceleration changes the maximum angular acceleration that a body can have.
func (*Scene) SetMaxLinearAcceleration ¶ added in v0.18.0
SetMaxLinearAcceleration changes the maximum linear acceleration that a body can have.
func (*Scene) SetMediumSolver ¶ added in v0.18.0
SetMediumSolver changes the solver that is used to calculate the medium properties of the scene.
func (*Scene) SetTimeSpeed ¶ added in v0.10.0
SetTimeSpeed changes the rate at which time runs.
func (*Scene) SubscribeDoubleBodyCollision ¶ added in v0.18.0
func (s *Scene) SubscribeDoubleBodyCollision(callback DoubleBodyCollisionCallback) *DoubleBodyCollisionSubscription
SubscribeDoubleBodyCollision registers a callback that is invoked when two bodies collide.
func (*Scene) SubscribePostUpdate ¶ added in v0.18.0
func (s *Scene) SubscribePostUpdate(callback UpdateCallback) *UpdateSubscription
SubscribePostUpdate registers a callback that is invoked after each physics iteration.
func (*Scene) SubscribePreUpdate ¶ added in v0.18.0
func (s *Scene) SubscribePreUpdate(callback UpdateCallback) *UpdateSubscription
SubscribePreUpdate registers a callback that is invoked before each physics iteration.
func (*Scene) SubscribeSingleBodyCollision ¶ added in v0.18.0
func (s *Scene) SubscribeSingleBodyCollision(callback SingleBodyCollisionCallback) *SingleBodyCollisionSubscription
SubscribeSingleBodyCollision registers a callback that is invoked when a body collides with a static object.
type SingleBodyCollisionCallback ¶ added in v0.18.0
SingleBodyCollisionCallback is a mechanism to receive notifications about collisions between a body and a prop in the scene.
type SingleBodyCollisionSubscription ¶ added in v0.18.0
type SingleBodyCollisionSubscription = observer.Subscription[SingleBodyCollisionCallback]
SingleBodyCollisionSubscription represents a notification subscription for single body collisions.
type SingleBodyCollisionSubscriptionSet ¶ added in v0.18.0
type SingleBodyCollisionSubscriptionSet = observer.SubscriptionSet[SingleBodyCollisionCallback]
SingleBodyCollisionSubscriptionSet represents a set of single body collision subscriptions.
func NewSingleBodyCollisionSubscriptionSet ¶ added in v0.18.0
func NewSingleBodyCollisionSubscriptionSet() *SingleBodyCollisionSubscriptionSet
NewSingleBodyCollisionSubscriptionSet creates a new SingleBodyCollisionSubscriptionSet.
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) SetDragCoefficient ¶ added in v0.18.0
func (s *SurfaceAerodynamicShape) SetDragCoefficient(coefficient float64) *SurfaceAerodynamicShape
func (*SurfaceAerodynamicShape) SetLiftCoefficient ¶ added in v0.18.0
func (s *SurfaceAerodynamicShape) SetLiftCoefficient(coefficient float64) *SurfaceAerodynamicShape
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
NewTransform creates a new Transform with the specified position and rotation.
func (Transform) Transformed ¶ added in v0.10.0
Transformed returns a new Transform that is based on this one but has the specified Transform applied to it.
type UpdateCallback ¶ added in v0.18.0
UpdateCallback is a mechanism to receive update notifications.
type UpdateSubscription ¶ added in v0.18.0
type UpdateSubscription = observer.Subscription[UpdateCallback]
UpdateSubscription represents a notification subscription for updates.
type UpdateSubscriptionSet ¶ added in v0.18.0
type UpdateSubscriptionSet = observer.SubscriptionSet[UpdateCallback]
UpdateSubscriptionSet represents a set of update subscriptions.
func NewUpdateSubscriptionSet ¶ added in v0.18.0
func NewUpdateSubscriptionSet() *UpdateSubscriptionSet
NewUpdateSubscriptionSet creates a new UpdateSubscriptionSet.