#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using SharpDX; namespace PackingPlanVisualizations { public class CuboidShapePreparations { #region Private Members //Define the shape in a way so that the position is in the center of the shape. //Define the 8 defining points of the cube Vector3 topLeftFront; Vector3 bottomLeftFront; Vector3 topRightFront; Vector3 bottomRightFront; Vector3 topLeftBack; Vector3 topRightBack; Vector3 bottomLeftBack; Vector3 bottomRightBack; //Define normal vectors of the 6 surfaces Vector3 frontNormal; Vector3 backNormal; Vector3 topNormal; Vector3 bottomNormal; Vector3 leftNormal; Vector3 rightNormal; //Define colors of the 6 surfaces Color frontColor = Color.Black; Color backColor = Color.Black; Color topColor = Color.Black; Color bottomColor = Color.Black; Color leftColor = Color.Black; Color rightColor = Color.Black; //Define positions of the textures Vector2 textureTopLeft; Vector2 textureTopRight; Vector2 textureBottomLeft; Vector2 textureBottomRight; #endregion Private Members public CuboidShapePreparations(Vector3 shapeSize, Vector3 shapePosition) : this (shapeSize, shapePosition, Color.Black) { } public CuboidShapePreparations(Vector3 shapeSize, Vector3 shapePosition, Color color) { var halfShapeSize = shapeSize / 2; //Define the shape in a way so that the position is in the center of the shape. //Define the 8 defining points of the cube topLeftFront = shapePosition + new Vector3(-1.0f, 1.0f, 1.0f) * halfShapeSize; bottomLeftFront = shapePosition + new Vector3(-1.0f, -1.0f, 1.0f) * halfShapeSize; topRightFront = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * halfShapeSize; bottomRightFront = shapePosition + new Vector3(1.0f, -1.0f, 1.0f) * halfShapeSize; topLeftBack = shapePosition + new Vector3(-1.0f, 1.0f, -1.0f) * halfShapeSize; topRightBack = shapePosition + new Vector3(1.0f, 1.0f, -1.0f) * halfShapeSize; bottomLeftBack = shapePosition + new Vector3(-1.0f, -1.0f, -1.0f) * halfShapeSize; bottomRightBack = shapePosition + new Vector3(1.0f, -1.0f, -1.0f) * halfShapeSize; //Define normal vectors of the 6 surfaces frontNormal = new Vector3(0.0f, 0.0f, 1.0f) * halfShapeSize; backNormal = new Vector3(0.0f, 0.0f, -1.0f) * halfShapeSize; topNormal = new Vector3(0.0f, 1.0f, 0.0f) * halfShapeSize; bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * halfShapeSize; leftNormal = new Vector3(-1.0f, 0.0f, 0.0f) * halfShapeSize; rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * halfShapeSize; //Define colors of the 6 surfaces frontColor = color; backColor = color; topColor = color; bottomColor = color; leftColor = color; rightColor = color; //Define positions of the textures textureTopLeft = new Vector2(0.5f * halfShapeSize.X, 0.0f * halfShapeSize.Y); textureTopRight = new Vector2(0.0f * halfShapeSize.X, 0.0f * halfShapeSize.Y); textureBottomLeft = new Vector2(0.5f * halfShapeSize.X, 0.5f * halfShapeSize.Y); textureBottomRight = new Vector2(0.0f * halfShapeSize.X, 0.5f * halfShapeSize.Y); } public VertexPositionColorNormal[] CreateVertexDefinitionsForTriangles () { //Definition of the actual triangles VertexPositionColorNormal[] shapeVertices = new VertexPositionColorNormal[36]; // Front face. shapeVertices[0] = new VertexPositionColorNormal(frontColor, topLeftFront, frontNormal); shapeVertices[1] = new VertexPositionColorNormal(frontColor, bottomLeftFront, frontNormal); shapeVertices[2] = new VertexPositionColorNormal(frontColor, topRightFront, frontNormal); shapeVertices[3] = new VertexPositionColorNormal(frontColor, bottomLeftFront, frontNormal); shapeVertices[4] = new VertexPositionColorNormal(frontColor, bottomRightFront, frontNormal); shapeVertices[5] = new VertexPositionColorNormal(frontColor, topRightFront, frontNormal); // Back face. shapeVertices[6] = new VertexPositionColorNormal(backColor, topLeftBack, backNormal); shapeVertices[7] = new VertexPositionColorNormal(backColor, topRightBack, backNormal); shapeVertices[8] = new VertexPositionColorNormal(backColor, bottomLeftBack, backNormal); shapeVertices[9] = new VertexPositionColorNormal(backColor, bottomLeftBack, backNormal); shapeVertices[10] = new VertexPositionColorNormal(backColor, topRightBack, backNormal); shapeVertices[11] = new VertexPositionColorNormal(backColor, bottomRightBack, backNormal); // Top face. shapeVertices[12] = new VertexPositionColorNormal(topColor, topLeftFront, topNormal); shapeVertices[13] = new VertexPositionColorNormal(topColor, topRightBack, topNormal); shapeVertices[14] = new VertexPositionColorNormal(topColor, topLeftBack, topNormal); shapeVertices[15] = new VertexPositionColorNormal(topColor, topLeftFront, topNormal); shapeVertices[16] = new VertexPositionColorNormal(topColor, topRightFront, topNormal); shapeVertices[17] = new VertexPositionColorNormal(topColor, topRightBack, topNormal); // Bottom face. shapeVertices[18] = new VertexPositionColorNormal(bottomColor, bottomLeftFront, bottomNormal); shapeVertices[19] = new VertexPositionColorNormal(bottomColor, bottomLeftBack, bottomNormal); shapeVertices[20] = new VertexPositionColorNormal(bottomColor, bottomRightBack, bottomNormal); shapeVertices[21] = new VertexPositionColorNormal(bottomColor, bottomLeftFront, bottomNormal); shapeVertices[22] = new VertexPositionColorNormal(bottomColor, bottomRightBack, bottomNormal); shapeVertices[23] = new VertexPositionColorNormal(bottomColor, bottomRightFront, bottomNormal); // Left face. shapeVertices[24] = new VertexPositionColorNormal(leftColor, topLeftFront, leftNormal); shapeVertices[25] = new VertexPositionColorNormal(leftColor, bottomLeftBack, leftNormal); shapeVertices[26] = new VertexPositionColorNormal(leftColor, bottomLeftFront, leftNormal); shapeVertices[27] = new VertexPositionColorNormal(leftColor, topLeftBack, leftNormal); shapeVertices[28] = new VertexPositionColorNormal(leftColor, bottomLeftBack, leftNormal); shapeVertices[29] = new VertexPositionColorNormal(leftColor, topLeftFront, leftNormal); // Right face. shapeVertices[30] = new VertexPositionColorNormal(rightColor, topRightFront, rightNormal); shapeVertices[31] = new VertexPositionColorNormal(rightColor, bottomRightFront, rightNormal); shapeVertices[32] = new VertexPositionColorNormal(rightColor, bottomRightBack, rightNormal); shapeVertices[33] = new VertexPositionColorNormal(rightColor, topRightBack, rightNormal); shapeVertices[34] = new VertexPositionColorNormal(rightColor, topRightFront, rightNormal); shapeVertices[35] = new VertexPositionColorNormal(rightColor, bottomRightBack, rightNormal); return shapeVertices; } public VertexPositionColorNormal[] CreateVertexDefinitionsForEdgeLines() { return CreateVertexDefinitionsForEdgeLines(frontColor); } public VertexPositionColorNormal[] CreateVertexDefinitionsForEdgeLines(Color color) { //Definition of the actual lines VertexPositionColorNormal[] shapeVertices = new VertexPositionColorNormal[48]; //shapeVertices[0] = new VertexPositionColorNormal(color, topRightFront, frontNormal); //shapeVertices[1] = new VertexPositionColorNormal(color, topLeftFront, frontNormal); //shapeVertices[2] = new VertexPositionColorNormal(color, topLeftFront, frontNormal); //shapeVertices[3] = new VertexPositionColorNormal(color, bottomLeftFront, frontNormal); //shapeVertices[4] = new VertexPositionColorNormal(color, bottomLeftFront, frontNormal); //shapeVertices[5] = new VertexPositionColorNormal(color, bottomRightFront, frontNormal); //shapeVertices[6] = new VertexPositionColorNormal(color, bottomRightFront, frontNormal); //shapeVertices[7] = new VertexPositionColorNormal(color, topRightFront, frontNormal); //shapeVertices[8] = new VertexPositionColorNormal(color, topRightBack, backNormal); //shapeVertices[9] = new VertexPositionColorNormal(color, topLeftBack, backNormal); //shapeVertices[10] = new VertexPositionColorNormal(color, topLeftBack, backNormal); //shapeVertices[11] = new VertexPositionColorNormal(color, bottomLeftBack, backNormal); //shapeVertices[12] = new VertexPositionColorNormal(color, bottomLeftBack, backNormal); //shapeVertices[13] = new VertexPositionColorNormal(color, bottomRightBack, backNormal); //shapeVertices[14] = new VertexPositionColorNormal(color, bottomRightBack, backNormal); //shapeVertices[15] = new VertexPositionColorNormal(color, topRightBack, backNormal); //shapeVertices[16] = new VertexPositionColorNormal(color, topLeftFront, topNormal); //shapeVertices[17] = new VertexPositionColorNormal(color, topLeftBack, topNormal); //shapeVertices[18] = new VertexPositionColorNormal(color, topRightFront, topNormal); //shapeVertices[19] = new VertexPositionColorNormal(color, topRightBack, topNormal); //shapeVertices[20] = new VertexPositionColorNormal(color, topLeftFront, topNormal); //shapeVertices[21] = new VertexPositionColorNormal(color, topRightFront, topNormal); //shapeVertices[22] = new VertexPositionColorNormal(color, topRightBack, topNormal); //shapeVertices[23] = new VertexPositionColorNormal(color, topLeftBack, topNormal); //shapeVertices[24] = new VertexPositionColorNormal(color, bottomLeftFront, bottomNormal); //shapeVertices[25] = new VertexPositionColorNormal(color, bottomRightFront, bottomNormal); //shapeVertices[26] = new VertexPositionColorNormal(color, bottomLeftBack, bottomNormal); //shapeVertices[27] = new VertexPositionColorNormal(color, bottomRightBack, bottomNormal); //shapeVertices[28] = new VertexPositionColorNormal(color, bottomRightFront, bottomNormal); //shapeVertices[29] = new VertexPositionColorNormal(color, bottomRightBack, bottomNormal); //shapeVertices[30] = new VertexPositionColorNormal(color, bottomLeftFront, bottomNormal); //shapeVertices[31] = new VertexPositionColorNormal(color, bottomLeftBack, bottomNormal); //shapeVertices[32] = new VertexPositionColorNormal(color, topLeftFront, leftNormal); //shapeVertices[33] = new VertexPositionColorNormal(color, topLeftBack, leftNormal); //shapeVertices[34] = new VertexPositionColorNormal(color, topLeftBack, leftNormal); //shapeVertices[35] = new VertexPositionColorNormal(color, bottomLeftBack, leftNormal); //shapeVertices[36] = new VertexPositionColorNormal(color, bottomLeftBack, leftNormal); //shapeVertices[37] = new VertexPositionColorNormal(color, bottomLeftFront, leftNormal); //shapeVertices[38] = new VertexPositionColorNormal(color, bottomLeftFront, leftNormal); //shapeVertices[39] = new VertexPositionColorNormal(color, topLeftFront, leftNormal); //shapeVertices[40] = new VertexPositionColorNormal(color, topRightFront, rightNormal); //shapeVertices[41] = new VertexPositionColorNormal(color, topRightBack, rightNormal); //shapeVertices[42] = new VertexPositionColorNormal(color, topRightBack, rightNormal); //shapeVertices[43] = new VertexPositionColorNormal(color, bottomRightBack, rightNormal); //shapeVertices[44] = new VertexPositionColorNormal(color, bottomRightBack, rightNormal); //shapeVertices[45] = new VertexPositionColorNormal(color, bottomRightFront, rightNormal); //shapeVertices[46] = new VertexPositionColorNormal(color, bottomRightFront, rightNormal); //shapeVertices[47] = new VertexPositionColorNormal(color, topRightFront, rightNormal); Vector3 topRightFrontNormal = (topNormal + rightNormal + frontNormal) / 3; Vector3 topRightBackNormal = (topNormal + rightNormal + backNormal) / 3; Vector3 topLeftFrontNormal = (topNormal + leftNormal + frontNormal) / 3; Vector3 topLeftBackNormal = (topNormal + leftNormal + backNormal) / 3; Vector3 bottomRightFrontNormal = (topNormal + rightNormal + frontNormal) / 3; Vector3 bottomRightBackNormal = (topNormal + rightNormal + backNormal) / 3; Vector3 bottomLeftFrontNormal = (topNormal + leftNormal + frontNormal) / 3; Vector3 bottomLeftBackNormal = (topNormal + leftNormal + backNormal) / 3; shapeVertices[0] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal); shapeVertices[1] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal); shapeVertices[2] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal); shapeVertices[3] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal); shapeVertices[4] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal); shapeVertices[5] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal); shapeVertices[6] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal); shapeVertices[7] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal); shapeVertices[8] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal); shapeVertices[9] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal); shapeVertices[10] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal); shapeVertices[11] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal); shapeVertices[12] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal); shapeVertices[13] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal); shapeVertices[14] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal); shapeVertices[15] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal); shapeVertices[16] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal); shapeVertices[17] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal); shapeVertices[18] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal); shapeVertices[19] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal); shapeVertices[20] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal); shapeVertices[21] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal); shapeVertices[22] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal); shapeVertices[23] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal); shapeVertices[24] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal); shapeVertices[25] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal); shapeVertices[26] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal); shapeVertices[27] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal); shapeVertices[28] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal); shapeVertices[29] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal); shapeVertices[30] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal); shapeVertices[31] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal); shapeVertices[32] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal); shapeVertices[33] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal); shapeVertices[34] = new VertexPositionColorNormal(color, topLeftBack, topLeftBackNormal); shapeVertices[35] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal); shapeVertices[36] = new VertexPositionColorNormal(color, bottomLeftBack, bottomLeftBackNormal); shapeVertices[37] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal); shapeVertices[38] = new VertexPositionColorNormal(color, bottomLeftFront, bottomLeftFrontNormal); shapeVertices[39] = new VertexPositionColorNormal(color, topLeftFront, topLeftFrontNormal); shapeVertices[40] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal); shapeVertices[41] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal); shapeVertices[42] = new VertexPositionColorNormal(color, topRightBack, topRightBackNormal); shapeVertices[43] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal); shapeVertices[44] = new VertexPositionColorNormal(color, bottomRightBack, bottomRightBackNormal); shapeVertices[45] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal); shapeVertices[46] = new VertexPositionColorNormal(color, bottomRightFront, bottomRightFrontNormal); shapeVertices[47] = new VertexPositionColorNormal(color, topRightFront, topRightFrontNormal); return shapeVertices; } } }