collision

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIntersectionBoxWithMesh

func CheckIntersectionBoxWithMesh(box Box, mesh Mesh, flipped bool, resultSet IntersectionCollection)

CheckIntersectionBoxWithMesh checks if a Box shape intersects with a Mesh shape.

func CheckIntersectionLineWithMesh

func CheckIntersectionLineWithMesh(line Line, mesh Mesh, flipped bool, resultSet IntersectionCollection)

CheckIntersectionLineWithMesh checks if a Line shape intersects with a Mesh shape.

func CheckIntersectionLineWithTriangle

func CheckIntersectionLineWithTriangle(line Line, triangle Triangle, flipped bool, resultSet IntersectionCollection)

CheckIntersectionLineWithTriangle checks if a Line shape intersects with a Triangle shape.

func CheckIntersectionSetWithSet

func CheckIntersectionSetWithSet(first, second Set, resultSet IntersectionCollection)

CheckIntersectionSetWithSet checks for any intersections between the two collision Sets.

func CheckIntersectionSphereWithBox

func CheckIntersectionSphereWithBox(sphere Sphere, box Box, flipped bool, resultSet IntersectionCollection)

CheckIntersectionSphereWithBox checks if a Sphere shape intersects with a Box shape.

func CheckIntersectionSphereWithMesh

func CheckIntersectionSphereWithMesh(sphere Sphere, mesh Mesh, flipped bool, resultSet IntersectionCollection)

CheckIntersectionSphereWithMesh checks if a Sphere shape intersects with a Mesh shape.

func CheckIntersectionSphereWithSphere

func CheckIntersectionSphereWithSphere(first, second Sphere, flipped bool, resultSet IntersectionCollection)

CheckIntersectionSphereWithSphere checks if a Sphere shape intersects with another Sphere shape.

func CheckIntersectionSphereWithTriangle

func CheckIntersectionSphereWithTriangle(sphere Sphere, triangle Triangle, flipped bool, resultSet IntersectionCollection)

CheckIntersectionSphereWithTriangle checks if a Sphere shape intersects with a Triangle shape.

func IsSphereWithSphereIntersecting

func IsSphereWithSphereIntersecting(bs1, bs2 Sphere) bool

IsSphereWithSphereIntersecting is a quick check to determine if two spheres are intersecting.

func LineWithSphereIntersectionPoints

func LineWithSphereIntersectionPoints(line Line, sphere Sphere) (dprec.Vec3, dprec.Vec3, bool)

LineWithSphereIntersectionPoints returns the two intersection points of a line with a sphere, if there are such.

func LineWithSurfaceIntersectionPoint

func LineWithSurfaceIntersectionPoint(line Line, point, normal dprec.Vec3) (dprec.Vec3, bool)

LineWithSurfaceIntersectionPoint returns the point where a line intersects with a surface, if there is one.

Types

type BestIntersection

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

BestIntersection is an implementation of IntersectionCollection that keeps track of the best (smallest depth) observed intersection.

func (*BestIntersection) AddIntersection

func (i *BestIntersection) AddIntersection(intersection Intersection)

AddIntersection tracks the specified intersection.

func (*BestIntersection) Intersection

func (i *BestIntersection) Intersection() (Intersection, bool)

Intersection returns the best observed intersection and a flag whether there was actually any intersection observed.

func (*BestIntersection) Reset

func (i *BestIntersection) Reset()

Reset clears any observed intersection.

type Box

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

Box represents a 3D box shape.

func NewBox

func NewBox(position dprec.Vec3, rotation dprec.Quat, size dprec.Vec3) Box

NewBox creates a new Box shape.

func (*Box) BoundingSphere

func (b *Box) BoundingSphere() Sphere

BoundingSphere returns a sphere that encompases this box.

func (*Box) HalfHeight

func (b *Box) HalfHeight() float64

HalfHeight returns half of the height of this box.

func (*Box) HalfLength

func (b *Box) HalfLength() float64

HalfLength returns half of the length of this box.

func (*Box) HalfWidth

func (b *Box) HalfWidth() float64

HalfWidth returns half of the width of this box.

func (*Box) Height

func (b *Box) Height() float64

Height returns the height of this box.

func (*Box) Length

func (b *Box) Length() float64

Length returns the length of this box.

func (*Box) Position

func (b *Box) Position() dprec.Vec3

Position returns the position of this box.

func (*Box) Replace

func (b *Box) Replace(template Box, transform Transform)

Replace replaces this shape with the template one after the specified transformation has been applied to it.

func (*Box) Rotation

func (b *Box) Rotation() dprec.Quat

Rotation returns the rotation of this box.

func (*Box) Size

func (b *Box) Size() dprec.Vec3

Size returns the size of this box.

func (*Box) Width

func (b *Box) Width() float64

