// main initializes windowing, creates a new, continuously draws some pixels, // waits for close event, destroys the window and terminates windowing. func main() { width := 1024 height := 768 w, err := window.NewWindow(width, height, "Three Animate", true) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(-1) } defer window.Terminate() x := width / 2 y := height / 2 r := rand.New(rand.NewSource(0)) for close := false; !close; close = w.ShouldClose() { w.Setxy(x, y, 0, 0, 0) width = w.Width() height = w.Height() x = x + r.Intn(3) - 1 x = tmath.Mini(width, tmath.Maxi(0, x)) y = y + r.Intn(3) - 1 y = tmath.Mini(height, tmath.Maxi(0, y)) w.Setxy(x, y, 255, 0, 0) w.Update() } w.Destroy() }
// run initializes windowing, creates a new, waits for close event, destroys // the window and terminates windowing. func run(testing bool) { w, err := window.NewWindow(1024, 768, "Three Example", !testing) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(-1) } defer window.Terminate() for close := false; !close; close = w.ShouldClose() { w.Update() if testing { w.SetClose() } } w.Destroy() }
// main creates a new scene with a camera and a triangle, renders the scene, // draws the result to a window and displays it. The middle point of the // triangle continuously changes position relative to the current time. func main() { win, err := window.NewWindow(1024, 768, "Three Render 2", true) if err != nil { panic(err) } defer window.Terminate() cam := render.NewDefCam() p := geom.NewTri4(-1, 0, -3, 0, 1, -3, 1, 0, -3) for close := false; !close; close = win.ShouldClose() { now := time.Now() m := &p[1][1] *m = math.Sin(float64(now.UnixNano()) / 1e9) c := &cam.At[0] *c = math.Cos(float64(now.UnixNano()) / 1e9) cam.Ar = float64(win.Width()) / float64(win.Height()) t := cam.PerspTransf(win.Width(), win.Height()) q := p.Transf(t) win.Clear() q.Draw(win) win.Update() } }
// main creates a new scene with a camera and a triangle, renders the scene, // draws the result to a window and displays it. The middle point of the // triangle continuously changes position relative to the current time. func main() { win, err := window.NewWindow(1024, 768, "Three Move", true) if err != nil { panic(err) } defer window.Terminate() cam := render.NewDefCam() p := geom.NewTri4(-1, 0, -3, 0, 1, -3, 1, 0, -3) then := time.Now() now := time.Now() for close := false; !close; close = win.ShouldClose() || win.KeyDown(window.KeyQ) { then = now now = time.Now() dt := now.Sub(then) d := mgeom.Vec3{0, 0, 0} if win.KeyDown(window.KeyW) { d.Add(&cam.At) } if win.KeyDown(window.KeyS) { d.Sub(&cam.At) } if win.KeyDown(window.KeyA) { d.Add(mgeom.Cross(&cam.At, &cam.Up)) } if win.KeyDown(window.KeyD) { d.Add(mgeom.Cross(&cam.Up, &cam.At)) } d.Norm() d.Scale(dt.Seconds()) cam.Eye.Add(&d) cam.Ar = float64(win.Width()) / float64(win.Height()) t := cam.PerspTransf(win.Width(), win.Height()) q := p.Transf(t) win.Clear() q.Draw(win) win.Update() } }