collision

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: BSD-2-Clause Imports: 8 Imported by: 1

Documentation

Overview

Package collision implements collision related algorithms and data structures. WARNING: Parts of this package are experimental and incomplete!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckConvex

func CheckConvex(g1, g2 *geometry.Geometry) bool

Types

type Contact

type Contact struct {
	Point  math32.Vector3
	Normal math32.Vector3
	Depth  float32
}

Contact describes a contact point, normal, and depth.

type Intersect added in v0.2.0

type Intersect struct {
	// Distance between the origin of the ray and the intersect
	Distance float32
	// Point of intersection in world coordinates
	Point math32.Vector3
	// Intersected node
	Object core.INode
	// If the geometry has indices, this field is the
	// index in the Indices buffer of the vertex intersected
	// or the first vertex of the intersected face.
	// If the geometry doesn't have indices, this field is the
	// index in the positions buffer of the vertex intersected
	// or the first vertex of the insersected face.
	Index uint32
}

Intersect describes the intersection between a ray and an object

type Matrix

type Matrix [][]bool

Matrix is a triangular collision matrix indicating which pairs of bodies are colliding.

func NewMatrix

func NewMatrix() Matrix

NewMatrix creates and returns a pointer to a new collision Matrix.

func (*Matrix) Get

func (m *Matrix) Get(i, j int) bool

Get returns whether i and j are colliding.

func (*Matrix) Reset

func (m *Matrix) Reset()

Reset clears all values.

func (*Matrix) Set

func (m *Matrix) Set(i, j int, val bool)

Set sets whether i and j are colliding.

type Raycaster added in v0.2.0

type Raycaster struct {
	// The distance from the ray origin to the intersected points
	// must be greater than the value of this field to be considered.
	// The defaul value is 0.0
	Near float32
	// The distance from the ray origin to the intersected points
	// must be less than the value of this field to be considered.
	// The defaul value is +Infinity.
	Far float32
	// Minimum distance in world coordinates between the ray and
	// a line segment when checking intersects with lines.
	// The default value is 0.1
	LinePrecision float32
	// Minimum distance in world coordinates between the ray and
	// a point when checking intersects with points.
	// The default value is 0.1
	PointPrecision float32
	// This field must be set with the camera view matrix used
	// when checking for sprite intersections.
	// It is set automatically when using camera.SetRaycaster
	ViewMatrix math32.Matrix4
	// Embedded ray
	math32.Ray
}

Raycaster represents an empty object that can cast rays and check for ray intersections.

func NewRaycaster added in v0.2.0

func NewRaycaster(origin, direction *math32.Vector3) *Raycaster

NewRaycaster creates and returns a pointer to a new raycaster object with the specified origin and direction.

func (*Raycaster) IntersectObject added in v0.2.0

func (rc *Raycaster) IntersectObject(inode core.INode, recursive bool) []Intersect

IntersectObject checks intersections between this raycaster and and the specified node. If recursive is true, it also checks the intersection with the node's children. Intersections are returned sorted by distance, closest first.

func (*Raycaster) IntersectObjects added in v0.2.0

func (rc *Raycaster) IntersectObjects(inodes []core.INode, recursive bool) []Intersect

IntersectObjects checks intersections between this raycaster and the specified array of scene nodes. If recursive is true, it also checks the intersection with each nodes' children. Intersections are returned sorted by distance, closest first.

func (*Raycaster) RaycastLineStrip added in v0.2.0

func (rc *Raycaster) RaycastLineStrip(l *graphic.LineStrip, intersects *[]Intersect)

RaycastLineStrip

func (*Raycaster) RaycastLines added in v0.2.0

func (rc *Raycaster) RaycastLines(l *graphic.Lines, intersects *[]Intersect)

RaycastLines

func (*Raycaster) RaycastMesh added in v0.2.0

func (rc *Raycaster) RaycastMesh(m *graphic.Mesh, intersects *[]Intersect)

RaycastMesh

func (*Raycaster) RaycastPoints added in v0.2.0

func (rc *Raycaster) RaycastPoints(p *graphic.Points, intersects *[]Intersect)

RaycastPoints

func (*Raycaster) RaycastSprite added in v0.2.0

func (rc *Raycaster) RaycastSprite(s *graphic.Sprite, intersects *[]Intersect)

RaycastSprite checks intersections between the raycaster and the specified sprite and if any found appends it to the specified intersects array.

func (*Raycaster) SetFromCamera added in v0.2.0

func (rc *Raycaster) SetFromCamera(cam *camera.Camera, sx, sy float32) error

SetRaycaster sets the specified raycaster with this camera position in world coordinates pointing to the direction defined by the specified coordinates unprojected using this camera.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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