Exemplo n.º 1
0
        private int GetClosestIndex(List <D3DXVECTOR2> PList, D3DXVECTOR2 curPos)
        {
            var n = 0;

            PList.ForEach(p => n = Distance(curPos, p) < Distance(curPos, PList[n]) ? PList.IndexOf(p) : n);

            return(n);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Rotates the character's model, to face the given destination point.
        /// </summary>
        /// <param name="pointB">The destination point</param>
        protected void ModelRotation(D3DXVECTOR2 pointB)
        {
            // Get new heading angle, for the given point.
            var newHeading = HeadingToRad(Game.Get2DPos(), pointB);

            // Get new 3D matrix Y axis vector, rotated to the given angle.
            var newVector = GetNewVector(newHeading);

            // Set new heading
            Game.PCMobEntity[0].PCMob->Heading = newHeading;

            // Set new rotation vector.
            Game.PCMobEntity[0].PCMob->subStruct->VectorX = newVector.x;
            Game.PCMobEntity[0].PCMob->subStruct->VectorY = newVector.y;
        }
Exemplo n.º 3
0
 protected float HeadingToRad(D3DXVECTOR2 from, D3DXVECTOR2 to)
 {
     return((float)Math.Atan2((to.x - from.x), (to.y - from.y)));
 }
Exemplo n.º 4
0
 protected float Distance(D3DXVECTOR2 p1, D3DXVECTOR2 p2)
 {
     return(Distance(p1.y, p1.x, p2.y, p2.x));
 }