shapes

package
v0.15.5 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAxis

func CheckAxis(origin, direction, minimum, maximum float64) (float64, float64)

CheckAxis Checks two sides of a cube on an axis from a ray's path on that axis

func CheckCap

func CheckCap(r primitives.Ray, t float64) bool

CheckCap Checks if an intersection happens at the cap

func IntersectEquals

func IntersectEquals(xs Intersections, dists []float64) bool

IntersectEquals Check if two slices are equal

func MinMax

func MinMax(values []float64) (float64, float64)

MinMax Sort an array of floats and return the minimum and maximum values

Types

type Bounds

type Bounds struct {
	Min, Max primitives.PV
}

Bounds Bounding box structure with a minimum and maximum point representing an axis-aligned cube

func CombineBounds

func CombineBounds(bounds_slice []*Bounds) *Bounds

CombineBounds Combine a slice of bounds into one

func (*Bounds) AddBounds

func (b *Bounds) AddBounds(bounds *Bounds)

AddBounds Add bounds with another bounds

func (*Bounds) Intersect

func (b *Bounds) Intersect(ray primitives.Ray) bool

func (*Bounds) Transform

func (b *Bounds) Transform(transform primitives.Matrix) *Bounds

type Cone

type Cone struct {
	ShapeBase
	// contains filtered or unexported fields
}

Cone Represents a cone

func MakeCone

func MakeCone(closed bool) *Cone

MakeCone Make a regular cone with an identity matrix for transform

func (*Cone) GetBounds

func (cone *Cone) GetBounds() *Bounds

GetBounds Return an axis aligned bounding box for the sphere

func (*Cone) Intersect

func (cone *Cone) Intersect(r primitives.Ray) Intersections

Intersect Check if a ray intersects

func (*Cone) Normal

func (cone *Cone) Normal(worldPoint primitives.PV, u, v float64) primitives.PV

Normal Calculate the normal at a given point on the Cone

func (*Cone) UVMapping

func (cone *Cone) UVMapping(point primitives.PV) primitives.PV

UVMapping Return the 2D coordinates of an intersection point

type Cube

type Cube struct {
	ShapeBase
}

Cube Basic cube representation

func MakeCube

func MakeCube() *Cube

MakeCube Make a regular cube with an identity matrix for transform

func (*Cube) GetBounds

func (c *Cube) GetBounds() *Bounds

GetBounds Return an axis aligned bounding box for the sphere

func (*Cube) Intersect

func (c *Cube) Intersect(r primitives.Ray) Intersections

Intersect Check for intersection along one of the six sides of the cube

func (*Cube) Normal

func (c *Cube) Normal(worldPoint primitives.PV, u, v float64) primitives.PV

Normal Calculate the normal at a given point on the cube

func (*Cube) UVMapping

func (c *Cube) UVMapping(point primitives.PV) primitives.PV

UVMapping Return the 2D coordinates of an intersection point

type Cylinder

type Cylinder struct {
	ShapeBase
	// contains filtered or unexported fields
}

Cylinder Represents a cylinder

func MakeCylinder

func MakeCylinder(closed bool) *Cylinder

MakeCylinder Make a regular cylinder with an identity matrix for transform

func (*Cylinder) GetBounds

func (cyl *Cylinder) GetBounds() *Bounds

GetBounds Return an axis aligned bounding box for the sphere

func (*Cylinder) Intersect

func (cyl *Cylinder) Intersect(r primitives.Ray) Intersections

Intersect Check if a ray intersects

func (*Cylinder) Normal

func (cyl *Cylinder) Normal(worldPoint primitives.PV, u, v float64) primitives.PV

Normal Calculate the normal at a given point on the Cylinder

func (*Cylinder) UVMapping

func (cyl *Cylinder) UVMapping(point primitives.PV) primitives.PV

UVMapping Return the 2D coordinates of an intersection point

type Group

type Group struct {
	ShapeBase
	// contains filtered or unexported fields
}

Group Represents a group of other shapes

func MakeGroup

func MakeGroup() *Group

MakeGroup Make an empty set of shapes

func (*Group) AddShape

func (g *Group) AddShape(shape Shape)

AddShape Add a shape to the group and set its parent

func (*Group) GetBounds

func (g *Group) GetBounds() *Bounds

GetBounds Return an axis aligned bounding box for the sphere

func (*Group) Intersect

func (g *Group) Intersect(r primitives.Ray) Intersections

Intersect Check if a ray intersects

func (*Group) Normal

func (g *Group) Normal(worldPoint primitives.PV, u, v float64) primitives.PV

Normal Calculate the normal at a given point on the sphere

func (*Group) UVMapping

func (g *Group) UVMapping(point primitives.PV) primitives.PV

UVMapping Return the 2D coordinates of an intersection point

type Intersection

type Intersection struct {
	Distance float64
	Obj      Shape
	U, V     float64
}

Intersection Structure to hold intersection information

type Intersections

type Intersections []Intersection

Intersections Sortable list of intersection structs

func (Intersections) Hit

func (i Intersections) Hit() (Intersection, bool)

Hit Get the closest hit from intersections, assumes i is sorted

func (Intersections) Len

func (i Intersections) Len() int

Necessary functions to make Intersections sortable

func (Intersections) Less

func (i Intersections) Less(j, k int) bool

