#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 {
//Basic information
private Vector3 shapeSize;
public Vector3 ShapeSize { get { return shapeSize; } }
private Vector3 shapePosition;
public Vector3 ShapePosition { get { return shapePosition; } }
private int shapeID;
public int ShapeID { get { return shapeID; } }
public int Material { get; set; }
//Vertices
private VertexPositionColorNormal[] shapeTriangleVertices;
private VertexPositionColorNormal[] shapeLineVertices;
public BasicCuboidShape(Vector3 size, Vector3 position, int shapeNr, int material) {
shapeSize = size;
shapePosition = position;
shapeID = shapeNr;
this.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();
Buffer shapeLineBuffer = Buffer.Vertex.New(
device,
shapeLineVertices);
VertexInputLayout 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();
Buffer shapeTriangleBuffer = Buffer.Vertex.New(
device,
shapeTriangleVertices);
VertexInputLayout 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 bottomLeftBack = shapePosition + new Vector3(-1.0f, -1.0f, 1.0f) * shapeSize;
Vector3 newPosition = itemPosition - (shapeSize/2 - itemSize/2);
return newPosition;
}
}
}