Documentation ¶
Index ¶
- Constants
- Variables
- type BoundingBox
- type Camera
- func (c *Camera) BuildRay(x, y int) Ray
- func (c *Camera) Project(p Point3) (int, int)
- func (c *Camera) RotateX(x float64) *Camera
- func (c *Camera) RotateY(y float64) *Camera
- func (c *Camera) RotateZ(z float64) *Camera
- func (c *Camera) Scale(x, y, z float64) *Camera
- func (c *Camera) Translate(x, y, z float64) *Camera
- type Cube
- func (c *Cube) Intersect(r Ray) *Hit
- func (c *Cube) MinMax() (Point3, Point3)
- func (c *Cube) Name() string
- func (c *Cube) RotateX(x float64) *Cube
- func (c *Cube) RotateY(y float64) *Cube
- func (c *Cube) RotateZ(z float64) *Cube
- func (c *Cube) Scale(x, y, z float64) *Cube
- func (c *Cube) SetName(name string)
- func (c *Cube) Surf() *Surface
- func (c *Cube) Translate(x, y, z float64) *Cube
- type FloatColor
- type Hit
- type Light
- type Matrix4
- type Object
- type Plane
- func (p *Plane) Intersect(r Ray) *Hit
- func (*Plane) MinMax() (Point3, Point3)
- func (p *Plane) Name() string
- func (p *Plane) RotateX(x float64) *Plane
- func (p *Plane) RotateY(y float64) *Plane
- func (p *Plane) RotateZ(z float64) *Plane
- func (p *Plane) Scale(x, y, z float64) *Plane
- func (p *Plane) SetName(name string)
- func (p *Plane) Surf() *Surface
- func (p *Plane) Translate(x, y, z float64) *Plane
- type Point3
- type PointLight
- type Preview
- type Ray
- type Scene
- type Sphere
- func (s *Sphere) Intersect(r Ray) *Hit
- func (s *Sphere) MinMax() (Point3, Point3)
- func (s *Sphere) Name() string
- func (s *Sphere) RotateX(x float64) *Sphere
- func (s *Sphere) RotateY(y float64) *Sphere
- func (s *Sphere) RotateZ(z float64) *Sphere
- func (s *Sphere) Scale(x, y, z float64) *Sphere
- func (s *Sphere) SetName(name string)
- func (s *Sphere) Surf() *Surface
- func (s *Sphere) Translate(x, y, z float64) *Sphere
- type Surface
- type Transform
- func (t *Transform) Check() Matrix4
- func (t *Transform) PointToGlobal(p Point3) Point3
- func (t *Transform) PointToLocal(p Point3) Point3
- func (t *Transform) RayToGlobal(r Ray) Ray
- func (t *Transform) RayToLocal(r Ray) Ray
- func (t *Transform) RotateX(a float64)
- func (t *Transform) RotateY(a float64)
- func (t *Transform) RotateZ(a float64)
- func (t *Transform) Scale(x, y, z float64)
- func (t *Transform) Translate(x, y, z float64)
- type Transformer
- type Vector3
Constants ¶
const ( X int = 0 Y = 1 Z = 2 )
Variables ¶
var BigEpsilon = 1e-3
var Blue = FloatColor{B: 1}
Blue ...
var Building = Surface{ Ka: 0.5, Kd: 0.9, Ks: 0.2, Color: FloatColor{R: .5, G: .5, B: .5}, Nphong: 10, }
var DefaultSurface = Surface{ Ka: 0.5, Kd: 0.5, Ks: 0.5, Color: FloatColor{R: 0.5, G: 0.5, B: 0.5}, Nphong: 30, }
var Diffuse = Surface{ Ka: 0.5, Kd: 0.8, Ks: 0.2, Color: FloatColor{R: 0.6, G: 0.4, B: 0.3}, Nphong: 30, }
var Epsilon = 1e-8
var Epsilon = math.Nextafter(1.0, 2.0) - 1.0
var Green = FloatColor{G: 1}
Green ...
var IDTransform = Transform{/* contains filtered or unexported fields */}
IDTransform ...
var MaxDepth = 7
MaxDepth is the max tracing recursion level
var Mirror = Surface{ Ka: 0, Kd: 0.1, Ks: 0.9, Color: FloatColor{R: 0, G: 0, B: 0}, Nphong: 1000, }
var Ocher2 = Surface{ Ka: 0.7, Kd: 0.5, Ks: 0.4, Color: FloatColor{R: 1, G: 1 / 1.5, B: 1 / 2}, Nphong: 50, }
var Origin = Point3{0, 0, 0}
var Red = FloatColor{R: 1}
Red ...
var White = FloatColor{R: 1, G: 1, B: 1}
White ...
var White1 = Surface{ Ka: 0.5, Kd: 0.9, Ks: 0.5, Color: FloatColor{R: 1, G: 1, B: 1}, Nphong: 100, }
Functions ¶
This section is empty.
Types ¶
type BoundingBox ¶
type BoundingBox struct { Transform // contains filtered or unexported fields }
BoundingBox ...
type Camera ¶
type Camera struct { Transform Width int Height int Image *image.RGBA // contains filtered or unexported fields }
Camera is the canonical camera object, tracing rays and writing to an image
func NewCamera ¶
NewCamera creates a camera with a focal length, camera width, camera height and image width. Located at origin and points towards negative z in an orthonormal basis
type Cube ¶
Cube is a canonical cube, centered of origin, of side 2 (-1 to +1)
type FloatColor ¶
FloatColor implements the color.Color interface by having a RGBA() method
func (*FloatColor) Add ¶
func (fc *FloatColor) Add(b FloatColor) FloatColor
Add adds each RGB component of a color with another color component
func (FloatColor) MulC ¶
func (fc FloatColor) MulC(b FloatColor) FloatColor
MulC multiplies each RGB component of a color by another color component
func (FloatColor) MulF ¶
func (fc FloatColor) MulF(b float64) FloatColor
MulF multiplies each RGB component by a scalar
type Hit ¶
type Hit struct { *Surface // material properties // contains filtered or unexported fields }
Hit contains intersection informations: surface where hit, and incident and normal ray (both global and local)
type Matrix4 ¶
type Matrix4 [4][4]float64
func RotationX ¶
RotationX returns a matrix describing a rotation in radians around X-axis in right-hand coordinates.
func RotationY ¶
RotationY returns a matrix describing a rotation in radians around Y-axis in right-hand coordinates.
func RotationZ ¶
RotationZ returns a matrix describing a rotation in radians around Z-axis in right-hand coordinates.
func Translation ¶
Translation returns a matrix describing a translation along all 3 axis in space.
type Object ¶
type Object interface { Transformer Intersect(Ray) *Hit Name() string MinMax() (Point3, Point3) // in local coords }
Object is the interface for all raytraced objects
type Plane ¶
Plane is a plane of all points with y = 0
func NewPlane ¶
func NewPlane() *Plane
NewPlane creates a xz plane of 2 units sides centered on origin
type Point3 ¶
type Point3 [3]float64
func (Point3) SquareDist ¶
SquareDist returns the squared distance between points a and b.
type PointLight ¶
type PointLight struct { Transform // contains filtered or unexported fields }
func NewPointLight ¶
func NewPointLight(c FloatColor) *PointLight
func (*PointLight) Color ¶
func (p *PointLight) Color(r Ray) FloatColor
func (*PointLight) RayToLight ¶
func (p *PointLight) RayToLight(pt Point3) Ray
func (*PointLight) SetSun ¶
func (p *PointLight) SetSun(sun bool)
func (*PointLight) Sun ¶
func (p *PointLight) Sun() bool
func (*PointLight) Translate ¶
func (p *PointLight) Translate(x, y, z float64) *PointLight
Translate applies a translation
type Preview ¶
type Preview struct {
// contains filtered or unexported fields
}
Preview ...
type Ray ¶
type Ray struct {
// contains filtered or unexported fields
}
Ray contains a point (the origin) and a vector (the direction).
type Scene ¶
type Scene struct { MaxDepth int Ambiant FloatColor Preview bool // contains filtered or unexported fields }
Scene contains the objects, lights, camera and method to render them
func (*Scene) AddObjects ¶
AddObjects adds the objects to the scene
type Sphere ¶
Sphere is a canonical sphere, centered of origin, of radius 1
func (*Sphere) Intersect ¶
Intersect finds the intersection point (if any) between a global ray and this sphere, and the normal at intersection point
type Surface ¶
type Surface struct { Ka float64 Kd float64 Ks float64 Color FloatColor Nphong float64 }
func (*Surface) ColorAt ¶
func (s *Surface) ColorAt(h *Hit) FloatColor
type Transform ¶
type Transform struct {
// contains filtered or unexported fields
}
Transform ...
func (*Transform) PointToGlobal ¶
PointToGlobal ...
type Transformer ¶
type Transformer interface { PointToLocal(Point3) Point3 PointToGlobal(Point3) Point3 RayToLocal(Ray) Ray RayToGlobal(Ray) Ray }
Transformer ...
type Vector3 ¶
type Vector3 [3]float64
func (Vector3) Cross ¶
Cross returns a new vector which is the cross product of the vector parameters. The result is a vector orthogonal to the plane formed by the 2 input vectors, and such that uvw is a direct ...
func (Vector3) Mult ¶
Mult returns a new vector where all components have been multiplied by the given factor.
func (*Vector3) Normalize ¶
func (v *Vector3) Normalize()
Normalize the vector, which is modified (has a norm of 1).