Beispiel #1
0
 public OrthogonalCamera(System.Windows.Media.Media3D.OrthographicCamera cam)
 {
     CameraViewPoint  = new Point(cam.Position);
     CameraDirection  = new Direction(cam.LookDirection);
     CameraUpVector   = new Direction(cam.UpDirection);
     ViewToWorldScale = cam.Width;
 }
Beispiel #2
0
        //------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------

        private static void WidthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            OrthographicCamera target = ((OrthographicCamera)d);


            target.PropertyChanged(WidthProperty);
        }
 /// <summary>
 /// Resets the specified orthographic camera.
 /// </summary>
 /// <param name="camera">The camera.</param>
 public static void Reset(OrthographicCamera camera)
 {
     if (camera == null)
         return;
     camera.Position = new Point3D(2, 16, 20);
     camera.LookDirection = new Vector3D(-2, -16, -20);
     camera.UpDirection = new Vector3D(0, 0, 1);
     camera.Width = 40;
     camera.NearPlaneDistance = 0.1;
     camera.FarPlaneDistance = 100000;
 }
Beispiel #4
0
        private static Matrix3D GetProjectionMatrix(OrthographicCamera camera, double aspectRatio)
        {
            if (camera == null) throw new ArgumentNullException("camera");

            // This math is identical to what you find documented for
            // D3DXMatrixOrthoRH with the exception that in WPF only
            // the camera's width is specified.  Height is calculated
            // from width and the aspect ratio.

            double w = camera.Width;
            double h = w / aspectRatio;
            double zn = camera.NearPlaneDistance;
            double zf = camera.FarPlaneDistance;

            double m33 = 1 / (zn - zf);
            double m43 = zn * m33;

            return new Matrix3D(
                2 / w, 0, 0, 0,
                  0, 2 / h, 0, 0,
                  0, 0, m33, 0,
                  0, 0, m43, 1);
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 7 "..\..\MainWindow.xaml"
                ((WPFDreiDWuerfel.MainWindow)(target)).KeyDown += new System.Windows.Input.KeyEventHandler(this.Window_KeyDown);

            #line default
            #line hidden
                return;

            case 2:
                this.Oc = ((System.Windows.Media.Media3D.OrthographicCamera)(target));
                return;

            case 3:
                this.Dl = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;
            }
            this._contentLoaded = true;
        }
