Exemplo n.º 1
0
 public void AddShape(Shape s)
 {
     IndexedShape ishape = new IndexedShape(s, this.Vertices.Count);
     if (!allShapes.Contains(ishape))
     {
         AddVertices(s);
         allShapes.Add(ishape);
         s.ShapeUpdated += new ShapeChangeEventHandler(s_ShapeUpdated);
         this.Update();
     }
 }
Exemplo n.º 2
0
 public Shape ConvertArrayToShape(Array data)
 {
     width = data.GetLength(1);
     height = data.GetLength(0);
     shape = new Shape();
     double[] prevRow = ReadRow(data, 0);
     for (int y = 1; y < height; y++)
     {
         double[] nextRow = ReadRow(data, y);
         Vertex[] verts = GetRowOfVertices(nextRow, prevRow, y - 1);
         shape.Vertices.AddRange(verts);
         prevRow = nextRow;
     }
     return shape;
 }
Exemplo n.º 3
0
 public Shape ConvertImageToShape(Image image)
 {
     Bitmap bmp = (Bitmap)image;
         byte [] bytes = ImageConverter.ConvertImageToBytes(bmp);
         width = image.Width;
         height = image.Height;
         shape = new Shape();
         int[] prevRow = ReadRow(bmp, 0);
         for (int y = 1; y < height; y++)
         {
             int[] nextRow = ReadRow(bmp, y);
             Vertex[] verts = GetRowOfVertices(nextRow,prevRow, y - 1);
             shape.Vertices.AddRange(verts);
             prevRow = nextRow;
         }
         return shape;
 }
Exemplo n.º 4
0
 public void UpdateShape(Shape s)
 {
     s.Update(device, shaderSignature);
 }
Exemplo n.º 5
0
 public bool RemoveShape(Shape s)
 {
     IndexedShape ishape = new IndexedShape(s, 0);
     bool ret = allShapes.Remove(ishape);
     if (ret)
     {
         s.ShapeUpdated -= s_ShapeUpdated;
         RebuildList();
         this.Update();
     }
     return ret;
 }
Exemplo n.º 6
0
 public IndexedShape(Shape s, int index)
 {
     this.shape = s;
     this.offset = index;
 }
Exemplo n.º 7
0
 private void AddVertices(Shape s)
 {
     for(int i = 0; i < s.Vertices.Count; i+=3)
     {
         Vertex[] triangle = Vertex.TransformTriangle(new Vertex[] { s.Vertices[i], s.Vertices[i+1], s.Vertices[i+2] }, s.World);
         this.Vertices.AddRange(triangle);
     }
 }
Exemplo n.º 8
0
 public ShapeChangeEventArgs(Shape changedShape, ChangeAction action)
 {
     this.changedShape = changedShape;
     this.action = action;
 }
Exemplo n.º 9
0
 public void CopyShapeTo(Shape other)
 {
     other.Vertices = this.Vertices;
     other.Location = this.Location;
     other.Rotation = this.Rotation;
     other.Scale = this.Scale;
     other.Update();
 }
Exemplo n.º 10
0
 public void CopyShapeFrom(Shape other)
 {
     this.Vertices = other.Vertices;
     this.Location = other.Location;
     this.Rotation = other.Rotation;
     this.Scale = other.Scale;
     this.Update();
 }
Exemplo n.º 11
0
 public bool RemoveShape(Shape s)
 {
     bool ret = engine.ShapeList.Remove(s);
     return ret;
 }
Exemplo n.º 12
0
 public void InsertShape(int index,Shape s)
 {
     engine.ShapeList.Insert(index,s);
     engine.UpdateShape(s);
 }
