tracer

package
v0.0.0-...-06b0cfe Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlendedPattern

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

BlendedPattern represents a blended pattern.

func NewBlendedPattern

func NewBlendedPattern(a Pattern, b Pattern) *BlendedPattern

NewBlendedPattern constructs a new blended pattern.

func (*BlendedPattern) ColorAt

func (l *BlendedPattern) ColorAt(p *Point) *Color

ColorAt implements the Pattern interface.

func (*BlendedPattern) EqualsPattern

func (l *BlendedPattern) EqualsPattern(p Pattern) bool

EqualsPattern implements the Pattern interface.

func (*BlendedPattern) Transform

func (t *BlendedPattern) Transform() *Matrix4

func (*BlendedPattern) WithTransform

func (l *BlendedPattern) WithTransform(t *Matrix4) *BlendedPattern

WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.

type Camera

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

Camera represents a camera in a scene.

func NewCamera

func NewCamera(w, h int, fieldOfView float64) *Camera

NewCamera constructs a new camera.

func (*Camera) FieldOfView

func (c *Camera) FieldOfView() float64

FieldOfView returns this camera's field of view.

func (*Camera) Height

func (c *Camera) Height() int

Height returns the vertical size in pixels of this camera's canvas.

func (*Camera) PixelSize

func (c *Camera) PixelSize() float64

PixelSize returns the size in world space units of a pixel on this canvas.

func (*Camera) RayForPixel

func (c *Camera) RayForPixel(x, y int) *Ray

RayForPixel returns a ray starting from this camera and passing through the pixel on the canvas at (x, y).

func (*Camera) Render

func (c *Camera) Render(w *World) *Canvas

Render returns an image with this camera's rendering of the world.

func (*Camera) Transform

func (t *Camera) Transform() *Matrix4

func (*Camera) Width

func (c *Camera) Width() int

Width returns the horizontal size in pixels of this camera's canvas.

func (*Camera) WithThreads

func (c *Camera) WithThreads(threads int) *Camera

WithThreads sets the number of threads this camera uses to render the image.

func (*Camera) WithTransform

func (c *Camera) WithTransform(t *Matrix4) *Camera

WithTransform sets this camera's view transform. May return nil if the transform is invalid.

func (*Camera) WithTransformFromParameters

func (c *Camera) WithTransformFromParameters(from *Point, to *Point, up *Vector) *Camera

WithTransformFromParameters sets this camera's view transform from human understandable parameters.

type Canvas

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

Canvas represents a canvas.

func NewCanvas

func NewCanvas(w, h int) *Canvas

NewCanvas constructs a new canvas.

func (*Canvas) ColorAt

func (c *Canvas) ColorAt(x, y int) *Color

ColorAt returns the color of the pixel at (x, y). May return nil.

func (*Canvas) Height

func (c *Canvas) Height() int

Height returns the height of the canvas.

func (*Canvas) SetColor

func (c *Canvas) SetColor(x, y int, d *Color)

SetColor sets the color of the pixel at (x, y) to a color.

func (*Canvas) ToFile

func (c *Canvas) ToFile()

ToFile converts this canvas to an image file.

func (*Canvas) Width

func (c *Canvas) Width() int

Width returns the width of the canvas.

type CheckerPattern

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

CheckerPattern represents a checker pattern.

func NewCheckerPattern

func NewCheckerPattern(a Pattern, b Pattern) *CheckerPattern

NewCheckerPattern constructs a new checker pattern.

func (*CheckerPattern) ColorAt

func (c *CheckerPattern) ColorAt(p *Point) *Color

ColorAt implements the Pattern interface.

func (*CheckerPattern) EqualsPattern

func (c *CheckerPattern) EqualsPattern(p Pattern) bool

EqualsPattern implements the Pattern interface.

func (*CheckerPattern) Transform

func (t *CheckerPattern) Transform() *Matrix4

func (*CheckerPattern) WithTransform

func (c *CheckerPattern) WithTransform(t *Matrix4) *CheckerPattern

WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.

type Color

type Color [3]float64

Color represents a color.

func NewColor

func NewColor(r, g, b float64) *Color

NewColor constructs a new color.

func (*Color) B

func (c *Color) B() float64

B returns the blue value.

func (*Color) Equals

func (c *Color) Equals(d *Color) bool

Equals returns whether a color is approximately equal to this color.

