solver

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const Epsilon = float64(0.00001)

Epsilon indicates a small enough amount that something could be ignored.

Variables

This section is empty.

Functions

func RestitutionClamp added in v0.10.0

func RestitutionClamp(effectiveVelocity float64) float64

RestitutionClamp specifies a ratio that describes how much the restitution coefficient should be allowed to apply.

The goal of this clamp is to reduce bounciness of objects when they are barely moving.

Types

type Constraint added in v0.10.0

type Constraint interface {
	// Reset clears the internal cache state for this constraint solver.
	//
	// This is called at the start of every iteration.
	Reset(ctx Context)

	// ApplyImpulses is called by the physics engine to instruct the solver
	// to apply the necessary impulses to its object.
	//
	// This is called multiple times per iteration.
	ApplyImpulses(ctx Context)

	// ApplyNudges is called by the physics engine to instruct the solver to
	// apply the necessary nudges to its object.
	//
	// This is called multiple times per iteration.
	ApplyNudges(ctx Context)
}

Constraint represents the algorithm necessary to solve a single-object constraint.

type Context added in v0.10.0

type Context struct {
	DeltaTime   float64
	ImpulseBeta float64
	NudgeBeta   float64

	Target *Placeholder
}

Context contains information related to single-object constraint processing.

func (Context) JacobianImpulseLambda added in v0.10.0

func (c Context) JacobianImpulseLambda(jacobian Jacobian, drift, restitution float64) float64

JacobianImpulseLambda returns the impulse lambda for the specified constraint Jacobian, positional drift and restitution.

func (Context) JacobianImpulseSolution added in v0.10.0

func (c Context) JacobianImpulseSolution(jacobian Jacobian, drift, restitution float64) Impulse

JacobianImpulseSolution returns an impulse solution based on the specified constraint Jacobian, positional drift and restitution.

func (Context) JacobianNudgeLambda added in v0.10.0

func (c Context) JacobianNudgeLambda(jacobian Jacobian, drift float64) float64

JacobianNudgeLambda returns the nudge lambda for the specified constraint Jacobian and positional drift.

func (Context) JacobianNudgeSolution added in v0.10.0

func (c Context) JacobianNudgeSolution(jacobian Jacobian, drift float64) Nudge

JacobianNudgeSolution returns a nudge solution based on the specified constraint Jacobian and positional drift.

type Impulse added in v0.10.0

type Impulse struct {
	Linear  dprec.Vec3
	Angular dprec.Vec3
}

type Jacobian added in v0.10.0

type Jacobian struct {
	LinearSlope  dprec.Vec3
	AngularSlope dprec.Vec3
}

Jacobian represents the 1x6 Jacobian matrix of a single-object velocity constraint.

func (Jacobian) EffectiveVelocity added in v0.10.0

func (j Jacobian) EffectiveVelocity(target *Placeholder) float64

EffectiveVelocity returns the amount of velocity in the wrong direction of the target.

func (Jacobian) Impulse added in v0.10.0

func (j Jacobian) Impulse(lambda float64) Impulse

Impulse returns an Impulse solution based on the lambda impulse amount applied according to this Jacobian.

func (Jacobian) InverseEffectiveMass added in v0.10.0

func (j Jacobian) InverseEffectiveMass(target *Placeholder) float64

InverseEffectiveMass returns the inverse of the effective mass with which the target affects the constraint.

func (Jacobian) Nudge added in v0.10.0

func (j Jacobian) Nudge(lambda float64) Nudge

Nudge returns a nudge solution based on the lambda nudge amount applied according to this Jacobian.

type Nudge added in v0.10.0

type Nudge struct {
	Linear  dprec.Vec3
	Angular dprec.Vec3
}

type PairConstraint added in v0.10.0

type PairConstraint interface {
	// Reset clears the internal cache state for this constraint solver.
	//
	// This is called at the start of every iteration.
	Reset(ctx PairContext)

	// ApplyImpulses is called by the physics engine to instruct the solver
	// to apply the necessary impulses to its objects.
	//
	// This is called multiple times per iteration.
	ApplyImpulses(ctx PairContext)

	// ApplyNudges is called by the physics engine to instruct the solver to
	// apply the necessary nudges to its objects.
	//
	// This is called multiple times per iteration.
	ApplyNudges(ctx PairContext)
}

PairConstraint represents the algorithm necessary to solve a double-object constraint.

type PairContext added in v0.10.0

type PairContext struct {
	DeltaTime   float64
	ImpulseBeta float64
	NudgeBeta   float64

	Target *Placeholder
	Source *Placeholder
}

PairContext contains information related to double-object constraint processing.

func (PairContext) JacobianImpulseLambda added in v0.10.0

func (c PairContext) JacobianImpulseLambda(jacobian PairJacobian, drift, restitution float64) float64

JacobianImpulseLambda returns the impulse lambda for the specified constraint Jacobian, positional drift and restitution.

func (PairContext) JacobianImpulseSolution added in v0.10.0

func (c PairContext) JacobianImpulseSolution(jacobian PairJacobian, drift, restitution float64) PairImpulse

JacobianImpulseSolution returns an impulse solution based on the specified constraint Jacobian, positional drift and restitution.

func (PairContext) JacobianNudgeLambda added in v0.10.0

func (c PairContext) JacobianNudgeLambda(jacobian PairJacobian, drift float64) float64

JacobianNudgeLambda returns the nudge lambda for the specified constraint Jacobian and positional drift.

func (PairContext) JacobianNudgeSolution added in v0.10.0

func (c PairContext) JacobianNudgeSolution(jacobian PairJacobian, drift float64) PairNudge

JacobianNudgeSolution returns a nudge solution based on the specified constraint Jacobian and positional drift.

type PairImpulse added in v0.10.0

type PairImpulse struct {
	Target Impulse
	Source Impulse
}

type PairJacobian added in v0.10.0

type PairJacobian struct {
	Target Jacobian
	Source Jacobian
}

PairJacobian represents the 1x12 Jacobian matrix of a double-object velocity constraint.

func (PairJacobian) EffectiveVelocity added in v0.10.0

func (j PairJacobian) EffectiveVelocity(target, source *Placeholder) float64

EffectiveVelocity returns the amount of the combined velocities of the two objects that is going in the wrong direction.

func (PairJacobian) Impulse added in v0.10.0

func (j PairJacobian) Impulse(lambda float64) PairImpulse

Impulse returns an impulse solution based on the lambda impulse amount applied according to this Jacobian.

func (PairJacobian) InverseEffectiveMass added in v0.10.0

func (j PairJacobian) InverseEffectiveMass(target, source *Placeholder) float64

InverseEffectiveMass returns the inverse of the effective mass with which the two bodies affect the constraint.

func (PairJacobian) Nudge added in v0.10.0

func (j PairJacobian) Nudge(lambda float64) PairNudge

Nudge returns a nudge solution based on the lambda nudge amount applied according to this Jacobian.

type PairNudge added in v0.10.0

type PairNudge struct {
	Target Nudge
	Source Nudge
}

type Placeholder added in v0.10.0

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

func (*Placeholder) AngularVelocity added in v0.10.0

func (p *Placeholder) AngularVelocity() dprec.Vec3

func (*Placeholder) ApplyImpulse added in v0.10.0

func (p *Placeholder) ApplyImpulse(impulse Impulse)

func (*Placeholder) ApplyNudge added in v0.10.0

func (p *Placeholder) ApplyNudge(nudge Nudge)

func (*Placeholder) Init added in v0.10.0

func (p *Placeholder) Init(state PlaceholderState)

func (*Placeholder) LinearVelocity added in v0.10.0

func (p *Placeholder) LinearVelocity() dprec.Vec3

func (*Placeholder) Position added in v0.10.0

func (p *Placeholder) Position() dprec.Vec3

func (*Placeholder) Rotation added in v0.10.0

func (p *Placeholder) Rotation() dprec.Quat

func (*Placeholder) SetAngularVelocity added in v0.10.0

func (p *Placeholder) SetAngularVelocity(velocity dprec.Vec3)

func (*Placeholder) SetLinearVelocity added in v0.10.0

func (p *Placeholder) SetLinearVelocity(velocity dprec.Vec3)

func (*Placeholder) SetPosition added in v0.10.0

func (p *Placeholder) SetPosition(position dprec.Vec3)

func (*Placeholder) SetRotation added in v0.10.0

func (p *Placeholder) SetRotation(rotation dprec.Quat)

type PlaceholderState added in v0.10.0

type PlaceholderState struct {
	Mass            float64
	MomentOfInertia dprec.Mat3

	LinearVelocity  dprec.Vec3
	AngularVelocity dprec.Vec3

	Position dprec.Vec3
	Rotation dprec.Quat
}

Jump to

Keyboard shortcuts

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