Esempio n. 1
0
    public void Reset()
    {
        left  = points[0].x;
        right = points[0].x;
        up    = points[0].y;
        down  = points[0].y;

        for (int i = 0; i < points.Length; i++)
        {
            if (this[i].x < left)
            {
                left = this[i].x;
            }
            if (this[i].x > right)
            {
                right = this[i].x;
            }
            if (this[i].y < down)
            {
                down = this[i].y;
            }
            if (this[i].y > up)
            {
                up = this[i].y;
            }
        }

        width  = FixedMath.Max(FixedMath.Abs(left), FixedMath.Abs(right)) * 2;
        height = FixedMath.Max(FixedMath.Abs(down), FixedMath.Abs(up)) * 2;
    }
Esempio n. 2
0
    public void Normal()
    {
        if (FixedMath.Abs(direction.GetRotationAngle(new Vector2d(1, 0))) < 1)
        {
            direction  = new Vector2d(1, 0);
            isStandard = true;
        }

        if (FixedMath.Abs(direction.GetRotationAngle(new Vector2d(-1, 0))) < 1)
        {
            direction  = new Vector2d(1, 0);
            isStandard = true;
        }

        if (FixedMath.Abs(direction.GetRotationAngle(new Vector2d(0, 1))) < 1)
        {
            direction  = new Vector2d(1, 0);
            isStandard = true;

            long tmp = length;
            length = width;
            width  = tmp;
        }

        if (FixedMath.Abs(direction.GetRotationAngle(new Vector2d(0, -1))) < 1)
        {
            direction  = new Vector2d(1, 0);
            isStandard = true;

            long tmp = length;
            length = width;
            width  = tmp;
        }
    }
Esempio n. 3
0
    public bool Intersects(IShape other)
    {
        if (other is Rectangle rect)
        {
            Fixed xDist = FixedMath.Abs(rect.center.x - this.x);
            Fixed yDist = FixedMath.Abs(rect.center.y - this.y);

            Fixed r = this.r;
            Fixed w = rect.width;
            Fixed h = rect.height;

            if (xDist > (r + w) || yDist > (r + h))
            {
                return(false);
            }

            if (xDist <= w || yDist <= h)
            {
                return(true);
            }

            Fixed edge = ((xDist - w) * (xDist - w)) + ((yDist - h) * (yDist - h));
            return(edge <= this.rSquared);
        }


        return(false);
    }
Esempio n. 4
0
        /// <summary>
        /// Performs movement and collision detection in the Z plane.
        /// </summary>
        protected virtual void DoZMovement()
        {
            Accum velZAbs = FixedMath.Abs(vel.Z);

            if (vel.Z == Accum.Zero)
            {
                DoZCollisionDetection(true);
            }
            else if (velZAbs < this.Height)
            {
                bCylinder.Position += vel;
                if (DoZCollisionDetection(true) == CollisionType.SpcColResp_StopMovement)
                {
                    vel = Vector3k.Zero;
                }
            }
            else
            {
                Accum moveCount = FixedMath.Ceil(velZAbs / this.Height);
                Accum stepVel   = vel.Z / this.Height;
                for (int i = 0; i < moveCount; i += 1)
                {
                    bCylinder.Position += stepVel;
                    if (DoZCollisionDetection(true) == CollisionType.SpcColResp_StopMovement)
                    {
                        vel = Vector3k.Zero;
                        return;
                    }
                }
                if (DoZCollisionDetection(true) == CollisionType.SpcColResp_StopMovement)
                {
                    vel = Vector3k.Zero;
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Performs movement and collision detection in the XY plane.
 /// </summary>
 protected virtual void DoMovement()
 {
     if ((vel.X | vel.Y) == Accum.Zero)
     {
         DoXYCollisionDetection(true);
     }
     else if (FixedMath.Abs(vel.X * vel.X + vel.Y * vel.Y) < (this.Radius * this.Radius))
     {
         bCylinder.X += vel.X;
         bCylinder.Y += vel.Y;
         if (DoXYCollisionDetection(true) == CollisionType.SpcColResp_StopMovement)
         {
             vel = Vector3k.Zero;
         }
     }
     else
     {
         Accum    moveCount = FixedMath.Ceil((vel.X * vel.X + vel.Y * vel.Y) / this.Radius);
         Vector3k stepVel   = new Vector3k(vel.X / this.Radius, vel.Y / this.Radius, Accum.Zero);
         for (int i = 0; i < moveCount; i += 1)
         {
             bCylinder.X += vel.X;
             bCylinder.Y += vel.Y;
             if (DoXYCollisionDetection(true) == CollisionType.SpcColResp_StopMovement)
             {
                 vel = Vector3k.Zero;
                 return;
             }
         }
         if (DoXYCollisionDetection(true) == CollisionType.SpcColResp_StopMovement)
         {
             vel = Vector3k.Zero;
         }
     }
 }
Esempio n. 6
0
    public void Normal()
    {
        //Debug.Log(direction.GetRotationAngle(new Vector2d(1, 0)).ToFloat());
        //Debug.Log(direction.GetRotationAngle(new Vector2d(-1, 0)).ToFloat());
        //Debug.Log(direction.GetRotationAngle(new Vector2d(0, 1)).ToFloat());
        //Debug.Log(direction.GetRotationAngle(new Vector2d(0, -1)).ToFloat());

        if (FixedMath.Abs(direction.GetRotationAngle(new Vector2d(1, 0))) < FixedMath.Create(10) ||
            direction == new Vector2d(1, 0)
            )
        {
            direction  = new Vector2d(1, 0);
            isStandard = true;
        }

        if (FixedMath.Abs(direction.GetRotationAngle(new Vector2d(-1, 0))) < FixedMath.Create(10) ||
            direction == new Vector2d(-1, 0)
            )
        {
            direction  = new Vector2d(1, 0);
            isStandard = true;
        }

        if (FixedMath.Abs(direction.GetRotationAngle(new Vector2d(0, 1))) < FixedMath.Create(10) ||
            direction == new Vector2d(0, 1)
            )
        {
            direction  = new Vector2d(1, 0);
            isStandard = true;

            long tmp = length;
            length = width;
            width  = tmp;
        }

        if (FixedMath.Abs(direction.GetRotationAngle(new Vector2d(0, -1))) < FixedMath.Create(10) ||
            direction == new Vector2d(0, -1)
            )
        {
            direction  = new Vector2d(1, 0);
            isStandard = true;

            long tmp = length;
            length = width;
            width  = tmp;
        }
    }
Esempio n. 7
0
 /// <summary>
 /// Checks for intersection with a bounding cylinder in the XY axes.
 /// </summary>
 /// <param name="b">The bounding cylinder to check for intersection with.</param>
 /// <returns>Returns a boolean indicating whether an intersection happened.</returns>
 public bool IntersectsXY(BoundingCylinder b)
 {
     return(FixedMath.Abs(IntersectionDistXY(b).LengthSquared) < FixedMath.Square(this.Radius + b.Radius));
 }