Beispiel #6
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 4 "..\..\Window1.xaml"
                ((WPFChart3D.Window1)(target)).KeyDown += new System.Windows.Input.KeyEventHandler(this.OnKeyDown);

            #line default
            #line hidden
                return;

            case 2:
                this.mainViewport = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 3:
                this.camera = ((System.Windows.Media.Media3D.OrthographicCamera)(target));
                return;

            case 4:
                this.Light1 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 5:
                this.Light2 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 6:
                this.Light3 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 7:
                this.canvasOn3D = ((System.Windows.Controls.Canvas)(target));

            #line 52 "..\..\Window1.xaml"
                this.canvasOn3D.MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.OnViewportMouseUp);

            #line default
            #line hidden

            #line 53 "..\..\Window1.xaml"
                this.canvasOn3D.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.OnViewportMouseDown);

            #line default
            #line hidden

            #line 54 "..\..\Window1.xaml"
                this.canvasOn3D.MouseMove += new System.Windows.Input.MouseEventHandler(this.OnViewportMouseMove);

            #line default
            #line hidden
                return;

            case 8:
                this.statusPane = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 9:
                this.controlPane = ((System.Windows.Controls.Canvas)(target));
                return;

            case 10:
                this.label1 = ((System.Windows.Controls.Label)(target));
                return;

            case 11:
                this.gridNo = ((System.Windows.Controls.TextBox)(target));
                return;

            case 12:
                this.surfaceButton = ((System.Windows.Controls.Button)(target));

            #line 78 "..\..\Window1.xaml"
                this.surfaceButton.Click += new System.Windows.RoutedEventHandler(this.surfaceButton_Click);

            #line default
            #line hidden
                return;

            case 13:
                this.label2 = ((System.Windows.Controls.Label)(target));
                return;

            case 14:
                this.dataNo = ((System.Windows.Controls.TextBox)(target));
                return;

            case 15:
                this.checkBoxShape = ((System.Windows.Controls.CheckBox)(target));
                return;

            case 16:
                this.scatterButton = ((System.Windows.Controls.Button)(target));

            #line 87 "..\..\Window1.xaml"
                this.scatterButton.Click += new System.Windows.RoutedEventHandler(this.scatterButton_Click);

            #line default
            #line hidden
                return;

            case 17:
                this.labelVertNo = ((System.Windows.Controls.Label)(target));
                return;

            case 18:
                this.labelTriNo = ((System.Windows.Controls.Label)(target));
                return;
            }
            this._contentLoaded = true;
        }
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     
     #line 6 "..\..\Graph3DWindow.xaml"
     ((IMPressive.Graph3DWindow)(target)).Loaded += new System.Windows.RoutedEventHandler(this.Window_Loaded);
     
     #line default
     #line hidden
     
     #line 6 "..\..\Graph3DWindow.xaml"
     ((IMPressive.Graph3DWindow)(target)).SizeChanged += new System.Windows.SizeChangedEventHandler(this.Window_SizeChanged);
     
     #line default
     #line hidden
     
     #line 6 "..\..\Graph3DWindow.xaml"
     ((IMPressive.Graph3DWindow)(target)).KeyDown += new System.Windows.Input.KeyEventHandler(this.Window_KeyDown);
     
     #line default
     #line hidden
     
     #line 6 "..\..\Graph3DWindow.xaml"
     ((IMPressive.Graph3DWindow)(target)).MouseWheel += new System.Windows.Input.MouseWheelEventHandler(this.Window_MouseWheel);
     
     #line default
     #line hidden
     return;
     case 2:
     this.mainViewport = ((System.Windows.Controls.Viewport3D)(target));
     return;
     case 3:
     this.camera = ((System.Windows.Media.Media3D.OrthographicCamera)(target));
     return;
     case 4:
     this.Light1 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
     return;
     case 5:
     this.btnLoad = ((System.Windows.Controls.Button)(target));
     
     #line 49 "..\..\Graph3DWindow.xaml"
     this.btnLoad.Click += new System.Windows.RoutedEventHandler(this.btnLoad_Click);
     
     #line default
     #line hidden
     return;
     case 6:
     this.txtOperation = ((System.Windows.Controls.AutoCompleteBox)(target));
     
     #line 51 "..\..\Graph3DWindow.xaml"
     this.txtOperation.KeyUp += new System.Windows.Input.KeyEventHandler(this.txtOperation_KeyUp);
     
     #line default
     #line hidden
     return;
     case 7:
     this.btnClear = ((System.Windows.Controls.Button)(target));
     
     #line 60 "..\..\Graph3DWindow.xaml"
     this.btnClear.Click += new System.Windows.RoutedEventHandler(this.btnClear_Click);
     
     #line default
     #line hidden
     return;
     case 8:
     this.bg2 = ((System.Windows.Controls.Border)(target));
     return;
     case 9:
     this.cpxColor = ((Xceed.Wpf.Toolkit.ColorPicker)(target));
     return;
     }
     this._contentLoaded = true;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="HelixViewport3D" /> class. Initializes a new instance of the
        ///     <see
        ///         cref="HelixViewport3D" />
        /// class.
        /// </summary>
        public HelixViewport3D()
        {
            // The Viewport3D must be created here since the Children collection is attached directly
            this.viewport = new Viewport3D();

            // viewport.SetBinding(UIElement.IsHitTestVisibleProperty, new Binding("IsViewportHitTestVisible") { Source = this });
            // viewport.SetBinding(UIElement.ClipToBoundsProperty, new Binding("ClipToBounds") { Source = this });

            // headlight
            this.lights = new Model3DGroup();
            this.viewport.Children.Add(new ModelVisual3D { Content = this.lights });

            this.perspectiveCamera = new PerspectiveCamera();
            this.orthographicCamera = new OrthographicCamera();
            CameraHelper.Reset(this.perspectiveCamera);
            CameraHelper.Reset(this.orthographicCamera);

            this.Camera = this.Orthographic ? (ProjectionCamera)this.orthographicCamera : this.perspectiveCamera;

            // http://blogs.msdn.com/wpfsdk/archive/2007/01/15/maximizing-wpf-3d-performance-on-tier-2-hardware.aspx
            // RenderOptions.EdgeMode?

            // start a watch for FPS calculations
            this.fpsWatch.Start();

            this.Loaded += this.OnControlLoaded;
            this.Unloaded += this.OnControlUnloaded;

            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, this.CopyHandler));
            this.CommandBindings.Add(new CommandBinding(OrthographicToggleCommand, this.OrthographicToggle));
            this.renderingEventListener = new RenderingEventListener(this.CompositionTargetRendering);
        }
Beispiel #9
0
        /// <summary>
        /// Animates the orthographic width.
        /// </summary>
        /// <param name="camera">
        /// An ortographic camera.
        /// </param>
        /// <param name="newWidth">
        /// The width to animate to.
        /// </param>
        /// <param name="animationTime">
        /// Animation time in milliseconds
        /// </param>
        public static void AnimateWidth(OrthographicCamera camera, double newWidth, double animationTime)
        {
            double fromWidth = camera.Width;

            camera.Width = newWidth;

            if (animationTime > 0)
            {
                var a1 = new DoubleAnimation(
                    fromWidth, newWidth, new Duration(TimeSpan.FromMilliseconds(animationTime)))
                    {
                        AccelerationRatio = 0.3,
                        DecelerationRatio = 0.5,
                        FillBehavior = FillBehavior.Stop
                    };
                camera.BeginAnimation(OrthographicCamera.WidthProperty, a1);
            }
        }
 static void OnCameraProjectionModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     Visualizer visualizer = (Visualizer)d;
     CameraProjectionMode cameraProjectionMode = (CameraProjectionMode)e.NewValue;
     if (cameraProjectionMode == CameraProjectionMode.Perspective)
     {
         OrthographicCamera orthographicCamera = (OrthographicCamera) visualizer.camera;
         PerspectiveCamera perspectiveCamera = new PerspectiveCamera(visualizer.camera.Position, visualizer.camera.LookDirection, visualizer.camera.UpDirection,
             visualizer.FieldOfView);
         visualizer.viewport.Camera = visualizer.camera = perspectiveCamera;
     }
     if (cameraProjectionMode == CameraProjectionMode.Orthographic)
     {
         PerspectiveCamera perspectiveCamera = (PerspectiveCamera)visualizer.camera;
         OrthographicCamera orthographicCamera = new OrthographicCamera(visualizer.camera.Position, visualizer.camera.LookDirection, visualizer.camera.UpDirection,
             2.0 * visualizer.Distance * Math.Tan(((perspectiveCamera.FieldOfView * Math.PI) / 180.0) / 2.0));
         visualizer.viewport.Camera = visualizer.camera = orthographicCamera;
     }
 }
