Documentation
¶
Index ¶
- Constants
- func AsNode(n tree.Node) (Node, *NodeBase)
- type BBox
- type Body
- type BodyBase
- type BodyPoint
- type Box
- type Capsule
- type Contact
- type Contacts
- type Cylinder
- func (cy *Cylinder) InitAbs(par *NodeBase)
- func (cy *Cylinder) RelToAbs(par *NodeBase)
- func (cy *Cylinder) SetBBox()
- func (t *Cylinder) SetBotRad(v float32) *Cylinder
- func (t *Cylinder) SetHeight(v float32) *Cylinder
- func (t *Cylinder) SetTopRad(v float32) *Cylinder
- func (cy *Cylinder) Step(step float32)
- type Group
- func (gp *Group) GroupBBox()
- func (gp *Group) InitAbs(par *NodeBase)
- func (gp *Group) RayBodyIntersections(ray math32.Ray) []*BodyPoint
- func (gp *Group) RelToAbs(par *NodeBase)
- func (gp *Group) Step(step float32)
- func (gp *Group) WorldCollide(dynTop bool) []Contacts
- func (gp *Group) WorldDynGroupBBox()
- func (gp *Group) WorldInit()
- func (gp *Group) WorldRelToAbs()
- func (gp *Group) WorldStep(step float32)
- type Node
- type NodeBase
- func (nb *NodeBase) AsBody() Body
- func (nb *NodeBase) AsNodeBase() *NodeBase
- func (nb *NodeBase) InitAbsBase(par *NodeBase)
- func (nb *NodeBase) RelToAbsBase(par *NodeBase)
- func (t *NodeBase) SetDynamic(v bool) *NodeBase
- func (nb *NodeBase) SetInitAngVel(vel math32.Vector3) *NodeBase
- func (nb *NodeBase) SetInitLinVel(vel math32.Vector3) *NodeBase
- func (nb *NodeBase) SetInitPos(pos math32.Vector3) *NodeBase
- func (nb *NodeBase) SetInitQuat(quat math32.Quat) *NodeBase
- func (t *NodeBase) SetInitial(v State) *NodeBase
- func (t *NodeBase) SetRel(v State) *NodeBase
- func (nb *NodeBase) StepBase(step float32)
- type Rigid
- type Sphere
- type State
- func (ps *State) Defaults()
- func (ps *State) EulerRotation() math32.Vector3
- func (ps *State) EulerRotationRad() math32.Vector3
- func (ps *State) FromRel(rel, par *State)
- func (ps *State) Move(delta math32.Vector3)
- func (ps *State) MoveOnAxis(x, y, z, dist float32)
- func (ps *State) MoveOnAxisAbs(x, y, z, dist float32)
- func (ps *State) RotateEuler(x, y, z float32)
- func (ps *State) RotateEulerRad(x, y, z, angle float32)
- func (ps *State) RotateOnAxis(x, y, z, angle float32)
- func (ps *State) RotateOnAxisRad(x, y, z, angle float32)
- func (ps *State) SetAxisRotation(x, y, z, angle float32)
- func (ps *State) SetAxisRotationRad(x, y, z, angle float32)
- func (ps *State) SetEulerRotation(x, y, z float32)
- func (ps *State) SetEulerRotationRad(x, y, z float32)
- func (ps *State) StepByAngVel(step float32)
- func (ps *State) StepByLinVel(step float32)
Constants ¶
const ( // DynsTopGps is passed to WorldCollide when all dynamic objects are in separate top groups DynsTopGps = true // DynsSubGps is passed to WorldCollide when all dynamic objects are in separate groups under top // level (i.e., one level deeper) DynsSubGps )
const AngMotionMax = math.Pi / 4
AngMotionMax is maximum angular motion that can be taken per update
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BBox ¶
type BBox struct { // bounding box in world coords (Axis-Aligned Bounding Box = AABB) BBox math32.Box3 // velocity-projected bounding box in world coords: extend BBox to include future position of moving bodies -- collision must be made on this basis VelBBox math32.Box3 // bounding sphere in local coords BSphere math32.Sphere // area Area float32 // volume Volume float32 }
BBox contains bounding box and other gross object properties
func (*BBox) IntersectsVelBox ¶
IntersectsVelBox returns true if two velocity-projected bounding boxes intersect
func (*BBox) UpdateFromBBox ¶
func (bb *BBox) UpdateFromBBox()
UpdateFromBBox updates other values from BBox
func (*BBox) VelNilProject ¶
func (bb *BBox) VelNilProject()
VelNilProject is for static items -- just copy the BBox
func (*BBox) VelProject ¶
VelProject computes the velocity-projected bounding box for given velocity and step size
type BodyBase ¶
type BodyBase struct { NodeBase // rigid body properties, including mass, bounce, friction etc Rigid Rigid // visualization name -- looks up an entry in the scene library that provides the visual representation of this body Vis string // default color of body for basic InitLibrary configuration Color string }
BodyBase is the base type for all specific Body types
func NewBodyBase ¶
NewBodyBase returns a new BodyBase with the given optional parent: BodyBase is the base type for all specific Body types
func (*BodyBase) AsBodyBase ¶
func (*BodyBase) SetColor ¶
SetColor sets the [BodyBase.Color]: default color of body for basic InitLibrary configuration
type Box ¶
type Box struct { BodyBase // size of box in each dimension (units arbitrary, as long as they are all consistent -- meters is typical) Size math32.Vector3 }
Box is a box body shape
type Capsule ¶
type Capsule struct { BodyBase // height of the cylinder portion of the capsule Height float32 // radius of the top hemisphere TopRad float32 // radius of the bottom hemisphere BotRad float32 }
Capsule is a generalized cylinder body shape, with hemispheres at each end, with separate radii for top and bottom.
func NewCapsule ¶
NewCapsule returns a new Capsule with the given optional parent: Capsule is a generalized cylinder body shape, with hemispheres at each end, with separate radii for top and bottom.
func (*Capsule) SetHeight ¶
SetHeight sets the [Capsule.Height]: height of the cylinder portion of the capsule
type Contact ¶
type Contact struct { // one body A Body // the other body B Body // normal pointing from center of B to center of A NormB math32.Vector3 // point on spherical shell of B where A is contacting PtB math32.Vector3 // distance from PtB along NormB to contact point on spherical shell of A Dist float32 }
Contact is one pairwise point of contact between two bodies. Contacts are represented in spherical terms relative to the spherical BBox of A and B.
func (*Contact) UpdateDist ¶ added in v0.2.0
func (c *Contact) UpdateDist()
UpdateDist updates the distance information for the contact
type Contacts ¶
type Contacts []*Contact
Contacts is a slice list of contacts
func BodyVelBBoxIntersects ¶
BodyVelBBoxIntersects returns the list of potential contact nodes between a and b (could be the same or different groups) that have intersecting velocity-projected bounding boxes. In general a should be dynamic bodies and b either dynamic or static. This is the broad first-pass filtering.
type Cylinder ¶
type Cylinder struct { BodyBase // height of the cylinder Height float32 // radius of the top -- set to 0 for a cone TopRad float32 // radius of the bottom BotRad float32 }
Cylinder is a generalized cylinder body shape, with separate radii for top and bottom. A cone has a zero radius at one end.
func NewCylinder ¶
NewCylinder returns a new Cylinder with the given optional parent: Cylinder is a generalized cylinder body shape, with separate radii for top and bottom. A cone has a zero radius at one end.
type Group ¶
type Group struct {
NodeBase
}
Group is a container of bodies, joints, or other groups it should be used strategically to partition the space and its BBox is used to optimize tree-based collision detection. Use a group for the top-level World node as well.
func NewGroup ¶
NewGroup returns a new Group with the given optional parent: Group is a container of bodies, joints, or other groups it should be used strategically to partition the space and its BBox is used to optimize tree-based collision detection. Use a group for the top-level World node as well.
func (*Group) RayBodyIntersections ¶
RayBodyIntersections returns a list of bodies whose bounding box intersects with the given ray, with the point of intersection
func (*Group) WorldCollide ¶
WorldCollide does first pass filtering step of collision detection based on separate dynamic vs. dynamic and dynamic vs. static groups. If dynTop is true, then each Dynamic group is separate at the top level -- otherwise they are organized at the next group level. Contacts are organized by dynamic group, when non-nil, for easier processing.
func (*Group) WorldDynGroupBBox ¶
func (gp *Group) WorldDynGroupBBox()
WorldDynGroupBBox does a GroupBBox on all dynamic nodes
func (*Group) WorldInit ¶
func (gp *Group) WorldInit()
WorldInit does the full tree InitAbs and GroupBBox updates
func (*Group) WorldRelToAbs ¶
func (gp *Group) WorldRelToAbs()
WorldRelToAbs does a full RelToAbs update for all Dynamic groups, for Scripted mode updates with manual updating of Rel values.
type Node ¶
type Node interface { tree.Node // AsNodeBase returns a generic NodeBase for our node -- gives generic // access to all the base-level data structures without needing interface methods. AsNodeBase() *NodeBase // AsBody returns a generic Body interface for our node -- nil if not a Body AsBody() Body // GroupBBox sets bounding boxes for groups based on groups or bodies. // called in a FuncDownMeLast traversal. GroupBBox() // InitAbs sets current Abs physical state parameters from Initial values // which are local, relative to parent -- is passed the parent (nil = top). // Body nodes should also set their bounding boxes. // Called in a FuncDownMeFirst traversal. InitAbs(par *NodeBase) // RelToAbs updates current world Abs physical state parameters // based on Rel values added to updated Abs values at higher levels. // Abs.LinVel is updated from the resulting change from prior position. // This is useful for manual updating of relative positions (scripted movement). // It is passed the parent (nil = top). // Body nodes should also update their bounding boxes. // Called in a FuncDownMeFirst traversal. RelToAbs(par *NodeBase) // Step computes one update of the world Abs physical state parameters, // using *current* velocities -- add forces prior to calling. // Use this for physics-based state updates. // Body nodes should also update their bounding boxes. Step(step float32) }
Node is the common interface for all nodes.
type NodeBase ¶
type NodeBase struct { tree.NodeBase // Dynamic is whether this node can move. If it is false, then this is a Static node. // Any top-level group that is not Dynamic is immediately pruned from further consideration, // so top-level groups should be separated into Dynamic and Static nodes at the start. Dynamic bool // initial position, orientation, velocity in *local* coordinates (relative to parent) Initial State `display:"inline"` // current relative (local) position, orientation, velocity -- only change these values, as abs values are computed therefrom Rel State `display:"inline"` // current absolute (world) position, orientation, velocity Abs State `set:"-" edit:"-" display:"inline"` // bounding box in world coordinates (aggregated for groups) BBox BBox `set:"-"` }
NodeBase is the basic node, which has position, rotation, velocity and computed bounding boxes, etc. There are only three different kinds of Nodes: Group, Body, and Joint
func NewNodeBase ¶
NewNodeBase returns a new NodeBase with the given optional parent: NodeBase is the basic node, which has position, rotation, velocity and computed bounding boxes, etc. There are only three different kinds of Nodes: Group, Body, and Joint
func (*NodeBase) AsNodeBase ¶
func (*NodeBase) InitAbsBase ¶
InitAbsBase is the base-level version of InitAbs -- most nodes call this. InitAbs sets current Abs physical state parameters from Initial values which are local, relative to parent -- is passed the parent (nil = top). Body nodes should also set their bounding boxes. Called in a FuncDownMeFirst traversal.
func (*NodeBase) RelToAbsBase ¶
RelToAbsBase is the base-level version of RelToAbs -- most nodes call this. note: Group WorldRelToAbs ensures only called on Dynamic nodes. RelToAbs updates current world Abs physical state parameters based on Rel values added to updated Abs values at higher levels. Abs.LinVel is updated from the resulting change from prior position. This is useful for manual updating of relative positions (scripted movement). It is passed the parent (nil = top). Body nodes should also update their bounding boxes. Called in a FuncDownMeFirst traversal.
func (*NodeBase) SetDynamic ¶ added in v0.2.0
SetDynamic sets the [NodeBase.Dynamic]: Dynamic is whether this node can move. If it is false, then this is a Static node. Any top-level group that is not Dynamic is immediately pruned from further consideration, so top-level groups should be separated into Dynamic and Static nodes at the start.
func (*NodeBase) SetInitAngVel ¶
SetInitAngVel sets the initial angular velocity
func (*NodeBase) SetInitLinVel ¶
SetInitLinVel sets the initial linear velocity
func (*NodeBase) SetInitPos ¶
SetInitPos sets the initial position
func (*NodeBase) SetInitQuat ¶
SetInitQuat sets the initial rotation as a Quaternion
func (*NodeBase) SetInitial ¶
SetInitial sets the [NodeBase.Initial]: initial position, orientation, velocity in *local* coordinates (relative to parent)
func (*NodeBase) SetRel ¶
SetRel sets the [NodeBase.Rel]: current relative (local) position, orientation, velocity -- only change these values, as abs values are computed therefrom
func (*NodeBase) StepBase ¶
StepBase is base-level version of Step -- most nodes call this. note: Group WorldRelToAbs ensures only called on Dynamic nodes. Computes one update of the world Abs physical state parameters, using *current* velocities -- add forces prior to calling. Use this for physics-based state updates. Body nodes should also update their bounding boxes.
type Rigid ¶
type Rigid struct { // 1/mass -- 0 for no mass InvMass float32 // COR or coefficient of restitution -- how elastic is the collision i.e., final velocity / initial velocity Bounce float32 `min:"0" max:"1"` // friction coefficient -- how much friction is generated by transverse motion Friction float32 // record of computed force vector from last iteration Force math32.Vector3 // Last calculated rotational inertia matrix in local coords RotInertia math32.Matrix3 }
Rigid contains the full specification of a given object's basic physics properties including position, orientation, velocity. These
type Sphere ¶
Sphere is a spherical body shape.
func NewSphere ¶
NewSphere returns a new Sphere with the given optional parent: Sphere is a spherical body shape.
type State ¶
type State struct { // position of center of mass of object Pos math32.Vector3 // rotation specified as a Quat Quat math32.Quat // linear velocity LinVel math32.Vector3 // angular velocity AngVel math32.Vector3 }
State contains the basic physical state including position, orientation, velocity. These are only the values that can be either relative or absolute -- other physical state values such as Mass should go in Rigid.
func (*State) Defaults ¶
func (ps *State) Defaults()
Defaults sets defaults only if current values are nil
func (*State) EulerRotation ¶
EulerRotation returns the current rotation in Euler angles (degrees).
func (*State) EulerRotationRad ¶
EulerRotationRad returns the current rotation in Euler angles (radians).
func (*State) Move ¶
Move moves (translates) Pos by given amount, and sets the LinVel to the given delta -- this can be useful for Scripted motion to track movement.
func (*State) MoveOnAxis ¶
MoveOnAxis moves (translates) the specified distance on the specified local axis, relative to the current rotation orientation. The axis is normalized prior to aplying the distance factor. Sets the LinVel to motion vector.
func (*State) MoveOnAxisAbs ¶
MoveOnAxisAbs moves (translates) the specified distance on the specified local axis, in absolute X,Y,Z coordinates (does not apply the Quat rotation factor. The axis is normalized prior to aplying the distance factor. Sets the LinVel to motion vector.
func (*State) RotateEuler ¶
RotateEuler rotates by given Euler angles (in degrees) relative to existing rotation.
func (*State) RotateEulerRad ¶
RotateEulerRad rotates by given Euler angles (in radians) relative to existing rotation.
func (*State) RotateOnAxis ¶
RotateOnAxis rotates around the specified local axis the specified angle in degrees.
func (*State) RotateOnAxisRad ¶
RotateOnAxisRad rotates around the specified local axis the specified angle in radians.
func (*State) SetAxisRotation ¶
SetAxisRotation sets rotation from local axis and angle in degrees.
func (*State) SetAxisRotationRad ¶
SetAxisRotationRad sets rotation from local axis and angle in radians.
func (*State) SetEulerRotation ¶
SetEulerRotation sets the rotation in Euler angles (degrees).
func (*State) SetEulerRotationRad ¶
SetEulerRotationRad sets the rotation in Euler angles (radians).
func (*State) StepByAngVel ¶
StepByAngVel steps the Quat rotation from angular velocity
func (*State) StepByLinVel ¶
StepByLinVel steps the Pos from the linear velocity