Пример #1
0
        public HessePlane(ICoordinated a, ICoordinated b, ICoordinated c)
        {
            NormalVector = (b.Minus(a)).CrossProduct(c.Minus(a));
            NormalVector.Normalize();

            RootDistance = a.ScalarProduct(NormalVector);
            if (RootDistance < 0)
            {
                RootDistance   *= -1;
                NormalVector.X *= -1;
                NormalVector.Y *= -1;
                NormalVector.Z *= -1;
            }
        }
        public void UpdateCollisionWithWall(XNACS1Rectangle wall)
        {
            Vector2 mVectorV;
            Vector2 TangentVector;

            float   DistOnTangent;
            Vector2 PtOnTangentLine;
            Vector2 NormalVector;
            float   DistOnNormal;
            Vector2 mPtOnNormal;
            float   mDistOnTangern;

            if (Collided(wall))
            {
                mVectorV = Center - wall.Center;                    // V vector(vector from hero center to wall center)

                TangentVector = wall.FrontDirection;                //  tangent vector
                TangentVector.Normalize();
                DistOnTangent   = Vector2.Dot(mVectorV, TangentVector);
                PtOnTangentLine = wall.Center + (DistOnTangent * TangentVector);
                NormalVector    = mVectorV - (DistOnTangent * TangentVector);
                NormalVector.Normalize();
                DistOnNormal = Vector2.Dot(mVectorV, NormalVector);


                mPtOnNormal    = wall.Center + (DistOnNormal * NormalVector);
                mDistOnTangern = Vector2.Dot(mVectorV, TangentVector);

                if (Math.Abs(DistOnTangent) < wall.Width / 2f)                 // collided with top and bottom
                {
                    float dOnN = Height / 2 + (wall.Height / 2f);
                    if (Math.Abs(DistOnNormal) < dOnN)
                    {
                        Center = PtOnTangentLine + Math.Sign(DistOnNormal) * (dOnN * NormalVector);
                    }
                }
                else                  // collide with left and right

                {
                    if (Math.Abs(mDistOnTangern) < Width / 2 + (wall.Width / 2f))
                    {
                        Center = mPtOnNormal + Math.Sign(mDistOnTangern) * (Width / 2 + wall.Width / 2f) * TangentVector;
                    }
                }
            }
        }