Documentation
¶
Overview ¶
Package shape provides types and functions for defining 3D shapes and performing intersection (collision) checks between them.
Index ¶
- func CheckIntersection(first, second Shape, resultSet *IntersectionResultSet)
- func CheckLineIntersection(line StaticLine, mesh StaticMesh, resultSet *IntersectionResultSet)
- type Intersection
- type IntersectionResultSet
- type Placement
- type Shape
- type StaticBox
- type StaticLine
- type StaticMesh
- type StaticSphere
- type StaticTriangle
- func (t StaticTriangle) A() dprec.Vec3
- func (t StaticTriangle) Area() float64
- func (t StaticTriangle) B() dprec.Vec3
- func (t StaticTriangle) C() dprec.Vec3
- func (t StaticTriangle) ContainsPoint(point dprec.Vec3) bool
- func (t StaticTriangle) IsLookingTowards(direction dprec.Vec3) bool
- func (t StaticTriangle) Normal() dprec.Vec3
- func (t StaticTriangle) Transformed(translation dprec.Vec3, rotation dprec.Quat) StaticTriangle
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 ¶
NewIdentityPlacement returns a new Placement that is centered.
func NewPlacement ¶
NewPlacement creates a new Placement for the specified shape with the specified position and rotation.
func (Placement) BoundingSphereRadius ¶
BoundingSphereRadius returns the radius of a sphere that can encompass this shape.
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 ¶
NewStaticBox creates a new StaticBox shape.
func (StaticBox) BoundingSphereRadius ¶
BoundingSphereRadius returns the radius of a sphere that can encompass this shape.
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) 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.