/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
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using SlimDX.Direct3D9; 6using Microsoft.Research.Visualization3D.CameraUtilities; 7using Microsoft.Research.Visualization3D.MainLoops; 8 9namespace Microsoft.Research.Visualization3D 10{ 11 public abstract class DrawableComponent 12 { 13 protected Device device; 14 protected Effect effect; 15 protected Camera camera; 16 protected Visualization3DDataSource dataSource; 17 18 private bool isEnabled; 19 20 public bool IsEnabled 21 { 22 get { return isEnabled; } 23 set 24 { 25 isEnabled = value; 26 if (value) 27 this.Initialize(); 28 } 29 } 30 31 public abstract float CurrentValue 32 { 33 get; 34 set; 35 } 36 37 public Camera Camera 38 { 39 get { return camera; } 40 } 41 42 public Visualization3DDataSource DataSource 43 { 44 get { return this.dataSource; } 45 set 46 { 47 dataSource = value; 48 OnDataSourceChanged(); 49 } 50 } 51 52 public DrawableComponent(DX3DHost host, Visualization3DDataSource dataSource) 53 { 54 this.device = host.Device; 55 this.camera = host.Camera; 56 this.dataSource = dataSource; 57 58 this.isEnabled = false; 59 60 host.DeviceReset += OnDeviceReset; 61 host.DeviceLost += OnDeviceLost; 62 host.DeviceDestroyed += OnDeviceDestroyed; 63 } 64 65 public abstract void Draw(TimeEntity timeEntity); 66 public abstract void Update(TimeEntity timeEntity); 67 protected virtual void OnDeviceReset(object sender, EventArgs e) 68 { 69 70 } 71 protected virtual void OnDeviceLost(object sender, EventArgs e) 72 { 73 74 } 75 76 protected virtual void OnDeviceDestroyed(object sender, EventArgs e) 77 { 78 79 } 80 81 protected virtual void SetCamera() 82 { 83 84 } 85 86 protected virtual void OnDataSourceChanged() 87 { 88 89 } 90 91 public virtual void Initialize() 92 { 93 camera.NearPlane = 0.1f; 94 camera.FarPlane = 1000.0f; 95 camera.FieldOfView = (float)Math.PI / 4.0f; 96 camera.AspectRatio = (float)device.Viewport.Width / (float)device.Viewport.Height; 97 98 SetCamera(); 99 } 100 101 } 102}