engine: github.com/g3n/engine/experimental/physics Index | Files | Directories

package physics

import "github.com/g3n/engine/experimental/physics"

Package collision implements collision related algorithms and data structures.

Package physics implements a basic physics engine.

Package physics implements a basic physics engine. WARNING: This package is experimental and incomplete!

Package physics implements a basic physics engine.

Index

Package Files

broadphase.go debug.go doc.go forcefield.go logger.go material.go narrowphase.go particle.go simulation.go

Constants

const (
    BeginContactEvent = "physics.BeginContactEvent"
    EndContactEvent   = "physics.EndContactEvent"
    CollisionEv       = "physics.Collision"
)

func ShowContact Uses

func ShowContact(scene *core.Node, contact *collision.Contact)

func ShowPenAxis Uses

func ShowPenAxis(scene *core.Node, axis *math32.Vector3)

func ShowWorldFace Uses

func ShowWorldFace(scene *core.Node, face []math32.Vector3, color *math32.Color)

type AttractorForceField Uses

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 Uses

func NewAttractorForceField(position *math32.Vector3, mass float32) *AttractorForceField

NewAttractorForceField creates and returns a pointer to a new AttractorForceField.

func (*AttractorForceField) ForceAt Uses

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 Uses

func (pa *AttractorForceField) Mass() float32

Mass returns the mass of the AttractorForceField.

func (*AttractorForceField) Position Uses

func (pa *AttractorForceField) Position() *math32.Vector3

Position returns the position of the AttractorForceField.

func (*AttractorForceField) SetMass Uses

func (pa *AttractorForceField) SetMass(newMass float32)

SetMass sets the mass of the AttractorForceField.

func (*AttractorForceField) SetPosition Uses

func (pa *AttractorForceField) SetPosition(newPosition *math32.Vector3)

SetPosition sets the position of the AttractorForceField.

type Broadphase Uses

type Broadphase struct{}

Broadphase is the base class for broadphase implementations.

func NewBroadphase Uses

func NewBroadphase() *Broadphase

NewBroadphase creates and returns a pointer to a new Broadphase.

func (*Broadphase) FindCollisionPairs Uses

func (b *Broadphase) FindCollisionPairs(objects []*object.Body) []CollisionPair

FindCollisionPairs (naive implementation)

func (*Broadphase) NeedTest Uses

func (b *Broadphase) NeedTest(bodyA, bodyB *object.Body) bool

type CollideEvent Uses

type CollideEvent struct {
    // contains filtered or unexported fields
}

type CollisionPair Uses

type CollisionPair struct {
    BodyA *object.Body
    BodyB *object.Body
}

CollisionPair is a pair of bodies that may be colliding.

type ConstantForceField Uses

type ConstantForceField struct {
    // contains filtered or unexported fields
}

ConstantForceField is a constant force field. It can be used to simulate surface gravity.

func NewConstantForceField Uses

func NewConstantForceField(force *math32.Vector3) *ConstantForceField

NewConstantForceField creates and returns a pointer to a new ConstantForceField.

func (*ConstantForceField) Force Uses

func (g *ConstantForceField) Force() *math32.Vector3

Force returns the force of the force field.

func (*ConstantForceField) ForceAt Uses

func (g *ConstantForceField) ForceAt(pos *math32.Vector3) math32.Vector3

ForceAt satisfies the ForceField interface and returns the force at the specified position.

func (*ConstantForceField) SetForce Uses

func (g *ConstantForceField) SetForce(newDirection *math32.Vector3)

SetForce sets the force of the force field.

type ContactEvent Uses

type ContactEvent struct {
    // contains filtered or unexported fields
}

TODO AddBodyEvent, RemoveBodyEvent

type ContactMaterial Uses

type ContactMaterial struct {
    // contains filtered or unexported fields
}

func NewContactMaterial Uses

func NewContactMaterial() *ContactMaterial

type DebugHelper Uses

type DebugHelper struct {
}

This file contains helpful infrastructure for debugging physics

type ForceField Uses

type ForceField interface {
    ForceAt(pos *math32.Vector3) math32.Vector3
}

ForceField represents a force field. A force is defined for every point.

type Material Uses

type Material struct {
    // contains filtered or unexported fields
}

type Narrowphase Uses

type Narrowphase struct {
    // contains filtered or unexported fields
}

Narrowphase

func NewNarrowphase Uses

func NewNarrowphase(simulation *Simulation) *Narrowphase

NewNarrowphase creates and returns a pointer to a new Narrowphase.

func (*Narrowphase) ConvexConvex Uses

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 Uses

func (n *Narrowphase) GenerateEquations(pairs []CollisionPair) ([]*equation.Contact, []*equation.Friction)

