shapes

package
v0.0.0-...-4f29a8f Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const TriThreshold = 0.00000000001

Variables

This section is empty.

Functions

func Divide

func Divide(s Shape, threshold int)

func FaceFromPoint

func FaceFromPoint(point geom.Tuple4) int

func Flatten

func Flatten(g *Group, groups *[]*Group)

Flatten is meaningless since each level of the hierarchy seems to build upon its parent's transform.

func IntersectRayWithBox

func IntersectRayWithBox(ray geom.Ray, BoundingBox *BoundingBox) bool

func IntersectionAllowed

func IntersectionAllowed(op string, lhit, inl, inr bool) bool

func MakeSubGroup

func MakeSubGroup(g *Group, shapes ...Shape)

func PartitionChildren

func PartitionChildren(g *Group) (*Group, *Group)

func SphericalMap

func SphericalMap(p geom.Tuple4) (float64, float64)

func SplitBounds

func SplitBounds(b1 *BoundingBox) (*BoundingBox, *BoundingBox)

SplitBounds splits the passed bounding box perpendicular of its longest axis. (Impl from bonus chapter)

Types

type AlignCheck

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

type Basic

type Basic struct {
	Id               int64
	Label            string
	Transform        geom.Mat4x4
	Inverse          geom.Mat4x4
	InverseTranspose geom.Mat4x4
	Material         material.Material
}

type BoundingBox

type BoundingBox struct {
	Min geom.Tuple4
	Max geom.Tuple4
}

func BoundsOf

func BoundsOf(shape Shape) *BoundingBox

func NewBoundingBox

func NewBoundingBox(pointA geom.Tuple4, pointB geom.Tuple4) *BoundingBox

func NewBoundingBoxF

func NewBoundingBoxF(x1, y1, z1, x2, y2, z2 float64) *BoundingBox

func NewEmptyBoundingBox

func NewEmptyBoundingBox() *BoundingBox

func ParentSpaceBounds

func ParentSpaceBounds(shape Shape) *BoundingBox

func TransformBoundingBox

func TransformBoundingBox(bbox *BoundingBox, m1 geom.Mat4x4) *BoundingBox

func (*BoundingBox) Add

func (b *BoundingBox) Add(p geom.Tuple4)

func (*BoundingBox) ContainsBox

func (b *BoundingBox) ContainsBox(b2 *BoundingBox) bool

func (*BoundingBox) ContainsPoint

func (b *BoundingBox) ContainsPoint(p geom.Tuple4) bool

func (*BoundingBox) MergeWith

func (b *BoundingBox) MergeWith(b2 *BoundingBox)

type Cube

type Cube struct {
	Basic
	// contains filtered or unexported fields
}

func NewCube

func NewCube() *Cube

func (*Cube) GetInverse

func (c *Cube) GetInverse() geom.Mat4x4

func (*Cube) GetInverseTranspose

func (c *Cube) GetInverseTranspose() geom.Mat4x4

func (*Cube) GetMaterial

func (c *Cube) GetMaterial() material.Material

func (*Cube) GetParent

func (c *Cube) GetParent() Shape

func (*Cube) GetTransform

func (c *Cube) GetTransform() geom.Mat4x4

func (*Cube) ID

func (c *Cube) ID() int64

func (*Cube) Lbl

func (c *Cube) Lbl() string

func (*Cube) SetMaterial

func (c *Cube) SetMaterial(material material.Material)

func (*Cube) SetParent

func (c *Cube) SetParent(shape Shape)

func (*Cube) SetTransform

func (c *Cube) SetTransform(transform geom.Mat4x4)

type Cylinder

type Cylinder struct {
	Basic

	MinY float64
	MaxY float64
	// contains filtered or unexported fields
}

func NewCylinder

func NewCylinder() *Cylinder

func NewCylinderMM

func NewCylinderMM(min, max float64) *Cylinder

func NewCylinderMMC

func NewCylinderMMC(min, max float64, closed bool) *Cylinder

func (*Cylinder) GetInverse

func (c *Cylinder) GetInverse() geom.Mat4x4

func (*Cylinder) GetInverseTranspose

func (c *Cylinder) GetInverseTranspose() geom.Mat4x4

func (*Cylinder) GetMaterial

