StereoModePerformance.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Urho;
  2. using Urho.Shapes;
  3. namespace Playgrounds.Console
  4. {
  5. public class StereoModePerformance : Application
  6. {
  7. public StereoModePerformance(ApplicationOptions opts) : base(opts)
  8. {
  9. }
  10. public static void RunApp()
  11. {
  12. const float scale = 0.65f;
  13. const float width = 1280f * 2 * scale;
  14. const float height = 720f * scale;
  15. var app = new StereoModePerformance(new ApplicationOptions("Data") { Width = (int)width, Height = (int)height });
  16. app.Run();
  17. }
  18. protected override void Start()
  19. {
  20. var scene = new Scene();
  21. scene.CreateComponent<Octree>();
  22. scene.CreateComponent<Zone>().AmbientColor = new Color(0.3f, 0.3f, 0.3f);
  23. var lightNode = scene.CreateChild();
  24. lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f));
  25. var light = lightNode.CreateComponent<Light>();
  26. light.LightType = LightType.Directional;
  27. var leftEyeNode = scene.CreateChild();
  28. var leftEye = leftEyeNode.CreateComponent<Camera>();
  29. var rightEyeNode = scene.CreateChild();
  30. var rightEye = rightEyeNode.CreateComponent<Camera>();
  31. //some fake offset between eyes
  32. leftEyeNode.Translate(new Vector3(-0.2f, 0, 0));
  33. rightEyeNode.Translate(new Vector3(0.2f, 0, 0));
  34. Renderer.NumViewports = 2;
  35. var leftEyeRect = new IntRect(0, 0, Graphics.Width / 2, Graphics.Height);
  36. var rightEyeRect = new IntRect(Graphics.Width / 2, 0, Graphics.Width, Graphics.Height);
  37. var leftVp = new Viewport(Context, scene, leftEye, leftEyeRect, null);
  38. var rightVp = new Viewport(Context, scene, rightEye, rightEyeRect, null);
  39. var cullCamera = scene.CreateComponent<Camera>();
  40. leftVp.CullCamera = cullCamera;
  41. rightVp.CullCamera = cullCamera;
  42. var hud = Engine.CreateDebugHud();
  43. var xml = ResourceCache.GetXmlFile("UI/DefaultStyle.xml");
  44. hud.DefaultStyle = xml;
  45. hud.ToggleAll();
  46. Renderer.SetViewport(0, leftVp);
  47. Renderer.SetViewport(1, rightVp);
  48. for (int x = -10; x < 10; x++)
  49. {
  50. for (int y = -10; y < 10; y++)
  51. {
  52. for (int z = 1; z < 30; z++)
  53. {
  54. var child = scene.CreateChild();
  55. child.Position = new Vector3(x, y, z);
  56. child.SetScale(0.4f);
  57. var box = child.CreateComponent<Sphere>();
  58. box.Color = new Color(-x, -y, -z);
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }