Documentation ¶
Overview ¶
Package rtc implements the code for the Ray Tracer Challenge book.
Index ¶
- type BasePattern
- type BoundsT
- type CSGOperation
- type CSGT
- func (c *CSGT) Bounds() *BoundsT
- func (c *CSGT) FilterIntersections(xs []IntersectionT) []IntersectionT
- func (c *CSGT) Includes(other Object) bool
- func (c *CSGT) LocalIntersect(ray RayT) []IntersectionT
- func (c *CSGT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
- func (c *CSGT) SetMaterial(material MaterialT) Object
- func (c *CSGT) SetParent(parent Object) Object
- func (c *CSGT) SetTransform(m M4) Object
- type CameraT
- type Canvas
- func (c *Canvas) At(x, y int) color.Color
- func (c *Canvas) Bounds() image.Rectangle
- func (c *Canvas) ColorModel() color.Model
- func (c *Canvas) PixelAt(x, y int) Tuple
- func (c *Canvas) ToPPM() string
- func (c *Canvas) WritePNGFile(filename string) error
- func (c *Canvas) WritePPMFile(filename string) error
- func (c *Canvas) WritePixel(x, y int, color Tuple)
- type CheckersPatternT
- type Comps
- type ConeT
- func (c *ConeT) Bounds() *BoundsT
- func (c *ConeT) Includes(other Object) bool
- func (c *ConeT) LocalIntersect(ray RayT) []IntersectionT
- func (c *ConeT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
- func (c *ConeT) SetMaterial(material MaterialT) Object
- func (c *ConeT) SetParent(parent Object) Object
- func (c *ConeT) SetTransform(m M4) Object
- type CubeT
- func (c *CubeT) Bounds() *BoundsT
- func (c *CubeT) Includes(other Object) bool
- func (c *CubeT) LocalIntersect(ray RayT) []IntersectionT
- func (c *CubeT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
- func (c *CubeT) SetMaterial(material MaterialT) Object
- func (c *CubeT) SetParent(parent Object) Object
- func (c *CubeT) SetTransform(m M4) Object
- type CylinderT
- func (c *CylinderT) Bounds() *BoundsT
- func (c *CylinderT) Includes(other Object) bool
- func (c *CylinderT) LocalIntersect(ray RayT) []IntersectionT
- func (c *CylinderT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
- func (c *CylinderT) SetMaterial(material MaterialT) Object
- func (c *CylinderT) SetParent(parent Object) Object
- func (c *CylinderT) SetTransform(m M4) Object
- type GradientPatternT
- type GroupT
- func (g *GroupT) AddChild(shapes ...Object)
- func (g *GroupT) Bounds() *BoundsT
- func (g *GroupT) Includes(other Object) bool
- func (g *GroupT) LocalIntersect(ray RayT) []IntersectionT
- func (g *GroupT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
- func (g *GroupT) SetMaterial(material MaterialT) Object
- func (g *GroupT) SetParent(parent Object) Object
- func (g *GroupT) SetTransform(m M4) Object
- type IntersectionT
- type M2
- type M3
- type M4
- func (m M4) Cofactor(row, col int) float64
- func (m M4) Column(col int) Tuple
- func (m M4) Determinant() float64
- func (m M4) Equal(other M4) bool
- func (m M4) Get(row, col int) float64
- func (m M4) Inverse() M4
- func (m M4) Invertible() bool
- func (m M4) Minor(row, col int) float64
- func (m M4) Mult(other M4) M4
- func (m M4) MultTuple(other Tuple) Tuple
- func (m M4) RotateX(radians float64) M4
- func (m M4) RotateY(radians float64) M4
- func (m M4) RotateZ(radians float64) M4
- func (m M4) Scale(x, y, z float64) M4
- func (m M4) Shear(xy, xz, yx, yz, zx, zy float64) M4
- func (m M4) Submatrix(row, col int) M3
- func (m M4) Translate(x, y, z float64) M4
- func (m M4) Transpose() M4
- type MaterialT
- type Object
- type Pattern
- type PlaneT
- func (p *PlaneT) Bounds() *BoundsT
- func (p *PlaneT) Includes(other Object) bool
- func (p *PlaneT) LocalIntersect(ray RayT) []IntersectionT
- func (p *PlaneT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
- func (p *PlaneT) SetMaterial(material MaterialT) Object
- func (p *PlaneT) SetParent(parent Object) Object
- func (p *PlaneT) SetTransform(m M4) Object
- type PointLightT
- type RayT
- type RingPatternT
- type Shape
- type SmoothTriangleT
- func (s *SmoothTriangleT) Bounds() *BoundsT
- func (s *SmoothTriangleT) Includes(other Object) bool
- func (s *SmoothTriangleT) LocalIntersect(ray RayT) []IntersectionT
- func (s *SmoothTriangleT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
- func (s *SmoothTriangleT) SetMaterial(material MaterialT) Object
- func (s *SmoothTriangleT) SetParent(parent Object) Object
- func (s *SmoothTriangleT) SetTransform(m M4) Object
- type SphereT
- func (s *SphereT) Bounds() *BoundsT
- func (s *SphereT) Includes(other Object) bool
- func (s *SphereT) LocalIntersect(ray RayT) []IntersectionT
- func (s *SphereT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
- func (s *SphereT) SetMaterial(material MaterialT) Object
- func (s *SphereT) SetParent(parent Object) Object
- func (s *SphereT) SetTransform(m M4) Object
- type StripePatternT
- type TriangleT
- func (t *TriangleT) Bounds() *BoundsT
- func (t *TriangleT) Includes(other Object) bool
- func (t *TriangleT) LocalIntersect(ray RayT) []IntersectionT
- func (t *TriangleT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
- func (t *TriangleT) SetMaterial(material MaterialT) Object
- func (t *TriangleT) SetParent(parent Object) Object
- func (t *TriangleT) SetTransform(m M4) Object
- type Tuple
- func Color(red, green, blue float64) Tuple
- func Lighting(material *MaterialT, object Object, light *PointLightT, point Tuple, ...) Tuple
- func NormalToWorld(object Object, normal Tuple) Tuple
- func PatternAt(pattern Pattern, object Object, worldPoint Tuple) Tuple
- func Point(x, y, z float64) Tuple
- func Vector(x, y, z float64) Tuple
- func WorldToObject(object Object, point Tuple) Tuple
- func (t Tuple) Add(other Tuple) Tuple
- func (t Tuple) Alpha() float64
- func (t Tuple) Blue() float64
- func (t Tuple) Cross(other Tuple) Tuple
- func (t Tuple) DivScalar(f float64) Tuple
- func (t Tuple) Dot(other Tuple) float64
- func (t Tuple) Equal(other Tuple) bool
- func (t Tuple) Green() float64
- func (t Tuple) HadamardProduct(other Tuple) Tuple
- func (t Tuple) IsPoint() bool
- func (t Tuple) IsVector() bool
- func (t Tuple) Magnitude() float64
- func (t Tuple) MultScalar(f float64) Tuple
- func (t Tuple) Negate() Tuple
- func (t Tuple) Normalize() Tuple
- func (t Tuple) Red() float64
- func (t Tuple) Reflect(normal Tuple) Tuple
- func (t Tuple) Sub(other Tuple) Tuple
- func (t Tuple) W() float64
- func (t Tuple) X() float64
- func (t Tuple) Y() float64
- func (t Tuple) Z() float64
- type WorldT
- func (w *WorldT) ColorAt(ray RayT, remaining int) Tuple
- func (w *WorldT) IntersectWorld(ray RayT) []IntersectionT
- func (w *WorldT) IsShadowed(point Tuple, light *PointLightT) bool
- func (w *WorldT) ReflectedColor(comps *Comps, remaining int) Tuple
- func (w *WorldT) RefractedColor(comps *Comps, remaining int) Tuple
- func (w *WorldT) ShadeHit(comps *Comps, remaining int) Tuple
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BasePattern ¶
type BasePattern struct {
// contains filtered or unexported fields
}
BasePattern represents the common functionality for all patterns.
func (*BasePattern) SetTransform ¶
func (s *BasePattern) SetTransform(m M4)
SetTransform sets the object's transform 4x4 matrix.
func (*BasePattern) Transform ¶
func (s *BasePattern) Transform() M4
Transform returns the object's transform 4x4 matrix.
type BoundsT ¶
BoundsT represents a minimum bounding box of an object.
func UpdateTransformedBounds ¶
UpdateTransformedBounds returns the updated bounding box of an object, taking into account its own transformation. If a starting bounding box is supplied, it is updated (expanded), otherwise a new one is returned.
func (*BoundsT) LocalIntersect ¶
func (b *BoundsT) LocalIntersect(ray RayT, object Object) []IntersectionT
LocalIntersect returns a slice of IntersectionT values where the transformed (object space) ray intersects the object.
func (*BoundsT) UpdateBounds ¶
UpdateBounds updates the bounding box with the provided point.
type CSGOperation ¶
type CSGOperation int
CSGOperation represents a CSG operation.
const ( CSGUnion CSGOperation = iota CSGIntersection CSGDifference )
type CSGT ¶
type CSGT struct { Shape Operation CSGOperation Left Object Right Object // contains filtered or unexported fields }
CSGT represents a CSG object.
func CSG ¶
func CSG(operation CSGOperation, left, right Object) *CSGT
CSG represents a constructive solid geometry object.
func (*CSGT) Bounds ¶
Bounds returns the minimum bounding box of the object in object (untransformed) space.
func (*CSGT) FilterIntersections ¶
func (c *CSGT) FilterIntersections(xs []IntersectionT) []IntersectionT
FilterIntersections filters allowed CSG intersections from all possible intersections.
func (*CSGT) Includes ¶
Includes returns whether this object includes (or actually is) the other object.
func (*CSGT) LocalIntersect ¶
func (c *CSGT) LocalIntersect(ray RayT) []IntersectionT
LocalIntersect returns a slice of IntersectionT values where the transformed (object space) ray intersects the object.
func (*CSGT) LocalNormalAt ¶
func (c *CSGT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
LocalNormalAt returns the normal vector at the given point of intersection (transformed to object space) with the object.
func (*CSGT) SetMaterial ¶
SetMaterial sets the object's material.
func (*CSGT) SetTransform ¶
SetTransform sets the object's transform 4x4 matrix.
type CameraT ¶
type CameraT struct { HSize int VSize int FieldOfView float64 Transform M4 PixelSize float64 HalfWidth float64 HalfHeight float64 NumWorkers int // contains filtered or unexported fields }
CameraT represents a camera.
func Camera ¶
Camera creates a new CameraT with the provided canvas size and field of view (in radians).
func (*CameraT) RayForPixel ¶
RayForPixel returns a ray for the camera at the given pixel.
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas represents an image canvas and implements the image.Image interface.
func (*Canvas) ColorModel ¶
ColorModel returns the Image's color model.
func (*Canvas) WritePNGFile ¶
WritePNGFile writes a PNG file to the provided filename.
func (*Canvas) WritePPMFile ¶
WritePPMFile writes a PPM file to the provided filename.
func (*Canvas) WritePixel ¶
WritePixel writes a pixel to the canvas.
type CheckersPatternT ¶
type CheckersPatternT struct { BasePattern // contains filtered or unexported fields }
CheckersPatternT is a pattern that draws checkerss. It implements the Pattern interface.
func CheckersPattern ¶
func CheckersPattern(a, b Tuple) *CheckersPatternT
CheckersPattern returns a CheckersPatternT.
func (*CheckersPatternT) LocalPatternAt ¶
func (s *CheckersPatternT) LocalPatternAt(localPoint Tuple) Tuple
LocalPatternAt returns a color at a local point.
type Comps ¶
type Comps struct { T float64 Object Object Point Tuple EyeVector Tuple NormalVector Tuple ReflectVector Tuple Inside bool OverPoint Tuple // For shadow testing - slightly above surface of object. UnderPoint Tuple // For transparency and index of refraction calculations. N1 float64 // Refractive index of material being exited. N2 float64 // Refractive index of material being entered. }
Comps contains precomputed information about an intersection.
type ConeT ¶
ConeT represents a Cone.
func Cone ¶
func Cone() *ConeT
Cone creates a cone at the origin with its axis on the Y axis. It implements the Object interface.
func (*ConeT) Bounds ¶
Bounds returns the minimum bounding box of the object in object (untransformed) space.
func (*ConeT) Includes ¶
Includes returns whether this object includes (or actually is) the other object.
func (*ConeT) LocalIntersect ¶
func (c *ConeT) LocalIntersect(ray RayT) []IntersectionT
LocalIntersect returns a slice of IntersectionT values where the transformed (object space) ray intersects the object.
func (*ConeT) LocalNormalAt ¶
func (c *ConeT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
LocalNormalAt returns the normal vector at the given point of intersection (transformed to object space) with the object.
func (*ConeT) SetMaterial ¶
SetMaterial sets the object's material.
func (*ConeT) SetTransform ¶
SetTransform sets the object's transform 4x4 matrix.
type CubeT ¶
type CubeT struct {
Shape
}
CubeT represents a Cube.
func Cube ¶
func Cube() *CubeT
Cube creates a cube at the origin ranging from -1 to 1 on each axis. It implements the Object interface.
func (*CubeT) Bounds ¶
Bounds returns the minimum bounding box of the object in object (untransformed) space.
func (*CubeT) Includes ¶
Includes returns whether this object includes (or actually is) the other object.
func (*CubeT) LocalIntersect ¶
func (c *CubeT) LocalIntersect(ray RayT) []IntersectionT
LocalIntersect returns a slice of IntersectionT values where the transformed (object space) ray intersects the object.
func (*CubeT) LocalNormalAt ¶
func (c *CubeT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
LocalNormalAt returns the normal vector at the given point of intersection (transformed to object space) with the object.
func (*CubeT) SetMaterial ¶
SetMaterial sets the object's material.
func (*CubeT) SetTransform ¶
SetTransform sets the object's transform 4x4 matrix.
type CylinderT ¶
CylinderT represents a Cylinder.
func Cylinder ¶
func Cylinder() *CylinderT
Cylinder creates a cylinder at the origin with its axis on the Y axis. It implements the Object interface.
func (*CylinderT) Bounds ¶
Bounds returns the minimum bounding box of the object in object (untransformed) space.
func (*CylinderT) Includes ¶
Includes returns whether this object includes (or actually is) the other object.
func (*CylinderT) LocalIntersect ¶
func (c *CylinderT) LocalIntersect(ray RayT) []IntersectionT
LocalIntersect returns a slice of IntersectionT values where the transformed (object space) ray intersects the object.
func (*CylinderT) LocalNormalAt ¶
func (c *CylinderT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
LocalNormalAt returns the normal vector at the given point of intersection (transformed to object space) with the object.
func (*CylinderT) SetMaterial ¶
SetMaterial sets the object's material.
func (*CylinderT) SetTransform ¶
SetTransform sets the object's transform 4x4 matrix.
type GradientPatternT ¶
type GradientPatternT struct { BasePattern // contains filtered or unexported fields }
GradientPatternT is a pattern that draws gradients. It implements the Pattern interface.
func GradientPattern ¶
func GradientPattern(a, b Tuple) *GradientPatternT
GradientPattern returns a GradientPatternT.
func (*GradientPatternT) LocalPatternAt ¶
func (s *GradientPatternT) LocalPatternAt(localPoint Tuple) Tuple
LocalPatternAt returns a color at a local point.
type GroupT ¶
GroupT represents a group of objects with its own transformation matrix. It implements the Object interface.
func (*GroupT) Bounds ¶
Bounds returns the minimum bounding box of the object in object (untransformed) space.
func (*GroupT) Includes ¶
Includes returns whether this object includes (or actually is) the other object.
func (*GroupT) LocalIntersect ¶
func (g *GroupT) LocalIntersect(ray RayT) []IntersectionT
LocalIntersect returns a slice of IntersectionT values where the transformed (object space) ray intersects the object.
func (*GroupT) LocalNormalAt ¶
func (g *GroupT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
LocalNormalAt returns the normal vector at the given point of intersection (transformed to object space) with the object.
func (*GroupT) SetMaterial ¶
SetMaterial sets the object's material.
func (*GroupT) SetTransform ¶
SetTransform sets the object's transform 4x4 matrix.
type IntersectionT ¶
IntersectionT represents an intersection with an object.
func Hit ¶
func Hit(xs []IntersectionT) *IntersectionT
Hit returns the first non-negative intersection. It assumes that the intersections have already been sorted by Intersections above.
func Intersect ¶
func Intersect(object Object, ray RayT) []IntersectionT
Intersect returns a slice of IntersectionT values where the ray intersects the object.
func Intersection ¶
func Intersection(t float64, object Object) IntersectionT
Intersection returns an IntersectionT.
func IntersectionWithUV ¶
func IntersectionWithUV(t float64, object Object, u, v float64) IntersectionT
IntersectionWithUV returns an IntersectionT with U and V values for triangles.
func Intersections ¶
func Intersections(args ...IntersectionT) []IntersectionT
Intersections returns a slice of IntersectionT after sorting by intersection T values.
func (*IntersectionT) NormalAt ¶
func (hit *IntersectionT) NormalAt(worldPoint Tuple) Tuple
NormalAt returns the normal vector at the given point of intersection with the object.
func (*IntersectionT) PrepareComputations ¶
func (i *IntersectionT) PrepareComputations(ray RayT, xs []IntersectionT) *Comps
PrepareComputations returns a new data structure encapsulating information about the intersection.
type M2 ¶
type M2 [2]Tuple
M2 is a 2x2 matrix.
func (M2) Determinant ¶
Determinant finds the determinant of a 2x2 matrix.
type M3 ¶
type M3 [3]Tuple
M3 is a 3x3 matrix.
func (M3) Determinant ¶
Determinant returns the determinant of the 3x3 matrix.
type M4 ¶
type M4 [4]Tuple
M4 is a 4x4 matrix.
func RotationX ¶
RotationX returns a 4x4 rotation matrix clockwise about the X axis using the left-hand rule.
func RotationY ¶
RotationY returns a 4x4 rotation matrix clockwise about the Y axis using the left-hand rule.
func RotationZ ¶
RotationZ returns a 4x4 rotation matrix clockwise about the Z axis using the left-hand rule.
func Translation ¶
Translation returns a 4x4 translation matrix.
func ViewTransform ¶
ViewTransform creates a camera transformation matrix. from and to are Points, and up is a Vector.
func (M4) Determinant ¶
Determinant returns the determinant of the 4x4 matrix.
func (M4) Invertible ¶
Invertible returns the invertibility of the 4x4 matrix.
func (M4) RotateX ¶
RotateX rotates a 4x4 matrix clockwise about the X axis using the left-hand rule and returns a new 4x4 matrix.
func (M4) RotateY ¶
RotateX rotates a 4x4 matrix clockwise about the Y axis using the left-hand rule and returns a new 4x4 matrix.
func (M4) RotateZ ¶
RotateX rotates a 4x4 matrix clockwise about the Z axis using the left-hand rule and returns a new 4x4 matrix.
func (M4) Submatrix ¶
Submatrix returns a 3x3 submatrix with a row and column removed from a 4x4 matrix.
type MaterialT ¶
type MaterialT struct { Color Tuple Ambient float64 Diffuse float64 Specular float64 Shininess float64 Reflective float64 Transparency float64 RefractiveIndex float64 Pattern Pattern }
MaterialT represents a material.
type Object ¶
type Object interface { // LocalIntersect returns a slice of IntersectionT values where the // transformed (object space) ray intersects the object. LocalIntersect(ray RayT) []IntersectionT // Parent returns the object's parent object. Parent() Object // SetParent sets the object's parent object. SetParent(parent Object) Object // Transform returns the object's transform 4x4 matrix. Transform() M4 // SetTransform sets the object's transform 4x4 matrix. SetTransform(m M4) Object // Material returns the object's material. Material() *MaterialT // SetMaterial sets the object's material. SetMaterial(material MaterialT) Object // LocalNormalAt returns the normal vector at the given point of intersection // (transformed to object space) with the object. LocalNormalAt(localPoint Tuple, hit *IntersectionT) Tuple // Bounds returns the minimum bounding box of the object in object // (untransformed) space. Bounds() *BoundsT // Includes returns whether this object includes (or actually is) the // other object. Includes(other Object) bool }
Object is an interface that represents an object in the scene.
type Pattern ¶
type Pattern interface { // LocalPatternAt returns a color at a local point. LocalPatternAt(localPoint Tuple) Tuple // Transform returns the object's transform 4x4 matrix. Transform() M4 // SetTransform sets the object's transform 4x4 matrix. SetTransform(m M4) }
Pattern represents a color pattern.
type PlaneT ¶
type PlaneT struct {
Shape
}
PlaneT represents a Plane.
func Plane ¶
func Plane() *PlaneT
Plane creates a plane at the origin on the X-Z axes and +Y is up. It implements the Object interface.
func (*PlaneT) Bounds ¶
Bounds returns the minimum bounding box of the object in object (untransformed) space.
func (*PlaneT) Includes ¶
Includes returns whether this object includes (or actually is) the other object.
func (*PlaneT) LocalIntersect ¶
func (p *PlaneT) LocalIntersect(ray RayT) []IntersectionT
LocalIntersect returns a slice of IntersectionT values where the transformed (object space) ray intersects the object.
func (*PlaneT) LocalNormalAt ¶
func (p *PlaneT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
LocalNormalAt returns the normal vector at the given point of intersection (transformed to object space) with the object.
func (*PlaneT) SetMaterial ¶
SetMaterial sets the object's material.
func (*PlaneT) SetTransform ¶
SetTransform sets the object's transform 4x4 matrix.
type PointLightT ¶
type PointLightT struct {
// contains filtered or unexported fields
}
PointLightT represents a point light.
func PointLight ¶
func PointLight(position Tuple, intensity Tuple) *PointLightT
PointLight returns a point light at the given position (a point Tuple) with the provided intensity (a color Tuple).
type RayT ¶
RayT represents an origin and a direction in 3D space.
type RingPatternT ¶
type RingPatternT struct { BasePattern // contains filtered or unexported fields }
RingPatternT is a pattern that draws rings. It implements the Pattern interface.
func (*RingPatternT) LocalPatternAt ¶
func (s *RingPatternT) LocalPatternAt(localPoint Tuple) Tuple
LocalPatternAt returns a color at a local point.
type Shape ¶
type Shape struct {
// contains filtered or unexported fields
}
Shape represents the common functionality for all shapes.
type SmoothTriangleT ¶
SmoothTriangleT represents a smooth triangle object.
func SmoothTriangle ¶
func SmoothTriangle(p1, p2, p3, n1, n2, n3 Tuple) *SmoothTriangleT
SmoothTriangle returns a new smooth SmoothTriangleT.
func (*SmoothTriangleT) Bounds ¶
func (s *SmoothTriangleT) Bounds() *BoundsT
Bounds returns the minimum bounding box of the object in object (untransformed) space.
func (*SmoothTriangleT) Includes ¶
func (s *SmoothTriangleT) Includes(other Object) bool
Includes returns whether this object includes (or actually is) the other object.
func (*SmoothTriangleT) LocalIntersect ¶
func (s *SmoothTriangleT) LocalIntersect(ray RayT) []IntersectionT
LocalIntersect returns a slice of IntersectionT values where the transformed (object space) ray intersects the object.
func (*SmoothTriangleT) LocalNormalAt ¶
func (s *SmoothTriangleT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
LocalNormalAt returns the normal vector at the given point of intersection (transformed to object space) with the object.
func (*SmoothTriangleT) SetMaterial ¶
func (s *SmoothTriangleT) SetMaterial(material MaterialT) Object
SetMaterial sets the object's material.
func (*SmoothTriangleT) SetParent ¶
func (s *SmoothTriangleT) SetParent(parent Object) Object
SetParent sets the object's parent object.
func (*SmoothTriangleT) SetTransform ¶
func (s *SmoothTriangleT) SetTransform(m M4) Object
SetTransform sets the object's transform 4x4 matrix.
type SphereT ¶
type SphereT struct {
Shape
}
SphereT represents a sphere.
func GlassSphere ¶
func GlassSphere() *SphereT
GlassSphere creates a unit glass sphere at the origin. It implements the Object interface.
func Sphere ¶
func Sphere() *SphereT
Sphere creates a unit sphere at the origin. It implements the Object interface.
func (*SphereT) Bounds ¶
Bounds returns the minimum bounding box of the object in object (untransformed) space.
func (*SphereT) Includes ¶
Includes returns whether this object includes (or actually is) the other object.
func (*SphereT) LocalIntersect ¶
func (s *SphereT) LocalIntersect(ray RayT) []IntersectionT
LocalIntersect returns a slice of IntersectionT values where the transformed (object space) ray intersects the object.
func (*SphereT) LocalNormalAt ¶
func (s *SphereT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
LocalNormalAt returns the normal vector at the given point of intersection (transformed to object space) with the object.
func (*SphereT) SetMaterial ¶
SetMaterial sets the object's material.
func (*SphereT) SetTransform ¶
SetTransform sets the object's transform 4x4 matrix.
type StripePatternT ¶
type StripePatternT struct { BasePattern // contains filtered or unexported fields }
StripePatternT is a pattern that draws stripes. It implements the Pattern interface.
func StripePattern ¶
func StripePattern(a, b Tuple) *StripePatternT
StripePattern returns a StripePatternT.
func (*StripePatternT) LocalPatternAt ¶
func (s *StripePatternT) LocalPatternAt(localPoint Tuple) Tuple
LocalPatternAt returns a color at a local point.
type TriangleT ¶
type TriangleT struct { Shape P1 Tuple P2 Tuple P3 Tuple N1 Tuple N2 Tuple N3 Tuple E1 Tuple E2 Tuple Normal Tuple // contains filtered or unexported fields }
TriangleT represents a triangle object.
func (*TriangleT) Bounds ¶
Bounds returns the minimum bounding box of the object in object (untransformed) space.
func (*TriangleT) Includes ¶
Includes returns whether this object includes (or actually is) the other object.
func (*TriangleT) LocalIntersect ¶
func (t *TriangleT) LocalIntersect(ray RayT) []IntersectionT
LocalIntersect returns a slice of IntersectionT values where the transformed (object space) ray intersects the object.
func (*TriangleT) LocalNormalAt ¶
func (t *TriangleT) LocalNormalAt(objectPoint Tuple, hit *IntersectionT) Tuple
LocalNormalAt returns the normal vector at the given point of intersection (transformed to object space) with the object.
func (*TriangleT) SetMaterial ¶
SetMaterial sets the object's material.
func (*TriangleT) SetTransform ¶
SetTransform sets the object's transform 4x4 matrix.
type Tuple ¶
type Tuple [4]float64
Tuple is a 4-float vector.
func Lighting ¶
func Lighting(material *MaterialT, object Object, light *PointLightT, point Tuple, eyeVector Tuple, normalVector Tuple, inShadow bool) Tuple
Lighting calculates the lighting on an object and returns the color as a Tuple.
func NormalToWorld ¶
NormalToWorld converts an object-space normal to world space, taking into account all the parents of the object.
func WorldToObject ¶
WorldToObject converts a world-space point to object space, taking into account all the parents of the object.
func (Tuple) Cross ¶
Cross computes the cross product of two vectors (order matters and this implements t cross other).
func (Tuple) Dot ¶
Dot computes the dot product (aka "scalar product" or "inner product") of two vectors (Tuples). The dot product is the cosine of the angle between two unit vectors.
func (Tuple) HadamardProduct ¶
HadamardProduct computes the product of two colors.
func (Tuple) MultScalar ¶
MultScalar multiplies a tuple by a scalar.
type WorldT ¶
type WorldT struct { Objects []Object Lights []*PointLightT // TODO: Replace with light interfaces. }
WorldT represents the world to be rendered.
func (*WorldT) IntersectWorld ¶
func (w *WorldT) IntersectWorld(ray RayT) []IntersectionT
IntersectWorld intersects a world with a ray.
func (*WorldT) IsShadowed ¶
func (w *WorldT) IsShadowed(point Tuple, light *PointLightT) bool
IsShadowed determines if the provided point is in a shadow for the given light.
func (*WorldT) ReflectedColor ¶
ReflectedColor returns the reflected color for the precomputed intersection.
func (*WorldT) RefractedColor ¶
RefractedColor returns the refracted color for the precomputed intersection.