GenerateEquations is the Narrowphase entry point.

func (*Narrowphase) PlaneConvex Uses

func (n *Narrowphase) PlaneConvex(bodyA, bodyB *object.Body, planeA *shape.Plane, convexB *shape.ConvexHull, posA, posB *math32.Vector3, quatA, quatB *math32.Quaternion) ([]*equation.Contact, []*equation.Friction)

TODO

func (*Narrowphase) ResolveCollision Uses

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 Uses

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 Uses

func (n *Narrowphase) SpherePlane(bodyA, bodyB *object.Body, sphereA *shape.Sphere, planeB *shape.Plane, posA, posB *math32.Vector3, quatA, quatB *math32.Quaternion) ([]*equation.Contact, []*equation.Friction)

SpherePlane resolves the collision between a sphere and a plane analytically.

func (*Narrowphase) SphereSphere Uses

func (n *Narrowphase) SphereSphere(bodyA, bodyB *object.Body, sphereA, sphereB *shape.Sphere, posA, posB *math32.Vector3, quatA, quatB *math32.Quaternion) ([]*equation.Contact, []*equation.Friction)

SphereSphere resolves the collision between two spheres analytically.

type RepellerForceField Uses

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 Uses

func NewRepellerForceField(position *math32.Vector3, mass float32) *RepellerForceField

NewRepellerForceField creates and returns a pointer to a new RepellerForceField.

func (*RepellerForceField) ForceAt Uses

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 Uses

func (pr *RepellerForceField) Mass() float32

Mass returns the mass of the RepellerForceField.

func (*RepellerForceField) Position Uses

func (pr *RepellerForceField) Position() *math32.Vector3

Position returns the position of the RepellerForceField.

func (*RepellerForceField) SetMass Uses

func (pr *RepellerForceField) SetMass(newMass float32)

SetMass sets the mass of the RepellerForceField.

func (*RepellerForceField) SetPosition Uses

func (pr *RepellerForceField) SetPosition(newPosition *math32.Vector3)

SetPosition sets the position of the RepellerForceField.

type Simulation Uses

type Simulation struct {
    // contains filtered or unexported fields
}

Simulation represents a physics simulation.

func NewSimulation Uses

func NewSimulation(scene *core.Node) *Simulation

NewSimulation creates and returns a pointer to a new physics simulation.

func (*Simulation) AddBody Uses

func (s *Simulation) AddBody(body *object.Body, name string)

AddBody adds a body to the simulation.

func (*Simulation) AddConstraint Uses

func (s *Simulation) AddConstraint(c constraint.IConstraint)

AddConstraint adds a constraint to the simulation.

func (*Simulation) AddContactMaterial Uses

func (s *Simulation) AddContactMaterial(cmat *ContactMaterial)

Adds a contact material to the simulation

func (*Simulation) AddForceField Uses

func (s *Simulation) AddForceField(ff ForceField)

AddForceField adds a force field to the simulation.

func (*Simulation) AddMaterial Uses

func (s *Simulation) AddMaterial(mat *Material)

func (*Simulation) ApplySolution Uses

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 Uses

func (s *Simulation) Bodies() []*object.Body

Bodies returns the slice of bodies under simulation. The slice may contain nil values!

func (*Simulation) ClearForces Uses

func (s *Simulation) ClearForces()

ClearForces sets all body forces in the world to zero.

func (*Simulation) GetContactMaterial Uses

func (s *Simulation) GetContactMaterial(bodyA, bodyB *object.Body) *ContactMaterial

GetContactMaterial returns the contact material between the specified bodies.

func (*Simulation) Paused Uses

func (s *Simulation) Paused() bool

Paused returns the paused state of the simulation.

func (*Simulation) RemoveBody Uses

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 Uses

func (s *Simulation) RemoveConstraint(c constraint.IConstraint)

func (*Simulation) RemoveForceField Uses

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 Uses

func (s *Simulation) RemoveMaterial(mat *Material)

func (*Simulation) Scene Uses

func (s *Simulation) Scene() *core.Node

func (*Simulation) SetPaused Uses

func (s *Simulation) SetPaused(state bool)

SetPaused sets the paused state of the simulation.

func (*Simulation) Step Uses

func (s *Simulation) Step(frameDelta float32)

func (*Simulation) StepPlus Uses

func (s *Simulation) StepPlus(frameDelta float32, timeSinceLastCalled float32, maxSubSteps int)

Step steps the simulation. maxSubSteps should be 10 by default

Directories

PathSynopsis
constraintPackage constraint implements physics constraints.
equationPackage 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"
object
solverPackage physics implements a basic physics engine.

Package physics imports 13 packages (graph) and is imported by 1 packages. Updated 2018-08-04. Refresh now. Tools for package owners.