func (c *Cylinder) GetMaterial() material.Material

func (*Cylinder) GetParent

func (c *Cylinder) GetParent() Shape

func (*Cylinder) GetTransform

func (c *Cylinder) GetTransform() geom.Mat4x4

func (*Cylinder) ID

func (c *Cylinder) ID() int64

func (*Cylinder) Init

func (c *Cylinder) Init()

func (*Cylinder) Lbl

func (c *Cylinder) Lbl() string

func (*Cylinder) SetMaterial

func (c *Cylinder) SetMaterial(material material.Material)

func (*Cylinder) SetParent

func (c *Cylinder) SetParent(shape Shape)

func (*Cylinder) SetTransform

func (c *Cylinder) SetTransform(transform geom.Mat4x4)

type Group

type Group struct {
	Id               int64
	Transform        geom.Mat4x4
	Inverse          geom.Mat4x4
	InverseTranspose geom.Mat4x4
	Material         material.Material
	Mtl              material.Mtl
	Label            string

	Children []Shape

	InnerRays   []geom.Ray
	XsCache     Intersections
	BoundingBox *BoundingBox

	CastShadow bool
	// contains filtered or unexported fields
}

func NewGroup

func NewGroup() *Group

func (*Group) AddChild

func (g *Group) AddChild(s Shape)

func (*Group) AddChildren

func (g *Group) AddChildren(shapes ...Shape)

func (*Group) Bounds

func (g *Group) Bounds()

func (*Group) BoundsToCube

func (g *Group) BoundsToCube() *Cube

func (*Group) CastsShadow

func (g *Group) CastsShadow() bool

func (*Group) GetInverse

func (g *Group) GetInverse() geom.Mat4x4

func (*Group) GetInverseTranspose

func (g *Group) GetInverseTranspose() geom.Mat4x4

func (*Group) GetLocalRay

func (g *Group) GetLocalRay() geom.Ray

func (*Group) GetMaterial

func (g *Group) GetMaterial() material.Material

func (*Group) GetParent

func (g *Group) GetParent() Shape

func (*Group) GetTransform

func (g *Group) GetTransform() geom.Mat4x4

func (*Group) ID

func (g *Group) ID() int64

func (*Group) Lbl

func (g *Group) Lbl() string

func (*Group) Name

func (g *Group) Name() string

func (*Group) NormalAtLocal

func (g *Group) NormalAtLocal(point geom.Tuple4, intersection *Intersection) geom.Tuple4

func (*Group) SetMaterial

func (g *Group) SetMaterial(material material.Material)

func (*Group) SetParent

func (g *Group) SetParent(shape Shape)

func (*Group) SetTransform

func (g *Group) SetTransform(transform geom.Mat4x4)

type Intersection

type Intersection struct {
	T float64
	S Shape
	U float64
	V float64
}

type Intersections

type Intersections []Intersection

func (Intersections) Len

func (xs Intersections) Len() int

func (Intersections) Less

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

func (Intersections) Swap

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

type Plane

type Plane struct {
	Basic
	// contains filtered or unexported fields
}

func NewPlane

func NewPlane() *Plane

func (*Plane) GetInverse

func (p *Plane) GetInverse() geom.Mat4x4

func (*Plane) GetInverseTranspose

func (p *Plane) GetInverseTranspose() geom.Mat4x4

func (*Plane) GetMaterial

func (p *Plane) GetMaterial() material.Material

func (*Plane) GetParent

func (p *Plane) GetParent() Shape

func (*Plane) GetTransform

func (p *Plane) GetTransform() geom.Mat4x4

func (*Plane) ID

func (p *Plane) ID() int64

func (*Plane) Lbl

func (p *Plane) Lbl() string

func (*Plane) SetMaterial

func (p *Plane) SetMaterial(m material.Material)

SetMaterial passes a pointer to the Plane on which to set the material

func (*Plane) SetParent

func (p *Plane) SetParent(shape Shape)

func (*Plane) SetTransform

func (p *Plane) SetTransform(translation geom.Mat4x4)

SetTransform passes a pointer to the Plane on which to apply the translation matrix

type Shape

