/
simplegopher.go
49 lines (42 loc) · 1.38 KB
/
simplegopher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package scene
import (
"github.com/eriklupander/rt/internal/pkg/config"
"github.com/eriklupander/rt/internal/pkg/mat"
"github.com/eriklupander/rt/internal/pkg/obj"
"io/ioutil"
"math"
)
func SimpleGopher() *Scene {
camera := mat.NewCamera(config.Cfg.Width, config.Cfg.Height, math.Pi/3.5)
camera.Transform = mat.ViewTransform(mat.NewPoint(-.1, 1.2, 6), mat.NewPoint(0.05, 1.1, 0.05), mat.NewVector(0, 1, 0))
camera.Inverse = mat.Inverse(camera.Transform)
// Model
bytes, _ := ioutil.ReadFile("assets/models/gopher.obj")
model := obj.ParseObj(string(bytes)).ToGroup()
model.SetTransform(mat.Translate(0, 1.2, 0))
model.SetTransform(mat.RotateX(math.Pi / 2))
model.SetTransform(mat.RotateY(-math.Pi / 2))
model.SetTransform(mat.RotateX(-math.Pi / 8))
mat.Divide(model, 100)
model.Bounds()
w := mat.NewWorld()
w.Light = append(w.Light, mat.NewLight(mat.NewPoint(3.3, 4, 10.5), mat.NewColor(1, 1, 1)))
floor := mat.NewPlane()
pm := mat.NewMaterial(mat.NewColor(1, 1, 1), 0.025, 0.67, 0, 200)
pm.Reflectivity = 0.2
floor.SetMaterial(pm)
return &Scene{
Camera: camera,
// Lights: []mat.Light{{mat.NewPoint(-1, 1, 2.5), mat.NewColor(0.3, 0.3, 0.3)}},
AreaLights: []mat.AreaLight{mat.NewAreaLight(
mat.NewPoint(1.5, 2.5, 4.5),
mat.NewVector(-.5, 0, .5),
4,
mat.NewVector(0, 1, 0),
4,
mat.NewColor(0.9, 0.9, 0.9))},
Objects: []mat.Shape{
floor, model,
},
}
}