Beispiel #11
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 36 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.MenuItem_Click);

            #line default
            #line hidden
                return;

            case 2:

            #line 39 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.MenuItem_Click_1);

            #line default
            #line hidden
                return;

            case 3:

            #line 42 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.MenuItem_Test1);

            #line default
            #line hidden
                return;

            case 4:

            #line 43 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.MenuItem_Test2);

            #line default
            #line hidden
                return;

            case 5:

            #line 44 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.MenuItem_Test3);

            #line default
            #line hidden
                return;

            case 6:

            #line 45 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.MenuItem_Test4);

            #line default
            #line hidden
                return;

            case 7:

            #line 46 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.MenuItem_Test5);

            #line default
            #line hidden
                return;

            case 8:
                this.fText = ((System.Windows.Controls.TextBox)(target));
                return;

            case 9:
                this.phiText = ((System.Windows.Controls.TextBox)(target));
                return;

            case 10:
                this.muText = ((System.Windows.Controls.TextBox)(target));
                return;

            case 11:
                this.aText = ((System.Windows.Controls.TextBox)(target));
                return;

            case 12:
                this.bText = ((System.Windows.Controls.TextBox)(target));
                return;

            case 13:
                this.h1Text = ((System.Windows.Controls.TextBox)(target));
                return;

            case 14:
                this.h2Text = ((System.Windows.Controls.TextBox)(target));
                return;

            case 15:
                this.tauText = ((System.Windows.Controls.TextBox)(target));
                return;

            case 16:
                this.solutionText = ((System.Windows.Controls.TextBox)(target));
                return;

            case 17:
                this.sigma1Text = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 18:
                this.sigma2Text = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 19:
                this.maxRText = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 20:
                this.maxRRText = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 21:
                this.build = ((System.Windows.Controls.Button)(target));

            #line 335 "..\..\MainWindow.xaml"
                this.build.Click += new System.Windows.RoutedEventHandler(this.build_Click);

            #line default
            #line hidden
                return;

            case 22:
                this.Play = ((System.Windows.Controls.Button)(target));

            #line 343 "..\..\MainWindow.xaml"
                this.Play.Click += new System.Windows.RoutedEventHandler(this.Play_Click);

            #line default
            #line hidden
                return;

            case 23:
                this.next = ((System.Windows.Controls.Button)(target));

            #line 352 "..\..\MainWindow.xaml"
                this.next.Click += new System.Windows.RoutedEventHandler(this.next_Click);

            #line default
            #line hidden
                return;

            case 24:
                this.textChart1 = ((System.Windows.Controls.Label)(target));
                return;

            case 25:
                this.mainViewport = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 26:
                this.camera = ((System.Windows.Media.Media3D.OrthographicCamera)(target));
                return;

            case 27:
                this.Light1 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 28:
                this.Light2 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 29:
                this.Light3 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 30:
                this.mainViewport2 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 31:
                this.camera2 = ((System.Windows.Media.Media3D.OrthographicCamera)(target));
                return;

            case 32:
                this.Light12 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 33:
                this.Light22 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 34:
                this.Light32 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 35:
                this.textGraph1 = ((System.Windows.Controls.Label)(target));
                return;

            case 36:
                this.Graph1 = ((LiveCharts.Wpf.CartesianChart)(target));
                return;
            }
            this._contentLoaded = true;
        }
        void UpdateShadow()
        {
            if (substance == null) return;
            if (style == null) return;

            Thread.Sleep(300);

            // Black material
            DiffuseMaterial material = new DiffuseMaterial(Brushes.Black);
            material.Freeze();

            // Create molecules
            ModelVisual3D container = new ModelVisual3D();
            foreach (Data.Molecule molecule in substance.Molecules)
            {
                foreach (Data.Atom atom in molecule.Atoms)
                {
                    if (style.ColorStyle.ColorScheme[atom.Element].Diffuse.A < 5) continue;
                    Sphere sphere = new Sphere();
                    sphere.Material = material;
                    sphere.Radius = Atom.GetAtomRadius(atom, style.GeometryStyle);
                    sphere.Center = atom.Position;
                    container.Children.Add(sphere);
                }
                double bondRadius = Bond.GetBondRadius(style.GeometryStyle);
                foreach (Data.Bond bond in molecule.Bonds)
                {
                    if (style.ColorStyle.UseSingleBondMaterial)
                    {
                        if (style.ColorStyle.BondMaterial.Diffuse.A < 5) continue;
                    }
                    else if (style.ColorStyle.ColorScheme[bond.Begin.Element].Diffuse.A < 5 ||
                             style.ColorStyle.ColorScheme[bond.End.Element].Diffuse.A < 5) continue;
                    Cylinder cylinder = new Cylinder(bond.Begin.Position, bond.End.Position, bondRadius);
                    cylinder.Material = material;
                    container.Children.Add(cylinder);
                }

                #region Build approximation of ribbon

                double radius = 0.45;
                foreach (Data.Chain chain in molecule.Chains)
                {
                    for (int i = 0; i < chain.Residues.Count; i++)
                    {
                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Helix)
                           if (style.GeometryStyle.HelixHeight < 0.05 || style.GeometryStyle.HelixWidth < 0.05) continue;
                           else radius = Residue.HelixWidth * ((style.GeometryStyle.HelixHeight + style.GeometryStyle.HelixWidth) / 2.0);
                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Sheet)
                           if (style.GeometryStyle.SheetHeight < 0.05 || style.GeometryStyle.SheetWidth < 0.05) continue;
                           else radius = Residue.SheetWidth * ((style.GeometryStyle.SheetHeight + style.GeometryStyle.SheetWidth) / 2.0);
                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.NotDefined)
                           if (style.GeometryStyle.TurnHeight < 0.05 || style.GeometryStyle.TurnWidth < 0.05) continue;
                           else radius = Residue.TurnWidth * ((style.GeometryStyle.TurnHeight + style.GeometryStyle.TurnWidth) / 2.0);

                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Helix && style.ColorStyle.HelixMaterial.Diffuse.A < 5) continue;
                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.Sheet && style.ColorStyle.SheetMaterial.Diffuse.A < 5) continue;
                        if (chain.Residues[i].GetStructureType() == SecondaryStructureType.NotDefined && style.ColorStyle.TurnMaterial.Diffuse.A < 5) continue;

                        Data.Atom alfaCarbon = chain.Residues[i].AlfaCarbon;
                        if (alfaCarbon != null)
                        {
                            Point3D begin = alfaCarbon.Position;
                            alfaCarbon = null;
                            for (int j = i + 1; j < chain.Residues.Count; j++)
                            {
                                alfaCarbon = chain.Residues[j].AlfaCarbon;
                                if (alfaCarbon != null) break;
                            }
                            if (alfaCarbon != null)
                            {
                                Point3D end = alfaCarbon.Position;
                                Cylinder cylinder = new Cylinder(begin, end, radius);
                                container.Children.Add(cylinder);
                            }
                        }
                    }
                }

                #endregion
            }

            // Get bounding box
            Rect3D boundingBox = VisualTreeHelper.GetDescendantBounds(container);
            if (boundingBox.IsEmpty)
            {
                shadowRefreshStarted = false;
                return;
            }

            #region Render Shadow

            const double blurSize = 25;
            const int renderTargetWidth = 200;
            int renderTargetHeight = (int)(200.0 * (boundingBox.SizeX / boundingBox.SizeY));
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(renderTargetWidth, renderTargetHeight, 96, 96, PixelFormats.Pbgra32);

            Viewport3D shadowViewport3D = new Viewport3D();
            Border border = new Border();
            border.Padding = new Thickness(blurSize);
            border.Child = shadowViewport3D;

            // Change size of the visualizer
            border.Width = renderTargetBitmap.PixelWidth;
            border.Height = renderTargetBitmap.PixelHeight;
            border.Measure(new Size(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight));
            border.Arrange(new Rect(0, 0, renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight));

            shadowViewport3D.Children.Add(container);

            // Create camera
            OrthographicCamera orthographicCamera = new OrthographicCamera();

            #region Accomodate camera to fit content

            orthographicCamera.Position = new Point3D(boundingBox.Location.X + boundingBox.SizeX / 2.0,
                                                      boundingBox.Location.Y,
                                                      boundingBox.Location.Z + boundingBox.SizeZ / 2.0);
            orthographicCamera.LookDirection = new Vector3D(0, 1, 0);
            orthographicCamera.UpDirection = new Vector3D(-1, 0, 0);
            orthographicCamera.Width = boundingBox.SizeZ;

            #endregion

            orthographicCamera.NearPlaneDistance = 0;

            // Set the camera & correct lights
            shadowViewport3D.Camera = orthographicCamera;

            BlurEffect blurEffect = new BlurEffect();
            blurEffect.Radius = blurSize;

            border.Effect = blurEffect;

            renderTargetBitmap.Render(border);
            renderTargetBitmap.Freeze();

            #endregion

            // Invoke in main thread
            Dispatcher.BeginInvoke((Action) delegate
            {
                #region Create Plane

                Vector3D margin = new Vector3D(boundingBox.SizeX * 0.4, 0, boundingBox.SizeZ * 0.4);
                Point3D[] points = new Point3D[]
                {
                    boundingBox.Location + new Vector3D(-margin.X, -margin.Y, -margin.Z),
                    boundingBox.Location +
                    new Vector3D(margin.X + boundingBox.SizeX, -margin.Y, -margin.Z),
                    boundingBox.Location +
                    new Vector3D(margin.X + boundingBox.SizeX, -margin.Y,
                                margin.Z + boundingBox.SizeZ),
                    boundingBox.Location +
                    new Vector3D(-margin.X, -margin.Y, margin.Z + boundingBox.SizeZ)
                };

                Polygon shadowPlane = new Polygon();
                shadowPlane.Positions = points;
                shadowPlane.TextureCoordinates = new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0) };

                #endregion
                shadowBrush.ImageSource = renderTargetBitmap;
                shadowBrush.Stretch = Stretch.Fill;
                shadowTargetOpacity = 0.8;

                shadowPlane.Material = new DiffuseMaterial(shadowBrush);
                shadowContainer.Children.Clear();
                shadowContainer.Children.Add(shadowPlane);

                // Update shadow hash
                shadowRefreshStarted = false;

              }, DispatcherPriority.SystemIdle);
        }