Width returns the width of this box.

type Intersection

type Intersection struct {

	// Depth returns the amount of penetration between the two shapes.
	Depth float64

	// FirstContact returns the point of contact on the first shape.
	FirstContact dprec.Vec3

	// FirstDisplaceNormal returns the normal along which the second shape
	// needs to be moved in order to separate the two shapes the fastest.
	FirstDisplaceNormal dprec.Vec3

	// SecondContact returns the point of contact on the second shape.
	SecondContact dprec.Vec3

	// SecondDisplaceNormal returns the normal along which the first shape
	// needs to be moved in order to separate the two shapes the fastest.
	SecondDisplaceNormal dprec.Vec3
}

Intersection represents the collision between two shapes.

func (*Intersection) Flipped

func (i *Intersection) Flipped() Intersection

Flipped returns a new Intersection where the first and second shapes have their places swapped within the structure.

type IntersectionBucket

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

IntersectionBucket is a structure that can be used to collect the result of an intersection test.

func NewIntersectionBucket

func NewIntersectionBucket(initialCapacity int) *IntersectionBucket

NewIntersectionBucket creates a new IntersectionBucket instance with the specified initial capacity.

func (*IntersectionBucket) AddIntersection

func (b *IntersectionBucket) AddIntersection(intersection Intersection)

Add adds a new Intersection to this set.

func (*IntersectionBucket) Intersections

func (s *IntersectionBucket) Intersections() []Intersection

Intersections returns a slice of all intersections that have been observed.

NOTE: The slice must not be modified or cached as it will be reused.

func (*IntersectionBucket) IsEmpty

func (b *IntersectionBucket) IsEmpty() bool

IsEmpty returns whether no intersections were found.

func (*IntersectionBucket) Reset

func (b *IntersectionBucket) Reset()

Reset clears the buffer of this result set so that it can be reused.

type IntersectionCollection

type IntersectionCollection interface {
	AddIntersection(intersection Intersection)
}

IntersectionCollection represents a data structure that can hold intersections.

type LastIntersection

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

LastIntersection is an implementation of IntersectionCollection that keeps track of the last observed intersection.

func (*LastIntersection) AddIntersection

func (i *LastIntersection) AddIntersection(intersection Intersection)

AddIntersection tracks the specified intersection.

func (*LastIntersection) Intersection

func (i *LastIntersection) Intersection() (Intersection, bool)

Intersection returns the last observed intersection and a flag whether there was actually any intersection observed.

func (*LastIntersection) Reset

func (i *LastIntersection) Reset()

Reset clears any observed intersection.

type Line

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

Line represents a line segment between two 3D points.

func NewLine

func NewLine(a, b dprec.Vec3) Line

NewLine creates a new Line shape.

func (*Line) A

func (l *Line) A() dprec.Vec3

A returns the starting point of this line.

func (*Line) B

func (l *Line) B() dprec.Vec3

B returns the ending point of this line.

func (*Line) Length

func (l *Line) Length() float64

Length returns the length of this line.

func (*Line) Replace

func (l *Line) Replace(template Line, transform Transform)

Replace replaces this shape with the template one after the specified transformation has been applied to it.

type Mesh

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

Mesh represents a collection of triangles.

func NewMesh

func NewMesh(triangles []Triangle) Mesh

NewMesh creates a new Mesh from the specified list of triangles.

NOTE: The Mesh becomes the owner of the slice so callers should not keep a reference to it afterwards or modify the contents in any way.

func (*Mesh) BoundingSphere

func (m *Mesh) BoundingSphere() Sphere

BoundingSphere returns a Sphere that encompases this mesh.

func (*Mesh) Replace

func (m *Mesh) Replace(template Mesh, transform Transform)

Replace replaces this shape with the template one after the specified transformation has been applied to it.

func (*Mesh) Triangles

func (m *Mesh) Triangles() []Triangle

Triangles returns the list of triangles that make up this mesh.

NOTE: This returns the internal slice of triangles so callers should not modify the contents in any way.

type Set

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

Set represents a collection of collision shapes.

func NewSet

func NewSet(opts ...SetOption) Set

NewSet constructs a new collision Set with the specified options.

func (*Set) BoundingSphere

func (s *Set) BoundingSphere() Sphere

BoundingSphere returns a sphere that encompases this set.

func (*Set) Boxes

func (s *Set) Boxes() []Box

Boxes returns all boxes contained in this set.

NOTE: This returns the internal slice which should not be modified in any way.

func (*Set) IsEmpty

func (s *Set) IsEmpty() bool

IsEmpty returns whether this set is shapeless.

func (*Set) Meshes

func (s *Set) Meshes() []Mesh

Meshes returns all meshes contained in this set.

NOTE: This returns the internal slice which should not be modified in any way.

func (*Set) Replace

