Beispiel #1
0
        public bool PixelTouches(TexturedPrimitive otherPrim, out Vector2 collidePoint)
        {
            bool touches = PrimitivesTouches(otherPrim);

            collidePoint = Position;

            if (touches)
            {
                bool pixelTouch = false;

                #region Step 3a.
                Vector2 myXDir    = ShowVector.RotateVectorByAngle(Vector2.UnitX, RotateAngleInRadian);
                Vector2 myYDir    = ShowVector.RotateVectorByAngle(Vector2.UnitY, RotateAngleInRadian);
                Vector2 otherXDir = ShowVector.RotateVectorByAngle(Vector2.UnitX, otherPrim.RotateAngleInRadian);
                Vector2 otherYDir = ShowVector.RotateVectorByAngle(Vector2.UnitY, otherPrim.RotateAngleInRadian);
                #endregion

                #region Step 3b.
                int i = 0;
                while ((!pixelTouch) && (i < mImage.Width))
                {
                    int j = 0;
                    while ((!pixelTouch) && (j < mImage.Height))
                    {
                        collidePoint = IndexToCameraPosition(i, j, myXDir, myYDir);
                        Color myColor = GetColor(i, j);
                        if (myColor.A > 0)
                        {
                            Vector2 otherIndex = otherPrim.CameraPositionToIndex(collidePoint, otherXDir, otherYDir);
                            int     xMin       = (int)otherIndex.X;
                            int     yMin       = (int)otherIndex.Y;
                            if ((xMin >= 0) && (xMin < otherPrim.mImage.Width) &&
                                (yMin >= 0) && (yMin < otherPrim.mImage.Height))
                            {
                                pixelTouch = (otherPrim.GetColor(xMin, yMin).A > 0);
                            }
                        }
                        j++;
                    }
                    i++;
                }
                #endregion
                touches = pixelTouch;
            }
            return(touches);
        }
Beispiel #2
0
        public bool PixelTouches(TexturedPrimitive otherPrim, out Vector2 collidePoint)
        {
            bool touches = PrimitivesTouches(otherPrim);

            collidePoint = Position;

            if (touches)
            {
                bool pixelTouch = false;

                int i = 0;
                while ((!pixelTouch) && (i < mImage.Width))
                {
                    int j = 0;
                    while ((!pixelTouch) && (j < mImage.Height))
                    {
                        collidePoint = IndexToCameraPosition(i, j);
                        Color myColor = GetColor(i, j);
                        if (myColor.A > 0)
                        {
                            Vector2 otherIndex = otherPrim.CameraPositionToIndex(collidePoint);
                            int     xMin       = (int)otherIndex.X;
                            int     yMin       = (int)otherIndex.Y;

                            if ((xMin >= 0) && (xMin < otherPrim.mImage.Width) &&
                                (yMin >= 0) && (yMin < otherPrim.mImage.Height))
                            {
                                pixelTouch = (otherPrim.GetColor(xMin, yMin).A > 0);
                            }
                        }
                        j++;
                    }
                    i++;
                }

                touches = pixelTouch;
            }
            return(touches);
        }