// draw the three axes of a LocalSpace: three lines parallel to the // basis vectors of the space, centered at its origin, of lengths // given by the coordinates of "size". public static void DrawAxes(ILocalSpace ls, Vector3 size, Color color) { Vector3 x = new Vector3(size.X / 2, 0, 0); Vector3 y = new Vector3(0, size.Y / 2, 0); Vector3 z = new Vector3(0, 0, size.Z / 2); iDrawLine(ls.GlobalizePosition(x), ls.GlobalizePosition(x * -1), color); iDrawLine(ls.GlobalizePosition(y), ls.GlobalizePosition(y * -1), color); iDrawLine(ls.GlobalizePosition(z), ls.GlobalizePosition(z * -1), color); }
// used to detect if vehicle body is on any obstacles public bool ScanLocalXZRectangle(ILocalSpace localSpace, float xMin, float xMax, float zMin, float zMax) { float spacing = MinSpacing() / 2; for (float x = xMin; x < xMax; x += spacing) { for (float z = zMin; z < zMax; z += spacing) { Vector3 sample = new Vector3(x, 0, z); Vector3 global = localSpace.GlobalizePosition(sample); if (GetMapValue(global)) { return(true); } } } return(false); }
// draw the edges of a box with a given position, orientation, size // and color. The box edges are aligned with the axes of the given // LocalSpace, and it is centered at the origin of that LocalSpace. // "size" is the main diagonal of the box. // // use gGlobalSpace to draw a box aligned with global space public static void DrawBoxOutline(ILocalSpace localSpace, Vector3 size, Color color) { Vector3 s = size / 2.0f; // half of main diagonal Vector3 a = new Vector3(+s.X, +s.Y, +s.Z); Vector3 b = new Vector3(+s.X, -s.Y, +s.Z); Vector3 c = new Vector3(-s.X, -s.Y, +s.Z); Vector3 d = new Vector3(-s.X, +s.Y, +s.Z); Vector3 e = new Vector3(+s.X, +s.Y, -s.Z); Vector3 f = new Vector3(+s.X, -s.Y, -s.Z); Vector3 g = new Vector3(-s.X, -s.Y, -s.Z); Vector3 h = new Vector3(-s.X, +s.Y, -s.Z); Vector3 A = localSpace.GlobalizePosition(a); Vector3 B = localSpace.GlobalizePosition(b); Vector3 C = localSpace.GlobalizePosition(c); Vector3 D = localSpace.GlobalizePosition(d); Vector3 E = localSpace.GlobalizePosition(e); Vector3 F = localSpace.GlobalizePosition(f); Vector3 G = localSpace.GlobalizePosition(g); Vector3 H = localSpace.GlobalizePosition(h); iDrawLine(A, B, color); iDrawLine(B, C, color); iDrawLine(C, D, color); iDrawLine(D, A, color); iDrawLine(A, E, color); iDrawLine(B, F, color); iDrawLine(C, G, color); iDrawLine(D, H, color); iDrawLine(E, F, color); iDrawLine(F, G, color); iDrawLine(G, H, color); iDrawLine(H, E, color); }
// used to detect if vehicle body is on any obstacles public bool ScanLocalXZRectangle(ILocalSpace localSpace, float xMin, float xMax, float zMin, float zMax) { float spacing = MinSpacing() / 2; for (float x = xMin; x < xMax; x += spacing) { for (float z = zMin; z < zMax; z += spacing) { Vector3 sample = new Vector3(x, 0, z); Vector3 global = localSpace.GlobalizePosition(sample); if (GetMapValue(global)) return true; } } return false; }