mat

package
v0.0.0-...-6765b72 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const Epsilon = 0.001
View Source
const TriThreshold = 0.00000000001

Variables

View Source
var IdentityMatrix = identity.Matrix

Functions

func Add3

func Add3(t1, t2, t3 Tuple4, out *Tuple4)

func AddPtr

func AddPtr(t1, t2 Tuple4, t3 *Tuple4)

func AddPtr2

func AddPtr2(t1, t2 *Tuple4, t3 *Tuple4)

func Cofactor3x3

func Cofactor3x3(m1 Mat3x3, row, col int) float64

Cofactor3x3 may change the sign of the computed minor of the passed matrix

func Cofactor4x4

func Cofactor4x4(m1 Mat4x4, row, col int) float64

Cofactor4x4 may change the sign of the computed minor of the passed matrix

func Cross2

func Cross2(a *Tuple4, b *Tuple4, c *Tuple4)

func CrossProduct

func CrossProduct(f1, f2, out *Tuple4)

func Determinant2x2

func Determinant2x2(m1 Mat2x2) float64

Determinant2x2 returns A-D minus B-C for a [A,B] [C,D] Matrix.

func Determinant3x3

func Determinant3x3(m1 Mat3x3) float64

Determinant3x3 takes the first row of the passed matrix, summing the colvalue * Cofactor of the same col

func Determinant4x4

func Determinant4x4(m1 Mat4x4) float64

Determinant4x4

func Divide

func Divide(s Shape, threshold int)

func Dot

func Dot(t1 Tuple4, t2 Tuple4) float64

Dot product is the sum of the products of the corresponding entries of the two sequences of numbers a product is simply put the result of a multiplication. The dot product of two tuples is simply t1.x * t2.x + t1.y * t2.y + t1.z * t2.z + t1[3] * t2[3]

func DotPtr

func DotPtr(t1 *Tuple4, t2 *Tuple4) float64

func Eq

func Eq(a, b float64) bool

func Equals

func Equals(m1, m2 Mat4x4) bool

func Equals2x2

func Equals2x2(m1, m2 Mat2x2) bool

func Equals3x3

func Equals3x3(m1, m2 Mat3x3) bool

func HadamardPtr

func HadamardPtr(t1 *Tuple4, t2 Tuple4, out *Tuple4)

func IntersectRayWithBox

func IntersectRayWithBox(ray Ray, BoundingBox *BoundingBox) bool

func IntersectionAllowed

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

func IntersectionEqual

func IntersectionEqual(i1, i2 Intersection) bool

func IsInvertible

func IsInvertible(m1 Mat4x4) bool

func Magnitude

func Magnitude(t1 Tuple4) float64

Magnitude measures the length of the passed vector. It's basically pythagoras sqrt(x2 + y2 + z2 + w2)

func MagnitudePtr

func MagnitudePtr(t1 *Tuple4) float64

func MakeSubGroup

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

func Minor3x3

func Minor3x3(m1 Mat3x3, row, col int) float64

Minor3x3 computes the submatrix at row/col and returns the determinant of the computed matrix.

func Minor4x4

func Minor4x4(m1 Mat4x4, row, col int) float64

Minor4x4 computes the submatrix at row/col and returns the determinant of the computed matrix.

func MultiplyByScalarPtr

func MultiplyByScalarPtr(t1 Tuple4, scalar float64, out *Tuple4)

func MultiplyByTuplePtr

func MultiplyByTuplePtr(m *Mat4x4, f2 *Tuple4, _f4 *Tuple4)

func MultiplyByTupleUsingPointers

func MultiplyByTupleUsingPointers(m1 *Mat4x4, t, out *Tuple4)

func MultiplyByTupleUsingValues

func MultiplyByTupleUsingValues(m1 Mat4x4, t Tuple4, out *Tuple4)

func NegatePtr

func NegatePtr(t1 Tuple4, out *Tuple4)

func NormalToWorldPtr

func NormalToWorldPtr(shape Shape, normal *Tuple4)

func NormalizePtr

func NormalizePtr(t1 *Tuple4, out *Tuple4)

func NormalizePtr2

func NormalizePtr2(t1 Tuple4, out *Tuple4)

func OrientAreaLight

func OrientAreaLight(light *AreaLight, source Tuple4, target Tuple4)

func PartitionChildren

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

func PositionPtr

func PositionPtr(r Ray, distance float64, out *Tuple4)

func PrepareComputationForIntersectionPtr

