private void Viewport_OnStartRendering(object sender, EventArgs e) { bool isGoingOut = true; bool isAddingNode = false; RenderLoop.Run(window, () => { if (resizeRequested) { viewport.Resize(window.ClientSize.Width, window.ClientSize.Height); resizeRequested = false; return; } var pos = camera.Position; var t = Stopwatch.GetTimestamp(); var elapse = t - previousTime; previousTime = t; cameraController.OnTimeStep(); viewport.Render(); #if TESTADDREMOVE if (groupSphere.Items.Count > 0 && !isAddingNode) { groupSphere.RemoveChildNode(groupSphere.Items.First()); if (groupSphere.Items.Count == 0) { isAddingNode = true; Console.WriteLine($"{effectsManager.GetResourceCountSummary()}"); groupSphere.AddChildNode(groupBox); groupSphere.AddChildNode(groupPoints); groupPoints.AddChildNode(groupLines); } } else { var materialCount = materialList.Length; var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); groupSphere.AddChildNode(new MeshNode() { Geometry = box, Material = materialList[groupSphere.Items.Count % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back }); transform = Matrix.Translation(new Vector3(rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20))); groupSphere.AddChildNode(new MeshNode() { Geometry = sphere, Material = materialList[groupSphere.Items.Count % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back }); if (groupSphere.Items.Count > NumItems) { isAddingNode = false; } } #endif }); }
private void Viewport_OnStartRendering(object sender, EventArgs e) { bool isGoingOut = true; RenderLoop.Run(window, () => { if (resizeRequested) { viewport.Resize(window.Width, window.Height); resizeRequested = false; return; } var pos = camera.Position; var t = Stopwatch.GetTimestamp(); var elapse = t - previousTime; previousTime = t; var angle = ((double)elapse / Stopwatch.Frequency) * 0.05; var camRotate = Matrix.RotationAxis(Vector3.UnitY, (float)(angle * Math.PI)); camera.Position = Vector3.TransformCoordinate(pos, camRotate); camera.LookDirection = -camera.Position; if (isGoingOut) { camera.Position += 0.05f * Vector3.Normalize(camera.Position); if (camera.Position.LengthSquared() > 10000) { isGoingOut = false; } } else { camera.Position -= 0.05f * Vector3.Normalize(camera.Position); if (camera.Position.LengthSquared() < 2500) { isGoingOut = true; } } viewport.Render(); viewport.InvalidateRender(); }); }
/// <summary> /// Must be called from same thread created the viewport object. /// </summary> /// <param name="width"></param> /// <param name="height"></param> public void Resize(int width, int height) { viewport.Resize(width, height); }
private void Viewport_OnStartRendering(object sender, EventArgs e) { bool isGoingOut = true; bool isAddingNode = false; RenderLoop.Run(window, () => { if (resizeRequested) { viewport.Resize(window.Width, window.Height); resizeRequested = false; return; } var pos = camera.Position; var t = Stopwatch.GetTimestamp(); var elapse = t - previousTime; previousTime = t; var angle = ((double)elapse / Stopwatch.Frequency) * 0.05; var camRotate = Matrix.RotationAxis(Vector3.UnitY, (float)(angle * Math.PI)); camera.Position = Vector3.TransformCoordinate(pos, camRotate); camera.LookDirection = -camera.Position; if (isGoingOut) { camera.Position += 0.05f * Vector3.Normalize(camera.Position); if (camera.Position.LengthSquared() > 10000) { isGoingOut = false; } } else { camera.Position -= 0.05f * Vector3.Normalize(camera.Position); if (camera.Position.LengthSquared() < 2500) { isGoingOut = true; } } viewport.Render(); viewport.InvalidateRender(); #if TESTADDREMOVE if (groupSphere.Items.Count > 0 && !isAddingNode) { groupSphere.RemoveChildNode(groupSphere.Items.First()); if (groupSphere.Items.Count == 0) { isAddingNode = true; Console.WriteLine($"{effectsManager.GetResourceCountSummary()}"); groupSphere.AddChildNode(groupBox); groupSphere.AddChildNode(groupPoints); groupPoints.AddChildNode(groupLines); } } else { var materialCount = materialList.Length; var transform = Matrix.Translation(new Vector3(rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50), rnd.NextFloat(-50, 50))); groupSphere.AddChildNode(new MeshNode() { Geometry = box, Material = materialList[groupSphere.Items.Count % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back }); transform = Matrix.Translation(new Vector3(rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20), rnd.NextFloat(-20, 20))); groupSphere.AddChildNode(new MeshNode() { Geometry = sphere, Material = materialList[groupSphere.Items.Count % materialCount], ModelMatrix = transform, CullMode = SharpDX.Direct3D11.CullMode.Back }); if (groupSphere.Items.Count > NumItems) { isAddingNode = false; } } #endif }); }