func multiplexEvents(engine g3.Engine) { for { select { case me := <-engine.MouseEventChan(): alpha += float32(-me.Dx) / 100 beta += float32(-me.Dy) / 100 beta = g3.Clamp(beta, -g3.Pi/2, g3.Pi/2) ud := g3.MakeXRotationMatrix(beta) lr := g3.MakeZRotationMatrix(alpha) m := lr.Multiply(&ud) dir = m.Transform(dirBase) up = m.Transform(upBase) left = m.Transform(leftBase) case ke := <-engine.KeyEventChan(): //fmt.Println(ke) if ke.Type == g3.KeyPressed { switch ke.Key { case g3.KeyW: speed += 0.0001 case g3.KeyS: speed -= 0.0001 case g3.KeyA: pos.Accumulate(left.Scaled(0.01)) case g3.KeyD: pos.Accumulate(left.Scaled(-0.01)) case g3.KeyF1: if wireframe { engine.GetGraphicsDevice().SetFillMode(g3.FillSolid) } else { engine.GetGraphicsDevice().SetFillMode(g3.FillWireFrame) } wireframe = !wireframe case g3.KeyPageUp: pos.Z += 0.01 case g3.KeyPageDown: pos.Z -= 0.01 } } case fe := <-engine.FrameEventChan(): update(engine, fe.DeltaTime) render(engine) engine.SwapBuffers() case se := <-engine.SystemEventChan(): //fmt.Println(se) if se.Type == g3.SystemQuit { return } } } }
func calculateLOD(frustum *g3.Frustum, center *g3.Vec3, width float32, maxLOD uint) int { // TODO: Use actual position instead of near clipping plane for distance calculation? d := int(g3.Clamp(frustum.Near.DistanceToPoint(center)/(width), 0.0, float32(maxLOD-1))) return d }