func PrepareComputationForIntersectionPtr(i Intersection, r Ray, comps *Computation, xs ...Intersection)

func ReflectPtr

func ReflectPtr(vec Tuple4, normal Tuple4, out *Tuple4)

in - normal * 2 * dot(in, normal)

func Schlick

func Schlick(comps Computation) float64

func ShadowIntersect

func ShadowIntersect(w World, r Ray, distance float64, inRay *Ray) bool

func SplitBounds

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

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

func SubPtr

func SubPtr(t1, t2 Tuple4, out *Tuple4)

func TransformRayPtr

func TransformRayPtr(r Ray, m1 Mat4x4, out *Ray)

func TupleEquals

func TupleEquals(t1, t2 Tuple4) bool

func TupleXYZEq

func TupleXYZEq(t1, t2 Tuple4) bool

func WorldToObjectPtr

func WorldToObjectPtr(shape Shape, point Tuple4, out *Tuple4)

Types

type AreaLight

type AreaLight struct {
	Corner    Tuple4
	UVec      Tuple4
	USteps    int
	VVec      Tuple4
	VSteps    int
	Intensity Tuple4
	Samples   float64
	Position  Tuple4
}

func NewAreaLight

func NewAreaLight(corner Tuple4, uVec Tuple4, usteps int, vVec Tuple4, vsteps int, intensity Tuple4) AreaLight

func (AreaLight) Intens

func (al AreaLight) Intens() Tuple4

func (AreaLight) Pos

func (al AreaLight) Pos() Tuple4

type BoundingBox

type BoundingBox struct {
	Min Tuple4
	Max Tuple4
}

func BoundsOf

func BoundsOf(shape Shape) *BoundingBox

func NewBoundingBox

func NewBoundingBox(pointA Tuple4, pointB 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 Mat4x4) *BoundingBox

func (*BoundingBox) Add

func (b *BoundingBox) Add(p Tuple4)

func (*BoundingBox) ContainsBox

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

func (*BoundingBox) ContainsPoint

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

func (*BoundingBox) MergeWith

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

type CSG

type CSG struct {
	Id               int64
	Transform        Mat4x4
	Inverse          Mat4x4
	InverseTranspose Mat4x4
	Left             Shape
	Right            Shape
	Operation        string

	Material Material
	Label    string

	BoundingBox *BoundingBox

	CastShadow bool
	// contains filtered or unexported fields
}

func NewCSG

func NewCSG(operation string, left, right Shape) *CSG

func (*CSG) Bounds

func (c *CSG) Bounds()

func (*CSG) CastsShadow

func (c *CSG) CastsShadow() bool

func (*CSG) GetInverse

func (c *CSG) GetInverse() Mat4x4

func (*CSG) GetInverseTranspose

func (c *CSG) GetInverseTranspose() Mat4x4

func (*CSG) GetLocalRay

func (c *CSG) GetLocalRay() Ray

func (*CSG) GetMaterial

func (c *CSG) GetMaterial() Material

func (*CSG) GetParent

func (c *CSG) GetParent() Shape

func (*CSG) GetTransform

func (c *CSG) GetTransform() Mat4x4

func (*CSG) ID

func (c *CSG) ID() int64

func (*CSG) IntersectLocal

func (c *CSG) IntersectLocal(ray Ray) []Intersection

func (*CSG) Name

func (c *CSG) Name() string

func (*CSG) NormalAtLocal

func (c *CSG) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4

func (*CSG) SetMaterial

func (c *CSG) SetMaterial(material Material)

func (*CSG) SetParent

func (c *CSG) SetParent(shape Shape)

func (*CSG) SetTransform

func (c *CSG) SetTransform(transform Mat4x4)

type Camera

type Camera struct {
	Width       int
	Height      int
	Fov         float64
	Transform   Mat4x4
	Inverse     Mat4x4
	PixelSize   float64
	HalfWidth   float64
	HalfHeight  float64
	Aperture    float64
	FocalLength float64
}

func NewCamera

func NewCamera(width int, height int, fov float64) Camera

func NewCameraWithAperture

func NewCameraWithAperture(width int, height int, fov, aperture, focalLength float64) Camera

type Canvas

type Canvas struct {
	W        int
	H        int
	MaxIndex int
	Pixels   []Tuple4
}

func NewCanvas

func NewCanvas(w int, h int) *Canvas

func (*Canvas) ColorAt

func (c *Canvas) ColorAt(col, row int) Tuple4

func (*Canvas) ToPPM

func (c *Canvas) ToPPM() string

func (*Canvas) WritePixel

func (c *Canvas) WritePixel(col, row int, color Tuple4)

func (*Canvas) WritePixelMutex

func (c *Canvas) WritePixelMutex(col, row int, color Tuple4)

func (*Canvas) WritePixelToIndex

func (c *Canvas) WritePixelToIndex(idx int, color Tuple4)

type CheckerPattern

type CheckerPattern struct {
	ColorA    Tuple4
	ColorB    Tuple4
	Transform Mat4x4
	Inverse   Mat4x4
}

func NewCheckerPattern

func NewCheckerPattern(colorA Tuple4, colorB Tuple4) *CheckerPattern

func (*CheckerPattern) GetInverse

func (c *CheckerPattern) GetInverse() Mat4x4

func (*CheckerPattern) GetTransform

func (c *CheckerPattern) GetTransform() Mat4x4

func (*CheckerPattern) PatternAt

func (c *CheckerPattern) PatternAt(point Tuple4) Tuple4

func (*CheckerPattern) SetPatternTransform

func (c *CheckerPattern) SetPatternTransform(transform Mat4x4)

type Computation

type Computation struct {
	T          float64
	Object     Shape
	Point      Tuple4
	EyeVec     Tuple4
	NormalVec  Tuple4
	Inside     bool
	OverPoint  Tuple4
	UnderPoint Tuple4
	ReflectVec Tuple4
	N1         float64
	N2         float64
	// contains filtered or unexported fields
}

func NewComputation

func NewComputation() Computation

func PrepareComputationForIntersection

func PrepareComputationForIntersection(i Intersection, r Ray, xs ...Intersection) Computation

TODO refactor so tests uses the other one instead.

type Cone

type Cone struct {
	Id               int64
	Transform        Mat4x4
	Inverse          Mat4x4
	InverseTranspose Mat4x4
	Material         Material
	Label            string

	MinY       float64
	MaxY       float64
	Closed     bool
	CastShadow bool
	// contains filtered or unexported fields
}

func NewCone

func NewCone() *Cone

func NewConeMMC

func NewConeMMC(min, max float64, closed bool) *Cone

func (*Cone) CastsShadow

func (c *Cone) CastsShadow() bool

func (*Cone) GetInverse

func (c *Cone) GetInverse() Mat4x4

func (*Cone) GetInverseTranspose

func (c *Cone) GetInverseTranspose() Mat4x4

func (*Cone) GetLocalRay

func (c *Cone) GetLocalRay() Ray

func (*Cone) GetMaterial

func (c *Cone) GetMaterial() Material

func (*Cone) GetParent

func (c *Cone) GetParent() Shape

func (*Cone) GetTransform

func (c *Cone) GetTransform() Mat4x4

func (*Cone) ID

func (c *Cone) ID() int64

func (*Cone) IntersectLocal

func (c *Cone) IntersectLocal(ray Ray) []Intersection

func (*Cone) Name

func (c *Cone) Name() string

func (*Cone) NormalAtLocal

func (c *Cone) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4

func (*Cone) SetMaterial

func (c *Cone) SetMaterial(material Material)

func (*Cone) SetParent

func (c *Cone) SetParent(shape Shape)

func (*Cone) SetTransform

func (c *Cone) SetTransform(transform Mat4x4)

type Cube

type Cube struct {
	Id               int64
	Transform        Mat4x4
	Inverse          Mat4x4
	InverseTranspose Mat4x4
	Material         Material
	Label            string

	CastShadow bool
	// contains filtered or unexported fields
}

func NewCube

func NewCube() *Cube

func (*Cube) CastsShadow

func (c *Cube) CastsShadow() bool

func (*Cube) GetInverse

func (c *Cube) GetInverse() Mat4x4

func (*Cube) GetInverseTranspose

func (c *Cube) GetInverseTranspose() Mat4x4

func (*Cube) GetLocalRay

func (c *Cube) GetLocalRay() Ray

func (*Cube) GetMaterial

func (c *Cube) GetMaterial() Material

func (*Cube) GetParent

func (c *Cube) GetParent() Shape

func (*Cube) GetTransform

func (c *Cube) GetTransform() Mat4x4

func (*Cube) ID

func (c *Cube) ID() int64

func (*Cube) Init

func (c *Cube) Init()

func (*Cube) IntersectLocal

func (c *Cube) IntersectLocal(ray Ray) []Intersection

func (*Cube) Name

func (c *Cube) Name() string

func (*Cube) NormalAtLocal