func (*Color) G

func (c *Color) G() float64

G returns the green value.

func (*Color) MinusColor

func (c *Color) MinusColor(d *Color) *Color

MinusColor returns a color representing this color minus another color.

func (*Color) PlusColor

func (c *Color) PlusColor(d *Color) *Color

PlusColor returns a color representing this color plus another color.

func (*Color) R

func (c *Color) R() float64

R returns the red value.

func (*Color) RGBA

func (c *Color) RGBA() (r, g, b, a uint32)

RGBA implements the image.Color interface.

func (*Color) TimesColor

func (c *Color) TimesColor(d *Color) *Color

TimesColor returns this color multiplied by another color.

func (*Color) TimesScalar

func (c *Color) TimesScalar(f float64) *Color

TimesScalar returns this color multiplied by a scalar.

type GradientPattern

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

GradientPattern represents a gradient pattern.

func NewGradientPattern

func NewGradientPattern(a Pattern, b Pattern) *GradientPattern

NewGradientPattern constructs a new gradient pattern.

func (*GradientPattern) ColorAt

func (g *GradientPattern) ColorAt(p *Point) *Color

ColorAt implements the Pattern interface.

func (*GradientPattern) EqualsPattern

func (g *GradientPattern) EqualsPattern(p Pattern) bool

EqualsPattern implements the Pattern interface.

func (*GradientPattern) Transform

func (t *GradientPattern) Transform() *Matrix4

func (*GradientPattern) WithTransform

func (g *GradientPattern) WithTransform(t *Matrix4) *GradientPattern

WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.

type Intersection

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

Intersection represents an intersection.

func NewIntersection

func NewIntersection(s Shape, r *Ray, t float64) *Intersection

NewIntersection constructs a new intersection.

func (*Intersection) ComputeMetadata

func (i *Intersection) ComputeMetadata()

ComputeMetadata computes and sets the metadata about this intersection.

func (*Intersection) Equals

func (i *Intersection) Equals(j *Intersection) bool

Equals returns whether an intersection is approximately equal to this intersection.

func (*Intersection) Eye

func (i *Intersection) Eye() *Vector

Eye returns the eye vector at this intersection. Returns nil if ComputeMetadata has not yet been called.

func (*Intersection) Inside

func (i *Intersection) Inside() bool

Inside returns whether the intersection is on the inside of the shape. Returns false if ComputeMetadata has not yet been called.

func (*Intersection) Normal

func (i *Intersection) Normal() *Vector

Normal returns the normal vector at this intersection. Returns nil if ComputeMetadata has not yet been called.

func (*Intersection) Point

func (i *Intersection) Point() *Point

Point returns the point in world space where this intersection is. Returns nil if ComputeMetadata has not yet been called.

func (*Intersection) Ray

func (i *Intersection) Ray() *Ray

Ray returns the ray used to create this intersection.

func (*Intersection) Shape

func (i *Intersection) Shape() Shape

Shape returns the shape intersected with to create this intersection.

func (*Intersection) ShiftedPoint

func (i *Intersection) ShiftedPoint() *Point

ShiftedPoint returns the point in world space just over actual point. Returns nil if ComputeMetadata has not yet been called.

func (*Intersection) T

func (i *Intersection) T() float64

T returns the intersection point on the ray used to create this intersection.

type Intersections

type Intersections []*Intersection

Intersections represents an ordered collection of intersections.

func MergeIntersections

func MergeIntersections(i []Intersections) Intersections

MergeIntersections merges a collection of collections of intersections.

func NewIntersections

func NewIntersections(is ...*Intersection) Intersections

NewIntersections constructs a new ordered collection of intersections.

func (Intersections) Equals

func (i Intersections) Equals(j Intersections) bool

Equals returns whether a collection of intersections is approximately equal to this collection of intersections.

func (Intersections) Hit

func (i Intersections) Hit() *Intersection

Hit returns the hit intersection from a collection of intersections. May return nil.

type Light

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

Light represents a point light.

func NewLight

func NewLight(p *Point, i *Color) *Light

NewLight constructs a new light.

func (*Light) Illuminate

func (l *Light) Illuminate(s Shape, p *Point, normal *Vector, eye *Vector, isShadowed bool) *Color

Illuminate returns the color of a point given the shape the point is on, normal vector, eye vector, and whether it's in shadow.

