/// <summary>
        /// Called when a edge list is finished
        /// </summary>
        protected override void OnFinished( Point3[] points, bool loop )
        {
            try
            {
                LevelGeometry level = LevelGeometry.FromCurrentScene( );

                Point2[] points2 = new Point2[ points.Length ];
                for ( int ptIndex = 0; ptIndex < points.Length; ++ptIndex )
                {
                    points2[ ptIndex ] = new Point2( points[ ptIndex ].X, points[ ptIndex ].Z );
                }

                UiPolygon brush = new UiPolygon( "", points2 );
                level.Add( brush, false, false );

                AppLog.Info( "Combined brush with current level geometry" );
            }
            catch ( Exception ex )
            {
                AppLog.Exception( ex, "Failed to combine brush with current level geometry" );
                ErrorMessageBox.Show( Resources.FailedToCombineCsgBrush );
            }
        }
예제 #2
0
        /// <summary>
        /// Builds a BSP tree from a CSG brush
        /// </summary>
        private static BspNode Build( UiPolygon brush, bool reverse )
        {
            Point2[] points = brush.Points;
            if ( reverse )
            {
                Array.Reverse( points );
            }

            //	Create edges
            List< Edge > sourceEdges = new List< Edge >( points.Length );
            for ( int ptIndex = 0; ptIndex < points.Length; ++ptIndex )
            {
                Edge edge = new Edge( points[ ptIndex ], points[ ( ptIndex + 1 ) % points.Length ] );
                sourceEdges.Add( edge );
            }

            //	Build the BSP tree from the edge list
            BspNode node = BuildNode( null, sourceEdges );

            return node;
        }
예제 #3
0
 /// <summary>
 /// Combines a brush with the current geometry set
 /// </summary>
 /// <param name="op">CSG operation</param>
 /// <param name="brush">Brush to add to the level geometry</param>
 /// <exception cref="InvalidOperationException">Thrown by convex region builder if BSP tree is internally invalid</exception>
 public void Combine( Operation op, UiPolygon brush )
 {
     BspNode brushBsp = Build( brush, op == Operation.Complement );
     BspNode newRoot = null;
     if ( m_Root == null )
     {
         if ( op == Operation.Union || op == Operation.EdgeUnion )
         {
             newRoot = brushBsp;
         }
     }
     else
     {
         newRoot = Combine( op, m_Root, brushBsp );
     }
     if ( newRoot != null )
     {
         FixUpDoubleSidedNodes( newRoot );
         BuildConvexRegions( newRoot );
         m_Root = newRoot;
     }
     if ( GeometryChanged != null )
     {
         GeometryChanged( this, null );
     }
 }
        private void AddCircleToLevelGeometry( LevelGeometry geometry )
        {
            try
            {
                Point2[] points2 = new Point2[ EdgeCount ];

                float angle = m_AngleStart;
                float angleIncrement = Constants.TwoPi / EdgeCount;
                for ( int ptIndex = 0; ptIndex < EdgeCount; ++ptIndex )
                {
                    float x = m_CentrePoint.X + Functions.Sin( angle ) * m_Radius;
                    float y = m_CentrePoint.Z + Functions.Cos( angle ) * m_Radius;

                    points2[ ptIndex ] = new Point2( x, y );

                    angle += angleIncrement;
                    if ( angle > Constants.TwoPi )
                    {
                        angle -= Constants.TwoPi;
                    }
                }

                UiPolygon brush = new UiPolygon( "", points2 );
                geometry.Add( brush, false, false );
                AppLog.Info( "Combined brush with current level geometry" );
            }
            catch ( Exception ex )
            {
                AppLog.Exception( ex, "Failed to combine circle brush with current level geometry" );
                ErrorMessageBox.Show( Resources.FailedToCombineCsgBrush );
            }

            m_DefiningRadius = false;
        }