Browse Source

added Rectangle (for drawing plane)

Alexander Hendrich 11 years ago
parent
commit
06ee7edef9
4 changed files with 69 additions and 9 deletions
  1. 1 1
      bbiwarg/Graphics/Output.cs
  2. 8 8
      bbiwarg/Graphics/Point.cs
  3. 59 0
      bbiwarg/Graphics/Rectangle.cs
  4. 1 0
      bbiwarg/bbiwarg.csproj

+ 1 - 1
bbiwarg/Graphics/Output.cs

@@ -82,7 +82,7 @@ namespace bbiwarg.Graphics
             int numVertices = vertexArray.getNumVertices();
             depthPixels = new Point[numVertices];
 
-            float size = 0.001f;
+            float size = 0.002f;
             for (int i = 0; i < numVertices; i++) {
                 Vertex vertex = vertexArray.getVertex(i);
                 Color color = vertexArray.getColor(i);

+ 8 - 8
bbiwarg/Graphics/Point.cs

@@ -27,10 +27,10 @@ namespace bbiwarg.Graphics
             GL.Color4(color);
 
             GL.Begin(BeginMode.Polygon);
-            GL.Vertex3(position.x - size, position.y + size, -position.z);
-            GL.Vertex3(position.x + size, position.y + size, -position.z);
-            GL.Vertex3(position.x + size, position.y - size, -position.z);
-            GL.Vertex3(position.x - size, position.y - size, -position.z);
+            GL.Vertex3(position.x - size/2, position.y + size/2, -position.z);
+            GL.Vertex3(position.x + size/2, position.y + size/2, -position.z);
+            GL.Vertex3(position.x + size/2, position.y - size/2, -position.z);
+            GL.Vertex3(position.x - size/2, position.y - size/2, -position.z);
             GL.End();
         }
 
@@ -39,10 +39,10 @@ namespace bbiwarg.Graphics
 
             List<Vector> result = new List<Vector>();
 
-            result.Add(new DenseVector(new float[] { position.x - size, position.y + size, -position.z }));
-            result.Add(new DenseVector(new float[] { position.x + size, position.y + size, -position.z }));
-            result.Add(new DenseVector(new float[] { position.x + size, position.y - size, -position.z }));
-            result.Add(new DenseVector(new float[] { position.x - size, position.y - size, -position.z }));
+            result.Add(new DenseVector(new float[] { position.x - size/2, position.y + size/2, -position.z }));
+            result.Add(new DenseVector(new float[] { position.x + size/2, position.y + size/2, -position.z }));
+            result.Add(new DenseVector(new float[] { position.x + size/2, position.y - size/2, -position.z }));
+            result.Add(new DenseVector(new float[] { position.x - size/2, position.y - size/2, -position.z }));
 
             return result;
 

+ 59 - 0
bbiwarg/Graphics/Rectangle.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using OpenTK.Graphics.OpenGL;
+using MathNet.Numerics.LinearAlgebra.Single;
+
+namespace bbiwarg.Graphics
+{
+    class Rectangle : IGraphicElement
+    {
+        public Vertex[] corners;
+        public Color color;
+
+        public Rectangle(Vertex[] corners, Color color)
+        {
+            this.corners = corners;
+            this.color = color;
+        }
+
+        public void draw()
+        {
+            GL.Color4(color);
+
+            GL.Begin(BeginMode.Polygon);
+            GL.Vertex3(corners[0].x, corners[0].y, -corners[0].z);
+            GL.Vertex3(corners[1].x, corners[0].y, -corners[0].z);
+            GL.Vertex3(corners[1].x, corners[1].y, -corners[1].z);
+            GL.Vertex3(corners[0].x, corners[1].y, -corners[1].z);
+            GL.End();
+        }
+
+        public List<Vector> getVertices()
+        {
+
+            List<Vector> result = new List<Vector>();
+
+            result.Add(new DenseVector(new float[] { corners[0].x, corners[0].y, -corners[0].z }));
+            result.Add(new DenseVector(new float[] { corners[1].x, corners[0].y, -corners[0].z }));
+            result.Add(new DenseVector(new float[] { corners[1].x, corners[1].y, -corners[1].z }));
+            result.Add(new DenseVector(new float[] { corners[0].x, corners[1].y, -corners[1].z }));
+
+            return result;
+
+        }
+
+        public uint[] getTriangleIndices()
+        {
+            return new uint[] { 0, 1, 2, 0, 2, 3 };
+        }
+
+        public Color getColor()
+        {
+            return color;
+        }
+    }
+}

+ 1 - 0
bbiwarg/bbiwarg.csproj

@@ -64,6 +64,7 @@
     <Compile Include="DataSource\IisuDataSource.cs" />
     <Compile Include="DataSource\IVideoDataSource.cs" />
     <Compile Include="DataSource\VertexArray.cs" />
+    <Compile Include="Graphics\Rectangle.cs" />
     <Compile Include="Graphics\IGraphicElement.cs" />
     <Compile Include="Graphics\Point.cs" />
     <Compile Include="Graphics\Vertex.cs" />