当前位置: 首页>>代码示例>>C#>>正文


C# LineSegment.IntersectsWith方法代码示例

本文整理汇总了C#中LineSegment.IntersectsWith方法的典型用法代码示例。如果您正苦于以下问题:C# LineSegment.IntersectsWith方法的具体用法?C# LineSegment.IntersectsWith怎么用?C# LineSegment.IntersectsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LineSegment的用法示例。


在下文中一共展示了LineSegment.IntersectsWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IntersectsWith

 public void IntersectsWith()
 {
     var line1 = new LineSegment(new Point(0, 0), new Point(1, 0));
     var line2 = new LineSegment(new Point(1, 1), new Point(2, 1));
     Assert.IsFalse(line1.IntersectsWith(line2), "collinear");
     var line3 = new LineSegment(new Point(1, 1), new Point(0, 0));
     Assert.IsTrue(line1.IntersectsWith(line3), "intersecting");
     var line4 = new LineSegment(new Point(1, 1), new Point(-1, 0));
     Assert.IsFalse(line1.IntersectsWith(line4), "intersection is outside segment");
 }
开发者ID:chantsunman,项目名称:helix-toolkit,代码行数:10,代码来源:LineSegmentTests.cs

示例2: CircleBoxCollisionHandling

        private void CircleBoxCollisionHandling(GameTime gameTime, Ball other)
        {
            //Safety check.
            if (other == null)
            {
                return;
            }

            //Put the circle back according the velocity.
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
            other.Position -= other.Velocity * dt;

            if (other is Player.PlayerBall && other.CircleBoxCollision(this))
            {
                other.Position -= other.Velocity * dt;
            }

            //Calculate the connectionline.
            LineSegment connectionLine = new LineSegment(Position, other.Position);

            //Get each point.
            Vector2 p1 = Position - HalfSize;
            Vector2 p2 = new Vector2(Position.X + HalfSize.X, Position.Y - HalfSize.Y);
            Vector2 p3 = Position + HalfSize;
            Vector2 p4 = new Vector2(Position.X - HalfSize.X, Position.Y + HalfSize.Y);

            //Fill an array with all lines.
            LineSegment[] lines = new LineSegment[4];
            lines[0] = new LineSegment(p1, p2);
            lines[1] = new LineSegment(p2, p3);
            lines[2] = new LineSegment(p3, p4);
            lines[3] = new LineSegment(p4, p1);

            //Get the vector in which we reflect the velocity;
            Vector2 reflectionVec = Vector2.Zero;

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].IntersectsWith(connectionLine) &&
                    connectionLine.IntersectsWith(lines[i]))
                {
                    reflectionVec = lines[i].Direction();

                    //Is the other a ScoreBall?
                    if (other is ScoreBall)
                    {
                        //Is this a vertical collision?
                        reflectionVec.Normalize();
                        float dot = Math.Abs(Vector2.Dot(reflectionVec, Vector2.UnitY));

                        const float dotBorder = 0.5f;

                        if (dot > dotBorder)
                        {
                            //Reverse the x movement.
                            ScoreBall temp = other as ScoreBall;
                            temp.ReverseXMovement();
                        }
                        else
                        {
                            //Reverse the y movement.
                            ScoreBall temp = other as ScoreBall;
                            temp.ReverseYMovement();
                        }
                    }

                }
            }

            //Reflect the velocity.
            other.Velocity = Vector2.Reflect(other.Velocity, reflectionVec);
        }
开发者ID:Whojoo,项目名称:Bubble-popper,代码行数:72,代码来源:Wall.cs


注:本文中的LineSegment.IntersectsWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。