Beispiel #13
0
        public HelixView3D()
        {
            // The Viewport3D must be created here since the Children collection is attached directly
            viewport = new Viewport3D { IsHitTestVisible = this.IsHitTestVisible, ClipToBounds = this.ClipToBounds };

            // headlight
            lights = new Model3DGroup();
            viewport.Children.Add(new ModelVisual3D { Content = lights });

            perspectiveCamera = new PerspectiveCamera();
            CameraHelper.Reset(perspectiveCamera);
            orthographicCamera = new OrthographicCamera();
            CameraHelper.Reset(orthographicCamera);
            // perspectiveCamera.Changed += Camera_Changed;
            // orthographicCamera.Changed += Camera_Changed;

            // Set the current camera
            OnOrthographicChanged();

            // http://blogs.msdn.com/wpfsdk/archive/2007/01/15/maximizing-wpf-3d-performance-on-tier-2-hardware.aspx
            // RenderOptions.EdgeMode?

            // start a watch for FPS calculations
            fpsWatch.Start();

            // Using the rendering event to calculate FPS
            // todo: is this giving correct numbers??
            CompositionTarget.Rendering += CompositionTarget_Rendering;
            Loaded += HelixView3D_Loaded;
        }
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     
     #line 8 "..\..\MainWindow.xaml"
     ((WpfApplication2.MainWindow)(target)).Loaded += new System.Windows.RoutedEventHandler(this.MainWindow_Loaded);
     
     #line default
     #line hidden
     return;
     case 2:
     this.buttonReset = ((System.Windows.Controls.Button)(target));
     
     #line 14 "..\..\MainWindow.xaml"
     this.buttonReset.Click += new System.Windows.RoutedEventHandler(this.buttonReset_Click);
     
     #line default
     #line hidden
     return;
     case 3:
     
     #line 16 "..\..\MainWindow.xaml"
     ((System.Windows.Controls.DockPanel)(target)).MouseWheel += new System.Windows.Input.MouseWheelEventHandler(this.MouseWheelHandler);
     
     #line default
     #line hidden
     
     #line 17 "..\..\MainWindow.xaml"
     ((System.Windows.Controls.DockPanel)(target)).MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.MouseDownHandler);
     
     #line default
     #line hidden
     
     #line 18 "..\..\MainWindow.xaml"
     ((System.Windows.Controls.DockPanel)(target)).MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.MouseUpHandler);
     
     #line default
     #line hidden
     
     #line 19 "..\..\MainWindow.xaml"
     ((System.Windows.Controls.DockPanel)(target)).MouseMove += new System.Windows.Input.MouseEventHandler(this.MouseMoveHandler);
     
     #line default
     #line hidden
     return;
     case 4:
     this.Viewport = ((System.Windows.Controls.Viewport3D)(target));
     return;
     case 5:
     this.camera = ((System.Windows.Media.Media3D.OrthographicCamera)(target));
     return;
     case 6:
     this.UIGroup = ((System.Windows.Media.Media3D.ContainerUIElement3D)(target));
     return;
     case 7:
     this.Model = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
     return;
     case 8:
     this.ModelGroup = ((System.Windows.Media.Media3D.Model3DGroup)(target));
     return;
     case 9:
     this.Grid = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
     return;
     case 10:
     this.GridGroup = ((System.Windows.Media.Media3D.Model3DGroup)(target));
     return;
     case 11:
     this.FixedLight = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
     return;
     case 12:
     this.FixedLightGroup = ((System.Windows.Media.Media3D.Model3DGroup)(target));
     return;
     }
     this._contentLoaded = true;
 }