type Shape interface {
	ID() int64
	Lbl() string
	GetTransform() geom.Mat4x4
	GetInverse() geom.Mat4x4
	GetInverseTranspose() geom.Mat4x4
	SetTransform(transform geom.Mat4x4)
	GetMaterial() material.Material
	SetMaterial(material material.Material)
	GetParent() Shape
	SetParent(shape Shape)
}

type Sphere

type Sphere struct {
	Basic
	// contains filtered or unexported fields
}

func NewSphere

func NewSphere() *Sphere

func (*Sphere) GetInverse

func (s *Sphere) GetInverse() geom.Mat4x4

func (*Sphere) GetInverseTranspose

func (s *Sphere) GetInverseTranspose() geom.Mat4x4

func (*Sphere) GetMaterial

func (s *Sphere) GetMaterial() material.Material

func (*Sphere) GetParent

func (s *Sphere) GetParent() Shape

func (*Sphere) GetTransform

func (s *Sphere) GetTransform() geom.Mat4x4

func (*Sphere) ID

func (s *Sphere) ID() int64

func (*Sphere) Lbl

func (s *Sphere) Lbl() string

func (*Sphere) SetMaterial

func (s *Sphere) SetMaterial(m material.Material)

SetMaterial passes a pointer to the Sphere on which to set the material

func (*Sphere) SetParent

func (s *Sphere) SetParent(shape Shape)

func (*Sphere) SetTransform

func (s *Sphere) SetTransform(translation geom.Mat4x4)

SetTransform passes a pointer to the Sphere on which to apply the translation matrix

type Triangle

type Triangle struct {
	P1       geom.Tuple4
	P2       geom.Tuple4
	P3       geom.Tuple4
	E1       geom.Tuple4
	E2       geom.Tuple4
	N        geom.Tuple4
	N1       geom.Tuple4
	N2       geom.Tuple4
	N3       geom.Tuple4
	Material material.Material
	Label    string

	D00   float64
	D01   float64
	D11   float64
	Denom float64
	// contains filtered or unexported fields
}

func DefaultTriangle

func DefaultTriangle() *Triangle

func NewTriangle

func NewTriangle(p1 geom.Tuple4, p2 geom.Tuple4, p3 geom.Tuple4, n1 geom.Tuple4, n2 geom.Tuple4, n3 geom.Tuple4) *Triangle

func NewTriangle3P

func NewTriangle3P(p1 geom.Tuple4, p2 geom.Tuple4, p3 geom.Tuple4) *Triangle

func NewTriangleN

func NewTriangleN(p1 geom.Tuple4, p2 geom.Tuple4, p3 geom.Tuple4) *Triangle

func (*Triangle) Barycentric

func (s *Triangle) Barycentric(p geom.Tuple4, u *float64, v *float64, w *float64)

Barycentric computes barycentric coordinates (u, v, w) for point p with respect to triangle defined by pre-computed vectors E1 and E2, which was derived into points d00, d01, d11 and denominator in constructor func.

func (*Triangle) GetInverse

func (s *Triangle) GetInverse() geom.Mat4x4

func (*Triangle) GetInverseTranspose

func (s *Triangle) GetInverseTranspose() geom.Mat4x4

func (*Triangle) GetLocalRay

func (s *Triangle) GetLocalRay() geom.Ray

func (*Triangle) GetMaterial

func (s *Triangle) GetMaterial() material.Material

func (*Triangle) GetParent

func (s *Triangle) GetParent() Shape

func (*Triangle) GetTransform

func (s *Triangle) GetTransform() geom.Mat4x4

func (*Triangle) ID

func (s *Triangle) ID() int64

func (*Triangle) IntersectLocal

func (s *Triangle) IntersectLocal(ray geom.Ray) []Intersection

func (*Triangle) Lbl

func (s *Triangle) Lbl() string

func (*Triangle) Name

func (s *Triangle) Name() string

func (*Triangle) NormalAtLocal

func (s *Triangle) NormalAtLocal(point geom.Tuple4, intersection *Intersection) geom.Tuple4

func (*Triangle) SetMaterial

func (s *Triangle) SetMaterial(material material.Material)

func (*Triangle) SetParent

func (s *Triangle) SetParent(shape Shape)

func (*Triangle) SetTransform

func (s *Triangle) SetTransform(transform geom.Mat4x4)

Jump to

Keyboard shortcuts

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