Exemplo n.º 1
0
func main() {
	scene := pt.Scene{}
	scene.SetColor(pt.Color{1, 1, 1})
	meshes := []*pt.Mesh{
		CreateBrick(1),  // white
		CreateBrick(21), // bright red
		CreateBrick(23), // bright blue
		CreateBrick(24), // bright yellow
		CreateBrick(26), // black
		CreateBrick(28), // dark green
	}
	for x := -30; x <= 50; x += 2 {
		for y := -50; y <= 20; y += 4 {
			h := rand.Intn(5) + 1
			for i := 0; i < h; i++ {
				dy := 0
				if (x/2+i)%2 == 0 {
					dy = 2
				}
				z := float64(i) * H
				mesh := meshes[rand.Intn(len(meshes))]
				m := pt.Translate(pt.Vector{float64(x), float64(y + dy), z})
				scene.Add(pt.NewTransformedShape(mesh, m))
			}
		}
	}
	// light := pt.LightMaterial(pt.Color{0.2, 0.2, 0.2}, 10, pt.QuadraticAttenuation(0.01))
	// scene.Add(pt.NewSphere(pt.Vector{0, 0, 25}, 1, light))
	camera := pt.LookAt(pt.Vector{-23, 13, 20}, pt.Vector{0, 0, 0}, pt.Vector{0, 0, 1}, 45)
	pt.RenderToWindow(pt.Render(&scene, &camera))
}
Exemplo n.º 2
0
func main() {
	scene := pt.Scene{}
	scene.SetColor(pt.HexColor(0xFEE7E0))
	// material := pt.GlossyMaterial(pt.HexColor(0x5C832F), 1.5, pt.Radians(20))
	material := pt.TransparentMaterial(pt.HexColor(0xFFFFFF), 2, pt.Radians(20), 0)
	mesh, err := pt.LoadOBJ("examples/dragon.obj", material)
	if err != nil {
		panic(err)
	}
	mesh.FitInside(pt.Box{pt.Vector{-1, 0, -1}, pt.Vector{1, 2, 1}}, pt.Vector{0.5, 0, 0.5})
	scene.Add(mesh)
	floor := pt.GlossyMaterial(pt.HexColor(0xD8CAA8), 1.2, pt.Radians(20))
	scene.Add(pt.NewCube(pt.Vector{-1000, -1000, -1000}, pt.Vector{1000, 0, 1000}, floor))
	scene.Add(pt.NewSphere(pt.Vector{0, 10, 0}, 1, pt.LightMaterial(pt.Color{1, 1, 1}, 1, pt.NoAttenuation)))
	camera := pt.LookAt(pt.Vector{-3, 2, -1}, pt.Vector{0, 0.5, 0}, pt.Vector{0, 1, 0}, 35)
	pt.RenderToWindow(pt.Render(&scene, &camera))
}