#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; using SharpDX.Toolkit.Graphics; using Buffer = SharpDX.Toolkit.Graphics.Buffer; namespace PackingPlanVisualizations { public class BasicCuboidShape { public Vector3 ShapeSize { get; private set; } public Vector3 ShapePosition { get; private set; } public int ShapeID { get; private set; } public int Material { get; private set; } private VertexPositionColorNormal[] shapeTriangleVertices; private VertexPositionColorNormal[] shapeLineVertices; public BasicCuboidShape(Vector3 size, Vector3 position, int shapeNr, int material) { ShapeSize = size; ShapePosition = position; ShapeID = shapeNr; Material = material; } public BasicCuboidShape(Vector3 size, int shapeNr) : this(size, new Vector3(0, 0, 0), shapeNr, 0) { } public void RenderShapeLines(GraphicsDevice device) { RenderShapeLines(device, new Color(255, 255, 255)); } public void RenderShapeLines(GraphicsDevice device, Color color) { shapeLineVertices = new CuboidShapePreparations(ShapeSize, ShapePosition, color).CreateVertexDefinitionsForEdgeLines(); var shapeLineBuffer = Buffer.Vertex.New(device, shapeLineVertices); var inputLayoutLine = VertexInputLayout.FromBuffer(0, shapeLineBuffer); device.SetVertexBuffer(shapeLineBuffer); device.SetVertexInputLayout(inputLayoutLine); device.Draw(PrimitiveType.LineList, shapeLineBuffer.ElementCount); } public void RenderShapeTriangles(GraphicsDevice device) { RenderShapeTriangles(device, Material == 0 ? new Color(60, 60, 60) : new Color(0, 0, 0)); } public void RenderShapeTriangles(GraphicsDevice device, Color color) { shapeTriangleVertices = new CuboidShapePreparations(ShapeSize, ShapePosition, color).CreateVertexDefinitionsForTriangles(); var shapeTriangleBuffer = Buffer.Vertex.New(device, shapeTriangleVertices); var inputLayoutTriangles = VertexInputLayout.FromBuffer(0, shapeTriangleBuffer); device.SetVertexBuffer(shapeTriangleBuffer); device.SetVertexInputLayout(inputLayoutTriangles); device.Draw(PrimitiveType.TriangleList, shapeTriangleBuffer.ElementCount); } public void RenderShapeTrianglesAndLines(GraphicsDevice device) { RenderShapeLines(device); RenderShapeTriangles(device); } public Vector3 CalculatePositionRelativeToBottomLeftBackCorner(Vector3 itemSize, Vector3 itemPosition) { Vector3 newPosition = itemPosition - (ShapeSize / 2 - itemSize / 2); return newPosition; } } }