shape

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package shape provides types and functions for defining 3D shapes and performing intersection (collision) checks between them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIntersection

func CheckIntersection(first, second Shape, resultSet *IntersectionResultSet)

CheckIntersection checks whether the two shapes intersect.

func CheckLineIntersection

func CheckLineIntersection(line StaticLine, mesh StaticMesh, resultSet *IntersectionResultSet)

Types

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 IntersectionResultSet

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

IntersectionResultSet is a structure that can be used to collection the result of an intersection test.

func NewIntersectionResultSet

func NewIntersectionResultSet(capacity int) *IntersectionResultSet

NewIntersectionResultSet creates a new IntersectionResultSet instance with the specified initial capacity. The set is allowed to grow past the specified capacity.

func (*IntersectionResultSet) Add

func (s *IntersectionResultSet) Add(intersection Intersection)

Add adds a new Intersection to this set.

func (*IntersectionResultSet) AddFlipped

func (s *IntersectionResultSet) AddFlipped(flipped bool)

AddFlipped controls whether newly added Intersections should be flipped beforehand.

func (*IntersectionResultSet) Found

func (s *IntersectionResultSet) Found() bool

Found returns whether this set contains any intersections.

func (*IntersectionResultSet) Intersections

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

Intersections returns a list of all intersections that have been found. The returned slice must not be modified or cached as it will be reused.

func (*IntersectionResultSet) Reset

func (s *IntersectionResultSet) Reset()

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

type Placement

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

Placement represents a mechanism through which a shape can have dynamic position and orientation assigned.

func NewIdentityPlacement

func NewIdentityPlacement(shape Shape) Placement

NewIdentityPlacement returns a new Placement that is centered.

func NewPlacement

func NewPlacement(shape Shape, position dprec.Vec3, rotation dprec.Quat) Placement

NewPlacement creates a new Placement for the specified shape with the specified position and rotation.

func (Placement) BoundingSphereRadius

func (p Placement) BoundingSphereRadius() float64

BoundingSphereRadius returns the radius of a sphere that can encompass this shape.

func (Placement) Position

func (p Placement) Position() dprec.Vec3

Position returns this Placement's position.

func (Placement) Rotation

func (p Placement) Rotation() dprec.Quat

Rotation returns this Placement's rotation.

func (Placement) Shape

func (p Placement) Shape() Shape

Shape returns the Shape held by this Placement.

func (Placement) Transformed

func (p Placement) Transformed(translation dprec.Vec3, rotation dprec.Quat) Placement

Transformed returns a new Placement that is based on the current one but with the specified translation and rotation applied on top of this one.

type Shape

type Shape interface {

	// BoundingSphereRadius returns the radius from the center of the shape
	// after which the shape is no longer present.
	//
	// Ideally this radius should be the smallest possible to get the most
	// performance optimization.
	BoundingSphereRadius() float64
}

Shape represent a 3D shape.

type StaticBox

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

StaticBox represents a box shape that cannot be resized.

func NewStaticBox

func NewStaticBox(width, height, length float64) StaticBox

NewStaticBox creates a new StaticBox shape.

func (StaticBox) BoundingSphereRadius

func (b StaticBox) BoundingSphereRadius() float64

BoundingSphereRadius returns the radius of a sphere that can encompass this shape.

func (StaticBox) Height

func (b StaticBox) Height() float64

Height returns the height of this box.

func (StaticBox) Length

func (b StaticBox) Length() float64

Length returns the length of this box.

func (StaticBox) Width

func (b StaticBox) Width() float64

Width returns the width of this box.

type StaticLine

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

StaticLine represents a line segment between two 3D points that cannot be resized.

func NewStaticLine

func NewStaticLine(a, b dprec.Vec3) StaticLine

NewStaticLine creates a new StaticLine.

func (StaticLine) A

func (l StaticLine) A() dprec.Vec3

A returns the starting point of the line.

func (StaticLine) B

func (l StaticLine) B() dprec.Vec3

B returns the ending point of the line.

func (StaticLine) Length

func (l StaticLine) Length() float64

Length returns the length of the line.

type StaticMesh

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

StaticMesh represents a collection of triangles that cannot be resized or repositioned.

func NewStaticMesh

func NewStaticMesh(triangles []StaticTriangle) StaticMesh

NewStaticMesh creates a new StaticMesh from the specified list of triangles.

func (StaticMesh) BoundingSphereRadius

func (m StaticMesh) BoundingSphereRadius() float64

BoundingSphereRadius returns the radius of a sphere that can encompass this shape.

func (StaticMesh) Triangles

func (m StaticMesh) Triangles() []StaticTriangle

Triangles returns the list of triangles that make up this mesh. The contents of the returned slice must never be modified.

type StaticSphere

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

StaticSphere represents a 3D sphere that cannot be resized.

func NewStaticSphere

func NewStaticSphere(radius float64) StaticSphere

NewStaticSphere returns a new StaticSphere.

func (StaticSphere) BoundingSphereRadius

func (s StaticSphere) BoundingSphereRadius() float64

BoundingSphereRadius returns the radius of a sphere that can encompass this shape.

func (StaticSphere) Radius

func (s StaticSphere) Radius() float64

Radius returns the radius of the sphere.

type StaticTriangle

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

StaticTriangle represents a tringle in 3D space.

func NewStaticTriangle

func NewStaticTriangle(a, b, c dprec.Vec3) StaticTriangle

NewStaticTriangle creates a new StaticTriangle.

func (StaticTriangle) A

func (t StaticTriangle) A() dprec.Vec3

A returns the first corner of the triangle.

func (StaticTriangle) Area

func (t StaticTriangle) Area() float64

Area returns the triangle's surface area.

func (StaticTriangle) B

func (t StaticTriangle) B() dprec.Vec3

B returns the second corner of the triangle.

func (StaticTriangle) C

func (t StaticTriangle) C() dprec.Vec3

C returns the third corner of the triangle.

func (StaticTriangle) ContainsPoint

func (t StaticTriangle) ContainsPoint(point dprec.Vec3) bool

ContainsPoint checks whether the specified point is is inside the triangle.

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

func (StaticTriangle) IsLookingTowards

func (t StaticTriangle) IsLookingTowards(direction dprec.Vec3) bool

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

func (StaticTriangle) Normal

func (t StaticTriangle) Normal() dprec.Vec3

Normal returns the orientation of the triangle's surface.

func (StaticTriangle) Transformed

func (t StaticTriangle) Transformed(translation dprec.Vec3, rotation dprec.Quat) StaticTriangle

Transformed returns a new StaticTriangle that is the result of applying the specified rotation and translation to the current triangle.

Jump to

Keyboard shortcuts

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