public override Solid CreateSolid(AABB bounds) { Solid brush = new Solid { Bounds = (AABB)bounds.Clone() }; Vector3 min = bounds.Min; Vector3 max = bounds.Max; // create 4 top corners Vector3 topLeftMax = new Vector3(min.X, max.Y, max.Z); Vector3 topRightMax = new Vector3(max.X, max.Y, max.Z); Vector3 bottomRightMax = new Vector3(max.X, min.Y, max.Z); Vector3 bottomLeftMax = new Vector3(min.X, min.Y, max.Z); // create 4 bottom corners Vector3 topLeftMin = new Vector3(min.X, max.Y, min.Z); Vector3 topRightMin = new Vector3(max.X, max.Y, min.Z); Vector3 bottomRightMin = new Vector3(max.X, min.Y, min.Z); Vector3 bottomLeftMin = new Vector3(min.X, min.Y, min.Z); brush.VertexPositions.Add(topLeftMax); brush.VertexPositions.Add(topRightMax); brush.VertexPositions.Add(bottomRightMax); brush.VertexPositions.Add(bottomLeftMax); brush.VertexPositions.Add(topLeftMin); brush.VertexPositions.Add(topRightMin); brush.VertexPositions.Add(bottomRightMin); brush.VertexPositions.Add(bottomLeftMin); // front brush.Faces.Add(CreateFace(7, 6, 5, 4)); // back brush.Faces.Add(CreateFace(2, 3, 0, 1)); // top brush.Faces.Add(CreateFace(4, 5, 1, 0)); // bottom brush.Faces.Add(CreateFace(3, 2, 6, 7)); // left brush.Faces.Add(CreateFace(3, 7, 4, 0)); // right brush.Faces.Add(CreateFace(6, 2, 1, 5)); return(brush); }
public override Solid CreateSolid(AABB bounds) { Solid brush = new Solid { Bounds = (AABB)bounds.Clone() }; Vector3 start = bounds.Min; Vector3 end = bounds.Max; // create 4 top corners Vector3 topLeftMax = new Vector3(start.X, end.Y, end.Z); Vector3 bottomRightMax = new Vector3(end.X, start.Y, end.Z); Vector3 bottomLeftMax = new Vector3(start.X, start.Y, end.Z); // create 4 bottom corners Vector3 topLeftMin = new Vector3(start.X, end.Y, start.Z); Vector3 bottomRightMin = new Vector3(end.X, start.Y, start.Z); Vector3 bottomLeftMin = new Vector3(start.X, start.Y, start.Z); brush.VertexPositions.Add(topLeftMax); brush.VertexPositions.Add(bottomRightMax); brush.VertexPositions.Add(bottomLeftMax); brush.VertexPositions.Add(topLeftMin); brush.VertexPositions.Add(bottomRightMin); brush.VertexPositions.Add(bottomLeftMin); // right brush.Faces.Add(CreateFace(5, 4, 3)); // left brush.Faces.Add(CreateFace(1, 2, 0)); // bottom brush.Faces.Add(CreateFace(2, 1, 4, 5)); // back brush.Faces.Add(CreateFace(2, 5, 3, 0)); // top brush.Faces.Add(CreateFace(4, 1, 0, 3)); return(brush); }
public override Solid CreateSolid(AABB bounds) { int piePieces = sidesPropertyControl.Sides; Solid solidCone = new Solid(); SolidFace bottomFace = new SolidFace(); // create 4 corners points for the box float halfWidth = (bounds.Max.X - bounds.Min.X) / 2.0f; float halfHeight = (bounds.Max.Y - bounds.Min.Y) / 2.0f; float halfDepth = (bounds.Max.Z - bounds.Min.Z) / 2.0f; solidCone.Bounds = (AABB)bounds.Clone(); solidCone.VertexPositions.Add(new Vector3(bounds.Center.X, bounds.Center.Y, -halfDepth)); float degToRad = (float)(Math.PI / 180.0); float radPiece = (360.0f / piePieces * degToRad); // create vertices for (int i = 0; i < piePieces; i++) { SolidIndex index = new SolidIndex(); Vector3 position = new Vector3 { X = (float)Math.Cos(i * -radPiece) * halfWidth, Y = (float)Math.Sin(i * -radPiece) * halfHeight, Z = halfDepth }; index.Index = i + 1; solidCone.VertexPositions.Add(bounds.Center + position); bottomFace.Indices.Add(index); } solidCone.Faces.Add(bottomFace); int vertexCount = solidCone.VertexPositions.Count; // generate body for (int i = 0; i < piePieces; i++) { int index = i + 1; int nextIndex = index + 1; if (nextIndex == vertexCount) { nextIndex = 1; } SolidFace bodyFace = new SolidFace(); SolidIndex a = new SolidIndex { Index = 0 }; SolidIndex b = new SolidIndex { Index = index }; SolidIndex c = new SolidIndex { Index = nextIndex }; bodyFace.Indices.Add(c); bodyFace.Indices.Add(b); bodyFace.Indices.Add(a); solidCone.Faces.Add(bodyFace); } return(solidCone); }
public override Solid CreateSolid(AABB bounds) { int piePieces = sidesPropertyControl.Sides; Solid solidCylinder = new Solid(); SolidFace topFace = new SolidFace(); SolidFace bottomFace = new SolidFace(); solidCylinder.Bounds = (AABB)bounds.Clone(); Vector3 center = bounds.Center; // create 4 corners points for the box float halfWidth = (bounds.Max.X - bounds.Min.X) / 2.0f; float halfHeight = (bounds.Max.Y - bounds.Min.Y) / 2.0f; float halfDepth = (bounds.Max.Z - bounds.Min.Z) / 2.0f; float degToRad = (float)(Math.PI / 180.0); float radPiece = (360.0f / piePieces * degToRad); // create top and bottom face for (int i = 0; i < piePieces; i++) { SolidIndex topIndex = new SolidIndex(); SolidIndex bottomIndex = new SolidIndex(); Vector3 position = new Vector3 { X = (float)Math.Cos(i * radPiece) * halfWidth, Y = (float)Math.Sin(i * radPiece) * halfHeight }; solidCylinder.VertexPositions.Add(center + new Vector3(position.X, position.Y, -halfDepth)); solidCylinder.VertexPositions.Add(center + new Vector3(position.X, position.Y, halfDepth)); topIndex.Index = i * 2; bottomIndex.Index = piePieces * 2 - (i * 2 + 1); topFace.Indices.Add(topIndex); bottomFace.Indices.Add(bottomIndex); } solidCylinder.Faces.Add(topFace); solidCylinder.Faces.Add(bottomFace); // generate body for (int i = 0; i < piePieces; i++) { int nextIndex = i + 1; if (nextIndex == piePieces) { nextIndex = 0; } SolidFace bodyFace = new SolidFace(); SolidIndex a = new SolidIndex(); SolidIndex b = new SolidIndex(); SolidIndex c = new SolidIndex(); SolidIndex d = new SolidIndex(); a.Index = i * 2; b.Index = i * 2 + 1; c.Index = nextIndex * 2 + 1; d.Index = nextIndex * 2; bodyFace.Indices.Add(a); bodyFace.Indices.Add(b); bodyFace.Indices.Add(c); bodyFace.Indices.Add(d); solidCylinder.Faces.Add(bodyFace); } return(solidCylinder); }