Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** A rect with all nodes that the bounds could touch.
- * This correctly handles rotated graphs and other transformations.
- * The returned rect is guaranteed to not extend outside the graph bounds.
- */
- protected IntRect GetRectFromBounds (Bounds bounds) {
- // Take the bounds and transform it using the matrix
- // Then convert that to a rectangle which contains
- // all nodes that might be inside the bounds
- bounds = transform.InverseTransform(bounds);
- Vector3 min = bounds.min;
- Vector3 max = bounds.max;
- int minX = Mathf.RoundToInt(min.x-0.5F);
- int maxX = Mathf.RoundToInt(max.x-0.5F);
- int minZ = Mathf.RoundToInt(min.z-0.5F);
- int maxZ = Mathf.RoundToInt(max.z-0.5F);
- var originalRect = new IntRect(minX, minZ, maxX, maxZ);
- // Rect which covers the whole grid
- var gridRect = new IntRect(0, 0, width-1, depth-1);
- // Clamp the rect to the grid
- return IntRect.Intersection(originalRect, gridRect);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement