solver

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 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 Acceleration added in v0.18.0

type Acceleration interface {

	// ApplyAcceleration applies acceleration to the target.
	ApplyAcceleration(ctx AccelerationContext)
}

Acceleration represents a solver that can apply acceleration to a target.

type AccelerationContext added in v0.18.0

type AccelerationContext struct {
	Target *AccelerationTarget
}

AccelerationContext provides information about the target that is being accelerated.

type AccelerationTarget added in v0.18.0

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

AccelerationTarget represents a target that can be accelerated.

func NewAccelerationTarget added in v0.18.0

func NewAccelerationTarget(
	mass float64,
	momentOfInertia dprec.Mat3,
	position dprec.Vec3,
	rotation dprec.Quat,
	linearVelocity dprec.Vec3,
	angularVelocity dprec.Vec3,
) AccelerationTarget

NewAccelerationTarget creates a new AccelerationTarget.

func (*AccelerationTarget) AccumulatedAngularAcceleration added in v0.18.0

func (t *AccelerationTarget) AccumulatedAngularAcceleration() dprec.Vec3

AccumulatedAngularAcceleration returns the accumulated angular acceleration of the target.

func (*AccelerationTarget) AccumulatedLinearAcceleration added in v0.18.0

func (t *AccelerationTarget) AccumulatedLinearAcceleration() dprec.Vec3

AccumulatedLinearAcceleration returns the accumulated linear acceleration of the target.

func (*AccelerationTarget) AddAngularAcceleration added in v0.18.0

func (t *AccelerationTarget) AddAngularAcceleration(acceleration dprec.Vec3)

AddAngularAcceleration adds angular acceleration to the target.

func (*AccelerationTarget) AddLinearAcceleration added in v0.18.0

func (t *AccelerationTarget) AddLinearAcceleration(acceleration dprec.Vec3)

AddLinearAcceleration adds linear acceleration to the target.

func (*AccelerationTarget) AngularVelocity added in v0.18.0

func (t *AccelerationTarget) AngularVelocity() dprec.Vec3

AngularVelocity returns the angular velocity of the target.

func (*AccelerationTarget) ApplyForce added in v0.18.0

func (t *AccelerationTarget) ApplyForce(force dprec.Vec3)

ApplyForce adds force to the target.

func (*AccelerationTarget) ApplyTorque added in v0.18.0

func (t *AccelerationTarget) ApplyTorque(torque dprec.Vec3)

func (*AccelerationTarget) LinearVelocity added in v0.18.0

func (t *AccelerationTarget) LinearVelocity() dprec.Vec3

LinearVelocity returns the linear velocity of the target.

func (*AccelerationTarget) Mass added in v0.18.0

func (t *AccelerationTarget) Mass() float64

Mass returns the mass of the target.

func (*AccelerationTarget) Position added in v0.18.0

func (t *AccelerationTarget) Position() dprec.Vec3

Position returns the position of the target.

func (*AccelerationTarget) Rotation added in v0.18.0

func (t *AccelerationTarget) Rotation() dprec.Quat

Rotation returns the rotation of the target.

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 Medium added in v0.18.0

type Medium interface {

	// Density returns the density of the medium at the specified
	// position.
	Density(position dprec.Vec3) float64

	// Velocity returns the velocity of the medium at the specified
	// position.
	Velocity(position dprec.Vec3) dprec.Vec3
}

Medium represents a medium that can be used to simulate the effects of drag and lift.

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