physics

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SymmetricMomentOfInertia

func SymmetricMomentOfInertia(value float32) sprec.Mat3

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

func (b *Body) AngularDragFactor() float32

AngularDragFactor returns the angular drag factor for this body.

func (*Body) AngularVelocity

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

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

func (b *Body) DragFactor() float32

DragCoefficient returns the drag factor of this body.

func (*Body) Mass

func (b *Body) Mass() float32

Mass returns the mass of this body in kg.

func (*Body) MomentOfInertia

func (b *Body) MomentOfInertia() sprec.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() sprec.Quat

Orientation returns the quaternion rotation of this body.

func (*Body) Position

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

Position returns the body's position in world space.

func (*Body) RestitutionCoefficient

func (b *Body) RestitutionCoefficient() float32

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 float32)

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 sprec.Vec3)

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

func (b *Body) SetDragFactor(factor float32)

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 float32)

SetMass changes the mass of this body.

func (*Body) SetMomentOfInertia

func (b *Body) SetMomentOfInertia(inertia sprec.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 sprec.Quat)

SetOrientation changes the quaterntion rotation of this body.

func (*Body) SetPosition

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

SetPosition changes the position of this body.

func (*Body) SetRestitutionCoefficient

func (b *Body) SetRestitutionCoefficient(coefficient float32)

SetRestitutionCoefficient changes the restitution coefficient for this body.

func (*Body) SetStatic

func (b *Body) SetStatic(static bool)

SetStatic changes whether this body is static.

func (*Body) SetVelocity

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

SetVelocity changes the velocity of this body.

func (*Body) Static

func (b *Body) Static() bool

Static returns whether this body is static.

func (*Body) Velocity

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

Velocity returns 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) 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) 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 (*DBJacobianConstraintSolver) CalculateNudges

func (*DBJacobianConstraintSolver) Reset

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

type DBSolverContext struct {
	Primary        *Body
	Secondary      *Body
	ElapsedSeconds float32
}

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 NewEngine

func NewEngine() *Engine

NewEngine creates a new physics engine.

func (*Engine) CreateScene

func (e *Engine) CreateScene(stepSeconds float32) *Scene

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

type Jacobian

type Jacobian struct {
	SlopeVelocity        sprec.Vec3
	SlopeAngularVelocity sprec.Vec3
}

func (Jacobian) EffectiveVelocity

func (j Jacobian) EffectiveVelocity(body *Body) float32

func (Jacobian) ImpulseLambda

func (j Jacobian) ImpulseLambda(body *Body) float32

func (Jacobian) ImpulseSolution

func (j Jacobian) ImpulseSolution(body *Body, lambda float32) SBImpulseSolution

func (Jacobian) InverseEffectiveMass

func (j Jacobian) InverseEffectiveMass(body *Body) float32

func (Jacobian) NudgeLambda

func (j Jacobian) NudgeLambda(body *Body, drift float32) float32

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 (*NilDBConstraintSolver) CalculateNudges

func (*NilDBConstraintSolver) Reset

type NilSBConstraintSolver

type NilSBConstraintSolver struct{}

NilConstraintSolver is an SBConstraintSolver that does nothing.

func (*NilSBConstraintSolver) CalculateImpulses

func (*NilSBConstraintSolver) CalculateNudges

func (*NilSBConstraintSolver) Reset

type PairJacobian

type PairJacobian struct {
	Primary   Jacobian
	Secondary Jacobian
}

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) 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) 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

type SBImpulseSolution struct {
	Impulse        sprec.Vec3
	AngularImpulse sprec.Vec3
}

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 (*SBJacobianConstraintSolver) CalculateNudges

func (*SBJacobianConstraintSolver) Reset

type SBNudgeSolution

type SBNudgeSolution struct {
	Nudge        sprec.Vec3
	AngularNudge sprec.Vec3
}

SBNudgeSolution is a solution to a single-body constraint that contains the nudges that need to be applied to the body.

type SBSolverContext

type SBSolverContext struct {
	Body           *Body
	ElapsedSeconds float32
}

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

func (s *Scene) CreateBody() *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 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) Gravity

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

Gravity returns the gravity acceleration.

func (*Scene) SetGravity

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

SetGravity changes the gravity acceleration.

func (*Scene) SetWindDensity

func (s *Scene) SetWindDensity(density float32)

SetWindDensity changes the wind density.

func (*Scene) SetWindVelocity

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

SetWindVelocity sets the wind speed.

func (*Scene) Update

func (s *Scene) Update(elapsedSeconds float32)

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() float32

WindDensity returns the wind density.

func (*Scene) WindVelocity

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

WindVelocity returns the wind speed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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