コード例 #1
0
 /// <summary>
 /// This adds a LinkedList of objects
 /// </summary>
 /// <param name="actorList">The list of objects</param>
 public void Add(DXMAN.Physics.xVolume[] xObjects)
 {
     foreach(DXMAN.Physics.xVolume obj in xObjects)
     {
         Add(obj);
     }
 }
コード例 #2
0
        /// <summary>
        /// Checks to see if two lines are intersecting
        /// </summary>
        /// <param name="xl1">line one</param>
        /// <param name="xl2">line two</param>
        /// <returns>returns true if two lines are intersecting, false if not</returns>
        public static bool LineToLine(DXMAN.Physics.xVolume xl1, DXMAN.Physics.xVolume xl2)
        {
            DXMAN.Primitives.xLine l1 = (DXMAN.Primitives.xLine)xl1;
            DXMAN.Primitives.xLine l2 = (DXMAN.Primitives.xLine)xl2;

            // http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d/
            // Given line (p1, p2) and line (p3, p4)
            // They can be expressed parameticly as:
            //    i = p1 + a (p2 - p1)
            //    i = p3 + b (p4 - p3)
            // where i is the intersection point and a and b are between 0 and 1
            // Bringing the equations together...
            //    p1 + a (p2 - p1) = p3 + b (p4 - p3)
            // This forms two equations:
            //    a = [(x4 - x3)(y1 - y3) - (y4 - y3)(x1 - x3)] /
            //        [(y4 - y3)(x2 - x1) - (x4 - x3)(y2 - y1)]
            //    b = [(x2 - x1)(y1 - y3) - (y2 - y1)(x1 - x3)] /
            //        [(y4 - y3)(x2 - x1) - (x4 - x3)(y2 - y1)]
            // As long as these are between 0 and 1, we have an intersection.
            // Oh, and check the denomator isn't zero or else the lines are
            // parallel. But if the numerator is zero also, they coincide.

            // These are the points
            float x1 = l1.Point1.X, y1 = l1.Point1.Y;
            float x2 = l1.Point2.X, y2 = l1.Point2.Y;
            float x3 = l2.Point1.X, y3 = l2.Point1.Y;
            float x4 = l2.Point2.X, y4 = l2.Point2.Y;

            // Calculate our interpolation values
            float denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
            float numer_a = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
            float numer_b = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
            if (denom == 0) // Parallel?
                return false;
            float a = numer_a / denom;
            float b = numer_b / denom;

            // Make sure they are between zero and one
            if (a >= 0 && a <= 1 && b >= 0 && b <= 1)
                return true;
            else return false;
        }
コード例 #3
0
ファイル: xCircle.cs プロジェクト: andrewgbliss/CS_DXMAN
        public override bool CheckOnClick(DXMAN.DirectInput.xMouse mouse)
        {
            float x1 = (float)mouse.XPos;
            float y1 = (float)mouse.YPos;

            float x2 = XPos + (Width * .5f);
            float y2 = YPos + (Height * .5f);

            double distance = DXMAN.Util.xMath.GetDistance(x1, y1, x2, y2);

            if(distance <= Radius)
            {
                if(mouse.OnClick())
                {
                    return true;
                }
            }

            return false;
        }
コード例 #4
0
 /// <summary>
 /// This adds an object to the manager
 /// </summary>
 /// <param name="actor">The object to add</param>
 public void Add(DXMAN.Physics.xVolume obj)
 {
     m_xObjects.Add(obj);
 }
コード例 #5
0
 /// <summary>
 /// This removes an object from the manager
 /// </summary>
 /// <param name="actor">The object to remove</param>
 public void Remove(DXMAN.Base.xRenderable obj)
 {
     xObjects.Remove(obj);
 }
コード例 #6
0
 /// <summary>
 /// This adds an object to the manager
 /// </summary>
 /// <param name="actor">The object to add</param>
 public void Add(DXMAN.Base.xRenderable obj)
 {
     xObjects.Add(obj);
 }
コード例 #7
0
 public xEventManager(DXMAN.DirectInput.xMouse m)
 {
     mouse = m;
     xObjects = new Util.LinkedList();
 }
コード例 #8
0
 /// <summary>
 /// This removes an object from the manager
 /// </summary>
 /// <param name="actor">The object to remove</param>
 public void Remove(DXMAN.Base.xObject obj)
 {
     xObjects.Remove(obj);
 }
