bvh

package
v0.0.0-...-3626a0a Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2015 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AABB

type AABB struct {
	Min mgl64.Vec3
	Max mgl64.Vec3
}

AABB is an axis-aligned bounding box.

func (*AABB) AABB

func (a *AABB) AABB() *AABB

AABB implements the AABB method for the Intersector interface.

func (*AABB) Center

func (a *AABB) Center() mgl64.Vec3

Center retuns the center of the AABB

func (*AABB) Intersect

func (a *AABB) Intersect(r *ray.Ray, res *IntersectResult)

Intersect implements the Intersect method of the Intersector interface..

type AABBFn

type AABBFn func() *AABB

AABBFn returns an AABB.

type IntersectFn

type IntersectFn func(*ray.Ray, *IntersectResult)

IntersectFn implements intersection with a ray.

type IntersectResult

type IntersectResult struct {
	Object Intersector
	T      float64
	Normal mgl64.Vec3
	UV     mgl64.Vec2
}

IntersectResult holds the results of an intersection.

type Intersector

type Intersector interface {
	// Intersect must make no assumtions about the initial state of IntersectionResult and
	// must be sure to set all fields appropriately.
	Intersect(*ray.Ray, *IntersectResult)
	AABB() *AABB
}

Intersector is an object that can be tested for intersection with a ray.

type Node

type Node struct {
	Right  *Node
	Left   *Node
	Object Intersector
	// contains filtered or unexported fields
}

Node is a node in the BVH tree. They have up to 2 child nodes and an optional Object. Nodes without children are leaves. Non-leaf Nodes are not expected to contain Objcts.

func NewTree

func NewTree(objects []Intersector) *Node

NewTree takes a list of Intersectors and returns the root of a BVH tree. An empty slice returns nil.

func (*Node) AABB

func (n *Node) AABB() *AABB

AABB implements the AABB method for the Intersector interface.

func (*Node) Intersect

func (n *Node) Intersect(r *ray.Ray, res *IntersectResult)

Intersect takes a ray which be used to find the object that needs to be tested. It does not test intersection with the object itself.

Jump to

Keyboard shortcuts

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