func (c *Cube) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4

NormalAtLocal uses the fact that given a unit cube, the point of the surface axis X,Y or Z is always either 1.0 for positive XYZ and -1.0 for negative XYZ. I.e - if the point is 0.4, 1, -0.5, we know that the point is on the top Y surface and we can return a 0,1,0 normal

func (*Cube) SetMaterial

func (c *Cube) SetMaterial(material Material)

func (*Cube) SetParent

func (c *Cube) SetParent(shape Shape)

func (*Cube) SetTransform

func (c *Cube) SetTransform(transform Mat4x4)

type Cylinder

type Cylinder struct {
	Id               int64
	Transform        Mat4x4
	Inverse          Mat4x4
	InverseTranspose Mat4x4
	Material         Material
	Label            string

	MinY float64
	MaxY float64

	CastShadow bool
	// 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) CastsShadow

func (c *Cylinder) CastsShadow() bool

func (*Cylinder) GetInverse

func (c *Cylinder) GetInverse() Mat4x4

func (*Cylinder) GetInverseTranspose

func (c *Cylinder) GetInverseTranspose() Mat4x4

func (*Cylinder) GetLocalRay

func (c *Cylinder) GetLocalRay() Ray

func (*Cylinder) GetMaterial

func (c *Cylinder) GetMaterial() Material

func (*Cylinder) GetParent

func (c *Cylinder) GetParent() Shape

func (*Cylinder) GetTransform

func (c *Cylinder) GetTransform() Mat4x4

func (*Cylinder) ID

func (c *Cylinder) ID() int64

func (*Cylinder) Init

func (c *Cylinder) Init()

func (*Cylinder) IntersectLocal

func (c *Cylinder) IntersectLocal(ray Ray) []Intersection

func (*Cylinder) Name

func (c *Cylinder) Name() string

func (*Cylinder) NormalAtLocal

func (c *Cylinder) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4

func (*Cylinder) SetMaterial

func (c *Cylinder) SetMaterial(material Material)

func (*Cylinder) SetParent

func (c *Cylinder) SetParent(shape Shape)

func (*Cylinder) SetTransform

func (c *Cylinder) SetTransform(transform Mat4x4)

type GradientPattern

type GradientPattern struct {
	FromColor Tuple4
	ToColor   Tuple4
	Transform Mat4x4
	Inverse   Mat4x4
}

func NewGradientPattern

func NewGradientPattern(from, to Tuple4) *GradientPattern

func (*GradientPattern) GetInverse

func (g *GradientPattern) GetInverse() Mat4x4

func (*GradientPattern) GetTransform

func (g *GradientPattern) GetTransform() Mat4x4

func (*GradientPattern) PatternAt

func (g *GradientPattern) PatternAt(point Tuple4) Tuple4

func (*GradientPattern) SetPatternTransform

func (g *GradientPattern) SetPatternTransform(transform Mat4x4)

type Group

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

	Children []Shape

	InnerRays   []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() Mat4x4

func (*Group) GetInverseTranspose

func (g *Group) GetInverseTranspose() Mat4x4

func (*Group) GetLocalRay

func (g *Group) GetLocalRay() Ray

func (*Group) GetMaterial

func (g *Group) GetMaterial() Material

func (*Group) GetParent

func (g *Group) GetParent() Shape

func (*Group) GetTransform

func (g *Group) GetTransform() Mat4x4

func (*Group) ID

func (g *Group) ID() int64

func (*Group) IntersectLocal

func (g *Group) IntersectLocal(ray Ray) []Intersection

func (*Group) Name

func (g *Group) Name() string

func (*Group) NormalAtLocal

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

func (*Group) SetMaterial

func (g *Group) SetMaterial(material Material)

func (*Group) SetParent

func (g *Group) SetParent(shape Shape)

func (*Group) SetTransform

func (g *Group) SetTransform(transform Mat4x4)

type Intersection

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

func FilterIntersections

func FilterIntersections(csg *CSG, xs []Intersection) []Intersection

func Hit

func Hit(intersections []Intersection) (Intersection, bool)

Hit finds the first intersection with a positive T (the passed intersections are assumed to have been sorted already)

func IntersectRayWithShape

func IntersectRayWithShape(s Shape, r2 Ray) []Intersection

TODO only used by unit tests, fix so tests use IntersectRayWithShapePtr and remove

func IntersectRayWithShapePtr

func IntersectRayWithShapePtr(s Shape, r2 Ray, in *Ray) []Intersection

func IntersectWithWorldPtr

func IntersectWithWorldPtr(w World, r Ray, xs Intersections, inRay *Ray) []Intersection

func IntersectWithWorldPtrForShadow

func IntersectWithWorldPtrForShadow(w World, r Ray, xs Intersections, inRay *Ray) []Intersection

func NewIntersection

func NewIntersection(t float64, s Shape) Intersection

func NewIntersectionUV

func NewIntersectionUV(t float64, s Shape, u, v float64) Intersection

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 Light

type Light struct {
	Position  Tuple4
	Intensity Tuple4
}

func NewLight

func NewLight(position Tuple4, intensity Tuple4) Light

func (Light) Intens

func (l Light) Intens() Tuple4

func (Light) Pos

func (l Light) Pos() Tuple4

type LightData

type LightData struct {
	Ambient        Tuple4
	Diffuse        Tuple4
	Specular       Tuple4
	EffectiveColor Tuple4
	LightVec       Tuple4
	ReflectVec     Tuple4
}

LightData is used for pre-allocated memory for lighting computations.

func NewLightData

func NewLightData() LightData

type LightSource

type LightSource interface {
	Pos() Tuple4
	Intens() Tuple4
}

type Mat2x2

type Mat2x2 [4]float64

func NewMat2x2

func NewMat2x2(elems []float64) Mat2x2

func Submatrix3x3

func Submatrix3x3(m1 Mat3x3, deleteRow, deleteCol int) Mat2x2

Submatrix3x3 extracts the 2x2 submatrix after deleting row and col from the passed 3x3

func (Mat2x2) Get

func (m Mat2x2) Get(row int, col int) float64

type Mat3x3

type Mat3x3 [9]float64

func NewMat3x3

func NewMat3x3(elems []float64) Mat3x3

func Submatrix4x4

func Submatrix4x4(m1 Mat4x4, deleteRow, deleteCol int) Mat3x3

Submatrix4x4 extracts the 3x3 submatrix after deleting row and col from the passed 4x4

func (Mat3x3) Get

func (m Mat3x3) Get(row int, col int) float64

type Mat4x4

type Mat4x4 [16]float64

func Inverse

func Inverse(m1 Mat4x4) Mat4x4

func Multiply

func Multiply(m1 Mat4x4, m2 Mat4x4) Mat4x4

func New4x4

func New4x4() Mat4x4

func NewIdentityMatrix

func NewIdentityMatrix() Mat4x4

func NewMat4x4

func NewMat4x4(elems []float64) Mat4x4

func RotateX

func RotateX(radians float64) Mat4x4

func RotateY

func RotateY(radians float64) Mat4x4

func RotateZ

func RotateZ(radians float64) Mat4x4

func Scale

func Scale(x, y, z float64) Mat4x4

func Shear

func Shear(xy, xz, yx, yz, zx, zy float64) Mat4x4

func ShearBy

func ShearBy(args []float64) Mat4x4

func Translate

func Translate(x, y, z float64) Mat4x4

Translate creates a translation matrix from the identity matrix, setting wx, wy, wz to the passed xyz coords.

func Transpose

func Transpose(m1 Mat4x4) Mat4x4

Transpose flips rows and cols in the matrix.

func ViewTransform

func ViewTransform(from, to, up Tuple4) Mat4x4

func (Mat4x4) Get

func (m Mat4x4) Get(row int, col int) float64

type Material

type Material struct {
	Color           Tuple4
	Ambient         float64
	Diffuse         float64
	Specular        float64
	Shininess       float64
	Pattern         Pattern
	Reflectivity    float64
	Transparency    float64
	RefractiveIndex float64
	Name            string
}

func NewDefaultMaterial

func NewDefaultMaterial() Material

func NewDefaultReflectiveMaterial

func NewDefaultReflectiveMaterial(reflectivity float64) Material

func NewGlassMaterial

func NewGlassMaterial(refractiveIndex float64) Material

func NewMaterial

func NewMaterial(color Tuple4, ambient float64, diffuse float64, specular float64, shininess float64) Material

func NewMaterialWithReflectivity

func NewMaterialWithReflectivity(color Tuple4, ambient float64, diffuse float64, specular float64, shininess, reflectivity float64) Material

func (*Material) HasPattern

func (m *Material) HasPattern() bool

type Mtl

type Mtl struct {
	Ambient         Tuple4
	Diffuse         Tuple4
	Specular        Tuple4
	Shininess       float64
	Reflectivity    float64
	Transparency    float64
	RefractiveIndex float64
	Name            string
}

type Pattern

type Pattern interface {
	PatternAt(point Tuple4) Tuple4
	SetPatternTransform(transform Mat4x4)
	GetTransform() Mat4x4
	GetInverse() Mat4x4
}

type Plane

type Plane struct {
	Id               int64
	Transform        Mat4x4
	Inverse          Mat4x4
	InverseTranspose Mat4x4
	Material         Material
	Label            string

	CastShadow bool
	// contains filtered or unexported fields
}

func NewPlane

func NewPlane() *Plane

func (*Plane) CastsShadow

func (p *Plane) CastsShadow() bool

func (*Plane) GetInverse

func (p *Plane) GetInverse() Mat4x4

func (*Plane) GetInverseTranspose

func (p *Plane) GetInverseTranspose() Mat4x4

func (*Plane) GetLocalRay

func (p *Plane) GetLocalRay() Ray

func (*Plane) GetMaterial

func (p *Plane) GetMaterial() Material

func (*Plane) GetParent

func (p *Plane) GetParent() Shape

func (*Plane) GetTransform

func (p *Plane) GetTransform() Mat4x4

func (*Plane) ID

func (p *Plane) ID() int64

func (*Plane) IntersectLocal

func (p *Plane) IntersectLocal(ray Ray) []Intersection

func (*Plane) Name

func (p *Plane) Name() string

func (*Plane) NormalAtLocal

func (p *Plane) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4

func (*Plane) SetMaterial

func (p *Plane) SetMaterial(m 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 Mat4x4)

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

type Ray

type Ray struct {
	Origin    Tuple4
	Direction Tuple4
}

func NewRay

func NewRay(origin Tuple4, direction Tuple4) Ray

func TransformRay

func TransformRay(r Ray, m1 Mat4x4) Ray

type RingPattern

type RingPattern struct {
	A         Tuple4
	B         Tuple4
	Transform Mat4x4
	Inverse   Mat4x4
}

func NewRingPattern

func NewRingPattern(a Tuple4, b Tuple4) *RingPattern

func (*RingPattern) GetInverse

func (r *RingPattern) GetInverse() Mat4x4

func (*RingPattern) GetTransform

func (r *RingPattern) GetTransform() Mat4x4

func (*RingPattern) PatternAt

func (r *RingPattern) PatternAt(point Tuple4) Tuple4

func (*RingPattern) SetPatternTransform

func (r *RingPattern) SetPatternTransform(transform Mat4x4)

type Shape

type Shape interface {
	ID() int64
	GetTransform() Mat4x4
	GetInverse() Mat4x4
	GetInverseTranspose() Mat4x4
	SetTransform(transform Mat4x4)
	GetMaterial() Material
	SetMaterial(material Material)
	IntersectLocal(ray Ray) []Intersection
	NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4
	GetLocalRay() Ray
	GetParent() Shape
	SetParent(shape Shape)
	CastsShadow() bool
	Name() string
}

type SmoothTriangle

type SmoothTriangle struct {
	P1         Tuple4
	P2         Tuple4
	P3         Tuple4
	E1         Tuple4
	E2         Tuple4
	N          Tuple4
	N1         Tuple4
	N2         Tuple4
	N3         Tuple4
	Material   Material
	CastShadow bool
	Label      string

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

func DefaultSmoothTriangle

func DefaultSmoothTriangle() *SmoothTriangle

func NewSmoothTriangle

func NewSmoothTriangle(p1 Tuple4, p2 Tuple4, p3 Tuple4, n1 Tuple4, n2 Tuple4, n3 Tuple4) *SmoothTriangle

func (*SmoothTriangle) Barycentric

func (s *SmoothTriangle) Barycentric(p 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 (*SmoothTriangle) CastsShadow

func (s *SmoothTriangle) CastsShadow() bool

func (*SmoothTriangle) GetInverse

func (s *SmoothTriangle) GetInverse() Mat4x4

func (*SmoothTriangle) GetInverseTranspose

func (s *SmoothTriangle) GetInverseTranspose() Mat4x4

func (*SmoothTriangle) GetLocalRay

func (s *SmoothTriangle) GetLocalRay() Ray

func (*SmoothTriangle) GetMaterial

func (s *SmoothTriangle) GetMaterial() Material

func (*SmoothTriangle) GetParent

func (s *SmoothTriangle) GetParent() Shape

func (*SmoothTriangle) GetTransform

func (s *SmoothTriangle) GetTransform() Mat4x4

func (*SmoothTriangle) ID

func (s *SmoothTriangle) ID() int64

func (*SmoothTriangle) IntersectLocal

func (s *SmoothTriangle) IntersectLocal(ray Ray) []Intersection

func (*SmoothTriangle) Name

func (s *SmoothTriangle) Name() string

func (*SmoothTriangle) NormalAtLocal

func (s *SmoothTriangle) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4

func (*SmoothTriangle) SetMaterial

func (s *SmoothTriangle) SetMaterial(material Material)

func (*SmoothTriangle) SetParent

func (s *SmoothTriangle) SetParent(shape Shape)

func (*SmoothTriangle) SetTransform

func (s *SmoothTriangle) SetTransform(transform Mat4x4)

type Sphere

type Sphere struct {
	Id               int64
	Transform        Mat4x4
	Inverse          Mat4x4
	InverseTranspose Mat4x4
	Material         Material
	Label            string

	CastShadow bool
	// contains filtered or unexported fields
}

func NewGlassSphere

func NewGlassSphere() *Sphere

func NewSphere

func NewSphere() *Sphere

func (*Sphere) CastsShadow

func (s *Sphere) CastsShadow() bool

func (*Sphere) GetInverse

func (s *Sphere) GetInverse() Mat4x4

func (*Sphere) GetInverseTranspose

func (s *Sphere) GetInverseTranspose() Mat4x4

func (*Sphere) GetLocalRay

func (s *Sphere) GetLocalRay() Ray

func (*Sphere) GetMaterial

func (s *Sphere) GetMaterial() Material

func (*Sphere) GetParent

func (s *Sphere) GetParent() Shape

func (*Sphere) GetTransform

func (s *Sphere) GetTransform() Mat4x4

func (*Sphere) ID

func (s *Sphere) ID() int64

func (*Sphere) IntersectLocal

func (s *Sphere) IntersectLocal(r Ray) []Intersection

IntersectLocal implements Sphere-ray intersection

func (*Sphere) Name

func (s *Sphere) Name() string

func (*Sphere) NormalAtLocal

func (s *Sphere) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4

func (*Sphere) SetMaterial

func (s *Sphere) SetMaterial(m 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 Mat4x4)

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

type StripePattern

type StripePattern struct {
	A         Tuple4
	B         Tuple4
	Transform Mat4x4
	Inverse   Mat4x4
}

func NewStripePattern

func NewStripePattern(colorA Tuple4, colorB Tuple4) *StripePattern

func (*StripePattern) GetInverse

func (p *StripePattern) GetInverse() Mat4x4

func (*StripePattern) GetTransform

func (p *StripePattern) GetTransform() Mat4x4

func (*StripePattern) PatternAt

func (p *StripePattern) PatternAt(point Tuple4) Tuple4

func (*StripePattern) SetPatternTransform

func (p *StripePattern) SetPatternTransform(transform Mat4x4)

type TestPattern

type TestPattern struct {
	Transform Mat4x4
	Inverse   Mat4x4
}

func NewTestPattern

func NewTestPattern() *TestPattern

func (*TestPattern) GetInverse

func (t *TestPattern) GetInverse() Mat4x4

func (*TestPattern) GetTransform

func (t *TestPattern) GetTransform() Mat4x4

func (*TestPattern) PatternAt

func (t *TestPattern) PatternAt(point Tuple4) Tuple4

func (*TestPattern) SetPatternTransform

func (t *TestPattern) SetPatternTransform(transform Mat4x4)

type Triangle

type Triangle struct {
	P1         Tuple4
	P2         Tuple4
	P3         Tuple4
	E1         Tuple4
	E2         Tuple4
	N          Tuple4
	Material   Material
	CastShadow bool
	Label      string
}

func NewTriangle

func NewTriangle(p1 Tuple4, p2 Tuple4, p3 Tuple4) *Triangle

func (*Triangle) CastsShadow

func (t *Triangle) CastsShadow() bool

func (*Triangle) GetInverse

func (t *Triangle) GetInverse() Mat4x4

func (*Triangle) GetInverseTranspose

func (t *Triangle) GetInverseTranspose() Mat4x4

func (*Triangle) GetLocalRay

func (t *Triangle) GetLocalRay() Ray

func (*Triangle) GetMaterial

func (t *Triangle) GetMaterial() Material

func (*Triangle) GetParent

func (t *Triangle) GetParent() Shape

func (*Triangle) GetTransform

func (t *Triangle) GetTransform() Mat4x4

func (*Triangle) ID

func (t *Triangle) ID() int64

func (*Triangle) IntersectLocal

func (t *Triangle) IntersectLocal(ray Ray) []Intersection

func (*Triangle) Name

func (t *Triangle) Name() string

func (*Triangle) NormalAtLocal

func (t *Triangle) NormalAtLocal(point Tuple4, intersection *Intersection) Tuple4

func (*Triangle) SetMaterial

func (t *Triangle) SetMaterial(material Material)

func (*Triangle) SetParent

func (t *Triangle) SetParent(shape Shape)

func (*Triangle) SetTransform

func (t *Triangle) SetTransform(transform Mat4x4)

type Tuple4

type Tuple4 [4]float64

func Add

func Add(t1, t2 Tuple4) Tuple4

func Cross

func Cross(t1 Tuple4, t2 Tuple4) Tuple4

func DivideByScalar

func DivideByScalar(t1 Tuple4, scalar float64) Tuple4

func Hadamard

func Hadamard(t1 Tuple4, t2 Tuple4) Tuple4

func Lighting

func Lighting(material Material, object Shape, light LightSource, position, eyeVec, normalVec Tuple4, intensity float64, lightData LightData) Tuple4

func LightingPointLight

func LightingPointLight(material Material, object Shape, light Light, position, eyeVec, normalVec Tuple4, inShadow bool, lightData LightData) Tuple4

LightingPointLight computes the color of a given pixel given phong shading a point light

func MultiplyByScalar

func MultiplyByScalar(t1 Tuple4, scalar float64) Tuple4

func MultiplyByTuple

func MultiplyByTuple(m1 Mat4x4, t Tuple4) Tuple4

func Negate

func Negate(t1 Tuple4) Tuple4

func NewColor

func NewColor(r, g, b float64) Tuple4

func NewPoint

func NewPoint(x, y, z float64) Tuple4

func NewTuple

func NewTuple() Tuple4

func NewTupleOf

func NewTupleOf(x, y, z, w float64) Tuple4

func NewVector

func NewVector(x, y, z float64) Tuple4

func NormalAt

func NormalAt(s Shape, worldPoint Tuple4, intersection *Intersection) Tuple4

func NormalToWorld

func NormalToWorld(shape Shape, normal Tuple4) Tuple4

func Normalize

func Normalize(t1 Tuple4) Tuple4

Normalize measures the length (magnitude) of the passed Vector. Each component in t1 is then divided my the magnitude in order to Normalize it to unit (1) size.

func PatternAtShape

func PatternAtShape(pattern Pattern, s Shape, worldPoint Tuple4) Tuple4

func PointOnLight

func PointOnLight(light AreaLight, u, v float64) Tuple4

func PointOnLightNoRandom

func PointOnLightNoRandom(light AreaLight, u, v float64) Tuple4

func Position

func Position(r Ray, distance float64) Tuple4

Position multiplies direction of ray with the passed distance and adds the result onto the origin. Used for finding the position along a ray.

func Reflect

func Reflect(vec Tuple4, normal Tuple4) Tuple4

in - normal * 2 * dot(in, normal)

func Sub

func Sub(t1, t2 Tuple4) Tuple4

func T4F32

func T4F32(x, y, z float32, w float64) Tuple4

func WorldToObject

func WorldToObject(shape Shape, point Tuple4) Tuple4

func (Tuple4) Add

func (t Tuple4) Add(t2 Tuple4) Tuple4

func (*Tuple4) AddNoRet

func (t *Tuple4) AddNoRet(t2 Tuple4)

func (*Tuple4) AddNoRetPtr

func (t *Tuple4) AddNoRetPtr(t2 *Tuple4)

func (Tuple4) Get

func (t Tuple4) Get(row int) float64

func (Tuple4) IsPoint

func (t Tuple4) IsPoint() bool

func (Tuple4) IsVector

func (t Tuple4) IsVector() bool

func (Tuple4) Multiply

func (t Tuple4) Multiply(scalar float64) Tuple4

func (Tuple4) ResetPoint

func (t Tuple4) ResetPoint() Tuple4

func (Tuple4) ResetVector

func (t Tuple4) ResetVector() Tuple4

type World

type World struct {
	Light     []Light
	AreaLight []AreaLight
	Objects   []Shape `yaml:"objects,flow"`
}

func NewDefaultWorld

func NewDefaultWorld() World

func NewWorld

func NewWorld() World

Jump to

Keyboard shortcuts

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