func (*Light) Intensity

func (l *Light) Intensity() *Color

Intensity returns this light's intensity.

func (*Light) Position

func (l *Light) Position() *Point

Position returns this light's position.

type Lights

type Lights []*Light

Lights represents a collection of lights.

type Material

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

Material represents a material.

func NewDefaultMaterial

func NewDefaultMaterial() *Material

NewDefaultMaterial constructs a new default material.

func NewMaterial

func NewMaterial(p Pattern, ambient float64, diffuse float64, specular float64, shininess float64) *Material

NewMaterial constructs a new material.

func (*Material) Ambient

func (m *Material) Ambient() float64

Ambient returns this material's ambient.

func (*Material) ColorAt

func (m *Material) ColorAt(p *Point) *Color

ColorAt returns this material's color at a point.

func (*Material) Diffuse

func (m *Material) Diffuse() float64

Diffuse returns this material's diffuse.

func (*Material) Equals

func (m *Material) Equals(n *Material) bool

Equals returns whether a material is approximately equal to this material.

func (*Material) Pattern

func (m *Material) Pattern() Pattern

Pattern this material's pattern.

func (*Material) Shininess

func (m *Material) Shininess() float64

Shininess returns this material's shininess.

func (*Material) Specular

func (m *Material) Specular() float64

Specular returns this material's specular.

type Matrix2

type Matrix2 [2][2]float64

Matrix2 represents a 2x2 matrix.

func NewMatrix2

func NewMatrix2(a, b, c, d float64) *Matrix2

NewMatrix2 constructs a new matrix of size 2.

func (*Matrix2) At

func (m *Matrix2) At(x, y int) float64

At returns the value at (x, y).

func (*Matrix2) Equals

func (m *Matrix2) Equals(n *Matrix2) bool

Equals returns whether a matrix is approximately equal to this matrix.

type Matrix3

type Matrix3 [3][3]float64

Matrix3 represents a 3x3 matrix.

func NewMatrix3

func NewMatrix3(a, b, c, d, e, f, g, h, i float64) *Matrix3

NewMatrix3 constructs a new matrix of size 3.

func (*Matrix3) At

func (m *Matrix3) At(x, y int) float64

At returns the value at (x, y).

func (*Matrix3) Equals

func (m *Matrix3) Equals(n *Matrix3) bool

Equals returns whether a matrix is approximately equal to this matrix.

type Matrix4

type Matrix4 [4][4]float64

Matrix4 represents a 4x4 matrix.

func NewIdentity

func NewIdentity() *Matrix4

NewIdentity returns a 4x4 identity matrix.

func NewMatrix4

func NewMatrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p float64) *Matrix4

NewMatrix4 constructs a new matrix of size 4.

func NewRotateX

func NewRotateX(x float64) *Matrix4

NewRotateX returns a matrix representing a rotation around the X axis.

func NewRotateY

func NewRotateY(x float64) *Matrix4

NewRotateY returns a matrix representing a rotation around the Y axis.

func NewRotateZ

func NewRotateZ(x float64) *Matrix4

NewRotateZ returns a matrix representing a rotation around the Z axis.

func NewScale

func NewScale(x, y, z float64) *Matrix4

NewScale returns a matrix representing a scaling operation.

func NewShear

func NewShear(xy, xz, yx, yz, zx, zy float64) *Matrix4

NewShear returns a matrix representing a shearing operation.

func NewTranslate

func NewTranslate(x, y, z float64) *Matrix4

NewTranslate returns a matrix representing a translation operation.

func (*Matrix4) At

func (m *Matrix4) At(x, y int) float64

At returns the value at (x, y).

func (*Matrix4) Equals

func (m *Matrix4) Equals(n *Matrix4) bool

Equals returns whether a matrix is approximately equal to this matrix.

func (*Matrix4) HasInverse

func (m *Matrix4) HasInverse() bool

HasInverse returns whether this matrix is invertible.

func (*Matrix4) Inverse

func (m *Matrix4) Inverse() *Matrix4

Inverse returns the inverse of this matrix. May return nil.

func (*Matrix4) RotateX

func (m *Matrix4) RotateX(x float64) *Matrix4

RotateX returns a matrix representing this matrix followed by a rotation around the X axis.

func (*Matrix4) RotateY

func (m *Matrix4) RotateY(x float64) *Matrix4