Exemplo n.º 13
0
 public void AddShape(Shape s)
 {
     engine.ShapeList.Add(s);
     engine.UpdateShape(s);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Reads a ComplexShape structure from an STL file.
        /// </summary>
        /// <param name="filename">Path of the file to read</param>
        /// <returns></returns>
        private static Shape CreateFromStlAsciiFile(Stream stream)
        {
            Shape ret = new Shape();
            System.Drawing.Color col = System.Drawing.Color.FromArgb(240, 240, 240);
            bool alreadyWarnedAboutNormal = false;
            int lineNum = 0;
            StreamReader reader = new StreamReader(stream);

            string line = reader.ReadLine();
            lineNum++;
            string[] words = line.Split(new char[] { ' ' });
            //ret. = words[1];
            List<Vector3> verts = new List<Vector3>();
            Vector3 norm = Vector3.Zero;
            // Loop through to end of file.
            while (!reader.EndOfStream)
            {
                line = reader.ReadLine();
                lineNum++;
                words = line.Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                if (words.Length < 1)
                    continue;
                else if (words[0].Equals("endsolid"))
                    break;
                else if (words[0].Equals("facet"))
                {
                    if (words[1].Equals("normal"))
                    {
                        norm = PopulateVector(words[2], words[3], words[4]);
                    }
                }
                else if (words[0].Equals("vertex"))
                {
                    verts.Add(PopulateVector(words[1], words[2], words[3]));
                }
                else if (words[0].Equals("endloop"))
                    continue;
                else if (words[0].Equals("endfacet"))
                {
                    if (verts.Count < 3) continue;
                    Vector3 calcNorm;
                    bool normCheck = ComplexShapeFactory.CheckNormal(norm, verts[0], verts[1], verts[2], out calcNorm);
                    if (!normCheck && !alreadyWarnedAboutNormal)
                    {
                        MessageBox.Show(""+stream + " line: " + lineNum + "\nCalculated Normal is different to Normal in file.\n" +
                            "\nin File:     " + norm +
                            "\ncalculated: " + calcNorm +
                            "\n\nV0: " + verts[0] +
                            "\nV1: " + verts[1] +
                            "\nV2: " + verts[2] +
                            "\n\nPerhaps it has a different meaning?");
                        alreadyWarnedAboutNormal = true;
                    }
                    ret.Vertices.Add(new Vertex(verts[0], col, norm));
                    ret.Vertices.Add(new Vertex(verts[1], col, norm));
                    ret.Vertices.Add(new Vertex(verts[2], col, norm));
                    ret.Vertices.Add(new Vertex(verts[2], col, -norm));
                    ret.Vertices.Add(new Vertex(verts[1], col, -norm));
                    ret.Vertices.Add(new Vertex(verts[0], col, -norm));
                    verts.Clear();
                }
                else
                    continue;

            }

            return ret;
        }
Exemplo n.º 15
0
        public Shape ReadShapeFromStream()
        {
            if (reader == null)
                throw new NullReferenceException("ShapeHGTFactory does not have a valid Stream");
            try
            {
                shape = new Shape();
                Initialize();
                SkipToStartRow();
                for (int r = 0; r < nRowsToRead - 1; r++)
                {
                    Vertex[] row = ReadNextRowOfTriangles();
                    shape.Vertices.AddRange(row);
                }

                return shape;
            }
            catch (Exception) { throw; }
        }
Exemplo n.º 16
0
 public Shape ReadAndReduceShapeFromFile(int logFactorToDecimate)
 {
     if (LatitudeDelta > 1 || LongitudeDelta > 1)
         return GenerateNullShape();
     Initialize();
     short[,] data = ReadHGT(startCol, startRow, nColumnsToRead, nRowsToRead);
     int width = data.GetLength(1);
     int height = data.GetLength(0);
     int factor = (int)Math.Pow(2.0, logFactorToDecimate);
     if (factor > 1)
     {
         Size newSize = new Size(width / factor, height / factor);
         data = Decimate(data, factor);
     }
     float latScale = (float)(UnitsPerDegreeLatitude * LatitudeDelta);
     float longScale = (float)(UnitsPerDegreeLatitude * LongitudeDelta);
     shape = ShapeArrayFactory.CreateFromArray(data, new PointF(latScale, longScale),verticalScale);
     return shape;
 }