public OrbitPoint At(float t) { KeyValuePair <float, OrbitPoint> prev = points.First(); if (t <= prev.Key) { return(prev.Value); } foreach (var next in points) { if (next.Key == t) { return(next.Value); } if (next.Key > t) { float length = next.Key - prev.Key; float magnitude = (float)System.Math.Abs(length); float u = 0.5f; if (magnitude > 0.0001f) { float offset = t - prev.Key; u = offset / length; } return(OrbitPoint.Mix(prev.Value, next.Value, u)); } prev = next; } return(prev.Value); }
public static OrbitPoint Mix(OrbitPoint a, OrbitPoint b, float t) { return(new OrbitPoint( t * (b.Theta - a.Theta) + a.Theta, t * (b.Phi - a.Phi) + a.Phi, t * (b.Distance - a.Distance) + a.Distance )); }
public void Update(float t) { OrbitPoint point = At(t); Vector3 newPosition = point.Cartesian(); lookAt.SetLookAt(newPosition, Vector3.Zero, Vector3.UnitY); frame.LocalToParent.Set(lookAt); }
public void DemoRender() { float t = Time.Now; if (t > LastDemoTime) { DemoStart(); t = 0.0f; } float e = exposure.At(t); (Renderer.GlobalParameters.Values["exposure"] as IParameterValue <Floats>).Value.Set(e); OrbitPoint o = cameraPath.At(t); AverageCpuUsage += CPUUsage; ++updateCounter; if (updateCounter == 10) { int cpu = (int)(AverageCpuUsage / updateCounter); int megabytesInUse = (int)(MemoryUsage / (1024.0f * 1024.0f)); base.Title = t.ToString("00.0") + " t = " + o.Theta.ToString("0.00") + " p = " + o.Phi.ToString("0.00") + " d = " + o.Distance.ToString("0.00") + " e = " + e.ToString("0.00") + " CPU Use " + cpu.ToString() + "% Mem Use " + megabytesInUse.ToString() + " MB" + " GC0 " + GC.CollectionCount(0) + " GC1 " + GC.CollectionCount(1) + " GC2 " + GC.CollectionCount(2) + " GC3 " + GC.CollectionCount(3) ; AverageCpuUsage = 0.0f; updateCounter = 0; } cameraPath.Update(t); GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); camera.Update(Renderer.CurrentViewport); PartialGLStateResetToDefaults(); Renderer.CurrentCamera = camera; Renderer.CurrentViewport = windowViewport; Renderer.CurrentModel = model; Renderer.CurrentMaterial = model.Material; Renderer.CurrentProgram = Renderer.CurrentMaterial.Program; Renderer.RenderCurrent(); SwapBuffers(); }