Beispiel #15
0
        /// <summary>
        /// Set the angle of view, near and far clipping distances.
        /// These are all of the fundamental perspective camera properties.
        /// </summary>
        /// <param name="shapeName">The 3DView object.</param>
        /// <param name="nearDistance">The near clipping distance (can improve near object e.g. wall hit detection).
        /// A negative value is 0.001 (default is 0.125).</param>
        /// <param name="farDistance">The far clipping distance (can improve performance).
        /// A negative value is infinity (default).</param>
        /// <param name="angle">The view angle cone of the camera in degrees (affects perspective vanishing point).
        /// If this is negative, then an Orthographic (no perspective) camera is used with view width set to -angle). </param>
        public static void CameraProperties(Primitive shapeName, Primitive nearDistance, Primitive farDistance, Primitive angle)
        {
            UIElement obj;

            try
            {
                if (_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    InvokeHelper ret = new InvokeHelper(delegate
                    {
                        try
                        {
                            if (obj.GetType() == typeof(Viewport3D))
                            {
                                Viewport3D viewport3D = (Viewport3D)obj;
                                ProjectionCamera cameraOld = (ProjectionCamera)viewport3D.Camera;

                                if (angle > 0)
                                {
                                    PerspectiveCamera camera = new PerspectiveCamera(cameraOld.Position, cameraOld.LookDirection, cameraOld.UpDirection, angle);
                                    camera.NearPlaneDistance = System.Math.Max(1.0e-3, nearDistance);
                                    camera.FarPlaneDistance = (farDistance < camera.NearPlaneDistance) ? double.PositiveInfinity : (double)farDistance;
                                    viewport3D.Camera = camera;
                                }
                                else
                                {
                                    OrthographicCamera camera = new OrthographicCamera(cameraOld.Position, cameraOld.LookDirection, cameraOld.UpDirection, -angle);
                                    camera.NearPlaneDistance = System.Math.Max(1.0e-3, nearDistance);
                                    camera.FarPlaneDistance = (farDistance < camera.NearPlaneDistance) ? double.PositiveInfinity : (double)farDistance;
                                    viewport3D.Camera = camera;
                                }

                                UpdateBillBoards(viewport3D, shapeName);
                            }
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        }
                    });
                    FastThread.Invoke(ret);
                }
                else
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
        }
Beispiel #16
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.Window = ((WpfPhotoAlbum.MainWindow)(target));
                return;

            case 2:
                this.Storyboard1_BeginStoryboard = ((System.Windows.Media.Animation.BeginStoryboard)(target));
                return;

            case 3:
                this.LayoutRoot = ((System.Windows.Controls.Grid)(target));
                return;

            case 4:
                this.image10 = ((System.Windows.Controls.Image)(target));
                return;

            case 5:
                this.image9 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 6:
                this.image9ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 7:
                this.image9Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 8:
                this.AmbientContainer5 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 9:
                this.Ambient5 = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 10:
                this.DirectionalContainer5 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 11:
                this.Directional5 = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 12:
                this.image8 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 13:
                this.image8ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 14:
                this.image8Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 15:
                this.AmbientContainer4 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 16:
                this.Ambient4 = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 17:
                this.DirectionalContainer4 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 18:
                this.Directional4 = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 19:
                this.image7 = ((System.Windows.Controls.Image)(target));
                return;

            case 20:
                this.image6 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 21:
                this.image6ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 22:
                this.image6Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 23:
                this.AmbientContainer3 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 24:
                this.Ambient3 = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 25:
                this.DirectionalContainer3 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 26:
                this.Directional3 = ((System.Windows.Media.Media3D.PointLight)(target));
                return;

            case 27:
                this.image5 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 28:
                this.image5ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 29:
                this.image5Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 30:
                this.AmbientContainer2 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 31:
                this.Ambient2 = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 32:
                this.DirectionalContainer2 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 33:
                this.Directional2 = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 34:
                this.image4 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 35:
                this.image4ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 36:
                this.image4Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 37:
                this.AmbientContainer1 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 38:
                this.Ambient1 = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 39:
                this.DirectionalContainer1 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 40:
                this.Directional1 = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 41:
                this.image3 = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 42:
                this.orthographicCamera = ((System.Windows.Media.Media3D.OrthographicCamera)(target));
                return;

            case 43:
                this.image3ModelContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 44:
                this.image3Model = ((System.Windows.Media.Media3D.GeometryModel3D)(target));
                return;

            case 45:
                this.AmbientContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 46:
                this.Ambient = ((System.Windows.Media.Media3D.AmbientLight)(target));
                return;

            case 47:
                this.DirectionalContainer = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 48:
                this.Directional = ((System.Windows.Media.Media3D.DirectionalLight)(target));
                return;

            case 49:
                this.image2 = ((System.Windows.Controls.Image)(target));
                return;

            case 50:
                this.image1 = ((System.Windows.Controls.Image)(target));
                return;

            case 51:
                this.rectangle1 = ((System.Windows.Shapes.Rectangle)(target));

            #line 732 "..\..\MainWindow.xaml"
                this.rectangle1.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Rectangle_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 52:
                this.rectangle2 = ((System.Windows.Shapes.Rectangle)(target));

            #line 745 "..\..\MainWindow.xaml"
                this.rectangle2.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Rectangle_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 53:
                this.rectangle3 = ((System.Windows.Shapes.Rectangle)(target));

            #line 758 "..\..\MainWindow.xaml"
                this.rectangle3.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.Rectangle_MouseLeftButtonDown);

            #line default
            #line hidden
                return;

            case 54:
                this.textblock1 = ((System.Windows.Controls.TextBlock)(target));
                return;
            }
            this._contentLoaded = true;
        }
