Documentation ¶
Index ¶
- func SymmetricMomentOfInertia(value float32) sprec.Mat3
- type AerodynamicShape
- type Body
- func (b *Body) AerodynamicShapes() []AerodynamicShape
- func (b *Body) AngularDragFactor() float32
- func (b *Body) AngularVelocity() sprec.Vec3
- func (b *Body) CollisionShapes() []CollisionShape
- func (b *Body) Delete()
- func (b *Body) DragFactor() float32
- func (b *Body) Mass() float32
- func (b *Body) MomentOfInertia() sprec.Mat3
- func (b *Body) Name() string
- func (b *Body) Orientation() sprec.Quat
- func (b *Body) Position() sprec.Vec3
- func (b *Body) RestitutionCoefficient() float32
- func (b *Body) SetAerodynamicShapes(shapes []AerodynamicShape)
- func (b *Body) SetAngularDragFactor(factor float32)
- func (b *Body) SetAngularVelocity(angularVelocity sprec.Vec3)
- func (b *Body) SetCollisionShapes(shapes []CollisionShape)
- func (b *Body) SetDragFactor(factor float32)
- func (b *Body) SetMass(mass float32)
- func (b *Body) SetMomentOfInertia(inertia sprec.Mat3)
- func (b *Body) SetName(name string)
- func (b *Body) SetOrientation(orientation sprec.Quat)
- func (b *Body) SetPosition(position sprec.Vec3)
- func (b *Body) SetRestitutionCoefficient(coefficient float32)
- func (b *Body) SetStatic(static bool)
- func (b *Body) SetVelocity(velocity sprec.Vec3)
- func (b *Body) Static() bool
- func (b *Body) Velocity() sprec.Vec3
- type CollisionShape
- type ConstraintSet
- func (s *ConstraintSet) CreateDoubleBodyConstraint(primary, secondary *Body, solver DBConstraintSolver) *DBConstraint
- func (s *ConstraintSet) CreateSingleBodyConstraint(body *Body, solver SBConstraintSolver) *SBConstraint
- func (s *ConstraintSet) Delete()
- func (s *ConstraintSet) Enabled() bool
- func (s *ConstraintSet) SetEnabled(enabled bool)
- type DBCalculateFunc
- type DBConstraint
- type DBConstraintSolver
- type DBImpulseSolution
- type DBJacobianConstraintSolver
- type DBNudgeSolution
- type DBSolverContext
- type Engine
- type Jacobian
- func (j Jacobian) EffectiveVelocity(body *Body) float32
- func (j Jacobian) ImpulseLambda(body *Body) float32
- func (j Jacobian) ImpulseSolution(body *Body, lambda float32) SBImpulseSolution
- func (j Jacobian) InverseEffectiveMass(body *Body) float32
- func (j Jacobian) NudgeLambda(body *Body, drift float32) float32
- func (j Jacobian) NudgeSolution(body *Body, lambda float32) SBNudgeSolution
- type NilDBConstraintSolver
- type NilSBConstraintSolver
- type PairJacobian
- func (j PairJacobian) EffectiveVelocity(primary, secondary *Body) float32
- func (j PairJacobian) ImpulseLambda(primary, secondary *Body) float32
- func (j PairJacobian) ImpulseSolution(primary, secondary *Body, lambda float32) DBImpulseSolution
- func (j PairJacobian) InverseEffectiveMass(primary, secondary *Body) float32
- func (j PairJacobian) NudgeLambda(primary, secondary *Body, drift float32) float32
- func (j PairJacobian) NudgeSolution(primary, secondary *Body, lambda float32) DBNudgeSolution
- type SBCalculateFunc
- type SBConstraint
- type SBConstraintSolver
- type SBImpulseSolution
- type SBJacobianConstraintSolver
- type SBNudgeSolution
- type SBSolverContext
- type Scene
- func (s *Scene) CreateBody() *Body
- func (s *Scene) CreateConstraintSet() *ConstraintSet
- func (s *Scene) CreateDoubleBodyConstraint(primary, secondary *Body, solver DBConstraintSolver) *DBConstraint
- func (s *Scene) CreateSingleBodyConstraint(body *Body, solver SBConstraintSolver) *SBConstraint
- func (s *Scene) Delete()
- func (s *Scene) Gravity() sprec.Vec3
- func (s *Scene) SetGravity(gravity sprec.Vec3)
- func (s *Scene) SetWindDensity(density float32)
- func (s *Scene) SetWindVelocity(velocity sprec.Vec3)
- func (s *Scene) Update(elapsedSeconds float32)
- func (s *Scene) WindDensity() float32
- func (s *Scene) WindVelocity() sprec.Vec3
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SymmetricMomentOfInertia ¶
SymmetricMomentOfInertia returns a moment of inertia tensor that represents a symmetric object across all axis.
Types ¶
type AerodynamicShape ¶
type AerodynamicShape interface{}
AerodynamicShape 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) CollisionShapes ¶
func (b *Body) CollisionShapes() []CollisionShape
CollisionShapes returns a slice of shapes that dictate how this body collides with others.
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) SetCollisionShapes ¶
func (b *Body) SetCollisionShapes(shapes []CollisionShape)
SetCollisionShapes sets the collision shapes for this body to be used in collision detection.
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.
type CollisionShape ¶
type CollisionShape interface{}
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 DBConstraintSolver) *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 SBConstraintSolver) *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 DBCalculateFunc ¶
type DBCalculateFunc func(DBSolverContext) (PairJacobian, float32)
DBCalculateFunc is a function that calculates a jacobian for a double body constraint.
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) Solver ¶
func (c *DBConstraint) Solver() DBConstraintSolver
Solver returns the constraint solver that will be used to enforce mathematically this constraint.
type DBConstraintSolver ¶
type DBConstraintSolver interface { // Reset clears the internal cache state for this constraint solver. // This is called at the start of every iteration. Reset(ctx DBSolverContext) // CalculateImpulses returns a set of impulses to be applied // to the two bodies. CalculateImpulses(ctx DBSolverContext) DBImpulseSolution // CalculateNudges returns a set of nudges to be applied // to the two bodies. CalculateNudges(ctx DBSolverContext) DBNudgeSolution }
DBConstraintSolver represents the algorithm necessary to enforce a double-body constraint.
type DBImpulseSolution ¶
type DBImpulseSolution struct { Primary SBImpulseSolution Secondary SBImpulseSolution }
DBImpulseSolution is a solution to a constraint that indicates the impulses that need to be applied to the primary body and optionally (if the body is not nil) secondary body.
type DBJacobianConstraintSolver ¶
type DBJacobianConstraintSolver struct {
// contains filtered or unexported fields
}
DBJacobianConstraintSolver is a helper implementation of DBConstraintSolver that is based on a Jacobian.
func NewDBJacobianConstraintSolver ¶
func NewDBJacobianConstraintSolver(calculate DBCalculateFunc) *DBJacobianConstraintSolver
NewDBJacobianConstraintSolver returns a new DBJacobianConstraintSolver based on the specified calculate function.
func (*DBJacobianConstraintSolver) CalculateImpulses ¶
func (s *DBJacobianConstraintSolver) CalculateImpulses(ctx DBSolverContext) DBImpulseSolution
func (*DBJacobianConstraintSolver) CalculateNudges ¶
func (s *DBJacobianConstraintSolver) CalculateNudges(ctx DBSolverContext) DBNudgeSolution
func (*DBJacobianConstraintSolver) Reset ¶
func (s *DBJacobianConstraintSolver) Reset(DBSolverContext)
type DBNudgeSolution ¶
type DBNudgeSolution struct { Primary SBNudgeSolution Secondary SBNudgeSolution }
DBNudgeSolution is a solution to a constraint that indicates the nudges that need to be applied to the primary body and optionally (if the body is not nil) secondary body.
type DBSolverContext ¶
DBSolverContext contains information related to the double-body constraint processing.
type Engine ¶
type Engine struct{}
Engine is the entrypoint to working with a physics simulation.
func (*Engine) CreateScene ¶
CreateScene creates a new Scene and configures the simulation for it to run at maximum stepSeconds intervals.
type Jacobian ¶
func (Jacobian) EffectiveVelocity ¶
func (Jacobian) ImpulseLambda ¶
func (Jacobian) ImpulseSolution ¶
func (j Jacobian) ImpulseSolution(body *Body, lambda float32) SBImpulseSolution
func (Jacobian) InverseEffectiveMass ¶
func (Jacobian) NudgeSolution ¶
func (j Jacobian) NudgeSolution(body *Body, lambda float32) SBNudgeSolution
type NilDBConstraintSolver ¶
type NilDBConstraintSolver struct{}
NilConstraintSolver is a DBConstraintSolver that does nothing.
func (*NilDBConstraintSolver) CalculateImpulses ¶
func (s *NilDBConstraintSolver) CalculateImpulses(DBSolverContext) DBImpulseSolution
func (*NilDBConstraintSolver) CalculateNudges ¶
func (s *NilDBConstraintSolver) CalculateNudges(DBSolverContext) DBNudgeSolution
func (*NilDBConstraintSolver) Reset ¶
func (s *NilDBConstraintSolver) Reset(DBSolverContext)
type NilSBConstraintSolver ¶
type NilSBConstraintSolver struct{}
NilConstraintSolver is an SBConstraintSolver that does nothing.
func (*NilSBConstraintSolver) CalculateImpulses ¶
func (s *NilSBConstraintSolver) CalculateImpulses(SBSolverContext) SBImpulseSolution
func (*NilSBConstraintSolver) CalculateNudges ¶
func (s *NilSBConstraintSolver) CalculateNudges(SBSolverContext) SBNudgeSolution
func (*NilSBConstraintSolver) Reset ¶
func (s *NilSBConstraintSolver) Reset(SBSolverContext)
type PairJacobian ¶
func (PairJacobian) EffectiveVelocity ¶
func (j PairJacobian) EffectiveVelocity(primary, secondary *Body) float32
func (PairJacobian) ImpulseLambda ¶
func (j PairJacobian) ImpulseLambda(primary, secondary *Body) float32
func (PairJacobian) ImpulseSolution ¶
func (j PairJacobian) ImpulseSolution(primary, secondary *Body, lambda float32) DBImpulseSolution
func (PairJacobian) InverseEffectiveMass ¶
func (j PairJacobian) InverseEffectiveMass(primary, secondary *Body) float32
func (PairJacobian) NudgeLambda ¶
func (j PairJacobian) NudgeLambda(primary, secondary *Body, drift float32) float32
func (PairJacobian) NudgeSolution ¶
func (j PairJacobian) NudgeSolution(primary, secondary *Body, lambda float32) DBNudgeSolution
type SBCalculateFunc ¶
type SBCalculateFunc func(SBSolverContext) (Jacobian, float32)
SBCalculateFunc is a function that calculates a jacobian for a single body constraint.
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) Solver ¶
func (c *SBConstraint) Solver() SBConstraintSolver
Solver returns the constraint solver that will be used to enforce mathematically this constraint.
type SBConstraintSolver ¶
type SBConstraintSolver interface { // Reset clears the internal cache state for this constraint solver. // This is called at the start of every iteration. Reset(ctx SBSolverContext) // CalculateImpulses returns a set of impulses to be applied // to the body. CalculateImpulses(ctx SBSolverContext) SBImpulseSolution // CalculateNudges returns a set of nudges to be applied // to the body. CalculateNudges(ctx SBSolverContext) SBNudgeSolution }
SBConstraintSolver represents the algorithm necessary to enforce a single-body constraint.
type SBImpulseSolution ¶
SBImpulseSolution is a solution to a single-body constraint that contains the impulses that need to be applied to the body.
type SBJacobianConstraintSolver ¶
type SBJacobianConstraintSolver struct {
// contains filtered or unexported fields
}
SBJacobianConstraintSolver is a helper implementation of SBConstraintSolver that is based on a Jacobian.
func NewSBJacobianConstraintSolver ¶
func NewSBJacobianConstraintSolver(calculate SBCalculateFunc) *SBJacobianConstraintSolver
NewSBJacobianConstraintSolver returns a new SBJacobianConstraintSolver based on the specified calculate function.
func (*SBJacobianConstraintSolver) CalculateImpulses ¶
func (s *SBJacobianConstraintSolver) CalculateImpulses(ctx SBSolverContext) SBImpulseSolution
func (*SBJacobianConstraintSolver) CalculateNudges ¶
func (s *SBJacobianConstraintSolver) CalculateNudges(ctx SBSolverContext) SBNudgeSolution
func (*SBJacobianConstraintSolver) Reset ¶
func (s *SBJacobianConstraintSolver) Reset(SBSolverContext)
type SBNudgeSolution ¶
SBNudgeSolution is a solution to a single-body constraint that contains the nudges that need to be applied to the body.
type SBSolverContext ¶
SBSolverContext contains information related to the single-body constraint processing.
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 DBConstraintSolver) *DBConstraint
CreateDoubleBodyConstraint creates a new physics constraint that acts on two bodies and enables it for this scene.
func (*Scene) CreateSingleBodyConstraint ¶
func (s *Scene) CreateSingleBodyConstraint(body *Body, solver SBConstraintSolver) *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) SetGravity ¶
SetGravity changes the gravity acceleration.
func (*Scene) SetWindDensity ¶
SetWindDensity changes the wind density.
func (*Scene) SetWindVelocity ¶
SetWindVelocity sets the wind speed.
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.