[13032] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[13028] | 22 | using SharpDX;
|
---|
| 23 | using SharpDX.Toolkit.Graphics;
|
---|
| 24 | using Buffer = SharpDX.Toolkit.Graphics.Buffer;
|
---|
| 25 |
|
---|
| 26 | namespace PackingPlanVisualizations {
|
---|
[13465] | 27 |
|
---|
[13028] | 28 | public class BasicCuboidShape {
|
---|
[13497] | 29 | public Vector3 ShapeSize { get; private set; }
|
---|
| 30 | public Vector3 ShapePosition { get; private set; }
|
---|
| 31 | public int ShapeID { get; private set; }
|
---|
| 32 | public int Material { get; private set; }
|
---|
[13028] | 33 |
|
---|
| 34 |
|
---|
| 35 | private VertexPositionColorNormal[] shapeTriangleVertices;
|
---|
| 36 | private VertexPositionColorNormal[] shapeLineVertices;
|
---|
| 37 |
|
---|
| 38 | public BasicCuboidShape(Vector3 size, Vector3 position, int shapeNr, int material) {
|
---|
[13497] | 39 | ShapeSize = size;
|
---|
| 40 | ShapePosition = position;
|
---|
| 41 | ShapeID = shapeNr;
|
---|
| 42 | Material = material;
|
---|
[13028] | 43 | }
|
---|
| 44 | public BasicCuboidShape(Vector3 size, int shapeNr) : this(size, new Vector3(0, 0, 0), shapeNr, 0) { }
|
---|
| 45 |
|
---|
| 46 | public void RenderShapeLines(GraphicsDevice device) {
|
---|
| 47 | RenderShapeLines(device, new Color(255, 255, 255));
|
---|
| 48 | }
|
---|
| 49 | public void RenderShapeLines(GraphicsDevice device, Color color) {
|
---|
[13497] | 50 | shapeLineVertices =
|
---|
| 51 | new CuboidShapePreparations(ShapeSize, ShapePosition, color).CreateVertexDefinitionsForEdgeLines();
|
---|
| 52 | var shapeLineBuffer = Buffer.Vertex.New(device, shapeLineVertices);
|
---|
| 53 | var inputLayoutLine = VertexInputLayout.FromBuffer(0, shapeLineBuffer);
|
---|
[13028] | 54 |
|
---|
| 55 | device.SetVertexBuffer(shapeLineBuffer);
|
---|
| 56 | device.SetVertexInputLayout(inputLayoutLine);
|
---|
| 57 | device.Draw(PrimitiveType.LineList, shapeLineBuffer.ElementCount);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public void RenderShapeTriangles(GraphicsDevice device) {
|
---|
[13465] | 61 | RenderShapeTriangles(device, Material == 0 ? new Color(60, 60, 60) : new Color(0, 0, 0));
|
---|
[13028] | 62 | }
|
---|
| 63 |
|
---|
| 64 | public void RenderShapeTriangles(GraphicsDevice device, Color color) {
|
---|
[13497] | 65 | shapeTriangleVertices =
|
---|
| 66 | new CuboidShapePreparations(ShapeSize, ShapePosition, color).CreateVertexDefinitionsForTriangles();
|
---|
| 67 | var shapeTriangleBuffer = Buffer.Vertex.New(device, shapeTriangleVertices);
|
---|
| 68 | var inputLayoutTriangles = VertexInputLayout.FromBuffer(0, shapeTriangleBuffer);
|
---|
[13028] | 69 |
|
---|
| 70 | device.SetVertexBuffer(shapeTriangleBuffer);
|
---|
| 71 | device.SetVertexInputLayout(inputLayoutTriangles);
|
---|
| 72 | device.Draw(PrimitiveType.TriangleList, shapeTriangleBuffer.ElementCount);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | public void RenderShapeTrianglesAndLines(GraphicsDevice device) {
|
---|
| 76 | RenderShapeLines(device);
|
---|
| 77 | RenderShapeTriangles(device);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[13465] | 80 | public Vector3 CalculatePositionRelativeToBottomLeftBackCorner(Vector3 itemSize, Vector3 itemPosition) {
|
---|
[13497] | 81 | Vector3 newPosition = itemPosition - (ShapeSize / 2 - itemSize / 2);
|
---|
[13028] | 82 | return newPosition;
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | } |
---|