Esempio n. 1
0
 private void getMinMax()
 {
     xmin = int.MaxValue;
     xmax = int.MinValue;
     ymin = int.MaxValue;
     ymax = int.MinValue;
     for (var j = 0; j < polygons.Count; j++)
     {
         var vertices = (ArrayList)polygons[j];
         for (var i = 0; i < vertices.Count; i++)
         {
             var vertex = (DoubleVector2)vertices[i];
             xmin = Math.Min(xmin, (int)vertex.x);
             xmax = Math.Max(xmax, (int)vertex.x);
             ymin = Math.Min(ymin, (int)vertex.y);
             ymax = Math.Max(ymax, (int)vertex.y);
         }
     }
     for (var i = 0; i < objects.Count; i++)
     {
         var vertex = new DoubleVector2(((ElmaObject)objects[i]).x, ((ElmaObject)objects[i]).y);
         xmin = Math.Min(xmin, (int)vertex.x);
         xmax = Math.Max(xmax, (int)vertex.x);
         ymin = Math.Min(ymin, (int)vertex.y);
         ymax = Math.Max(ymax, (int)vertex.y);
     }
 }
Esempio n. 2
0
        public void transformVectors(Matrix2D matrix)
        {
            var randGen = new Random();

            for (var j = 0; j < polygons.Count; j++)
            {
                var vertices = (ArrayList)polygons[j];
                for (var i = 0; i < vertices.Count; i++)
                {
                    var vertexOld = (DoubleVector2)vertices[i];
                    vertices.RemoveAt(i);
                    var vertexNew = vertexOld * matrix;
                    // add a little random jitter so as to remove the 'horizontal line' bug
                    vertexNew.x += randGen.NextDouble() / 100000.0;
                    vertexNew.y += randGen.NextDouble() / 100000.0;
                    vertices.Insert(i, vertexNew);
                }
            }
            for (var i = 0; i < objects.Count; i++)
            {
                var objectNow = (ElmaObject)objects[i];
                var vertexOld = new DoubleVector2(objectNow.x, objectNow.y);
                objects.RemoveAt(i);
                var vertexNew = vertexOld * matrix;
                objectNow.x = vertexNew.x;
                objectNow.y = vertexNew.y;
                objects.Insert(i, objectNow);
            }
            getMinMax();
        }
Esempio n. 3
0
        public static DoubleVector2 operator *(DoubleVector2 v, Matrix2D m)
        {
            var vector = new DoubleVector2();

            vector.x = v.x * m.elements[0, 0] + v.y * m.elements[0, 1] + m.elements[0, 2];
            vector.y = v.x * m.elements[1, 0] + v.y * m.elements[1, 1] + m.elements[1, 2];
            return(vector);
        }
Esempio n. 4
0
        protected void loadAsLev(string fileName)
        {
            var levReader = new BinaryReader(File.OpenRead(fileName));

            levReader.BaseStream.Seek(130, SeekOrigin.Begin);
            var numPolys = (int)Math.Round(levReader.ReadDouble() - 0.4643643);

            for (var j = 0; j < numPolys; j++)
            {
                var grassPoly   = levReader.ReadInt32();
                var numVertices = levReader.ReadInt32();
                if (grassPoly == 0)
                {
                    var vertices = new ArrayList(numVertices);
                    for (var i = 0; i < numVertices; i++)
                    {
                        var vertex = new DoubleVector2(levReader.ReadDouble(), levReader.ReadDouble());
                        vertices.Add(vertex);
                    }
                    polygons.Add(vertices);
                }
                else
                {
                    levReader.BaseStream.Seek(16 * numVertices, SeekOrigin.Current);
                }
            }
            var numObjects = (int)Math.Round(levReader.ReadDouble() - 0.4643643);

            objects = new ArrayList(numObjects);
            for (var j = 0; j < numObjects; j++)
            {
                var elmaObject = new ElmaObject(levReader.ReadDouble(), levReader.ReadDouble(),
                                                levReader.ReadUInt32(), levReader.ReadUInt32(), levReader.ReadUInt32());
                objects.Add(elmaObject);
            }
            levReader.Close();
            if (polygons.Count == 0)
            {
                throw new Exception("there must be at least one polygon!");
            }
            getMinMax();
        }
Esempio n. 5
0
 public double scalarProduct(DoubleVector2 dv2)
 {
     return (x * dv2.x + y * dv2.y);
 }
