Documentation ¶
Overview ¶
Package collision implements collision related algorithms and data structures.
Package physics implements a basic physics engine. WARNING: This package is experimental and incomplete!
Index ¶
- Constants
- func ShowContact(scene *core.Node, contact *collision.Contact)
- func ShowPenAxis(scene *core.Node, axis *math32.Vector3)
- func ShowWorldFace(scene *core.Node, face []math32.Vector3, color *math32.Color)
- type AttractorForceField
- func (pa *AttractorForceField) ForceAt(pos *math32.Vector3) math32.Vector3
- func (pa *AttractorForceField) Mass() float32
- func (pa *AttractorForceField) Position() *math32.Vector3
- func (pa *AttractorForceField) SetMass(newMass float32)
- func (pa *AttractorForceField) SetPosition(newPosition *math32.Vector3)
- type Broadphase
- type CollideEvent
- type CollisionPair
- type ConstantForceField
- type ContactEvent
- type ContactMaterial
- func (cm *ContactMaterial) GetContactEquationRelaxation() float32
- func (cm *ContactMaterial) GetContactEquationStiffness() float32
- func (cm *ContactMaterial) GetFriction() float32
- func (cm *ContactMaterial) GetFrictionEquationRelaxation() float32
- func (cm *ContactMaterial) GetFrictionEquationStiffness() float32
- func (cm *ContactMaterial) GetMat1() *Material
- func (cm *ContactMaterial) GetMat2() *Material
- func (cm *ContactMaterial) GetRestitution() float32
- func (cm *ContactMaterial) SetContactEquationRelaxation(relaxation float32)
- func (cm *ContactMaterial) SetContactEquationStiffness(stiffness float32)
- func (cm *ContactMaterial) SetFriction(friction float32)
- func (cm *ContactMaterial) SetFrictionEquationRelaxation(relaxation float32)
- func (cm *ContactMaterial) SetFrictionEquationStiffness(stiffness float32)
- func (cm *ContactMaterial) SetMat1(mat1 *Material)
- func (cm *ContactMaterial) SetMat2(mat2 *Material)
- func (cm *ContactMaterial) SetRestitution(restitution float32)
- type ContactMaterialTable
- type DebugHelper
- type ForceField
- type Material
- type Narrowphase
- func (n *Narrowphase) ConvexConvex(bodyA, bodyB *object.Body, convexA, convexB *shape.ConvexHull, ...) ([]*equation.Contact, []*equation.Friction)
- func (n *Narrowphase) GenerateEquations(pairs []CollisionPair) ([]*equation.Contact, []*equation.Friction)
- func (n *Narrowphase) PlaneConvex() ([]*equation.Contact, []*equation.Friction)
- func (n *Narrowphase) ResolveCollision(bodyA, bodyB *object.Body) ([]*equation.Contact, []*equation.Friction)
- func (n *Narrowphase) SphereConvex(bodyA, bodyB *object.Body, sphereA *shape.Sphere, convexB *shape.ConvexHull, ...) ([]*equation.Contact, []*equation.Friction)
- func (n *Narrowphase) SpherePlane(bodyA, bodyB *object.Body, sphereA *shape.Sphere, planeB *shape.Plane, ...) ([]*equation.Contact, []*equation.Friction)
- func (n *Narrowphase) SphereSphere(bodyA, bodyB *object.Body, sphereA, sphereB *shape.Sphere, ...) ([]*equation.Contact, []*equation.Friction)
- type RepellerForceField
- func (pr *RepellerForceField) ForceAt(pos *math32.Vector3) math32.Vector3
- func (pr *RepellerForceField) Mass() float32
- func (pr *RepellerForceField) Position() *math32.Vector3
- func (pr *RepellerForceField) SetMass(newMass float32)
- func (pr *RepellerForceField) SetPosition(newPosition *math32.Vector3)
- type Simulation
- func (s *Simulation) AddBody(body *object.Body, name string)
- func (s *Simulation) AddConstraint(c constraint.IConstraint)
- func (s *Simulation) AddContactMaterial(cmat *ContactMaterial)
- func (s *Simulation) AddForceField(ff ForceField)
- func (s *Simulation) AddMaterial(mat *Material)
- func (s *Simulation) ApplySolution(sol *solver.Solution)
- func (s *Simulation) Bodies() []*object.Body
- func (s *Simulation) ClearForces()
- func (s *Simulation) Paused() bool
- func (s *Simulation) RemoveBody(body *object.Body) bool
- func (s *Simulation) RemoveConstraint()
- func (s *Simulation) RemoveForceField(ff ForceField) bool
- func (s *Simulation) RemoveMaterial()
- func (s *Simulation) Scene() *core.Node
- func (s *Simulation) SetPaused(state bool)
- func (s *Simulation) Step(frameDelta float32)
- func (s *Simulation) StepPlus(frameDelta float32)
Constants ¶
const ( BeginContactEvent = "physics.BeginContactEvent" EndContactEvent = "physics.EndContactEvent" CollisionEv = "physics.Collision" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AttractorForceField ¶
type AttractorForceField struct {
// contains filtered or unexported fields
}
AttractorForceField is a force field where all forces point to a single point. The force strength changes with the inverse distance squared. This can be used to model planetary attractions.
func NewAttractorForceField ¶
func NewAttractorForceField(position *math32.Vector3, mass float32) *AttractorForceField
NewAttractorForceField creates and returns a pointer to a new AttractorForceField.
func (*AttractorForceField) ForceAt ¶
func (pa *AttractorForceField) ForceAt(pos *math32.Vector3) math32.Vector3
ForceAt satisfies the ForceField interface and returns the force at the specified position.
func (*AttractorForceField) Mass ¶
func (pa *AttractorForceField) Mass() float32
Mass returns the mass of the AttractorForceField.
func (*AttractorForceField) Position ¶
func (pa *AttractorForceField) Position() *math32.Vector3
Position returns the position of the AttractorForceField.
func (*AttractorForceField) SetMass ¶
func (pa *AttractorForceField) SetMass(newMass float32)
SetMass sets the mass of the AttractorForceField.
func (*AttractorForceField) SetPosition ¶
func (pa *AttractorForceField) SetPosition(newPosition *math32.Vector3)
SetPosition sets the position of the AttractorForceField.
type Broadphase ¶
type Broadphase struct{}
Broadphase is the base class for broadphase implementations.
func NewBroadphase ¶
func NewBroadphase() *Broadphase
NewBroadphase creates and returns a pointer to a new Broadphase.
func (*Broadphase) FindCollisionPairs ¶
func (b *Broadphase) FindCollisionPairs(objects []*object.Body) []CollisionPair
FindCollisionPairs (naive implementation)
type CollideEvent ¶
type CollideEvent struct {
// contains filtered or unexported fields
}
type CollisionPair ¶
CollisionPair is a pair of bodies that may be colliding.
type ConstantForceField ¶
type ConstantForceField struct {
// contains filtered or unexported fields
}
ConstantForceField is a constant force field. It can be used to simulate surface gravity.
func NewConstantForceField ¶
func NewConstantForceField(force *math32.Vector3) *ConstantForceField
NewConstantForceField creates and returns a pointer to a new ConstantForceField.
func (*ConstantForceField) Force ¶
func (g *ConstantForceField) Force() *math32.Vector3
Force returns the force of the force field.
func (*ConstantForceField) ForceAt ¶
func (g *ConstantForceField) ForceAt(_ *math32.Vector3) math32.Vector3
ForceAt satisfies the ForceField interface and returns the force at the specified position.
func (*ConstantForceField) SetForce ¶
func (g *ConstantForceField) SetForce(newDirection *math32.Vector3)
SetForce sets the force of the force field.
type ContactEvent ¶
type ContactEvent struct {
// contains filtered or unexported fields
}
TODO AddBodyEvent, RemoveBodyEvent
type ContactMaterial ¶
type ContactMaterial struct {
// contains filtered or unexported fields
}
func NewContactMaterial ¶
func NewContactMaterial() *ContactMaterial
func (*ContactMaterial) GetContactEquationRelaxation ¶
func (cm *ContactMaterial) GetContactEquationRelaxation() float32
func (*ContactMaterial) GetContactEquationStiffness ¶
func (cm *ContactMaterial) GetContactEquationStiffness() float32
func (*ContactMaterial) GetFriction ¶
func (cm *ContactMaterial) GetFriction() float32
func (*ContactMaterial) GetFrictionEquationRelaxation ¶
func (cm *ContactMaterial) GetFrictionEquationRelaxation() float32
func (*ContactMaterial) GetFrictionEquationStiffness ¶
func (cm *ContactMaterial) GetFrictionEquationStiffness() float32
func (*ContactMaterial) GetMat1 ¶
func (cm *ContactMaterial) GetMat1() *Material
func (*ContactMaterial) GetMat2 ¶
func (cm *ContactMaterial) GetMat2() *Material
func (*ContactMaterial) GetRestitution ¶
func (cm *ContactMaterial) GetRestitution() float32
func (*ContactMaterial) SetContactEquationRelaxation ¶
func (cm *ContactMaterial) SetContactEquationRelaxation(relaxation float32)
func (*ContactMaterial) SetContactEquationStiffness ¶
func (cm *ContactMaterial) SetContactEquationStiffness(stiffness float32)
func (*ContactMaterial) SetFriction ¶
func (cm *ContactMaterial) SetFriction(friction float32)
func (*ContactMaterial) SetFrictionEquationRelaxation ¶
func (cm *ContactMaterial) SetFrictionEquationRelaxation(relaxation float32)
func (*ContactMaterial) SetFrictionEquationStiffness ¶
func (cm *ContactMaterial) SetFrictionEquationStiffness(stiffness float32)
func (*ContactMaterial) SetMat1 ¶
func (cm *ContactMaterial) SetMat1(mat1 *Material)
func (*ContactMaterial) SetMat2 ¶
func (cm *ContactMaterial) SetMat2(mat2 *Material)
func (*ContactMaterial) SetRestitution ¶
func (cm *ContactMaterial) SetRestitution(restitution float32)
type ContactMaterialTable ¶
type ContactMaterialTable map[intPair]*ContactMaterial
type DebugHelper ¶
type DebugHelper struct { }
This file contains helpful infrastructure for debugging physics
type ForceField ¶
ForceField represents a force field. A force is defined for every point.
type Material ¶
type Material struct {
// contains filtered or unexported fields
}
func NewMaterial ¶
func (*Material) GetFriction ¶
func (*Material) GetRestitution ¶
func (*Material) SetFriction ¶
func (*Material) SetRestitution ¶
type Narrowphase ¶
type Narrowphase struct {
// contains filtered or unexported fields
}
Narrowphase
func NewNarrowphase ¶
func NewNarrowphase(simulation *Simulation) *Narrowphase
NewNarrowphase creates and returns a pointer to a new Narrowphase.
func (*Narrowphase) ConvexConvex ¶
func (n *Narrowphase) ConvexConvex(bodyA, bodyB *object.Body, convexA, convexB *shape.ConvexHull, posA, posB *math32.Vector3, quatA, quatB *math32.Quaternion) ([]*equation.Contact, []*equation.Friction)
ConvexConvex implements collision detection and contact resolution between two convex hulls.
func (*Narrowphase) GenerateEquations ¶
func (n *Narrowphase) GenerateEquations(pairs []CollisionPair) ([]*equation.Contact, []*equation.Friction)
GenerateEquations is the Narrowphase entry point.
func (*Narrowphase) PlaneConvex ¶
func (n *Narrowphase) PlaneConvex() ([]*equation.Contact, []*equation.Friction)
TODO
func (*Narrowphase) ResolveCollision ¶
func (n *Narrowphase) ResolveCollision(bodyA, bodyB *object.Body) ([]*equation.Contact, []*equation.Friction)
ResolveCollision figures out which implementation of collision detection and contact resolution to use depending on the shapes involved.
func (*Narrowphase) SphereConvex ¶
func (n *Narrowphase) SphereConvex(bodyA, bodyB *object.Body, sphereA *shape.Sphere, convexB *shape.ConvexHull, posA, posB *math32.Vector3, quatA, quatB *math32.Quaternion) ([]*equation.Contact, []*equation.Friction)
TODO The second half of this method is untested!!!
func (*Narrowphase) SpherePlane ¶
func (n *Narrowphase) SpherePlane(bodyA, bodyB *object.Body, sphereA *shape.Sphere, planeB *shape.Plane, posA, posB *math32.Vector3, quatB *math32.Quaternion) ([]*equation.Contact, []*equation.Friction)
SpherePlane resolves the collision between a sphere and a plane analytically.
type RepellerForceField ¶
type RepellerForceField struct {
// contains filtered or unexported fields
}
RepellerForceField is a force field where all forces point away from a single point. The force strength changes with the inverse distance squared.
func NewRepellerForceField ¶
func NewRepellerForceField(position *math32.Vector3, mass float32) *RepellerForceField
NewRepellerForceField creates and returns a pointer to a new RepellerForceField.
func (*RepellerForceField) ForceAt ¶
func (pr *RepellerForceField) ForceAt(pos *math32.Vector3) math32.Vector3
ForceAt satisfies the ForceField interface and returns the force at the specified position.
func (*RepellerForceField) Mass ¶
func (pr *RepellerForceField) Mass() float32
Mass returns the mass of the RepellerForceField.
func (*RepellerForceField) Position ¶
func (pr *RepellerForceField) Position() *math32.Vector3
Position returns the position of the RepellerForceField.
func (*RepellerForceField) SetMass ¶
func (pr *RepellerForceField) SetMass(newMass float32)
SetMass sets the mass of the RepellerForceField.
func (*RepellerForceField) SetPosition ¶
func (pr *RepellerForceField) SetPosition(newPosition *math32.Vector3)
SetPosition sets the position of the RepellerForceField.
type Simulation ¶
type Simulation struct {
// contains filtered or unexported fields
}
Simulation represents a physics simulation.
func NewSimulation ¶
func NewSimulation(scene *core.Node) *Simulation
NewSimulation creates and returns a pointer to a new physics simulation.
func (*Simulation) AddBody ¶
func (s *Simulation) AddBody(body *object.Body, name string)
AddBody adds a body to the simulation.
func (*Simulation) AddConstraint ¶
func (s *Simulation) AddConstraint(c constraint.IConstraint)
AddConstraint adds a constraint to the simulation.
func (*Simulation) AddContactMaterial ¶
func (s *Simulation) AddContactMaterial(cmat *ContactMaterial)
Adds a contact material to the simulation
func (*Simulation) AddForceField ¶
func (s *Simulation) AddForceField(ff ForceField)
AddForceField adds a force field to the simulation.
func (*Simulation) AddMaterial ¶
func (s *Simulation) AddMaterial(mat *Material)
func (*Simulation) ApplySolution ¶
func (s *Simulation) ApplySolution(sol *solver.Solution)
ApplySolution applies the specified solution to the bodies under simulation. The solution is a set of linear and angular velocity deltas for each body. This method alters the solution arrays.
func (*Simulation) Bodies ¶
func (s *Simulation) Bodies() []*object.Body
Bodies returns the slice of bodies under simulation. The slice may contain nil values!
func (*Simulation) ClearForces ¶
func (s *Simulation) ClearForces()
ClearForces sets all body forces in the world to zero.
func (*Simulation) Paused ¶
func (s *Simulation) Paused() bool
Paused returns the paused state of the simulation.
func (*Simulation) RemoveBody ¶
func (s *Simulation) RemoveBody(body *object.Body) bool
RemoveBody removes the specified body from the simulation. Returns true if found, false otherwise.
func (*Simulation) RemoveConstraint ¶
func (s *Simulation) RemoveConstraint()
func (*Simulation) RemoveForceField ¶
func (s *Simulation) RemoveForceField(ff ForceField) bool
RemoveForceField removes the specified force field from the simulation. Returns true if found, false otherwise.
func (*Simulation) RemoveMaterial ¶
func (s *Simulation) RemoveMaterial()
func (*Simulation) Scene ¶
func (s *Simulation) Scene() *core.Node
func (*Simulation) SetPaused ¶
func (s *Simulation) SetPaused(state bool)
SetPaused sets the paused state of the simulation.
func (*Simulation) Step ¶
func (s *Simulation) Step(frameDelta float32)
func (*Simulation) StepPlus ¶
func (s *Simulation) StepPlus(frameDelta float32)
Step steps the simulation. maxSubSteps should be 10 by default
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package constraint implements physics constraints.
|
Package constraint implements physics constraints. |
Package equation implements SPOOK equations based on the 2007 PhD thesis of Claude Lacoursière titled "Ghosts and Machines: Regularized Variational Methods for Interactive Simulations of Multibodies with Dry Frictional Contacts"
|
Package equation implements SPOOK equations based on the 2007 PhD thesis of Claude Lacoursière titled "Ghosts and Machines: Regularized Variational Methods for Interactive Simulations of Multibodies with Dry Frictional Contacts" |
Package physics implements a basic physics engine.
|
Package physics implements a basic physics engine. |