UnrealScript Game Programming Cookbook

(Chris Devlin) #1

Miscellaneous Recipes


248

BoundingBoxCoords[6] =
Canvas.Project(BoundingBoxCoords[6]);
/** X2, Y2 */
BoundingBoxCoords[7].X = CompBBox.Max.X;
BoundingBoxCoords[7].Y = CompBBox.Max.Y;
BoundingBoxCoords[7].Z = CompBBox.Max.Z;
oundingBoxCoords[7] =
Canvas.Project(BoundingBoxCoords[7]);

The CompBBox variable is a box that grabs the actor's bounding box, as definied
at the beginning of the function with the line Actor.GetComponentsBoundingBox
(CompBBox);.
The next step has us creating an array for each corner of our box. We need a
vector for our rectangle in the previous function to draw at. We get this vector,
BoundingBoxCoordinates by using the values of our actor's bounding box. The
first array sets BoundingBoxCoords.X to be equal to the minimum X value for
our pawn's bounding box, as found in the Object class. We do this for the Y and Z
variables as well, before finally combining them all and using Canvas.Project
to convert the 3D coordinates to 2D ones.


  1. Now we have to locate the top, bottom, left, and right coordinates for the pawn's
    bounding box. Using the edge of the canvas we find the minimum values for
    our X and Y variables, and set the max values to be zero.
    / Locates left, top, right & bottom coords /
    OutBox.Min.X = Canvas.ClipX;
    OutBox.Min.Y = Canvas.ClipY;
    OutBox.Max.X = 0;
    OutBox.Max.Y = 0;

  2. The final step has us iterating through our outside box coordinates to detect the
    smallest and largest coordinates. We do this by comparing the X and Y values
    of our pawn's bounding box. We return the value of Outbox, which is what we
    used in our RenderBoundingBox() function.
    /* Iterate though bounding box coordinates /
    for (i = 0; i < ArrayCount(BoundingBoxCoords); ++i)
    {
    /* Detect the smallest X coords /
    if (OutBox.Min.X > BoundingBoxCoords[i].X)
    {
    OutBox.Min.X = BoundingBoxCoords[i].X;
    }


/** Detect the smallest Y coords */
Free download pdf