RotateY returns a matrix representing this matrix followed by a rotation around the Y axis.

func (*Matrix4) RotateZ

func (m *Matrix4) RotateZ(x float64) *Matrix4

RotateZ returns a matrix representing this matrix followed by a rotation around the Z axis.

func (*Matrix4) Scale

func (m *Matrix4) Scale(x, y, z float64) *Matrix4

Scale returns a matrix representing this matrix followed by a scaling operation.

func (*Matrix4) Shear

func (m *Matrix4) Shear(xy, xz, yx, yz, zx, zy float64) *Matrix4

Shear returns a matrix representing this matrix followed by a shearing operation.

func (*Matrix4) TimesMatrix

func (m *Matrix4) TimesMatrix(n *Matrix4) *Matrix4

TimesMatrix returns a matrix representing this matrix multiplied by a matrix.

func (*Matrix4) TimesPoint

func (m *Matrix4) TimesPoint(p *Point) *Point

TimesPoint returns a point representing this matrix multiplied by a point.

func (*Matrix4) TimesRay

func (m *Matrix4) TimesRay(r *Ray) *Ray

TimesRay returns a ray representing this matrix multiplied by a ray.

func (*Matrix4) TimesVector

func (m *Matrix4) TimesVector(v *Vector) *Vector

TimesVector returns a vector representing this matrix multiplied by a vector.

func (*Matrix4) Translate

func (m *Matrix4) Translate(x, y, z float64) *Matrix4

Translate returns a matrix representing this matrix followed by a translation operation.

func (*Matrix4) Transpose

func (m *Matrix4) Transpose() *Matrix4

Transpose returns the tranpose of this matrix.

type Pattern

type Pattern interface {
	// ColorAt returns the color of this pattern at a point.
	ColorAt(*Point) *Color
	// EqualsPattern returns whether this pattern is approximately equal to another pattern.
	EqualsPattern(Pattern) bool
}

Pattern is an interface for coloriing patterns.

type PerturbedPattern

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

PerturbedPattern represents a perturbed pattern.

func NewPerturbedPattern

func NewPerturbedPattern(p Pattern, randomize bool) *PerturbedPattern

NewPerturbedPattern constructs a new perturbed pattern.

func (*PerturbedPattern) ColorAt

func (e *PerturbedPattern) ColorAt(p *Point) *Color

ColorAt implements the Pattern interface.

func (*PerturbedPattern) EqualsPattern

func (e *PerturbedPattern) EqualsPattern(p Pattern) bool

EqualsPattern implements the Pattern interface.

func (*PerturbedPattern) Transform

func (t *PerturbedPattern) Transform() *Matrix4

func (*PerturbedPattern) WithTransform

func (e *PerturbedPattern) WithTransform(t *Matrix4) *PerturbedPattern

WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.

type Plane

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

Plane represents a plane.

func NewPlane

func NewPlane() *Plane

NewPlane constructs a new plane.

func (*Plane) ColorAt

func (s *Plane) ColorAt(p *Point) *Color

ColorAt implements the Shape interface.

func (*Plane) Intersect

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

Intersect implements the Shape interface.

func (*Plane) Material

func (s *Plane) Material() *Material

Material implements the Shape interface.

func (*Plane) NormalAt

func (p *Plane) NormalAt(*Point) *Vector

NormalAt implements the Shape interface.

func (*Plane) WithMaterial

func (p *Plane) WithMaterial(m *Material) *Plane

WithMaterial sets this plane's material to a material.

func (*Plane) WithTransform

func (p *Plane) WithTransform(t *Matrix4) *Plane

WithTransform sets this plane's transform to a matrix. May return nil without setting the transform if the transform is invalid.

type Point

type Point [3]float64

Point represents a point.

func NewPoint

func NewPoint(x, y, z float64) *Point

NewPoint constructs a new point.

func (*Point) DividedByScalar

func (p *Point) DividedByScalar(f float64) *Point

DividedByScalar returns this point divided by a scalar.

func (*Point) Equals

func (p *Point) Equals(q *Point) bool

Equals returns whether a point is approximately equal to this point.

func (*Point) MinusPoint

func (p *Point) MinusPoint(q *Point) *Vector

MinusPoint returns a vector representing this point minus another point.

func (*Point) MinusVector

func (p *Point) MinusVector(v *Vector) *Point

