GetClosestPtOnBox() public static méthode

public static GetClosestPtOnBox ( BoxCoords box, System.Point pIn, System.Point &pOut ) : uint
box BoxCoords
pIn System.Point
pOut System.Point
Résultat uint
Exemple #1
0
        internal byte WalkboxFindTarget(Actor a, int destbox, Point walkdest)
        {
            var actor = (Actor0)a;

            byte nextBox = (byte)GetNextBox(a.Walkbox, (byte)destbox);

            if (nextBox != 0xFF && nextBox == destbox && AreBoxesNeighbors(a.Walkbox, nextBox))
            {
                actor.NewWalkTo = walkdest;
                return(nextBox);
            }

            if (nextBox != 0xFF && nextBox != a.Walkbox)
            {
                Point p;
                ScummMath.GetClosestPtOnBox(GetBoxCoordinates(nextBox), a.Position, out p);
                actor.NewWalkTo = p;
            }
            else
            {
                if (walkdest.X == -1)
                {
                    actor.NewWalkTo = actor.CurrentWalkTo;
                }
                else
                {
                    actor.NewWalkTo = walkdest;
                }
            }
            return(nextBox);
        }
Exemple #2
0
        void GetGates(BoxCoords box1, BoxCoords box2, Point[] gateA, Point[] gateB)
        {
            int i, j;
            var dist = new int[8];
            var minDist = new int[3];
            var closest = new int[3];
            var box = new bool[3];
            var closestPoint = new Point[8];
            var boxCorner = new Point[8];
            int line1, line2;

            // For all corner coordinates of the first box, compute the point closest
            // to them on the second box (and also compute the distance of these points).
            boxCorner[0] = box1.UpperLeft;
            boxCorner[1] = box1.UpperRight;
            boxCorner[2] = box1.LowerRight;
            boxCorner[3] = box1.LowerLeft;
            for (i = 0; i < 4; i++)
            {
                dist[i] = (int)ScummMath.GetClosestPtOnBox(box2, boxCorner[i], out closestPoint[i]);
            }

            // Now do the same but with the roles of the first and second box swapped.
            boxCorner[4] = box2.UpperLeft;
            boxCorner[5] = box2.UpperRight;
            boxCorner[6] = box2.LowerRight;
            boxCorner[7] = box2.LowerLeft;
            for (i = 4; i < 8; i++)
            {
                dist[i] = (int)ScummMath.GetClosestPtOnBox(box1, boxCorner[i], out closestPoint[i]);
            }

            // Find the three closest "close" points between the two boxes.
            for (j = 0; j < 3; j++)
            {
                minDist[j] = 0xFFFF;
                for (i = 0; i < 8; i++)
                {
                    if (dist[i] < minDist[j])
                    {
                        minDist[j] = dist[i];
                        closest[j] = i;
                    }
                }
                dist[closest[j]] = 0xFFFF;
                minDist[j]       = (int)Math.Sqrt(minDist[j]);
                box[j]           = (closest[j] > 3); // Is the point on the first or on the second box?
            }


            // Finally, compute the actual "gate".

            if (box[0] == box[1] && Math.Abs(minDist[0] - minDist[1]) < 4)
            {
                line1 = closest[0];
                line2 = closest[1];
            }
            else if (box[0] == box[1] && minDist[0] == minDist[1])
            {  // parallel
                line1 = closest[0];
                line2 = closest[1];
            }
            else if (box[0] == box[2] && minDist[0] == minDist[2])
            {  // parallel
                line1 = closest[0];
                line2 = closest[2];
            }
            else if (box[1] == box[2] && minDist[1] == minDist[2])
            {  // parallel
                line1 = closest[1];
                line2 = closest[2];
            }
            else if (box[0] == box[2] && Math.Abs(minDist[0] - minDist[2]) < 4)
            {
                line1 = closest[0];
                line2 = closest[2];
            }
            else if (Math.Abs(minDist[0] - minDist[2]) < 4)
            {
                line1 = closest[1];
                line2 = closest[2];
            }
            else if (Math.Abs(minDist[0] - minDist[1]) < 4)
            {
                line1 = closest[0];
                line2 = closest[1];
            }
            else
            {
                line1 = closest[0];
                line2 = closest[0];
            }

            // Set the gate
            if (line1 < 4)
            {
                gateA[0] = boxCorner[line1];
                gateA[1] = closestPoint[line1];
            }
            else
            {
                gateA[1] = boxCorner[line1];
                gateA[0] = closestPoint[line1];
            }

            if (line2 < 4)
            {
                gateB[0] = boxCorner[line2];
                gateB[1] = closestPoint[line2];
            }
            else
            {
                gateB[1] = boxCorner[line2];
                gateB[0] = closestPoint[line2];
            }
        }
Exemple #3
0
        public override void Walk()
        {
            Point foundPath, tmp;
            int   new_dir, next_box;

            if (Moving.HasFlag(MoveFlags.Turn))
            {
                new_dir = UpdateActorDirection(false);
                if (Facing != new_dir)
                {
                    SetDirection(new_dir);
                }
                else
                {
                    Moving = MoveFlags.None;
                }
                return;
            }

            if (Moving == MoveFlags.None)
            {
                return;
            }

            if (Moving.HasFlag(MoveFlags.InLeg))
            {
                ActorWalkStep();
            }
            else
            {
                if (Moving.HasFlag(MoveFlags.LastLeg))
                {
                    Moving = MoveFlags.None;
                    StartAnimActor(StandFrame);
                    if (_targetFacing != _walkdata.DestDir)
                    {
                        TurnToDirection(_walkdata.DestDir);
                    }
                }
                else
                {
                    SetBox(_walkdata.CurBox);
                    if (Walkbox == _walkdata.DestBox)
                    {
                        foundPath = _walkdata.Dest;
                        Moving   |= MoveFlags.LastLeg;
                    }
                    else
                    {
                        next_box = _scumm.GetNextBox(Walkbox, _walkdata.DestBox);
                        if (next_box < 0)
                        {
                            Moving |= MoveFlags.LastLeg;
                            return;
                        }

                        // Can't walk through locked boxes
                        var flags = _scumm.GetBoxFlags((byte)next_box);
                        if ((flags.HasFlag(BoxFlags.Locked)) && !((flags.HasFlag(BoxFlags.PlayerOnly) && !IsPlayer)))
                        {
                            Moving |= MoveFlags.LastLeg;
                            //_walkdata.destdir = -1;
                        }

                        _walkdata.CurBox = (byte)next_box;

                        ScummMath.GetClosestPtOnBox(_scumm.GetBoxCoordinates(_walkdata.CurBox), RealPosition, out tmp);
                        ScummMath.GetClosestPtOnBox(_scumm.GetBoxCoordinates(Walkbox), tmp, out foundPath);
                    }
                    CalcMovementFactor(foundPath);
                }
            }
        }