Ejemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (Initialized)
            {
                return;
            }

            var presentParams = new PresentParameters
            {
                Windowed               = true,
                SwapEffect             = SwapEffect.Discard,
                AutoDepthStencilFormat = DepthFormat.D16,
                EnableAutoDepthStencil = true,
                PresentationInterval   = PresentInterval.One
            };

            var enumerator = Manager.Adapters.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var adapterInfo = enumerator.Current as AdapterInformation;

                var d3dDeviceCaps = Manager.GetDeviceCaps(adapterInfo.Adapter, DeviceType.Hardware);

                var flags = d3dDeviceCaps.DeviceCaps.SupportsHardwareTransformAndLight ?
                            CreateFlags.HardwareVertexProcessing :
                            CreateFlags.SoftwareVertexProcessing;

                Device = new D3DDevice(adapterInfo.Adapter, d3dDeviceCaps.DeviceType, this, flags, presentParams);

                if (Device != null)
                {
                    break;
                }
            }

            Device.DeviceReset += new EventHandler(OnResetDevice);
            OnResetDevice(Device, null);

            Instance = new RenderObject(Device, Cache, Definition, new TagTool.Common.RealPoint3d(), new TagTool.Common.RealEulerAngles3d());

            if (Camera != null)
            {
                Camera.Dispose();
            }

            var compression = Instance.RenderModel.Geometry.Compression.Count > 0 ?
                              Instance.RenderModel.Geometry.Compression[0] :
                              new TagTool.Geometry.RenderGeometryCompression
            {
                X = new TagTool.Common.Bounds <float>(float.MinValue, float.MaxValue),
                Y = new TagTool.Common.Bounds <float>(float.MinValue, float.MaxValue),
                Z = new TagTool.Common.Bounds <float>(float.MinValue, float.MaxValue),
                U = new TagTool.Common.Bounds <float>(float.MinValue, float.MaxValue),
                V = new TagTool.Common.Bounds <float>(float.MinValue, float.MaxValue)
            };

            Camera = new RenderCamera(this)
            {
                Speed             = 0.005f,
                Position          = new Vector3(compression.X.Length + (Instance.Object.BoundingRadius * 2f), 0f, Instance.RenderModel.Nodes.FirstOrDefault().DefaultTranslation.Z),
                VerticalRadians   = 6.161014f,
                HorizontalRadians = 3.14159f
            };

            Camera.ComputePosition();

            RenderTimer = new Timer
            {
                Interval = 10
            };

            RenderTimer.Tick += OnRender;

            Initialized = true;

            RenderTimer.Start();
        }
Ejemplo n.º 2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (Initialized)
            {
                return;
            }

            var presentParams = new PresentParameters
            {
                Windowed               = true,
                SwapEffect             = SwapEffect.Discard,
                AutoDepthStencilFormat = DepthFormat.D16,
                EnableAutoDepthStencil = true,
                PresentationInterval   = PresentInterval.One
            };

            var enumerator = Manager.Adapters.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var adapterInfo = enumerator.Current as AdapterInformation;

                var d3dDeviceCaps = Manager.GetDeviceCaps(adapterInfo.Adapter, DeviceType.Hardware);

                var flags = d3dDeviceCaps.DeviceCaps.SupportsHardwareTransformAndLight ?
                            CreateFlags.HardwareVertexProcessing :
                            CreateFlags.SoftwareVertexProcessing;

                Device = new Direct3D.Device(adapterInfo.Adapter, d3dDeviceCaps.DeviceType, this, flags, presentParams);

                if (Device != null)
                {
                    break;
                }
            }

            Device.DeviceReset += new EventHandler(OnResetDevice);
            OnResetDevice(Device, null);

            // TODO: load instances here...

            if (Camera != null)
            {
                Camera.Dispose();
            }

            Camera = new RenderCamera(this)
            {
                Speed             = 0.005f,
                Position          = new Vector3(),
                VerticalRadians   = 6.161014f,
                HorizontalRadians = 3.14159f
            };

            Camera.ComputePosition();

            RenderTimer = new Timer
            {
                Interval = 10
            };

            RenderTimer.Tick += OnRender;
            RenderTimer.Start();

            Initialized = true;
        }