MinusVector returns a point representing this point minus a vector.

func (*Point) PlusVector

func (p *Point) PlusVector(v *Vector) *Point

PlusVector returns a point representing this point plus a vector.

func (*Point) TimesScalar

func (p *Point) TimesScalar(f float64) *Point

TimesScalar returns this point multiplied by a scalar.

func (*Point) W

func (p *Point) W() float64

W returns the w coordinate.

func (*Point) X

func (p *Point) X() float64

X returns the x coordinate.

func (*Point) Y

func (p *Point) Y() float64

Y returns the y coordinate.

func (*Point) Z

func (p *Point) Z() float64

Z returns the z coordinate.

type RadialGradientPattern

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

RadialGradientPattern represents a radial gradient pattern.

func NewRadialGradientPattern

func NewRadialGradientPattern(a Pattern, b Pattern) *RadialGradientPattern

NewRadialGradientPattern constructs a new gradient pattern.

func (*RadialGradientPattern) ColorAt

func (r *RadialGradientPattern) ColorAt(p *Point) *Color

ColorAt implements the Pattern interface.

func (*RadialGradientPattern) EqualsPattern

func (r *RadialGradientPattern) EqualsPattern(p Pattern) bool

EqualsPattern implements the Pattern interface.

func (*RadialGradientPattern) Transform

func (t *RadialGradientPattern) Transform() *Matrix4

func (*RadialGradientPattern) WithTransform

func (r *RadialGradientPattern) WithTransform(t *Matrix4) *RadialGradientPattern

WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.

type Ray

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

Ray represents a ray.

func NewRay

func NewRay(o *Point, d *Vector) *Ray

NewRay constructs a new ray.

func (*Ray) Direction

func (r *Ray) Direction() *Vector

Direction returns the origin of this ray.

func (*Ray) Equals

func (r *Ray) Equals(s *Ray) bool

Equals returns whether a ray is approximately equal to this ray.

func (*Ray) Origin

func (r *Ray) Origin() *Point

Origin returns the origin of this ray.

func (*Ray) Position

func (r *Ray) Position(t float64) *Point

Position returns a point representing the position a distance along this ray.

type RingPattern

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

RingPattern represents a ring pattern.

func NewRingPattern

func NewRingPattern(a Pattern, b Pattern) *RingPattern

NewRingPattern constructs a new ring pattern.

func (*RingPattern) ColorAt

func (r *RingPattern) ColorAt(p *Point) *Color

ColorAt implements the Pattern interface.

func (*RingPattern) EqualsPattern

func (r *RingPattern) EqualsPattern(p Pattern) bool

EqualsPattern implements the Pattern interface.

func (*RingPattern) Transform

func (t *RingPattern) Transform() *Matrix4

func (*RingPattern) WithTransform

func (r *RingPattern) WithTransform(t *Matrix4) *RingPattern

WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.

type Shape

type Shape interface {
	// Material returns this shape's material.
	Material() *Material
	// Intersect returns this shape's intersection points with a ray.
	Intersect(*Ray) Intersections
	// ColorAt returns the color at a point on this shape.
	ColorAt(*Point) *Color
	// NormalAt returns the normal at a point on this shape.
	NormalAt(*Point) *Vector
}

Shape is an interface for shapes.

type Shapes

type Shapes []Shape

Shapes represents a collection of shapes.

func (Shapes) Intersect

func (s Shapes) Intersect(r *Ray) Intersections

Intersect returns a collection of shapes' intersection points with a ray.

type SolidPattern

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

SolidPattern represents a solid pattern.

func NewSolidPattern

func NewSolidPattern(c *Color) *SolidPattern

NewSolidPattern constructs a new solid pattern.

func (*SolidPattern) ColorAt

func (s *SolidPattern) ColorAt(p *Point) *Color

ColorAt implements the Pattern interface.

func (*SolidPattern) EqualsPattern

func (s *SolidPattern) EqualsPattern(p Pattern) bool

EqualsPattern implements the Pattern interface.

type Sphere

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

Sphere represents a sphere.

func NewSphere

func NewSphere() *Sphere

NewSphere constructs a new sphere.

func (*Sphere) ColorAt

func (s *Sphere) ColorAt(p *Point) *Color

ColorAt implements the Shape interface.

func (*Sphere) Intersect

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