コード例 #9
0
ファイル: xQuad.cs プロジェクト: andrewgbliss/CS_DXMAN
        public override bool CheckOnMouseOut(DXMAN.DirectInput.xMouse mouse)
        {
            float x = (float)mouse.XPos;
            float y = (float)mouse.YPos;

            float left	 = XPos;
            float right	 = XPos + Width;
            float top	 = YPos;
            float bottom = YPos + Height;

            if(x < left || x > right || y < top || y > bottom)
            {
                if(isMouseOver)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

            return false;
        }
コード例 #10
0
        /// <summary>
        /// Returns the point of intersection
        /// </summary>
        /// <param name="xl1">line one</param>
        /// <param name="xl2">line two</param>
        /// <returns>vector3 containing the point of intersection</returns>
        public static Vector3 PointOfIntersectionLineToLine(DXMAN.Physics.xVolume xl1, DXMAN.Physics.xVolume xl2)
        {
            DXMAN.Primitives.xLine l1 = (DXMAN.Primitives.xLine)xl1;
            DXMAN.Primitives.xLine l2 = (DXMAN.Primitives.xLine)xl2;

            double m1 = (l1.Point2.Y - l1.Point1.Y) / (l1.Point2.X - l1.Point1.X);
            double m2 = (l2.Point2.Y - l2.Point1.Y) / (l2.Point2.X - l2.Point1.X);

            double b1 = l1.Point1.Y - (m1 * l1.Point1.X);
            double b2 = l2.Point1.Y - (m2 * l2.Point1.X);

            double x_intersect = (b2 - b1) / (m1 - m2);
            double y_intersect = (m1 * x_intersect) + b1;

            Vector3 point = new Vector3((float)x_intersect, (float)y_intersect, 0f);

            return point;
        }
コード例 #11
0
 /// <summary>
 /// This checks to see if the two volumes are intersecting
 /// </summary>
 /// <param name="v1">the first volume</param>
 /// <param name="v2">the second volume</param>
 /// <returns>true if the volume are intersecting, false if not</returns>
 public static bool RectToRect(DXMAN.Physics.xVolume v1, DXMAN.Physics.xVolume v2)
 {
     if(v1.XPos < (v2.XPos    + v2.Width)  &&
       (v1.XPos +  v1.Width)  > v2.XPos    &&
        v1.YPos < (v2.YPos    + v2.Height) &&
       (v1.YPos +  v1.Height) > v2.YPos)
     {
         return true;
     }
     return false;
 }
コード例 #12
0
        /// <summary>
        /// This checks to see if two radii are intersecting
        /// </summary>
        /// <param name="v1">the first volume</param>
        /// <param name="v2">the second volume</param>
        /// <returns>returns true if the radii are intersecting, false if not</returns>
        public static bool RadiusToRadius(DXMAN.Physics.xVolume v1, DXMAN.Physics.xVolume v2)
        {
            double x1 = v1.XPos + v1.Radius;
            double y1 = v1.YPos + v1.Radius;

            double x2 = v2.XPos + v2.Radius;
            double y2 = v2.YPos + v2.Radius;

            double distance = (double)DXMAN.Util.xMath.GetDistance((float)x1, (float)y1, (float)x2, (float)y2);

            double lengthBetween = v1.Radius + v2.Radius;

            if(distance < lengthBetween)
            {
                return true;
            }

            return false;
        }
コード例 #13
0
ファイル: xRenderable.cs プロジェクト: andrewgbliss/CS_DXMAN
 public virtual bool CheckOnMouseOver(DXMAN.DirectInput.xMouse mouse)
 {
     return false;
 }
コード例 #14
0
ファイル: xVolume.cs プロジェクト: andrewgbliss/CS_DXMAN
 public void defaultEvent(DXMAN.Physics.xVolume obj, DXMAN.Physics.xVolume other)
 {
 }
コード例 #15
0
ファイル: xVolume.cs プロジェクト: andrewgbliss/CS_DXMAN
 public void callOnCollision(DXMAN.Physics.xVolume obj, DXMAN.Physics.xVolume other)
 {
     OnCollision(obj, other);
 }
コード例 #16
0
 /// <summary>
 /// This adds a LinkedList of objects
 /// </summary>
 /// <param name="actorList">The list of objects</param>
 public void Add(DXMAN.Base.xRenderable[] xObjects)
 {
     foreach(DXMAN.Base.xRenderable obj in xObjects)
     {
         Add(obj);
     }
 }
コード例 #17
0
 /// <summary>
 /// This removes an object from the manager
 /// </summary>
 /// <param name="actor">The object to remove</param>
 public void Remove(DXMAN.Physics.xVolume obj)
 {
     m_xObjects.Remove(obj);
 }
コード例 #18
0
 /// <summary>
 /// This adds an object to the manager
 /// </summary>
 /// <param name="actor">The object to add</param>
 public void Add(DXMAN.Base.xObject obj)
 {
     xObjects.Add(obj);
 }
コード例 #19
0
ファイル: xQuad.cs プロジェクト: andrewgbliss/CS_DXMAN
        public override bool CheckOnMouseOver(DXMAN.DirectInput.xMouse mouse)
        {
            float x = (float)mouse.XPos;
            float y = (float)mouse.YPos;

            float left	 = XPos;
            float right	 = XPos + Width;
            float top	 = YPos;
            float bottom = YPos + Height;

            if(x >= left && x <= right && y >= top && y <= bottom)
            {
                isMouseOver = true;
                return true;
            }

            isMouseOver = false;
            return false;
        }
コード例 #20
0
ファイル: xCircle.cs プロジェクト: andrewgbliss/CS_DXMAN
        public override bool CheckOnMouseOver(DXMAN.DirectInput.xMouse mouse)
        {
            float x1 = (float)mouse.XPos;
            float y1 = (float)mouse.YPos;

            float x2 = XPos + (Width / 2);
            float y2 = YPos + (Height / 2);

            double distance = DXMAN.Util.xMath.GetDistance(x1, y1, x2, y2);

            if(distance <= Radius)
            {
                isMouseOver = true;
                return true;
            }

            isMouseOver = false;
            return false;
        }