object

package
v0.0.0-...-534c38e Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Black = NewColor(0, 0, 0)
	White = NewColor(1, 1, 1)
	Red   = NewColor(1, 0, 0)
	Green = NewColor(0, 1, 0)
	Blue  = NewColor(0, 0, 1)
)
View Source
var NoHit = Intersection{}

Functions

func NormalAt

func NormalAt(xs Intersection, worldPoint ray.Vector) ray.Vector

Types

type BasicObject

type BasicObject struct {
	Transform ray.Matrix
	Material  Material
}

type Group

type Group struct {
	Children []Object
	// contains filtered or unexported fields
}

func NewGroup

func NewGroup(opts ...Option) Group

func (*Group) AddChild

func (g *Group) AddChild(children ...Object)

func (Group) LocalIntersect

func (g Group) LocalIntersect(r ray.Ray) (xs Intersections)

func (Group) LocalNormalAt

func (g Group) LocalNormalAt(worldPoint ray.Vector, _ Intersection) ray.Vector

func (Group) Material

func (o Group) Material() Material

func (Group) NormalToWorld

func (o Group) NormalToWorld(normaVector ray.Vector) (resultVector ray.Vector)

func (Group) Object

func (g Group) Object() Object

func (Group) Parent

func (o Group) Parent() Object

func (*Group) SetMaterial

func (o *Group) SetMaterial(m Material)

func (*Group) SetParent

func (o *Group) SetParent(obj Object)

func (*Group) SetTransform

func (o *Group) SetTransform(t ray.Matrix) error

func (Group) Transform

func (o Group) Transform() ray.Matrix

func (Group) TransformInverse

func (o Group) TransformInverse() ray.Matrix

func (Group) WorldToObject

func (o Group) WorldToObject(worldPoint ray.Vector) (point ray.Vector)

type Intersection

type Intersection struct {
	T    float64 // Intersection value
	Obj  Object  // Intersected object
	U, V float64 // UV value between 0 - 1
}

func Hit

func Hit(intersections Intersections) Intersection

type Intersections

type Intersections []Intersection

func Intersect

func Intersect(obj Object, rr ray.Ray) Intersections

type Material

type Material struct {
	Color                                                                            RGB
	Pattern                                                                          Pattern
	Ambient, Diffuse, Specular, Shininess, Reflective, Transparency, RefractiveIndex float64
}

func DefaultMaterial

func DefaultMaterial() Material

func NewMaterial

func NewMaterial(color RGB,
	ambient, diffuse, specular, shininess, reflective, transparency, refractiveIndex float64) Material

type Object

type Object interface {
	LocalIntersect(ray ray.Ray) Intersections
	LocalNormalAt(worldPoint ray.Vector, hit Intersection) ray.Vector

	Transform() ray.Matrix
	TransformInverse() ray.Matrix
	SetTransform(t ray.Matrix) error

	Material() (m Material)
	SetMaterial(m Material)

	Parent() Object
	SetParent(obj Object)

	WorldToObject(worldPoint ray.Vector) (point ray.Vector)
	NormalToWorld(normalVector ray.Vector) (vector ray.Vector)
}

func DefaultCone

func DefaultCone() Object

func DefaultCylinder

func DefaultCylinder() Object

func DefaultGlassSphere

func DefaultGlassSphere() Object

func DefaultMetalSphere

func DefaultMetalSphere() Object

func DefaultSphere

func DefaultSphere(opts ...Option) Object

func NewCone

func NewCone(minimum, maximum float64, closed bool) Object

func NewCube

func NewCube() Object

func NewCylinder

func NewCylinder(minimum, maximum float64, closed bool) Object

func NewGlassSphere

func NewGlassSphere(center ray.Vector, radius float64, opts ...Option) (s Object)

func NewHexagon

func NewHexagon(opts ...Option) (hex Object)

func NewMetalSphere

func NewMetalSphere(center ray.Vector, radius float64, opts ...Option) (s Object)

func NewPlane

func NewPlane(opts ...Option) Object

func NewSmoothTriangle

func NewSmoothTriangle(p1, p2, p3, n1, n2, n3 ray.Vector, opts ...Option) Object

func NewSphere

func NewSphere(center ray.Vector, radius float64, opts ...Option) Object

func NewTestShape

func NewTestShape(opts ...Option) Object

func NewTriangle

func NewTriangle(p1, p2, p3 ray.Vector, opts ...Option) Object

type Option

type Option interface {
	Apply(object Object)
}

func WithChildren

func WithChildren(objs ...Object) Option

func WithMaterial

func WithMaterial(m Material) Option

func WithNormals

func WithNormals(n1, n2, n3 ray.Vector) Option

func WithTransform

func WithTransform(t ray.Matrix) Option

type OptionFunc

type OptionFunc func(object Object)

func (OptionFunc) Apply

func (of OptionFunc) Apply(o Object)

type Pattern

type Pattern struct {
	Transform        ray.Matrix
	TransformInverse ray.Matrix
	At               func(point ray.Vector) RGB
	IsNotEmpty       bool
}

func EmptyPattern

func EmptyPattern() Pattern

func NewCheckerPattern

func NewCheckerPattern(a, b RGB) (p Pattern)

func NewGradientPattern

func NewGradientPattern(a, b RGB) (p Pattern)

func NewRingPattern

func NewRingPattern(a, b RGB) (p Pattern)

func NewStripePattern

func NewStripePattern(a, b RGB) (p Pattern)

func NewTestPattern

func NewTestPattern() (p Pattern)

func (Pattern) AtObj

func (p Pattern) AtObj(obj Object, worldPoint ray.Vector) RGB

func (*Pattern) SetTransform

func (p *Pattern) SetTransform(transform ray.Matrix) error

type PointLight

type PointLight struct {
	Position  ray.Vector
	Intensity RGB
}

func NewPointLight

func NewPointLight(position ray.Vector, intensity RGB) PointLight

type RGB

type RGB struct {
	R, G, B float64
}

func Lighting

func Lighting(
	material Material,
	obj Object,
	light PointLight,
	position, eyev, normalv ray.Vector,
	inShadows bool) RGB

func NewColor

func NewColor(red, green, blue float64) RGB

func (RGB) Add

func (r RGB) Add(c RGB) RGB

func (RGB) Multiply

func (r RGB) Multiply(c RGB) RGB

Technically Hadamard product or Schur product

func (RGB) MultiplyBy

func (r RGB) MultiplyBy(scalar float64) RGB

func (RGB) Plus

func (r RGB) Plus(c RGB) RGB

func (RGB) Subtract

func (r RGB) Subtract(c RGB) RGB

type StripePattern

type StripePattern struct {
	Pattern
	A, B RGB
}

type WavefrontObj

type WavefrontObj struct {
	Vertices,
	Normals []ray.Vector
	Group Group
}

func NewWavefrontObj

func NewWavefrontObj(reader io.Reader, opts ...Option) (wv WavefrontObj, err error)

func (*WavefrontObj) Object

func (w *WavefrontObj) Object() Object

Jump to

Keyboard shortcuts

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