Documentation ¶
Index ¶
- Variables
- func Determinant(v1, v2, v3 *Vector) float64
- func ParseFloat(str string) (float64, error)
- func Render(sceneFile string)
- func SubRender(xStart int, yStart int, xEnd int, yEnd int, scene *Scene, camera *Camera, ...)
- type Camera
- type Color
- type Hit
- type Material
- type Mesh
- type PointLight
- type Ray
- type Scene
- type Shape
- type Sphere
- type Triangle
- type Vector
- func (v Vector) Add(o Vector) Vector
- func (v Vector) AddScalar(s float64) Vector
- func (v Vector) Cross(o Vector) Vector
- func (v Vector) DivScalar(d float64) Vector
- func (v Vector) Dot(o Vector) float64
- func (v Vector) Length() float64
- func (v Vector) Mul(m float64) Vector
- func (v Vector) Negate() Vector
- func (v Vector) Normalize() Vector
- func (v Vector) Sub(o Vector) Vector
- func (v Vector) SubScalar(s float64) Vector
Constants ¶
This section is empty.
Variables ¶
var EPS float64 = 1e-3
EPS represents a generic epsilon value
var HitEpsilon float64 = 1e-3
HitEpsilon is used to check ray intersections
var INF float64 = math.Inf(1)
INF represents infinity
var ShadowEpsilon float64 = 1e-3
ShadowEpsilon is used to shift intersection points to prevent surface acne
Functions ¶
func Determinant ¶
Determinant is used to take 3x3 matrix determinant
func ParseFloat ¶
ParseFloat parses floats from a given string by extending the functionality of strconv.ParseFloat to include scientific notation
Types ¶
type Camera ¶
type Camera struct { Position Vector U Vector V Vector W Vector NearPlane struct { Left float64 Right float64 Bottom float64 Top float64 } Distance float64 Resolution struct { Width int Height int } ImageName string // contains filtered or unexported fields }
Camera is the point where we look into the scene it holds a position, and the u, v, w vectors.
type Color ¶
type Color struct {
R, G, B float64
}
Color holds three float64s representing RGB values of a pixel
type Material ¶
type Material struct { AmbientReflectance Color DiffuseReflectance Color SpecularReflectance Color PhongExponent float64 }
Material contains different values used in shading
type Mesh ¶
Mesh defies a set of Triangles and a material for them
type PointLight ¶
PointLight represents a point light with a defined position and intensity
type Scene ¶
type Scene struct { BackgroundColor Color Cameras []Camera AmbientLight Color PointLights []PointLight Materials []Material VertexData []Vector Shapes []Shape }
Scene describes a scene with cameras, lights, shapes and their materials
func ParseScene ¶
ParseScene parses the given xml scene and fill in a Scene struct TODO: Fix this crappy code
type Shape ¶
type Shape interface { // Incersects a ray with a shape and returns the Hit data. Intersect(r Ray) *Hit // Material returns the material of a shape. Material() *Material }
Shape is an object a ray can intersect with
type Sphere ¶
Sphere represents a sphere in 3D, it has an origin and a radius
func (*Sphere) Intersect ¶
Intersect calculates the intersection point of a ray with the sphere It returns the distance of the intersection from the ray's origin if ray intersects the sphere, INF if it doesn't.
type Triangle ¶
Triangle consists of three points and a material
type Vector ¶
type Vector struct {
X, Y, Z float64
}
Vector is a 3D vector containing 3 float64s for each dimension