Documentation ¶
Overview ¶
Package glider is a library that handles 3d collision testing.
Index ¶
- Constants
- func Collide(c1 Collider, c2 Collider) int
- type AABBox
- func (aabb *AABBox) CollideVsAABBox(b2 *AABBox) int
- func (aabb *AABBox) CollideVsPlane(p *Plane) int
- func (aabb *AABBox) CollideVsRay(ray *CollisionRay) (int, float32)
- func (aabb *AABBox) CollideVsSphere(s *Sphere) int
- func (aabb *AABBox) IntersectPoint(v *mgl.Vec3) bool
- func (aabb *AABBox) SetOffset(offset *mgl.Vec3)
- func (aabb *AABBox) SetOffset3f(x, y, z float32)
- type AABSquare
- type Collider
- type CollisionRay
- type OBBox
- type Plane
- type Sphere
- func (s1 *Sphere) CollideVsAABBox(b *AABBox) int
- func (s1 *Sphere) CollideVsPlane(p *Plane) int
- func (s1 *Sphere) CollideVsRay(ray *CollisionRay) (int, float32)
- func (s1 *Sphere) CollideVsSphere(s2 *Sphere) int
- func (s1 *Sphere) SetOffset(offset *mgl.Vec3)
- func (s1 *Sphere) SetOffset3f(x, y, z float32)
Constants ¶
const ( // NoIntersect means there was no collision detect. NoIntersect = 0 // Intersect means there was a collision Intersect = 1 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AABBox ¶
type AABBox struct { // Min is the corner of the box opposite of Max. (e.g. lower-back-left corner) // and should be the more 'negative' corner (e.g. max={3,3,3} and min={1,1,1} ) Min mgl.Vec3 // Max is the corner of the box opposite of Min. (e.g. top-front-right corner) // and should be the more 'positive' corner (e.g. max={3,3,3} and min={1,1,1} ) Max mgl.Vec3 // Offset is the world-space location of the that can be considered an offset to both Min and Max Offset mgl.Vec3 // Tags provides a way to label an AABB geometry in a custom application // (e.g. labelling a collision as "wall" or "floor"). Tags []string }
AABBox is a axis aligned cube shape defined by a minimum and maximum corner.
func (*AABBox) CollideVsAABBox ¶
CollideVsAABBox tests to see if the AABBox parameter intersects the AABBox.
func (*AABBox) CollideVsPlane ¶
CollideVsPlane tests to see if the plane is intersects the AABBox.
func (*AABBox) CollideVsRay ¶
func (aabb *AABBox) CollideVsRay(ray *CollisionRay) (int, float32)
CollideVsRay tests to see if a raycast intersects the AABBox.
func (*AABBox) CollideVsSphere ¶
CollideVsSphere returns the intersection between an AABB and a sphere.
func (*AABBox) IntersectPoint ¶
IntersectPoint tests to see if the point is intersects the AABBox.
func (*AABBox) SetOffset3f ¶
SetOffset3f changes the offset of the collision object.
type AABSquare ¶
type AABSquare struct { // Min is the corner of the box opposite of Max. (e.g. lower-left corner) Min mgl.Vec2 // Max is the corner of the box opposite of Min. (e.g. top-right corner) Max mgl.Vec2 // Offset is the world-space location of the that can be considered an offset to both Min and Max Offset mgl.Vec2 // Tags provides a way to label an AABB geometry in a custom application // (e.g. labelling a collision as "wall" or "floor"). Tags []string }
AABSquare is a axis aligned sqare shape defined by a minimum and maximum corner.
type Collider ¶
type Collider interface { CollideVsSphere(sphere *Sphere) int CollideVsAABBox(box *AABBox) int CollideVsPlane(plane *Plane) int CollideVsRay(ray *CollisionRay) (int, float32) SetOffset(offset *mgl.Vec3) SetOffset3f(x, y, z float32) }
Collider is an interface for objects that con collide with other collision primitives.
type CollisionRay ¶
type CollisionRay struct { // Origin is the start of the ray Origin mgl.Vec3 // contains filtered or unexported fields }
CollisionRay represents a simple ray for casting in collision tests.
func (*CollisionRay) GetDirection ¶
func (cr *CollisionRay) GetDirection() mgl.Vec3
GetDirection gets the direction of the collision ray.
func (*CollisionRay) SetDirection ¶
func (cr *CollisionRay) SetDirection(d mgl.Vec3)
SetDirection sets the direction of the collision ray. Will be normalized and have some math cached as well.
type OBBox ¶ added in v0.2.0
type OBBox struct { // HalfSize holds the cube's half-sizes along each of its local axes. HalfSize mgl.Vec3 // Offset is the world-space center location of cube. Offset mgl.Vec3 // Tags provides a way to label an OBB geometry in a custom application // (e.g. labelling a collision as "wall" or "floor"). Tags []string // contains filtered or unexported fields }
OBBox is a oriented bounding box shape defined by a center ('Offset') and a HalfSize. HalfSize is used instead of Min/Max corners because the math is quicker.
func (*OBBox) CollideVsSphere ¶ added in v0.2.0
CollideVsSphere tests an OBBox vs Sphere collision.
func (*OBBox) SetOffset3f ¶ added in v0.2.0
SetOffset3f changes the offset of the collision object.
func (*OBBox) SetOrientation ¶ added in v0.2.0
SetOrientation sets the rotation of the box.
type Plane ¶
type Plane struct { // Normal is the direction the plane is facing; the normal of the plane. Normal mgl.Vec3 // D is the plane constant, considered to be the distance from the origin. D float32 }
Plane represents an infinite plane defined by a point and its normal.
func NewPlaneFromNormalAndPoint ¶
NewPlaneFromNormalAndPoint makes a new Plane object based on a normal and point in space.
type Sphere ¶
type Sphere struct { // Center is the center point of the sphere, in local space (model-space in 3d graphics) Center mgl.Vec3 // Offset is the world-space location of the that can be considered an offset to Center Offset mgl.Vec3 // Radius determines the size of the sphere Radius float32 }
Sphere is defined by a center point and a radius and can be used in collisions against AABB.
func (*Sphere) CollideVsAABBox ¶
CollideVsAABBox tests a collision between a sphere and an AABBox.
func (*Sphere) CollideVsPlane ¶
CollideVsPlane tests a collision between a sphere and a plane.
func (*Sphere) CollideVsRay ¶
func (s1 *Sphere) CollideVsRay(ray *CollisionRay) (int, float32)
CollideVsRay tests a collision between a sphere and a ray. FIXME: sphere's don't return a distance at present
func (*Sphere) CollideVsSphere ¶
CollideVsSphere tests a collision between two spheres.
func (*Sphere) SetOffset3f ¶
SetOffset3f changes the offset of the collision object.