Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/PackingPlanVisualizations/3D/BasicCuboidShape.cs @ 13365

Last change on this file since 13365 was 13032, checked in by gkronber, 9 years ago

#1966:

  • removed unused using
  • added/updated license headers
File size: 3.8 KB
Line 
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
22using SharpDX;
23using SharpDX.Toolkit.Graphics;
24using Buffer = SharpDX.Toolkit.Graphics.Buffer;
25
26namespace PackingPlanVisualizations {
27 
28  public class BasicCuboidShape {
29    //Basic information
30    private Vector3 shapeSize;
31    public Vector3 ShapeSize { get { return shapeSize; } }
32    private Vector3 shapePosition;
33    public Vector3 ShapePosition { get { return shapePosition; } }
34    private int shapeID;
35    public int ShapeID { get { return shapeID; } }
36    public int Material { get; set; }
37
38
39    //Vertices                                       
40    private VertexPositionColorNormal[] shapeTriangleVertices;
41    private VertexPositionColorNormal[] shapeLineVertices;
42
43    public BasicCuboidShape(Vector3 size, Vector3 position, int shapeNr, int material) {
44      shapeSize       = size;
45      shapePosition   = position;
46      shapeID     = shapeNr;
47      this.Material = material;
48    }
49    public BasicCuboidShape(Vector3 size, int shapeNr) : this(size, new Vector3(0, 0, 0), shapeNr, 0) { }
50
51    public void RenderShapeLines(GraphicsDevice device) {
52      RenderShapeLines(device, new Color(255, 255, 255));
53    }
54    public void RenderShapeLines(GraphicsDevice device, Color color) {
55      shapeLineVertices = (new CuboidShapePreparations(shapeSize, shapePosition, color)).CreateVertexDefinitionsForEdgeLines();
56      Buffer<VertexPositionColorNormal> shapeLineBuffer = Buffer.Vertex.New(
57          device,
58          shapeLineVertices);
59      VertexInputLayout inputLayoutLine = VertexInputLayout.FromBuffer(0, shapeLineBuffer);
60
61      device.SetVertexBuffer(shapeLineBuffer);
62      device.SetVertexInputLayout(inputLayoutLine);
63      device.Draw(PrimitiveType.LineList, shapeLineBuffer.ElementCount);
64    }
65
66    public void RenderShapeTriangles(GraphicsDevice device) {
67      RenderShapeTriangles(device, Material == 0 ? new Color(60,60,60) :new Color (0,0,0));
68    }
69
70    public void RenderShapeTriangles(GraphicsDevice device, Color color) {
71      shapeTriangleVertices = (new CuboidShapePreparations(shapeSize, shapePosition, color)).CreateVertexDefinitionsForTriangles();
72      Buffer<VertexPositionColorNormal> shapeTriangleBuffer = Buffer.Vertex.New(
73          device,
74          shapeTriangleVertices);
75      VertexInputLayout inputLayoutTriangles = VertexInputLayout.FromBuffer(0, shapeTriangleBuffer);
76
77      device.SetVertexBuffer(shapeTriangleBuffer);
78      device.SetVertexInputLayout(inputLayoutTriangles);
79      device.Draw(PrimitiveType.TriangleList, shapeTriangleBuffer.ElementCount);
80    }
81
82    public void RenderShapeTrianglesAndLines(GraphicsDevice device) {
83      RenderShapeLines(device);
84      RenderShapeTriangles(device);
85    }
86
87    public Vector3 CalculatePositionRelativeToBottomLeftBackCorner(Vector3 itemSize, Vector3 itemPosition) {     
88      //Vector3 bottomLeftBack = shapePosition + new Vector3(-1.0f, -1.0f, 1.0f) * shapeSize;
89      Vector3 newPosition = itemPosition - (shapeSize/2 - itemSize/2);
90      return newPosition;
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.