コード例 #1
0
ファイル: LineSurface.cs プロジェクト: darwin/silverstunts
        public bool IsRectangleColliding( RectangleParticle p )
        {
            p.GetCardYProjection();
            double depthY = TestIntervals( p.BMin, p.BMax, minY, maxY );
            if ( depthY == 0 ) return false;

            p.GetCardXProjection();
            double depthX = TestIntervals( p.BMin, p.BMax, minX, maxX );
            if ( depthX == 0 ) return false;

            p.GetAxisProjection( sideNormal );
            double depthS = TestIntervals( p.BMin, p.BMax, minS, maxS );
            if ( depthS == 0 ) return false;

            p.GetAxisProjection( faceNormal );
            double depthF = TestIntervals( p.BMin, p.BMax, minF, maxF );
            if ( depthF == 0 ) return false;

            double absX = Math.Abs( depthX );
            double absY = Math.Abs( depthY );
            double absS = Math.Abs( depthS );
            double absF = Math.Abs( depthF );

            if ( absX <= absY && absX <= absS && absX <= absF )
            {
                p.MTD.Set( depthX, 0 );
                collNormal.Set( p.MTD.X / absX, 0 );
            }
            else if ( absY <= absX && absY <= absS && absY <= absF )
            {
                p.MTD.Set( 0, depthY );
                collNormal.Set( 0, p.MTD.Y / absY );
            }
            else if ( absF <= absX && absF <= absY && absF <= absS )
            {
                p.MTD = faceNormal.MultNew( depthF );
                collNormal.Copy( faceNormal );
            }
            else if ( absS <= absX && absS <= absY && absS <= absF )
            {
                p.MTD = sideNormal.MultNew( depthS );
                collNormal.Copy( sideNormal );
            }

            return true;
        }
コード例 #2
0
        public bool IsRectangleColliding( RectangleParticle p )
        {
            p.GetCardXProjection();
            double depthX = TestIntervals( p.BMin, p.BMax, minX, maxX );
            if ( depthX == 0 ) return false;

            p.GetCardYProjection();
            double depthY = TestIntervals( p.BMin, p.BMax, minY, maxY );
            if ( depthY == 0 ) return false;

            p.SetXYMTD( depthX, depthY );
            normal.Set( p.MTD.X / Math.Abs( depthX ), p.MTD.Y / Math.Abs( depthY ) );
            return true;
        }
コード例 #3
0
ファイル: CircleSurface.cs プロジェクト: darwin/silverstunts
        // TBD: This method is basically identical to the isCircleColliding of the
        // RectangleSurface class. Need some type of CollisionResolver class to handle
        // all collisions and move responsibility away from the Surface classes.
        public bool IsRectangleColliding( RectangleParticle p )
        {
            p.GetCardXProjection();
            double depthX = TestIntervals( p.BMin, p.BMax, minX, maxX );
            if ( depthX == 0 ) return false;

            p.GetCardYProjection();
            double depthY = TestIntervals( p.BMin, p.BMax, minY, maxY );
            if ( depthY == 0 ) return false;

            // determine if the circle's center is in a vertex voronoi region
            bool isInVertexX = Math.Abs( depthX ) < radius;
            bool isInVertexY = Math.Abs( depthY ) < radius;

            if ( isInVertexX && isInVertexY )
            {
                // get the closest vertex
                double vx = p.Curr.X + Sign( center.X - p.Curr.X ) * ( p.Width / 2 );
                double vy = p.Curr.Y + Sign( center.Y - p.Curr.Y ) * ( p.Height / 2 );
                p.Vertex.Set( vx, vy );

                // get the distance from the vertex to circle center
                double dx = p.Vertex.X - center.X;
                double dy = p.Vertex.Y - center.Y;
                double mag = Math.Sqrt( dx * dx + dy * dy );
                double pen = radius - mag;

                // if there is a collision in one of the vertex regions
                if ( pen > 0 )
                {
                    dx /= mag;
                    dy /= mag;
                    p.MTD.Set( dx * pen, dy * pen );
                    normal.Set( dx, dy );
                    return true;
                }
                return false;
            }
            else
            {
                // collision on one of the 4 edges
                p.SetXYMTD( depthX, depthY );
                normal.Set( p.MTD.X / Math.Abs( depthX ), p.MTD.Y / Math.Abs( depthY ) );
                return true;
            }
        }