Beispiel #17
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 4 "..\..\Window1.xaml"
                ((WPFChart3D.Window1)(target)).KeyDown += new System.Windows.Input.KeyEventHandler(this.OnKeyDown);

            #line default
            #line hidden
                return;

            case 2:
                this.mygrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 3:
                this.mainViewport = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 4:
                this.camera = ((System.Windows.Media.Media3D.OrthographicCamera)(target));
                return;

            case 5:
                this.Light1 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 6:
                this.Light2 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 7:
                this.Light3 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 8:
                this.canvasOn3D = ((System.Windows.Controls.Canvas)(target));

            #line 53 "..\..\Window1.xaml"
                this.canvasOn3D.MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.OnViewportMouseUp);

            #line default
            #line hidden

            #line 54 "..\..\Window1.xaml"
                this.canvasOn3D.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.OnViewportMouseDown);

            #line default
            #line hidden

            #line 55 "..\..\Window1.xaml"
                this.canvasOn3D.MouseMove += new System.Windows.Input.MouseEventHandler(this.OnViewportMouseMove);

            #line default
            #line hidden
                return;

            case 9:
                this.label = ((System.Windows.Controls.Label)(target));
                return;

            case 10:
                this.statusPane = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 11:
                this.controlPane = ((System.Windows.Controls.Canvas)(target));
                return;
            }
            this._contentLoaded = true;
        }
 //Toggle between camera projections.
 public void ToggleCamera(object sender, EventArgs e)
 {
     if ((bool)CameraCheck.IsChecked == true)
     {
         OrthographicCamera myOCamera = new OrthographicCamera(new Point3D(0, 0, -3), new Vector3D(0, 0, 1), new Vector3D(0, 1, 0), 3);
         myViewport.Camera = myOCamera;
     }
     if ((bool)CameraCheck.IsChecked != true)
     {
         PerspectiveCamera myPCamera = new PerspectiveCamera(new Point3D(0, 0, -3), new Vector3D(0, 0, 1), new Vector3D(0, 1, 0), 50);
         myViewport.Camera = myPCamera;
     }
 }
