本文整理汇总了C#中Pathfinding.IntRect类的典型用法代码示例。如果您正苦于以下问题:C# IntRect类的具体用法?C# IntRect怎么用?C# IntRect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IntRect类属于Pathfinding命名空间,在下文中一共展示了IntRect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBox
int GetBox ( IntRect rect ) {
if ( count >= arr.Length ) EnsureCapacity ( count+1 );
arr[count] = new BBTreeBox ( rect );
count++;
return count-1;
}
示例2: Intersects
public static bool Intersects(IntRect a, IntRect b)
{
return a.xmin <= b.xmax && a.ymin <= b.ymax && a.xmax >= b.xmin && a.ymax >= b.ymin;
}
示例3: GetNodesInArea
/** All nodes inside the shape or if null, the bounding box.
* If a shape is supplied, it is assumed to be contained inside the bounding box.
* \see GraphUpdateShape.GetBounds
*/
private List<GraphNode> GetNodesInArea (Bounds b, GraphUpdateShape shape) {
if (nodes == null || width*depth != nodes.Length) {
return null;
}
List<GraphNode> inArea = Pathfinding.Util.ListPool<GraphNode>.Claim ();
Vector3 min, max;
GetBoundsMinMax (b,inverseMatrix,out min, out 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);
IntRect originalRect = new IntRect(minX,minZ,maxX,maxZ);
IntRect gridRect = new IntRect(0,0,width-1,depth-1);
IntRect rect = IntRect.Intersection (originalRect, gridRect);
for (int x = rect.xmin; x <= rect.xmax;x++) {
for (int z = rect.ymin;z <= rect.ymax;z++) {
int index = z*width+x;
GraphNode node = nodes[index];
if (b.Contains ((Vector3)node.position) && (shape == null || shape.Contains ((Vector3)node.position))) {
inArea.Add (node);
}
}
}
return inArea;
}
示例4: ExpandToContain
/** Returns a new IntRect which is expanded to contain the point */
public IntRect ExpandToContain (int x, int y) {
var r = new IntRect(
System.Math.Min(xmin,x),
System.Math.Min(ymin,y),
System.Math.Max(xmax,x),
System.Math.Max(ymax,y)
);
return r;
}
示例5: Intersects
/** Returns if the two rectangles intersect each other
*/
public static bool Intersects (IntRect a, IntRect b) {
return !(a.xmin > b.xmax || a.ymin > b.ymax || a.xmax < b.xmin || a.ymax < b.ymin);
}
示例6: GetNodesInArea
/** All nodes inside the shape or if null, the bounding box.
* If a shape is supplied, it is assumed to be contained inside the bounding box.
* \see GraphUpdateShape.GetBounds
*/
private List<GraphNode> GetNodesInArea (Bounds b, GraphUpdateShape shape) {
if (nodes == null || width*depth != nodes.Length) {
return null;
}
// Get a buffer we can use
List<GraphNode> inArea = Pathfinding.Util.ListPool<GraphNode>.Claim();
// 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
Vector3 min, max;
GetBoundsMinMax(b, inverseMatrix, out min, out 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
var rect = IntRect.Intersection(originalRect, gridRect);
// Loop through all nodes in the rectangle
for (int x = rect.xmin; x <= rect.xmax; x++) {
for (int z = rect.ymin; z <= rect.ymax; z++) {
int index = z*width+x;
GraphNode node = nodes[index];
// If it is contained in the bounds (and optionally the shape)
// then add it to the buffer
if (b.Contains((Vector3)node.position) && (shape == null || shape.Contains((Vector3)node.position))) {
inArea.Add(node);
}
}
}
return inArea;
}
示例7: UpdateAreaInit
public void UpdateAreaInit (GraphUpdateObject o) {
if (!o.updatePhysics) {
return;
}
if (!dynamic) {
throw new System.Exception ("Recast graph must be marked as dynamic to enable graph updates");
}
AstarProfiler.Reset ();
AstarProfiler.StartProfile ("UpdateAreaInit");
AstarProfiler.StartProfile ("CollectMeshes");
RelevantGraphSurface.UpdateAllPositions ();
List<ExtraMesh> extraMeshes;
Bounds b = o.bounds;
b.center -= forcedBounds.min;
//Calculate world bounds of all affected tiles
IntRect r = new IntRect (Mathf.FloorToInt (b.min.x / (tileSizeX*cellSize)), Mathf.FloorToInt (b.min.z / (tileSizeZ*cellSize)), Mathf.FloorToInt (b.max.x / (tileSizeX*cellSize)), Mathf.FloorToInt (b.max.z / (tileSizeZ*cellSize)));
//Clamp to bounds
r = IntRect.Intersection (r, new IntRect (0,0,tileXCount-1,tileZCount-1));
Bounds tileBounds = new Bounds();
Vector3 forcedBoundsMin = forcedBounds.min;
Vector3 forcedBoundsMax = forcedBounds.max;
float tcsx = tileSizeX*cellSize;
float tcsz = tileSizeZ*cellSize;
tileBounds.SetMinMax(new Vector3 (r.xmin*tcsx, 0, r.ymin*tcsz) + forcedBoundsMin,
new Vector3 ((r.xmax+1)*tcsx + forcedBoundsMin.x, forcedBoundsMax.y, (r.ymax+1)*tcsz + forcedBoundsMin.z)
);
int voxelCharacterRadius = Mathf.CeilToInt (characterRadius/cellSize);
int borderSize = voxelCharacterRadius + 3;
//Expand borderSize voxels on each side
tileBounds.Expand (new Vector3 (borderSize,0,borderSize)*cellSize*2);
Debug.DrawLine (tileBounds.min, tileBounds.max);
//Debug.Break ();
if (!CollectMeshes (out extraMeshes, tileBounds)) {
//return;
}
Voxelize vox = globalVox;
if (vox == null) {
//Create the voxelizer and set all settings
vox = new Voxelize (cellHeight, cellSize, walkableClimb, walkableHeight, maxSlope);
vox.maxEdgeLength = maxEdgeLength;
if (dynamic) globalVox = vox;
}
vox.inputExtraMeshes = extraMeshes;
AstarProfiler.EndProfile ("CollectMeshes");
AstarProfiler.EndProfile ("UpdateAreaInit");
}
示例8: RectArea
/** Returns the area of a rect */
static int RectArea (IntRect r) {
return r.Width*r.Height;
}
示例9: BBTreeBox
public BBTreeBox(IntRect rect)
{
this.node = null;
this.rect = rect;
this.left = (this.right = -1);
}
示例10: GetBox
private int GetBox(IntRect rect)
{
if (this.count >= this.arr.Length)
{
this.EnsureCapacity(this.count + 1);
}
this.arr[this.count] = new BBTree.BBTreeBox(rect);
this.count++;
return this.count - 1;
}
示例11: RectIntersectsCircle
private static bool RectIntersectsCircle(IntRect r, Vector3 p, float radius)
{
if (float.IsPositiveInfinity(radius))
{
return true;
}
Vector3 vector = p;
p.x = Math.Max(p.x, (float)r.xmin * 0.001f);
p.x = Math.Min(p.x, (float)r.xmax * 0.001f);
p.z = Math.Max(p.z, (float)r.ymin * 0.001f);
p.z = Math.Min(p.z, (float)r.ymax * 0.001f);
return (p.x - vector.x) * (p.x - vector.x) + (p.z - vector.z) * (p.z - vector.z) < radius * radius;
}
示例12: ExpansionRequired
private static int ExpansionRequired(IntRect r, IntRect r2)
{
int num = Math.Min(r.xmin, r2.xmin);
int num2 = Math.Max(r.xmax, r2.xmax);
int num3 = Math.Min(r.ymin, r2.ymin);
int num4 = Math.Max(r.ymax, r2.ymax);
return (num2 - num) * (num4 - num3) - BBTree.RectArea(r);
}
示例13: UpdateArea
public static void UpdateArea (GraphUpdateObject o, INavmesh graph) {
//System.DateTime startTime = System.DateTime.UtcNow;
Bounds bounds = o.bounds;
Rect r = Rect.MinMaxRect (bounds.min.x,bounds.min.z,bounds.max.x,bounds.max.z);
var r2 = new IntRect(
Mathf.FloorToInt(bounds.min.x*Int3.Precision),
Mathf.FloorToInt(bounds.min.z*Int3.Precision),
Mathf.FloorToInt(bounds.max.x*Int3.Precision),
Mathf.FloorToInt(bounds.max.z*Int3.Precision)
);
var a = new Int3(r2.xmin,0,r2.ymin);
var b = new Int3(r2.xmin,0,r2.ymax);
var c = new Int3(r2.xmax,0,r2.ymin);
var d = new Int3(r2.xmax,0,r2.ymax);
graph.GetNodes (_node => {
var node = _node as TriangleMeshNode;
bool inside = false;
int allLeft = 0;
int allRight = 0;
int allTop = 0;
int allBottom = 0;
for (int v=0;v<3;v++) {
Int3 p = node.GetVertex(v);
var vert = (Vector3)p;
if (r2.Contains (p.x,p.z)) {
inside = true;
break;
}
if (vert.x < r.xMin) allLeft++;
if (vert.x > r.xMax) allRight++;
if (vert.z < r.yMin) allTop++;
if (vert.z > r.yMax) allBottom++;
}
if (!inside) {
if (allLeft == 3 || allRight == 3 || allTop == 3 || allBottom == 3) {
return true;
}
}
for (int v=0;v<3;v++) {
int v2 = v > 1 ? 0 : v+1;
Int3 vert1 = node.GetVertex(v);
Int3 vert2 = node.GetVertex(v2);
if (Polygon.Intersects (a,b,vert1,vert2)) { inside = true; break; }
if (Polygon.Intersects (a,c,vert1,vert2)) { inside = true; break; }
if (Polygon.Intersects (c,d,vert1,vert2)) { inside = true; break; }
if (Polygon.Intersects (d,b,vert1,vert2)) { inside = true; break; }
}
if (node.ContainsPoint (a) || node.ContainsPoint (b) || node.ContainsPoint (c) || node.ContainsPoint (d)) {
inside = true;
}
if (!inside) {
return true;
}
o.WillUpdateNode(node);
o.Apply (node);
return true;
});
}
示例14: UpdateArea
public static void UpdateArea (GraphUpdateObject o, INavmesh graph) {
Bounds bounds = o.bounds;
// Bounding rectangle with floating point coordinates
Rect r = Rect.MinMaxRect (bounds.min.x,bounds.min.z,bounds.max.x,bounds.max.z);
// Bounding rectangle with int coordinates
var r2 = new IntRect(
Mathf.FloorToInt(bounds.min.x*Int3.Precision),
Mathf.FloorToInt(bounds.min.z*Int3.Precision),
Mathf.FloorToInt(bounds.max.x*Int3.Precision),
Mathf.FloorToInt(bounds.max.z*Int3.Precision)
);
// Corners of the bounding rectangle
var a = new Int3(r2.xmin,0,r2.ymin);
var b = new Int3(r2.xmin,0,r2.ymax);
var c = new Int3(r2.xmax,0,r2.ymin);
var d = new Int3(r2.xmax,0,r2.ymax);
var ymin = ((Int3)bounds.min).y;
var ymax = ((Int3)bounds.max).y;
// Loop through all nodes
graph.GetNodes (_node => {
var node = _node as TriangleMeshNode;
bool inside = false;
int allLeft = 0;
int allRight = 0;
int allTop = 0;
int allBottom = 0;
// Check bounding box rect in XZ plane
for (int v=0;v<3;v++) {
Int3 p = node.GetVertex(v);
var vert = (Vector3)p;
if (r2.Contains (p.x,p.z)) {
inside = true;
break;
}
if (vert.x < r.xMin) allLeft++;
if (vert.x > r.xMax) allRight++;
if (vert.z < r.yMin) allTop++;
if (vert.z > r.yMax) allBottom++;
}
if (!inside) {
if (allLeft == 3 || allRight == 3 || allTop == 3 || allBottom == 3) {
return true;
}
}
// Check if the polygon edges intersect the bounding rect
for (int v = 0; v < 3; v++) {
int v2 = v > 1 ? 0 : v+1;
Int3 vert1 = node.GetVertex(v);
Int3 vert2 = node.GetVertex(v2);
if (Polygon.Intersects (a,b,vert1,vert2)) { inside = true; break; }
if (Polygon.Intersects (a,c,vert1,vert2)) { inside = true; break; }
if (Polygon.Intersects (c,d,vert1,vert2)) { inside = true; break; }
if (Polygon.Intersects (d,b,vert1,vert2)) { inside = true; break; }
}
// Check if the node contains any corner of the bounding rect
if (inside || node.ContainsPoint (a) || node.ContainsPoint (b) || node.ContainsPoint (c) || node.ContainsPoint (d)) {
inside = true;
}
if (!inside) {
return true;
}
int allAbove = 0;
int allBelow = 0;
// Check y coordinate
for (int v = 0; v < 3; v++) {
Int3 p = node.GetVertex(v);
var vert = (Vector3)p;
if (vert.y < ymin) allBelow++;
if (vert.y > ymax) allAbove++;
}
// Polygon is either completely above the bounding box or completely below it
if (allBelow == 3 || allAbove == 3) return true;
// Triangle is inside the bounding box!
// Update it!
o.WillUpdateNode(node);
o.Apply (node);
return true;
});
}
示例15: Union
public static IntRect Union(IntRect a, IntRect b)
{
IntRect result = new IntRect(Math.Min(a.xmin, b.xmin), Math.Min(a.ymin, b.ymin), Math.Max(a.xmax, b.xmax), Math.Max(a.ymax, b.ymax));
return result;
}