Exemple #1
0
func NewScene(canvas *Canvas) *Scene {
	s := Scene{Canvas: canvas,
		Res:       canvas.Size,
		Objs:      make([]*Obj, 0, 2),
		CameraPos: vec.D(0.0, 0.0, 0.0),
		ViewDir:   vec.D(0.0, 0.0, 1.0),
		RightDir:  vec.D(1.0, 0.0, 0.0),
		UpDir:     vec.D(0.0, 1.0, 0.0),
		Fov:       90,
		Bg:        vec.C(0.0, 0.0, 0.5)}

	height := 2.0 * math.Tan(s.Fov/2.0)
	s.ViewPlane = vec.D2( // viewplane at distance 1.0
		(height*float64(s.Res.X))/float64(s.Res.Y),
		height)

	return &s
}
Exemple #2
0
func (p *parser) addV(args []string) {
	if len(args) != 3 {
		fmt.Print("invalid vertex", args)
		return
	}
	x, _ := strconv.ParseFloat(args[0], 64)
	y, _ := strconv.ParseFloat(args[1], 64)
	z, _ := strconv.ParseFloat(args[2], 64)
	//TODO check errors
	v := vec.D(x, y, z)
	p.numVerts++
	p.verts[p.numVerts] = v

	if debug {
		fmt.Println("vertex", p.numVerts, v)
	}
}