Beispiel #19
0
        private static Matrix3D GetProjectionMatrix(OrthographicCamera camera, double aspectRatio)
        {
            Debug.Assert(camera != null,
                "Caller needs to ensure camera is non-null.");

            // This math is identical to what you find documented for
            // D3DXMatrixOrthoRH with the exception that in WPF only
            // the camera's width is specified.  Height is calculated
            // from width and the aspect ratio.

            double w = camera.Width;
            double h = w / aspectRatio;
            double zn = camera.NearPlaneDistance;
            double zf = camera.FarPlaneDistance;

            double m33 = 1 / (zn - zf);
            double m43 = zn * m33;

            return new Matrix3D(
                2 / w, 0, 0, 0,
                  0, 2 / h, 0, 0,
                  0, 0, m33, 0,
                  0, 0, m43, 1);
        }
        /// <summary>
        /// Creates preview of this control (automatically setup the camera)
        /// </summary>
        public void CreatePreview(RenderTargetBitmap renderTargetBitmap)
        {
            bool wasDetached = !dataAttached;
            AttachData();

            if (moleculesContainer.Children.Count == 0)
            {
                if (wasDetached) DetachData();
                return;
            }

            ProjectionCamera backupCamera = camera;
            Double backupWidth = Width;
            Double backupHeight = Height;

            // Change size of the visualizer
            Width = renderTargetBitmap.PixelWidth;
            Height = renderTargetBitmap.PixelHeight;
            Measure(new Size(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight));
            Arrange(new Rect(0, 0, renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight));

            // Change camera
            // Prepare bounding box
            Rect3D boundingBox = VisualTreeHelper.GetDescendantBounds(moleculesContainer);
            if (boundingBox.IsEmpty)
            {
                renderTargetBitmap.Render(this);
                boundingBox = VisualTreeHelper.GetDescendantBounds(moleculesContainer);
                if (boundingBox.IsEmpty) return;
            }
            OrthographicCamera orthographicCamera = new OrthographicCamera();

            #region Accomodate camera to fit content

            if (boundingBox.SizeZ < boundingBox.SizeX && boundingBox.SizeZ < boundingBox.SizeY)
            {
                orthographicCamera.Position = new Point3D(boundingBox.Location.X + boundingBox.SizeX / 2.0,
                                                          boundingBox.Location.Y + boundingBox.SizeY / 2.0,
                                                          boundingBox.Location.Z);
                orthographicCamera.LookDirection = new Vector3D(0, 0, 1);
                orthographicCamera.UpDirection = new Vector3D(0, 1, 0);
                orthographicCamera.Width = Math.Max(boundingBox.SizeX, boundingBox.SizeY) * (Width / Height);

            }
            else if (boundingBox.SizeX < boundingBox.SizeZ && boundingBox.SizeX < boundingBox.SizeY)
            {
                orthographicCamera.Position = new Point3D(boundingBox.Location.X,
                                                          boundingBox.Location.Y + boundingBox.SizeY / 2.0,
                                                          boundingBox.Location.Z + boundingBox.SizeZ / 2.0);
                orthographicCamera.LookDirection = new Vector3D(1, 0, 0);
                orthographicCamera.UpDirection = new Vector3D(0, 1, 0);
                orthographicCamera.Width = Math.Max(boundingBox.SizeY, boundingBox.SizeZ);
            }
            else
            {
                orthographicCamera.Position = new Point3D(boundingBox.Location.X + boundingBox.SizeX / 2.0,
                                                          boundingBox.Location.Y,
                                                          boundingBox.Location.Z + boundingBox.SizeZ / 2.0);
                orthographicCamera.LookDirection = new Vector3D(0, 1, 0);
                orthographicCamera.UpDirection = new Vector3D(1, 0, 0);
                orthographicCamera.Width = Math.Max(boundingBox.SizeX, boundingBox.SizeZ);
            }

            #endregion

            orthographicCamera.NearPlaneDistance = 0;

            // Set the camera & correct lights
            viewport.Camera = orthographicCamera;
            lightFromEyes.Direction = orthographicCamera.LookDirection;
            RenderOptions.SetEdgeMode(this, EdgeMode.Unspecified);
            UpdateLayout();
            renderTargetBitmap.Render(this);

            // Restore original values of the properties
            viewport.Camera = camera = backupCamera;
            Width = backupWidth;
            Height = backupHeight;

            if (wasDetached) DetachData();
        }
