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 AccelerationContext
- type Accelerator
- type AerodynamicShape
- type AerodynamicSolver
- type Body
- func (b *Body) AerodynamicShapes() []AerodynamicShape
- func (b *Body) AngularDragFactor() float64
- func (b *Body) AngularVelocity() dprec.Vec3
- func (b *Body) CollisionGroup() int
- func (b *Body) CollisionSet() collision.Set
- func (b *Body) Delete()
- func (b *Body) DragFactor() float64
- func (b *Body) Mass() float64
- func (b *Body) MomentOfInertia() dprec.Mat3
- func (b *Body) Name() string
- func (b *Body) Orientation() dprec.Quat
- func (b *Body) Position() dprec.Vec3
- func (b *Body) RestitutionCoefficient() float64
- func (b *Body) SetAerodynamicShapes(shapes []AerodynamicShape)
- func (b *Body) SetAngularDragFactor(factor float64)
- func (b *Body) SetAngularVelocity(angularVelocity dprec.Vec3)
- func (b *Body) SetCollisionGroup(group int)
- func (b *Body) SetDragFactor(factor float64)
- func (b *Body) SetMass(mass float64)
- func (b *Body) SetMomentOfInertia(inertia dprec.Mat3)
- func (b *Body) SetName(name string)
- func (b *Body) SetOrientation(orientation dprec.Quat)
- func (b *Body) SetPosition(position dprec.Vec3)
- func (b *Body) SetRestitutionCoefficient(coefficient float64)
- func (b *Body) SetVelocity(velocity dprec.Vec3)
- func (b *Body) Velocity() dprec.Vec3
- func (b *Body) VisualOrientation() dprec.Quat
- func (b *Body) VisualPosition() 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 Engine
- type Material
- type MaterialInfo
- 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, solver solver.PairConstraint) *DBConstraint
- func (s *Scene) CreateProp(info PropInfo)
- func (s *Scene) CreateSingleBodyConstraint(body *Body, solver solver.Constraint) *SBConstraint
- func (s *Scene) Delete()
- func (s *Scene) Each(cb func(b *Body))
- func (s *Scene) Engine() *Engine
- func (s *Scene) Gravity() dprec.Vec3
- func (s *Scene) Nearby(body *Body, distance float64, cb func(b *Body))
- func (s *Scene) OnUpdate(elapsedTime time.Duration)
- func (s *Scene) SetGravity(gravity dprec.Vec3)
- func (s *Scene) SetTimeSpeed(timeSpeed float64)
- func (s *Scene) SetWindDensity(density float64)
- func (s *Scene) SetWindVelocity(velocity dprec.Vec3)
- func (s *Scene) TimeSpeed() float64
- func (s *Scene) Update(elapsedSeconds float64)
- func (s *Scene) WindDensity() float64
- func (s *Scene) WindVelocity() dprec.Vec3
- type SurfaceAerodynamicShape
- type Transform
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 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
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 ¶
AngularDragFactor returns the angular drag factor for this body.
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) Delete ¶
func (b *Body) Delete()
Delete removes this physical body. The object should no longer be used after calling this method.
func (*Body) DragFactor ¶
DragCoefficient returns the drag factor of this body.
func (*Body) MomentOfInertia ¶
MomentOfInertia returns the moment of inertia, or rotational inertia of this body.
func (*Body) Orientation ¶
Orientation returns the quaternion rotation of this body.
func (*Body) RestitutionCoefficient ¶
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 ¶
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 ¶
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) SetDragFactor ¶
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) SetMomentOfInertia ¶
SetMomentOfInertia changes the moment of inertia of this body.
func (*Body) SetOrientation ¶
SetOrientation changes the quaterntion rotation of this body.
func (*Body) SetPosition ¶
SetPosition changes the position of this body.
func (*Body) SetRestitutionCoefficient ¶
SetRestitutionCoefficient changes the restitution coefficient for this body.
func (*Body) SetVelocity ¶
SetVelocity changes the velocity of this body.
func (*Body) VisualOrientation ¶ added in v0.10.0
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
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 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) 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 (*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 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 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) 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 ¶
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
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) SetGravity ¶
SetGravity changes the gravity acceleration.
func (*Scene) SetTimeSpeed ¶ added in v0.10.0
SetTimeSpeed changes the rate at which time runs.
func (*Scene) SetWindDensity ¶
SetWindDensity changes the wind density.
func (*Scene) SetWindVelocity ¶
SetWindVelocity sets the wind speed.
func (*Scene) TimeSpeed ¶ added in v0.10.0
TimeSpeed returns the speed at which time runs, where 1.0 is the default and 0.0 is stopped.
func (*Scene) Update ¶
Update runs a number of physics iterations until the specified number of seconds worth of simulation have passed.
func (*Scene) WindDensity ¶
WindDensity returns the wind density.
func (*Scene) WindVelocity ¶
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
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.