glider

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2017 License: BSD-2-Clause Imports: 2 Imported by: 6

README

Glider v0.2.1

Glider is a simple collision library written in the Go programming language using axis aligned primitives and ray casts. Support for oriented primitives is still under development.

Installation

The library can be installed with the following command:

go get github.com/go-gl/mathgl/mgl32
go get github.com/tbogdala/glider

Current Features

  • Basic 2d box collision
  • AABB intersection vs AABB
  • AABB intersection vs Sphere
  • AABB intersection vs Ray
  • AABB intersection vs Plane
  • Sphere intersection tests vs AABB
  • Sphere intersection tests vs Sphere
  • Sphere intersection tests vs Ray
  • Sphere intersection tests vs Plane

Documentation

Currently, you'll have to use godoc to read the API documentation and check out the unit tests to figure out how to use the library.

It should be mostly easy to figure out, though.

LICENSE

Glider is released under the BSD license. See the LICENSE file for more details.

Documentation

Overview

Package glider is a library that handles 3d collision testing.

Index

Constants

View Source
const (
	// NoIntersect means there was no collision detect.
	NoIntersect = 0

	// Intersect means there was a collision
	Intersect = 1
)

Variables

This section is empty.

Functions

func Collide

func Collide(c1 Collider, c2 Collider) int

Collide tests two objects that are Colliders and returns the collision test result. NOTE: currently this supports cubes and spheres. FIXME: planes and rays are not tested here

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 NewAABBox

func NewAABBox() *AABBox

NewAABBox creates a new AABBox object

func (*AABBox) CollideVsAABBox

func (aabb *AABBox) CollideVsAABBox(b2 *AABBox) int

CollideVsAABBox tests to see if the AABBox parameter intersects the AABBox.

func (*AABBox) CollideVsPlane

func (aabb *AABBox) CollideVsPlane(p *Plane) int

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

func (aabb *AABBox) CollideVsSphere(s *Sphere) int

CollideVsSphere returns the intersection between an AABB and a sphere.

func (*AABBox) IntersectPoint

func (aabb *AABBox) IntersectPoint(v *mgl.Vec3) bool

IntersectPoint tests to see if the point is intersects the AABBox.

func (*AABBox) SetOffset

func (aabb *AABBox) SetOffset(offset *mgl.Vec3)

SetOffset changes the offset of the collision object.

func (*AABBox) SetOffset3f

func (aabb *AABBox) SetOffset3f(x, y, z float32)

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.

func NewAABSquare

func NewAABSquare() *AABSquare

NewAABSquare creates a new AABSquare object

func (*AABSquare) IntersectPoint

func (aabs *AABSquare) IntersectPoint(v *mgl.Vec2) bool

IntersectPoint tests to see if the point is intersects the AABSquare.

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 NewOBBox added in v0.2.0

func NewOBBox() *OBBox

NewOBBox creates a new OBBox object

func (*OBBox) CollideVsSphere added in v0.2.0

func (obb *OBBox) CollideVsSphere(sphere *Sphere) int

CollideVsSphere tests an OBBox vs Sphere collision.

func (*OBBox) SetOffset added in v0.2.0

func (obb *OBBox) SetOffset(offset mgl.Vec3)

SetOffset changes the offset of the collision object.

func (*OBBox) SetOffset3f added in v0.2.0

func (obb *OBBox) SetOffset3f(x, y, z float32)

SetOffset3f changes the offset of the collision object.

func (*OBBox) SetOrientation added in v0.2.0

func (obb *OBBox) SetOrientation(q mgl.Quat)

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

func NewPlaneFromNormalAndPoint(normal, point mgl.Vec3) *Plane

NewPlaneFromNormalAndPoint makes a new Plane object based on a normal and point in space.

func (*Plane) Distance

func (p *Plane) Distance(v mgl.Vec3) float32

Distance calculates the distance of the plane to the vertex

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 NewSphere added in v0.2.1

func NewSphere() *Sphere

NewSphere creates a new Sphere object.

func (*Sphere) CollideVsAABBox

func (s1 *Sphere) CollideVsAABBox(b *AABBox) int

CollideVsAABBox tests a collision between a sphere and an AABBox.

func (*Sphere) CollideVsPlane

func (s1 *Sphere) CollideVsPlane(p *Plane) int

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

func (s1 *Sphere) CollideVsSphere(s2 *Sphere) int

CollideVsSphere tests a collision between two spheres.

func (*Sphere) SetOffset

func (s1 *Sphere) SetOffset(offset *mgl.Vec3)

SetOffset changes the offset of the collision object.

func (*Sphere) SetOffset3f

func (s1 *Sphere) SetOffset3f(x, y, z float32)

SetOffset3f changes the offset of the collision object.

Jump to

Keyboard shortcuts

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