private static XMVector GetCollisionColor(ContainmentType collision) { XMVector ColorCollide = new XMUByteN4(255, 0, 0, 255); XMVector ColorPartialCollide = new XMUByteN4(255, 255, 0, 255); XMVector ColorNoCollide = new XMUByteN4(128, 192, 128, 255); return(collision switch { ContainmentType.Disjoint => ColorNoCollide, ContainmentType.Intersects => ColorPartialCollide, _ => ColorCollide, });
private void RenderObjects() { // Set up some color constants XMVector ColorWhite = new XMUByteN4(255, 255, 255, 255); XMVector ColorGround = new XMUByteN4(0, 0, 0, 255); XMVector ColorYellow = new XMUByteN4(255, 255, 0, 255); // Draw ground planes for (int i = 0; i < CameraCount; i++) { XMFloat3 vXAxis = new(20, 0, 0); XMFloat3 vYAxis = new(0, 0, 20); XMFloat3 vOrigin = new(this.cameraOrigins[i].X, this.cameraOrigins[i].Y - 10.0f, this.cameraOrigins[i].Z); int iXDivisions = 20; int iYDivisions = 20; this.DrawGrid(vXAxis, vYAxis, vOrigin, iXDivisions, iYDivisions, ColorGround); } // Draw primary collision objects in white this.DrawFrustum(this.primaryFrustum, ColorWhite); this.DrawAabb(this.primaryAABox, ColorWhite); this.DrawObb(this.primaryOrientedBox, ColorWhite); { XMVector origin = primaryRay.Origin; XMVector direction = this.primaryRay.Direction; this.DrawRay(origin, direction.Scale(10.0f), false, new XMUByteN4(80, 80, 80, 255)); this.DrawRay(origin, direction, false, ColorWhite); } // Draw secondary collision objects in colors based on collision results for (int i = 0; i < GroupCount; i++) { CollisionSphere sphere = this.secondarySpheres[i]; this.DrawSphere(sphere.Sphere, GetCollisionColor(sphere.Collision)); CollisionBox obox = this.secondaryOrientedBoxes[i]; this.DrawObb(obox.Box, GetCollisionColor(obox.Collision)); CollisionAABox aabox = this.secondaryAABoxes[i]; this.DrawAabb(aabox.Box, GetCollisionColor(aabox.Collision)); CollisionTriangle tri = this.secondaryTriangles[i]; this.DrawTriangle(tri.PointA, tri.PointB, tri.PointC, GetCollisionColor(tri.Collision)); } // Draw results of ray-object intersection, if there was a hit this frame if (this.rayHitResultBox.Collision != ContainmentType.Disjoint) { this.DrawAabb(this.rayHitResultBox.Box, ColorYellow); } }