shape

package
v0.0.0-...-8cfed74 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalAt

func NormalAt(s Shape, p tuple.Tuple) *tuple.Tuple

NormalAt returns the normal of a shape at a point

Types

type Computation

type Computation struct {
	Value     float64
	Object    Shape
	Point     tuple.Tuple
	Overpoint tuple.Tuple
	Eyev      tuple.Tuple
	Normal    tuple.Tuple
	Reflectv  tuple.Tuple
	Inside    bool
}

Computation object that contains data about an intersection

type Intersection

type Intersection struct {
	Value  float64
	Object Shape
}

Intersection represents a point where an object is intersected

func Hit

func Hit(intersections []Intersection) *Intersection

Hit returns the lowest nonnegative point of intersection

func Intersect

func Intersect(s Shape, r ray.Ray) []Intersection

Intersect intersects a shape with a ray

func Intersections

func Intersections(intersections ...Intersection) []Intersection

Intersections returns a an array of intersections

func NewIntersection

func NewIntersection(t float64, o Shape) Intersection

NewIntersection returns a new intersection object

func (*Intersection) PrepareComputations

func (i *Intersection) PrepareComputations(r ray.Ray) Computation

PrepareComputations calculates the Computation object for an intersection

type Plane

type Plane struct {
	Transform *matrix.Matrix
	Material  *material.Material
}

Plane is a flat surface that extends infinitely in xz

func NewPlane

func NewPlane() *Plane

NewPlane returns a sphere with a unique ID

func (*Plane) GetMaterial

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

GetMaterial returns the material of the plane

func (*Plane) GetTransform

func (p *Plane) GetTransform() *matrix.Matrix

GetTransform returns the transform of the plane

func (*Plane) LocalIntersect

func (p *Plane) LocalIntersect(r ray.Ray) []Intersection

LocalIntersect returns the points at which a ray intersects a plane

func (*Plane) LocalNormalAt

func (p *Plane) LocalNormalAt(point tuple.Tuple) *tuple.Tuple

LocalNormalAt returns the normal vector at point P on a plane

func (*Plane) SetMaterial

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

SetMaterial returns the material of the plane

func (*Plane) SetTransform

func (p *Plane) SetTransform(m *matrix.Matrix)

SetTransform sets given transform for sphere

type Shape

type Shape interface {
	LocalIntersect(ray.Ray) []Intersection
	LocalNormalAt(tuple.Tuple) *tuple.Tuple
	GetMaterial() *material.Material
	SetMaterial(*material.Material)
	SetTransform(*matrix.Matrix)
	GetTransform() *matrix.Matrix
}

Shape interface

type Sphere

type Sphere struct {
	ID        int64
	Transform *matrix.Matrix
	Material  *material.Material
}

Sphere struct

func NewSphere

func NewSphere() *Sphere

NewSphere returns a sphere with a unique ID

func (*Sphere) GetMaterial

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

GetMaterial returns the material of the sphere

func (*Sphere) GetTransform

func (s *Sphere) GetTransform() *matrix.Matrix

GetTransform returns the transform of the sphere

func (*Sphere) LocalIntersect

func (s *Sphere) LocalIntersect(r ray.Ray) []Intersection

LocalIntersect returns the points at which a ray intersects a sphere

func (*Sphere) LocalNormalAt

func (s *Sphere) LocalNormalAt(p tuple.Tuple) *tuple.Tuple

LocalNormalAt returns the normal vector at point P on a sphere

func (*Sphere) SetMaterial

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

SetMaterial returns the material of the sphere

func (*Sphere) SetTransform

func (s *Sphere) SetTransform(m *matrix.Matrix)

SetTransform sets given transform for sphere

Jump to

Keyboard shortcuts

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