PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/Microsoft.Research.Visualization3D/DrawableComponent.cs

#
C# | 102 lines | 81 code | 21 blank | 0 comment | 1 complexity | b4ac3cdf391754c624224c593bec45b6 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SlimDX.Direct3D9;
  6. using Microsoft.Research.Visualization3D.CameraUtilities;
  7. using Microsoft.Research.Visualization3D.MainLoops;
  8. namespace Microsoft.Research.Visualization3D
  9. {
  10. public abstract class DrawableComponent
  11. {
  12. protected Device device;
  13. protected Effect effect;
  14. protected Camera camera;
  15. protected Visualization3DDataSource dataSource;
  16. private bool isEnabled;
  17. public bool IsEnabled
  18. {
  19. get { return isEnabled; }
  20. set
  21. {
  22. isEnabled = value;
  23. if (value)
  24. this.Initialize();
  25. }
  26. }
  27. public abstract float CurrentValue
  28. {
  29. get;
  30. set;
  31. }
  32. public Camera Camera
  33. {
  34. get { return camera; }
  35. }
  36. public Visualization3DDataSource DataSource
  37. {
  38. get { return this.dataSource; }
  39. set
  40. {
  41. dataSource = value;
  42. OnDataSourceChanged();
  43. }
  44. }
  45. public DrawableComponent(DX3DHost host, Visualization3DDataSource dataSource)
  46. {
  47. this.device = host.Device;
  48. this.camera = host.Camera;
  49. this.dataSource = dataSource;
  50. this.isEnabled = false;
  51. host.DeviceReset += OnDeviceReset;
  52. host.DeviceLost += OnDeviceLost;
  53. host.DeviceDestroyed += OnDeviceDestroyed;
  54. }
  55. public abstract void Draw(TimeEntity timeEntity);
  56. public abstract void Update(TimeEntity timeEntity);
  57. protected virtual void OnDeviceReset(object sender, EventArgs e)
  58. {
  59. }
  60. protected virtual void OnDeviceLost(object sender, EventArgs e)
  61. {
  62. }
  63. protected virtual void OnDeviceDestroyed(object sender, EventArgs e)
  64. {
  65. }
  66. protected virtual void SetCamera()
  67. {
  68. }
  69. protected virtual void OnDataSourceChanged()
  70. {
  71. }
  72. public virtual void Initialize()
  73. {
  74. camera.NearPlane = 0.1f;
  75. camera.FarPlane = 1000.0f;
  76. camera.FieldOfView = (float)Math.PI / 4.0f;
  77. camera.AspectRatio = (float)device.Viewport.Width / (float)device.Viewport.Height;
  78. SetCamera();
  79. }
  80. }
  81. }