func (s *Set) Replace(template Set, transform Transform)

Replace replaces this shape with the template one after the specified transformation has been applied to it.

func (*Set) Spheres

func (s *Set) Spheres() []Sphere

Spheres returns all spheres contained in this set.

NOTE: This returns the internal slice which should not be modified in any way.

type SetOption

type SetOption func(s *Set)

SetOption represents a configuration option for a Set object.

func WithBoxes

func WithBoxes(boxes []Box) SetOption

WithBoxes specifies the box shapes contained by the set.

func WithMeshes

func WithMeshes(meshes []Mesh) SetOption

WithMeshes specifies the mesh shapes contained by the set.

func WithSpheres

func WithSpheres(spheres []Sphere) SetOption

WithSpheres specifies the sphere shapes contained by the set.

type Sphere

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

Sphere represents a 3D sphere shape.

func NewSphere

func NewSphere(position dprec.Vec3, radius float64) Sphere

NewSphere creates a new Sphere shape.

func (*Sphere) Diameter

func (s *Sphere) Diameter() float64

Diameter returns the diameter of this sphere.

func (*Sphere) Position

func (s *Sphere) Position() dprec.Vec3

Position returns the location of this sphere.

func (*Sphere) Radius

func (s *Sphere) Radius() float64

Radius returns the radius of this sphere.

func (*Sphere) Replace

func (s *Sphere) Replace(template Sphere, transform Transform)

Replace replaces this shape with the template one after the specified transformation has been applied to it.

type Transform

type Transform struct {
	Translation dprec.Vec3
	Rotation    dprec.Quat
}

Transform represents a shape transformation.

func ChainedTransform

func ChainedTransform(parent, child Transform) Transform

ChainedTransform returns the Transform that is the result of combining two Transforms together.

func IdentityTransform

func IdentityTransform() Transform

IdentityTransform returns a new Transform that represents the origin.

func RotationTransform

func RotationTransform(rotation dprec.Quat) Transform

RotationTransform returns a new Transform that represents a rotation.

func TRTransform

func TRTransform(translation dprec.Vec3, rotation dprec.Quat) Transform

TRTransform returns a new Transform that represents both a translation and a rotation.

func TranslationTransform

func TranslationTransform(translation dprec.Vec3) Transform

TranslationTransform returns a new Transform that represents a translation.

func (*Transform) Vector

func (t *Transform) Vector(v dprec.Vec3) dprec.Vec3

Vector returns the transformation of the specified vector.

type Triangle

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

Triangle represents a tringle in 3D space.

func NewTriangle

func NewTriangle(a, b, c dprec.Vec3) Triangle

NewTriangle creates a new Triangle shape.

func (*Triangle) A

func (t *Triangle) A() dprec.Vec3

A returns the first corner of the triangle.

func (*Triangle) Area

func (t *Triangle) Area() float64

Area returns the triangle's surface area.

func (*Triangle) B

func (t *Triangle) B() dprec.Vec3

B returns the second corner of the triangle.

func (*Triangle) BoundingSphere

func (t *Triangle) BoundingSphere() Sphere

BoundingSphere returns a Sphere shape that encompases this triangle.

func (*Triangle) C

func (t *Triangle) C() dprec.Vec3

C returns the third corner of the triangle.

func (*Triangle) Center

func (t *Triangle) Center() dprec.Vec3

Center returns the center of mass of the triangle.

func (*Triangle) ContainsPoint

func (t *Triangle) ContainsPoint(point dprec.Vec3) bool

ContainsPoint checks whether the specified Point is inside the triangle.

Beware, currently this method assumes that the point lies somewhere on the surface plane of the triangle.

func (*Triangle) IsLookingTowards

func (t *Triangle) IsLookingTowards(direction dprec.Vec3) bool

IsLookingTowards checks whether the orientation of the triangle looks towards the same hemisphere as the provided direction.

func (*Triangle) Normal

func (t *Triangle) Normal() dprec.Vec3

Normal returns the orientation of the triangle's surface.

func (*Triangle) Replace

func (t *Triangle) Replace(template Triangle, transform Transform)

Replace replaces this shape with the template one after the specified transformation has been applied to it.

type WorstIntersection

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

WorstIntersection is an implementation of IntersectionCollection that keeps track of the worst (largest depth) observed intersection.

func (*WorstIntersection) AddIntersection

func (i *WorstIntersection) AddIntersection(intersection Intersection)

AddIntersection tracks the specified intersection.

func (*WorstIntersection) Intersection

func (i *WorstIntersection) Intersection() (Intersection, bool)

Intersection returns the worst observed intersection and a flag whether there was actually any intersection observed.

func (*WorstIntersection) Reset

func (i *WorstIntersection) Reset()

Reset clears any observed intersection.

Jump to

Keyboard shortcuts

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