public static void DrawTransparentCuboid(ref Matrix worldMatrix, MyCuboid cuboid, ref Vector4 vctColor, bool bWireFramed, float thickness, MyTransparentMaterialEnum?lineMaterial = null) { foreach (MyLine line in cuboid.UniqueLines) { Vector3 from = Vector3.Transform(line.From, worldMatrix); Vector3 to = Vector3.Transform(line.To, worldMatrix); DrawLine(from, to, lineMaterial ?? MyTransparentMaterialEnum.ProjectileTrailLine, ref vctColor, thickness); } }
public MyCuboid CreateTransformed(ref Matrix worldMatrix) { Vector3[] vertices = new Vector3[8]; int i = 0; foreach (Vector3 vertex in Vertices) { vertices[i] = Vector3.Transform(vertex, worldMatrix); i++; } MyCuboid transformedCuboid = new MyCuboid(); transformedCuboid.CreateFromVertices(vertices); return(transformedCuboid); }
} //Create Cuboid public static void CutOutCuboid(MyVoxelMap voxelMap, MyCuboid cuboid, MyMwcVoxelMaterialsEnum? material) { BoundingBox aabb = cuboid.GetAABB(); MyMwcVector3Int minCorner = voxelMap.GetVoxelCoordinateFromMeters(aabb.Min - new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES)); MyMwcVector3Int maxCorner = voxelMap.GetVoxelCoordinateFromMeters(aabb.Max + new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES)); voxelMap.FixVoxelCoord(ref minCorner); voxelMap.FixVoxelCoord(ref maxCorner); MyMwcVector3Int tempVoxelCoord; for (tempVoxelCoord.X = minCorner.X; tempVoxelCoord.X <= maxCorner.X; tempVoxelCoord.X++) { for (tempVoxelCoord.Y = minCorner.Y; tempVoxelCoord.Y <= maxCorner.Y; tempVoxelCoord.Y++) { for (tempVoxelCoord.Z = minCorner.Z; tempVoxelCoord.Z <= maxCorner.Z; tempVoxelCoord.Z++) { Vector3 position = voxelMap.GetVoxelCenterPositionAbsolute(ref tempVoxelCoord); BoundingBox voxelAABB = new BoundingBox(position - new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF), position + new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF)); bool isInside = true; for (int i = 0; i < cuboid.Sides.Length; i++) { MyPlane side = cuboid.Sides[i].Plane; float distance = MyUtils.GetDistanceFromPointToPlane(ref position, ref side); if (distance > 0) { isInside = false; break; } } float minDistance = float.MaxValue; for (int i = 0; i < cuboid.Sides.Length; i++) { MyQuad quad = new MyQuad(); quad.Point0 = cuboid.Sides[i].Lines[0].From; quad.Point1 = cuboid.Sides[i].Lines[1].From; quad.Point2 = cuboid.Sides[i].Lines[3].From; quad.Point3 = cuboid.Sides[i].Lines[2].From; float distance = MyUtils.GetDistancePointToQuad(ref position, ref quad); if (distance < minDistance) { minDistance = distance; } } byte newContent = 0; if (isInside) { if (minDistance > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { newContent = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else { // This formula will work even if diff is positive or negative //newContent = MyVoxelConstants.VOXEL_CONTENT_EMPTY; newContent = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - minDistance / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); //newContent = (byte)(MyVoxelConstants.VOXEL_CONTENT_FULL - (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - minDistance / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL)); } } else { if (minDistance > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { newContent = MyVoxelConstants.VOXEL_CONTENT_FULL; } else { //newContent = MyVoxelConstants.VOXEL_CONTENT_FULL; // This formula will work even if diff is positive or negative //newContent = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - minDistance / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); newContent = (byte)(MyVoxelConstants.VOXEL_CONTENT_FULL - (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - minDistance / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL)); } } byte originalContent = voxelMap.GetVoxelContent(ref tempVoxelCoord); if (newContent < originalContent) { voxelMap.SetVoxelContent(newContent, ref tempVoxelCoord); if (material.HasValue) voxelMap.SetVoxelMaterialAndIndestructibleContent(material.Value, 0, ref tempVoxelCoord); } } } } voxelMap.InvalidateCache(minCorner, maxCorner); voxelMap.CalcAverageDataCellMaterials(); } //CutOut Cuboid
public MyCuboid CreateTransformed(ref Matrix worldMatrix) { Vector3[] vertices = new Vector3[8]; int i = 0; foreach (Vector3 vertex in Vertices) { vertices[i] = Vector3.Transform(vertex, worldMatrix); i++; } MyCuboid transformedCuboid = new MyCuboid(); transformedCuboid.CreateFromVertices(vertices); return transformedCuboid; }
public static void DrawTransparentCuboid(ref Matrix worldMatrix, MyCuboid cuboid, ref Vector4 vctColor, bool bWireFramed, float thickness, MyTransparentMaterialEnum? lineMaterial = null) { foreach (MyLine line in cuboid.UniqueLines) { Vector3 from = Vector3.Transform(line.From, worldMatrix); Vector3 to = Vector3.Transform(line.To, worldMatrix); DrawLine(from, to, lineMaterial ?? MyTransparentMaterialEnum.ProjectileTrailLine, ref vctColor, thickness); } }