예제 #1
0
/*        /// <summary>
 *      /// Render 2D scene
 *      /// </summary>
 *      /// <param name="tree">BSP tree</param>
 *      /// <param name="camera">Camera</param>
 *      /// <param name="frustum">View frustum</param>
 *      /// <param name="depthPlanes">Depth planes</param>
 *      private void Render2D( BSPTree tree, IList<IBSPItem> items, Point3D cameraPos, Matrix3D displayMatrix, Frustum frustum, DepthPlanes depthPlanes )
 *      {
 *          int index = 0;
 *          bool clipFade = ClipFade;
 *
 *          foreach ( BSPCube cube in items )
 *          {
 *              ContainmentType type = frustum.Contains( cube.Bounds );
 *
 *              if ( type != ContainmentType.Disjoint
 *                  && ( clipFade || type != ContainmentType.Intersects )
 *                  && depthPlanes.Includes( cube.Position ) )
 *              {
 *                  Sphere sphere;
 *
 *                  if ( index < canvas.Children.Count ) sphere = canvas.Children[ index ] as Sphere;
 *                  else canvas.Children.Add( sphere = new Sphere() );
 *
 *                  sphere.Visibility = Visibility.Visible;
 *                  sphere.RenderTransform = new MatrixTransform( cube.SphereMatrix( cameraPos, displayMatrix ) );
 *                  sphere.Brush = ( cube.MaterialOffset >= 0.5 ) ? SphereBrush : SelectedSphereBrush;
 *                  sphere.Opacity = Math.Abs( 0.5 - cube.MaterialOffset ) * 2;
 *
 *                  if ( type == ContainmentType.Intersects ) sphere.Opacity *= 0.2;
 *
 ++index;
 *              }
 *          }
 *
 *          while ( index < canvas.Children.Count ) canvas.Children[ index++ ].Visibility = Visibility.Hidden;
 *      }
 */
        /// <summary>
        /// Recursively render tree
        /// </summary>
        /// <param name="tree">Tree node</param>
        private void RenderTree(BSPTree tree, IList <IBSPItem> items, Point3D cameraPos, Frustum frustum, DepthPlanes depthPlanes)
        {
            bool limitDepth = LimitDepth;

            if (tree != null && frustum.Contains(tree.Bounds) != ContainmentType.Disjoint &&
                (!limitDepth || depthPlanes.Includes(tree.Bounds)))
            {
                Halfspace halfspace = tree.Partition.Classify(cameraPos);

                if (halfspace == Halfspace.Negative)
                {
                    if (tree.Front != null)
                    {
                        RenderTree(tree.Front, items, cameraPos, frustum, depthPlanes);
                    }
                }
                else if (tree.Back != null)
                {
                    RenderTree(tree.Back, items, cameraPos, frustum, depthPlanes);
                }

                foreach (IBSPItem item in tree.Items)
                {
                    items.Add(item);
                }

                if (halfspace == Halfspace.Negative)
                {
                    if (tree.Back != null)
                    {
                        RenderTree(tree.Back, items, cameraPos, frustum, depthPlanes);
                    }
                }
                else if (tree.Front != null)
                {
                    RenderTree(tree.Front, items, cameraPos, frustum, depthPlanes);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Render 3D scene
        /// </summary>
        /// <param name="tree">BSP tree</param>
        /// <param name="camera">Camera</param>
        /// <param name="frustum">View frustum</param>
        /// <param name="depthPlanes">Depth planes</param>
        private void Render3D(BSPTree tree, IList <IBSPItem> items, Point3D cameraPos, Matrix3D displayMatrix, Frustum frustum, DepthPlanes depthPlanes)
        {
            bool clipFade   = ClipFade;
            bool showCubes  = ShowCubes;
            bool limitDepth = LimitDepth;

            MeshGeometry3D thumbnailMesh = new MeshGeometry3D();
            MeshGeometry3D mesh          = new MeshGeometry3D();

            //MeshGeometry3D flatMesh = new MeshGeometry3D();

//			List<BSPCube> renderItems = new List<BSPCube>();

            foreach (BSPCube cube in items)
            {
                ContainmentType type = frustum.Contains(cube.Bounds);

                if (type != ContainmentType.Disjoint &&
                    (clipFade || type != ContainmentType.Intersects) &&
                    (!limitDepth || depthPlanes.Includes(cube.Position)))
                {
                    double alpha = (type == ContainmentType.Intersects) ? 0.2 : 1.0;

                    if (!string.IsNullOrEmpty(cube.Url) || EmptyImages)
                    {
                        cube.RenderThumbnail(thumbnailMesh, cameraPos, alpha, displayMatrix, thumbnails);
                    }

                    if (showCubes)
                    {
                        cube.Render(mesh, cameraPos, alpha);
                    }
                    //cube.RenderFlat( flatMesh, cameraPos, displayMatrix, new Rect( 0, 0, 0.5, 1 ) );
                }
            }

            geometry.Geometry          = mesh;
            thumbnailGeometry.Geometry = thumbnailMesh;
            //flatGeometry.Geometry = flatMesh;
        }
예제 #3
0
        /// <summary>
        /// Rendering
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event arguments</param>
        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            Quaternion q = Quaternion.Identity;

            if (Keyboard.IsKeyDown(Key.Left))
            {
                q *= new Quaternion(new Vector3D(0, 3, 0), 5);
            }
            if (Keyboard.IsKeyDown(Key.Right))
            {
                q *= new Quaternion(new Vector3D(0, 3, 0), -5);
            }
            if (Keyboard.IsKeyDown(Key.Up))
            {
                q *= new Quaternion(new Vector3D(3, 0, 0), 5);
            }
            ;
            if (Keyboard.IsKeyDown(Key.Down))
            {
                q *= new Quaternion(new Vector3D(3, 0, 0), -5);
            }

            /*
             *
             *          Vector3D l = camera.Transform.Transform( camera.LookDirection );
             *          Matrix3D rotateLeft = new Matrix3D();
             *          rotateLeft.Rotate( new Quaternion( new Vector3D( 0, 3, 0 ), 90 ) );
             *
             *          if ( Keyboard.IsKeyDown( Key.Up ) ) FPSCamera( l * 0.05 );
             *          if ( Keyboard.IsKeyDown( Key.Down ) ) FPSCamera( -l * 0.05 );
             *          if ( Keyboard.IsKeyDown( Key.Left ) ) FPSCamera( rotateLeft.Transform( l ) * 0.05 );
             *          if ( Keyboard.IsKeyDown( Key.Right ) ) FPSCamera( -rotateLeft.Transform( l ) * 0.05 );
             */

            if (!q.IsIdentity)
            {
                AxisAngleRotation3D rotation = trackball.Rotation;
                Quaternion          newQ     = new Quaternion(rotation.Axis, rotation.Angle) * q;

                rotation.Axis  = newQ.Axis;
                rotation.Angle = newQ.Angle;
            }

            if (cameraChanged && tree != null)
            {
                cameraChanged = false;

                MatrixCamera matrixCamera         = FactCubeCamera.CreateMatrixCamera(camera, ActualWidth, ActualHeight, 0.01, 3);
                Matrix3D     viewProjectionMatrix = matrixCamera.ViewMatrix * matrixCamera.ProjectionMatrix;

                Frustum     frustum     = new Frustum(viewProjectionMatrix, true);
                DepthPlanes depthPlanes = new DepthPlanes(camera, tree.Bounds, 1d / (dimensionSize - 1));

                Point3D cameraPos = camera.Transform.Transform(camera.Position);

                List <IBSPItem> items = new List <IBSPItem>();
                RenderTree(tree, items, cameraPos, frustum, depthPlanes);

                Matrix3D displayMatrix = viewProjectionMatrix
                                         * FactCubeCamera.GetHomogeneousToViewportTransform3D(ActualWidth, ActualHeight);

                //canvas.Children.Clear();
                Render3D(tree, items, cameraPos, displayMatrix, frustum, depthPlanes);
            }
        }
예제 #4
0
/*        /// <summary>
        /// Render 2D scene
        /// </summary>
        /// <param name="tree">BSP tree</param>
        /// <param name="camera">Camera</param>
        /// <param name="frustum">View frustum</param>
        /// <param name="depthPlanes">Depth planes</param>
        private void Render2D( BSPTree tree, IList<IBSPItem> items, Point3D cameraPos, Matrix3D displayMatrix, Frustum frustum, DepthPlanes depthPlanes )
        {
            int index = 0;
            bool clipFade = ClipFade;

            foreach ( BSPCube cube in items )
            {
                ContainmentType type = frustum.Contains( cube.Bounds );

                if ( type != ContainmentType.Disjoint
                    && ( clipFade || type != ContainmentType.Intersects )
                    && depthPlanes.Includes( cube.Position ) )
                {
                    Sphere sphere;

                    if ( index < canvas.Children.Count ) sphere = canvas.Children[ index ] as Sphere;
                    else canvas.Children.Add( sphere = new Sphere() );

                    sphere.Visibility = Visibility.Visible;
                    sphere.RenderTransform = new MatrixTransform( cube.SphereMatrix( cameraPos, displayMatrix ) );
                    sphere.Brush = ( cube.MaterialOffset >= 0.5 ) ? SphereBrush : SelectedSphereBrush;
                    sphere.Opacity = Math.Abs( 0.5 - cube.MaterialOffset ) * 2;

                    if ( type == ContainmentType.Intersects ) sphere.Opacity *= 0.2;

                    ++index;
                }
            }

            while ( index < canvas.Children.Count ) canvas.Children[ index++ ].Visibility = Visibility.Hidden;
        }
*/
		/// <summary>
		/// Recursively render tree
		/// </summary>
		/// <param name="tree">Tree node</param>
		private void RenderTree( BSPTree tree, IList<IBSPItem> items, Point3D cameraPos, Frustum frustum, DepthPlanes depthPlanes )
		{
			bool limitDepth = LimitDepth;

			if ( tree != null && frustum.Contains( tree.Bounds ) != ContainmentType.Disjoint
				&& ( !limitDepth || depthPlanes.Includes( tree.Bounds ) ) )
			{
				Halfspace halfspace = tree.Partition.Classify( cameraPos );

                if ( halfspace == Halfspace.Negative ) { if ( tree.Front != null ) RenderTree( tree.Front, items, cameraPos, frustum, depthPlanes ); }
                else if ( tree.Back != null ) RenderTree( tree.Back, items, cameraPos, frustum, depthPlanes );

				foreach ( IBSPItem item in tree.Items ) items.Add( item );

                if ( halfspace == Halfspace.Negative ) { if ( tree.Back != null ) RenderTree( tree.Back, items, cameraPos, frustum, depthPlanes ); }
                else if ( tree.Front != null ) RenderTree( tree.Front, items, cameraPos, frustum, depthPlanes );
			}
		}
예제 #5
0
        /// <summary>
        /// Render 3D scene
        /// </summary>
        /// <param name="tree">BSP tree</param>
        /// <param name="camera">Camera</param>
        /// <param name="frustum">View frustum</param>
        /// <param name="depthPlanes">Depth planes</param>
        private void Render3D( BSPTree tree, IList<IBSPItem> items, Point3D cameraPos, Matrix3D displayMatrix, Frustum frustum, DepthPlanes depthPlanes )
        {
			bool clipFade = ClipFade;
			bool showCubes = ShowCubes;
			bool limitDepth = LimitDepth;

			MeshGeometry3D thumbnailMesh = new MeshGeometry3D();
			MeshGeometry3D mesh = new MeshGeometry3D();
			//MeshGeometry3D flatMesh = new MeshGeometry3D();

//			List<BSPCube> renderItems = new List<BSPCube>();

            foreach ( BSPCube cube in items )
            {
                ContainmentType type = frustum.Contains( cube.Bounds );

                if ( type != ContainmentType.Disjoint
                    && ( clipFade || type != ContainmentType.Intersects )
                    && ( !limitDepth || depthPlanes.Includes( cube.Position ) ) )
                {
					double alpha = ( type == ContainmentType.Intersects ) ? 0.2 : 1.0;

					if ( !string.IsNullOrEmpty( cube.Url ) || EmptyImages )
					{
						cube.RenderThumbnail( thumbnailMesh, cameraPos, alpha, displayMatrix, thumbnails );
					}

					if ( showCubes ) cube.Render( mesh, cameraPos, alpha );
					//cube.RenderFlat( flatMesh, cameraPos, displayMatrix, new Rect( 0, 0, 0.5, 1 ) );
				}
            }

            geometry.Geometry = mesh;
			thumbnailGeometry.Geometry = thumbnailMesh;
			//flatGeometry.Geometry = flatMesh;
		}
예제 #6
0
		/// <summary>
		/// Rendering
		/// </summary>
		/// <param name="sender">Sender</param>
		/// <param name="e">Event arguments</param>
		void CompositionTarget_Rendering( object sender, EventArgs e )
		{
            Quaternion q = Quaternion.Identity;

            if ( Keyboard.IsKeyDown( Key.Left ) ) q *= new Quaternion( new Vector3D( 0, 3, 0 ), 5 );
            if ( Keyboard.IsKeyDown( Key.Right ) ) q *= new Quaternion( new Vector3D( 0, 3, 0 ), -5 );
            if ( Keyboard.IsKeyDown( Key.Up ) ) q *= new Quaternion( new Vector3D( 3, 0, 0 ), 5 ); ;
            if ( Keyboard.IsKeyDown( Key.Down ) ) q *= new Quaternion( new Vector3D( 3, 0, 0 ), -5 );
            /*

                        Vector3D l = camera.Transform.Transform( camera.LookDirection );
                        Matrix3D rotateLeft = new Matrix3D();
                        rotateLeft.Rotate( new Quaternion( new Vector3D( 0, 3, 0 ), 90 ) );

                        if ( Keyboard.IsKeyDown( Key.Up ) ) FPSCamera( l * 0.05 );
                        if ( Keyboard.IsKeyDown( Key.Down ) ) FPSCamera( -l * 0.05 );
                        if ( Keyboard.IsKeyDown( Key.Left ) ) FPSCamera( rotateLeft.Transform( l ) * 0.05 );
                        if ( Keyboard.IsKeyDown( Key.Right ) ) FPSCamera( -rotateLeft.Transform( l ) * 0.05 );
            */

            if ( !q.IsIdentity )
            {
                AxisAngleRotation3D rotation = trackball.Rotation;
                Quaternion newQ = new Quaternion( rotation.Axis, rotation.Angle ) * q;

                rotation.Axis = newQ.Axis;
                rotation.Angle = newQ.Angle;
            }

			if ( cameraChanged && tree != null )
			{
				cameraChanged = false;

				MatrixCamera matrixCamera = FactCubeCamera.CreateMatrixCamera( camera, ActualWidth, ActualHeight, 0.01, 3 );
				Matrix3D viewProjectionMatrix = matrixCamera.ViewMatrix * matrixCamera.ProjectionMatrix;

				Frustum frustum = new Frustum( viewProjectionMatrix, true );
                DepthPlanes depthPlanes = new DepthPlanes( camera, tree.Bounds, 1d / ( dimensionSize - 1 ) );

                Point3D cameraPos = camera.Transform.Transform( camera.Position );

                List<IBSPItem> items = new List<IBSPItem>();
                RenderTree( tree, items, cameraPos, frustum, depthPlanes );

				Matrix3D displayMatrix = viewProjectionMatrix
					* FactCubeCamera.GetHomogeneousToViewportTransform3D( ActualWidth, ActualHeight );

                //canvas.Children.Clear();
                Render3D( tree, items, cameraPos, displayMatrix, frustum, depthPlanes );
			}
		}