func (Intersections) Swap

func (i Intersections) Swap(j, k int)

type Plane

type Plane struct {
	ShapeBase
}

Plane Plane along the XZ axis

func MakePlane

func MakePlane() *Plane

MakePlane Make a default plane

func (*Plane) GetBounds

func (p *Plane) GetBounds() *Bounds

GetBounds Return an axis aligned bounding box for the sphere

func (*Plane) Intersect

func (p *Plane) Intersect(r primitives.Ray) Intersections

Intersect Check if a ray intersects

func (*Plane) Normal

func (p *Plane) Normal(worldPoint primitives.PV, u, v float64) primitives.PV

Normal Calculate the normal at a given point on the sphere

func (*Plane) UVMapping

func (p *Plane) UVMapping(point primitives.PV) primitives.PV

UVMapping Return the 2D coordinates of an intersected point

type Shape

type Shape interface {
	Intersect(primitives.Ray) Intersections
	Normal(primitives.PV, float64, float64) primitives.PV
	SetTransform(primitives.Matrix)
	Transform() primitives.Matrix
	SetMaterial(patterns.Material)
	Material() patterns.Material
	SetParent(Shape)
	Parent() Shape
	GetBounds() *Bounds
	UVMapping(primitives.PV) primitives.PV
	WorldToObjectPV(primitives.PV) primitives.PV
	ObjectToWorldPV(primitives.PV) primitives.PV
}

Shape Interface for different 3D and 2D shape modules

type ShapeBase

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

ShapeBase Base struct to be embedded in shape objects

func MakeShapeBase

func MakeShapeBase() ShapeBase

MakeShapeBase Make a regular sphere with an identity matrix for transform

func (*ShapeBase) Inverse

func (s *ShapeBase) Inverse() primitives.Matrix

Inverse Get the Inverse of the transform matrix

func (*ShapeBase) Material

func (s *ShapeBase) Material() patterns.Material

Material Get the material object

func (*ShapeBase) ObjectToWorldPV

func (s *ShapeBase) ObjectToWorldPV(pv primitives.PV) primitives.PV

ObjectToWorldPV Convert a Point/Vector from object to world-space

func (*ShapeBase) Parent

func (s *ShapeBase) Parent() Shape

Parent Get the parent object of the shape

func (*ShapeBase) SetMaterial

func (s *ShapeBase) SetMaterial(mat patterns.Material)

SetMaterial Set the material for the shape

func (*ShapeBase) SetParent

func (s *ShapeBase) SetParent(parent Shape)

SetParent Set the parent object of the shape

func (*ShapeBase) SetTransform

func (s *ShapeBase) SetTransform(m primitives.Matrix)

SetTransform Set the transform matrix

func (*ShapeBase) Transform

func (s *ShapeBase) Transform() primitives.Matrix

Transform Get the transform matrix

func (*ShapeBase) WorldToObjectPV

func (s *ShapeBase) WorldToObjectPV(pv primitives.PV) primitives.PV

WorldToObjectPV Convert a Point/Vector from world to object-space

type Sphere

type Sphere struct {
	ShapeBase
}

Sphere Represents a sphere of radius 1

func MakeSphere

func MakeSphere() *Sphere

MakeSphere Make a regular sphere with an identity matrix for transform

func (*Sphere) GetBounds

func (s *Sphere) GetBounds() *Bounds

GetBounds Return an axis aligned bounding box for the sphere

func (*Sphere) Intersect

func (s *Sphere) Intersect(r primitives.Ray) Intersections

Intersect Check if a ray intersects

func (*Sphere) Normal

func (s *Sphere) Normal(worldPoint primitives.PV, u, v float64) primitives.PV

Normal Calculate the normal at a given point on the sphere

func (*Sphere) UVMapping

func (s *Sphere) UVMapping(point primitives.PV) primitives.PV

UVMapping Return the 2D coordinates of an intersection point

type Triangle added in v0.15.5

type Triangle struct {
	ShapeBase
	Point1, Point2, Point3, Edge1, Edge2, Normal1, Normal2, Normal3 primitives.PV
	// contains filtered or unexported fields
}

Triangle Represents a triangle

func MakeSmoothTriangle added in v0.15.5

func MakeSmoothTriangle(point1, point2, point3, normal1, normal2, normal3 primitives.PV) *Triangle

MakeSmoothTriangle Create a smooth triangle from three points and three normals

func MakeTriangle added in v0.15.5

func MakeTriangle(point1, point2, point3 primitives.PV) *Triangle

MakeTriangle Create a triangle from three points

func (*Triangle) GetBounds added in v0.15.5

func (t *Triangle) GetBounds() *Bounds

GetBounds Return an axis aligned bounding box for the triangle

func (*Triangle) Intersect added in v0.15.5

func (t *Triangle) Intersect(ray primitives.Ray) Intersections

Intersect Check if a ray intersects

func (*Triangle) Normal added in v0.15.5

func (t *Triangle) Normal(worldPoint primitives.PV, u, v float64) primitives.PV

Normal Calculate the normal at a given point on the sphere

func (*Triangle) UVMapping added in v0.15.5

func (t *Triangle) UVMapping(point primitives.PV) primitives.PV

UVMapping Return the 2D coordinates of an intersection point

Jump to

Keyboard shortcuts

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