Esempio n. 6
0
 public static DoubleVector2 operator *(DoubleVector2 v, Matrix2D m)
 {
     DoubleVector2 vector = new DoubleVector2();
     vector.x = v.x * m.elements[0, 0] + v.y * m.elements[0, 1] + m.elements[0, 2];
     vector.y = v.x * m.elements[1, 0] + v.y * m.elements[1, 1] + m.elements[1, 2];
     return vector;
 }
Esempio n. 7
0
 void getMinMax()
 {
     xmin = Int32.MaxValue;
     xmax = Int32.MinValue;
     ymin = Int32.MaxValue;
     ymax = Int32.MinValue;
     for (int j = 0; j < polygons.Count; j++) {
         ArrayList vertices = (ArrayList)polygons[j];
         for (int i = 0; i < vertices.Count; i++) {
             DoubleVector2 vertex = (DoubleVector2)vertices[i];
             xmin = Math.Min(xmin, (int)vertex.x);
             xmax = Math.Max(xmax, (int)vertex.x);
             ymin = Math.Min(ymin, (int)vertex.y);
             ymax = Math.Max(ymax, (int)vertex.y);
         }
     }
     for (int i = 0; i < objects.Count; i++) {
         DoubleVector2 vertex = new DoubleVector2(((ElmaObject)objects[i]).x, ((ElmaObject)objects[i]).y);
         xmin = Math.Min(xmin, (int)vertex.x);
         xmax = Math.Max(xmax, (int)vertex.x);
         ymin = Math.Min(ymin, (int)vertex.y);
         ymax = Math.Max(ymax, (int)vertex.y);
     }
 }
Esempio n. 8
0
 protected void transformVectors(Matrix2D matrix)
 {
     Random randGen = new Random();
     for (int j = 0; j < polygons.Count; j++) {
         ArrayList vertices = (ArrayList)polygons[j];
         for (int i = 0; i < vertices.Count; i++) {
             DoubleVector2 vertexOld = (DoubleVector2)vertices[i];
             vertices.RemoveAt(i);
             DoubleVector2 vertexNew = vertexOld * matrix;
             // add a little random jitter so as to remove the 'horizontal line' bug
             vertexNew.x += randGen.NextDouble() / 100000.0;
             vertexNew.y += randGen.NextDouble() / 100000.0;
             vertices.Insert(i, vertexNew);
         }
     }
     for (int i = 0; i < objects.Count; i++) {
         ElmaObject objectNow = (ElmaObject)objects[i];
         DoubleVector2 vertexOld = new DoubleVector2(objectNow.x, objectNow.y);
         objects.RemoveAt(i);
         DoubleVector2 vertexNew = vertexOld * matrix;
         objectNow.x = vertexNew.x;
         objectNow.y = vertexNew.y;
         objects.Insert(i, objectNow);
     }
     getMinMax();
 }
Esempio n. 9
0
 protected void loadAsLev(String fileName)
 {
     BinaryReader levReader = new BinaryReader((Stream)File.OpenRead(fileName));
     levReader.BaseStream.Seek(130, SeekOrigin.Begin);
     int numPolys = (int)Math.Round(levReader.ReadDouble() - 0.4643643);
     for (int j = 0; j < numPolys; j++) {
         int grassPoly = levReader.ReadInt32();
         int numVertices = levReader.ReadInt32();
         if (grassPoly == 0) {
             ArrayList vertices = new ArrayList(numVertices);
             for (int i = 0; i < numVertices; i++) {
                 DoubleVector2 vertex = new DoubleVector2(levReader.ReadDouble(), levReader.ReadDouble());
                 vertices.Add(vertex);
             }
             polygons.Add(vertices);
         } else
             levReader.BaseStream.Seek(16 * numVertices, SeekOrigin.Current);
     }
     int numObjects = (int)Math.Round(levReader.ReadDouble() - 0.4643643);
     objects = new ArrayList(numObjects);
     for (int j = 0; j < numObjects; j++) {
         ElmaObject elmaObject = new ElmaObject(levReader.ReadDouble(), levReader.ReadDouble(), levReader.ReadUInt32(), levReader.ReadUInt32(), levReader.ReadUInt32());
         objects.Add(elmaObject);
     }
     levReader.Close();
     if (polygons.Count == 0)
         throw new Exception("there must be at least one polygon!");
     getMinMax();
 }
Esempio n. 10
0
 public double scalarProduct(DoubleVector2 dv2)
 {
     return(x * dv2.x + y * dv2.y);
 }