physics

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2020 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Overview

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

Constants

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

Variables

This section is empty.

Functions

func ShowContact

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

func ShowPenAxis

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

func ShowWorldFace

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

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)

func (*Broadphase) NeedTest

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

type CollideEvent

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

type CollisionPair

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

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(pos *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

type DebugHelper

type DebugHelper struct {
}

This file contains helpful infrastructure for debugging physics

type ForceField

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

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

type Material

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

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

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, quatA, quatB *math32.Quaternion) ([]*equation.Contact, []*equation.Friction)

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

func (*Narrowphase) SphereSphere

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

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

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

GetContactMaterial returns the contact material between the specified bodies.

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(c constraint.IConstraint)

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(mat *Material)

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, timeSinceLastCalled float32, maxSubSteps int)

Step steps the simulation. maxSubSteps should be 10 by default

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.

Jump to

Keyboard shortcuts

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