Intersect implements the Shape interface.

func (*Sphere) Material

func (s *Sphere) Material() *Material

Material implements the Shape interface.

func (*Sphere) NormalAt

func (s *Sphere) NormalAt(p *Point) *Vector

NormalAt implements the Shape interface.

func (*Sphere) WithMaterial

func (s *Sphere) WithMaterial(m *Material) *Sphere

WithMaterial sets this sphere's material to a material.

func (*Sphere) WithTransform

func (s *Sphere) WithTransform(t *Matrix4) *Sphere

WithTransform sets this sphere's transform to a matrix. May return nil without setting the transform if the transform is invalid.

type StripePattern

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

StripePattern represents a stripe pattern in the X dimension.

func NewStripePattern

func NewStripePattern(a Pattern, b Pattern) *StripePattern

NewStripePattern constructs a new stripe pattern.

func (*StripePattern) ColorAt

func (s *StripePattern) ColorAt(p *Point) *Color

ColorAt implements the Pattern interface.

func (*StripePattern) EqualsPattern

func (s *StripePattern) EqualsPattern(p Pattern) bool

EqualsPattern implements the Pattern interface.

func (*StripePattern) Transform

func (t *StripePattern) Transform() *Matrix4

func (*StripePattern) WithTransform

func (s *StripePattern) WithTransform(t *Matrix4) *StripePattern

WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.

type Vector

type Vector [3]float64

Vector represents a vector.

func NewVector

func NewVector(x, y, z float64) *Vector

NewVector constructs a new vector.

func (*Vector) CrossVector

func (v *Vector) CrossVector(w *Vector) *Vector

CrossVector returns the cross product of this vector and another vector.

func (*Vector) DividedByScalar

func (v *Vector) DividedByScalar(f float64) *Vector

DividedByScalar returns this vector divided by a scalar.

func (*Vector) DotVector

func (v *Vector) DotVector(w *Vector) float64

DotVector returns the dot product of this vector and another vector.

func (*Vector) Equals

func (v *Vector) Equals(w *Vector) bool

Equals returns whether a vector is approximately equal to this vector.

func (*Vector) Magnitude

func (v *Vector) Magnitude() float64

Magnitude returns the length of this vector.

func (*Vector) MinusVector

func (v *Vector) MinusVector(w *Vector) *Vector

MinusVector returns a vector representing this vector minus another vector.

func (*Vector) Negate

func (v *Vector) Negate() *Vector

Negate returns the negation of this vector.

func (*Vector) Normalize

func (v *Vector) Normalize() *Vector

Normalize returns a vector with the same direction as this vector but with length 1.

func (*Vector) PlusVector

func (v *Vector) PlusVector(w *Vector) *Vector

PlusVector returns a vector representing this vector plus another vector.

func (*Vector) Reflect

func (v *Vector) Reflect(w *Vector) *Vector

Reflect computes the reflection of a vector around this normal vector.

func (*Vector) TimesScalar

func (v *Vector) TimesScalar(f float64) *Vector

TimesScalar returns this vector multiplied by a scalar.

func (*Vector) W

func (v *Vector) W() float64

W returns the w coordinate.

func (*Vector) X

func (v *Vector) X() float64

X returns the x coordinate.

func (*Vector) Y

func (v *Vector) Y() float64

Y returns the y coordinate.

func (*Vector) Z

func (v *Vector) Z() float64

Z returns the z coordinate.

type World

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

World represents a world in a scene.

func NewDefaultWorld

func NewDefaultWorld() *World

NewDefaultWorld constructs a new world with some default objects.

func NewWorld

func NewWorld(s Shapes, l Lights) *World

NewWorld constructs a new world.

func (*World) ColorAt

func (w *World) ColorAt(r *Ray) *Color

ColorAt returns the color of a ray's intersection with this world.

func (*World) Intersect

func (w *World) Intersect(r *Ray) Intersections

Intersect returns this world's intersection points with a ray.

func (*World) IsShadowed

func (w *World) IsShadowed(p *Point, l *Light) bool

IsShadowed returns whether a point in this world is in shadow relative to a light.

func (*World) Lights

func (w *World) Lights() Lights

Lights returns this world's lights.

func (*World) Shapes

func (w *World) Shapes() Shapes

Shapes returns this world's shapes.

Jump to

Keyboard shortcuts

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