Beispiel #21
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.mainViewport = ((System.Windows.Controls.Viewport3D)(target));
                return;

            case 2:
                this.camera = ((System.Windows.Media.Media3D.OrthographicCamera)(target));
                return;

            case 3:
                this.Light1 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 4:
                this.Light2 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 5:
                this.Light3 = ((System.Windows.Media.Media3D.ModelVisual3D)(target));
                return;

            case 6:
                this.canvasOn3D = ((System.Windows.Controls.Canvas)(target));

            #line 55 "..\..\3DWindow.xaml"
                this.canvasOn3D.MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.OnViewportMouseUp);

            #line default
            #line hidden

            #line 56 "..\..\3DWindow.xaml"
                this.canvasOn3D.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.OnViewportMouseDown);

            #line default
            #line hidden

            #line 57 "..\..\3DWindow.xaml"
                this.canvasOn3D.MouseMove += new System.Windows.Input.MouseEventHandler(this.OnViewportMouseMove);

            #line default
            #line hidden
                return;

            case 7:
                this.controlPane = ((System.Windows.Controls.Canvas)(target));
                return;

            case 8:
                this.comboBoxX = ((System.Windows.Controls.ComboBox)(target));
                return;

            case 9:
                this.comboBoxY = ((System.Windows.Controls.ComboBox)(target));
                return;

            case 10:
                this.comboBoxZ = ((System.Windows.Controls.ComboBox)(target));
                return;

            case 11:
                this.draw3DButton = ((System.Windows.Controls.Button)(target));

            #line 82 "..\..\3DWindow.xaml"
                this.draw3DButton.Click += new System.Windows.RoutedEventHandler(this.Draw3DButton_Click);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _worldModels = GetTemplateChild("PART_WorldModels") as Model3DGroup;
            _camera = GetTemplateChild("PART_Camera") as OrthographicCamera;
            _world = GetTemplateChild("PART_World") as Viewport3D;

            _frameTimer = new System.Windows.Threading.DispatcherTimer();
            _frameTimer.Tick += OnFrame;
            _frameTimer.Interval = TimeSpan.FromSeconds(1.0 / 45.0);
            _frameTimer.Start();

            this._lastTick = Environment.TickCount;

            _pm = new ParticleSystemManager();

            this._worldModels.Children.Add(_pm.CreateParticleSystem(1000, Colors.Gray, ImageSource));
            this._worldModels.Children.Add(_pm.CreateParticleSystem(1000, Colors.Red, ImageSource));
            this._worldModels.Children.Add(_pm.CreateParticleSystem(1000, Colors.Silver, ImageSource));
            this._worldModels.Children.Add(_pm.CreateParticleSystem(1000, Colors.OldLace, ImageSource));
            this._worldModels.Children.Add(_pm.CreateParticleSystem(1000, Colors.YellowGreen, ImageSource));
            this._worldModels.Children.Add(_pm.CreateParticleSystem(1000, Colors.Orange, ImageSource));

            _rand = new Random(this.GetHashCode());
        }