raytrace

package
v0.0.0-...-e866bec Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CastRay

func CastRay(x, y int, invWidth, invHeight, aspectRatio, angle float64, config *Config) (color.Color, error)

func RenderImage

func RenderImage(config *Config, fieldOfView float64) (image.Image, error)

Types

type Camera

type Camera struct {
	Position Vector3 `json:"position"`
}

type Config

type Config struct {
	Image Image `json:"image"`
	Scene Scene `json:"scene"`
}

type Image

type Image struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

type Scene

type Scene struct {
	Camera  Camera   `json:"camera"`
	Spheres []Sphere `json:"spheres"`
}

type Sphere

type Sphere struct {
	Center       Vector3 `json:"center"`
	Radius       float64 `json:"radius"`
	SurfaceColor Vector3 `json:"surfaceColor"`
	EmitColor    Vector3 `json:"emitColor"`
	Transparency float64 `json:"transparency"`
	Reflection   float64 `json:"reflection"`
}

func (*Sphere) Intersect

func (s *Sphere) Intersect(rayOrigin Vector3, rayDirection Vector3) (bool, float64, float64)

func (*Sphere) RadiusSquared

func (s *Sphere) RadiusSquared() float64

type Vector3

type Vector3 struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
	Z float64 `json:"z"`
}

func Trace

func Trace(rayOrigin Vector3, rayDirection Vector3, spheres []Sphere, depth int) (Vector3, error)

func (Vector3) Add

func (v Vector3) Add(v2 Vector3) Vector3

func (Vector3) DotProduct

func (v Vector3) DotProduct(v2 Vector3) float64

func (Vector3) Length

func (v Vector3) Length() float64

func (Vector3) LengthSquared

func (v Vector3) LengthSquared() float64

func (Vector3) Multiply

func (v Vector3) Multiply(v2 Vector3) Vector3

func (Vector3) Negate

func (v Vector3) Negate(v2 Vector3) Vector3

func (Vector3) Normalize

func (v Vector3) Normalize() Vector3

func (Vector3) ScalarMultiply

func (v Vector3) ScalarMultiply(f float64) Vector3

func (Vector3) String

func (v Vector3) String() (string, error)

func (Vector3) Subtract

func (v Vector3) Subtract(v2 Vector3) Vector3

Jump to

Keyboard shortcuts

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