示例#1
0
 public LoTVModel()
 {
     Points = new LoTVPoint[0];
       PLength = 0;
       Edges = new LoTVEdge[0];
       ELength = 0;
       Polygons = new LoTVPolygon[0];
       LightVector = new double[3] { 1, 1, 1 };
       RLength = 0;
       Normals = new LoTVPoint[0];
       NLength = 0;
       Camera = new LoTVPoint(50, 50, 50);
 }
示例#2
0
 private LoTVPoint Rot(LoTVPoint Point, double Rotation, int Type)
 {
     double cos = Math.Cos(Rotation);
       double sin = Math.Sin(Rotation);
       switch (Type)
       {
     case 1:
       return new LoTVPoint(Point.X, Point.Y * cos + Point.Z * sin, Point.Y * -sin + Point.Z * cos);
     case 2:
       return new LoTVPoint(Point.X * cos + Point.Z * sin, Point.Y, Point.X * -sin + Point.Z * cos);
     case 3:
       return new LoTVPoint(Point.X * cos + Point.Y * sin, Point.X * -sin + Point.Y * cos, Point.Z);
       }
       return new LoTVPoint(Point.X, Point.Y, Point.Z);
 }
示例#3
0
        public void Parse(string Input)
        {
            double AllX = 0, AllY = 0, AllZ = 0;
              double X, Y, Z;
              string[] Arr = Input.Split(new string[] { "\n\r","\n"  }, StringSplitOptions.None);
              int Length = Arr.Length;
              string[] Row;
              bool flag = true;
              int FType = 1;  //1 - _ 2 - _/_ 3 - _/_/_ 4 - _//_
              for (int i = 0; i < Length; i++)
              {
            if (Arr[i] != "" && Arr[i][0] != '#')
              switch (Arr[i].Substring(0, 2))
              {
            case "v ":
              Row = Arr[i].Split(null as string[], StringSplitOptions.RemoveEmptyEntries);
              Array.Resize(ref Points, ++PLength);
              X = double.Parse(Row[1], System.Globalization.CultureInfo.InvariantCulture);
              Y = double.Parse(Row[2], System.Globalization.CultureInfo.InvariantCulture);
              Z = double.Parse(Row[3], System.Globalization.CultureInfo.InvariantCulture);
              AllX += X;
              AllY += Y;
              AllZ += Z;
              Points[PLength - 1] = new LoTVPoint(X, Y, Z);
              break;
            case "vn":
              Row = Arr[i].Split(null as string[], StringSplitOptions.RemoveEmptyEntries);
              X = double.Parse(Row[1], System.Globalization.CultureInfo.InvariantCulture);
              Y = double.Parse(Row[2], System.Globalization.CultureInfo.InvariantCulture);
              Z = double.Parse(Row[3], System.Globalization.CultureInfo.InvariantCulture);
              Array.Resize(ref Normals, ++NLength);
              Normals[NLength - 1] = new LoTVPoint(X, Y, Z);
              break;
            case "f ":
              if (flag)
              {
                string[] tmp = Arr[i].Split(' ');
                int Leng = tmp[1].Length;
                tmp = tmp[1].Split('/');
                if (tmp[1][0] != '/')
                {
                  FType = tmp.Length;
                }
                else
                  FType = 4;
                flag = false;
              }
              Row = Arr[i].Split(null as string[], StringSplitOptions.RemoveEmptyEntries);
              int RowLength = Row.Length - 1;
              string[] Temp;
              int[] F = new int[Row.Length - 1];
              int[] N = new int[Row.Length - 1];
              switch (FType)
              {
                case 1:
                  for (int k = 1; k <= RowLength; k++)
                    F[k - 1] = int.Parse(Row[k]);
                  break;
                case 2:
                  for (int k = 1; k <= RowLength; k++)
                  {
                    Temp = Row[k].Split('/');
                    F[k - 1] = int.Parse(Temp[0]);
                    //Здесь воткнуть массив для текстуры
                  }
                  break;
                case 3:
                  for (int k = 1; k <= RowLength; k++)
                  {
                    Temp = Row[k].Split('/');
                    F[k - 1] = int.Parse(Temp[0]);
                    //Здесь воткнуть массив для текстуры
                    N[k - 1] = int.Parse(Temp[2]);
                  }
                  break;
                case 4:
                  //Кек
                  break;
              }
              Array.Resize(ref Polygons, ++RLength);
              if (RowLength == 3)
                Polygons[RLength - 1] = new LoTVPolygon(F[0], F[1], F[2]);
              else
                Polygons[RLength - 1] = new LoTVPolygon(F[0], F[1], F[2], F[3]);

              if (FType > 2)
              {
                Polygons[RLength - 1].NF = N[0];
                Polygons[RLength - 1].NS = N[1];
                Polygons[RLength - 1].NT = N[2];
                if (FType == 4)
                  Polygons[RLength - 1].NFr = N[3];
              }
              switch (FType)
              {

                case 4:
                  Array.Resize(ref Edges, ELength + 4);
                  ELength += 4;
                  Edges[ELength - 4] = new LoTVEdge(F[0], F[1]);
                  Edges[ELength - 3] = new LoTVEdge(F[1], F[2]);
                  Edges[ELength - 2] = new LoTVEdge(F[2], F[3]);
                  Edges[ELength - 1] = new LoTVEdge(F[3], F[0]);
                  break;
                default:
                  Array.Resize(ref Edges, ELength + 3);
                  ELength += 3;
                  Edges[ELength - 3] = new LoTVEdge(F[0], F[1]);
                  Edges[ELength - 2] = new LoTVEdge(F[1], F[2]);
                  Edges[ELength - 1] = new LoTVEdge(F[2], F[0]);
                  break;
              }
              break;
              }
              }
              Vectors();
              Center = new LoTVPoint(AllX / PLength, AllY / PLength, AllZ / PLength);
        }
示例#4
0
 /*static double InterpolateHeight(LoTVPoint p1, LoTVPoint p2, LoTVPoint p3, double selfX, double selfY)
 {
   var tz = (p2.X * p3.Y - p1.X * p3.Y - p2.X * p1.Y - p3.X * p2.Y + p1.X * p2.Y + p3.X * p1.Y);
   var tx = (p2.Y * p3.Z - p1.Y * p3.Z - p2.Y * p1.Z - p3.Y * p2.Z + p1.Y * p2.Z + p3.Y * p1.Z);
   var ty = (p2.X * p3.Z - p1.X * p3.Z - p2.X * p1.Z - p3.X * p2.Z + p1.X * p2.Z + p3.X * p1.Z);
   return (1 / tz) * (((selfY - p1.Y) * ty) + p1.Z * tz - (selfX - p1.X) * tx);
 }*/
 private Point IJ(LoTVPoint P)
 {
     double Xn = (P.X - fxc) * Math.Cos(Alf) - (P.Y - fyc) * Math.Sin(Alf);
       double Yn = ((P.X - fxc) * Math.Sin(Alf) + (P.Y - fyc) * Math.Cos(Alf)) * Math.Cos(Bet) - (P.Z - fzc) * Math.Sin(Bet);
       double Zn = ((P.X - fxc) * Math.Sin(Alf) + (P.Y - fyc) * Math.Cos(Alf)) * Math.Sin(Bet) + (P.Z - fzc) * Math.Cos(Bet);
       Xn = Xn / (Zn * -0.2 + 1);
       Yn = Yn / (Zn * -0.2 + 1);
       int X = (int)Math.Round(I2 * (Xn - Xmin) / (Xmax - Xmin));
       int Y = Convert.ToInt32(J2 * (Yn - Ymax) / (Ymin - Ymax));
       return new Point(X, Y);
 }
示例#5
0
 /*static double[,] Multiplication(double[,] a, double[,] b)
 {
   double[,] r = new double[a.GetLength(0), b.GetLength(1)];
   for (int i = 0; i < a.GetLength(0); i++)
 for (int j = 0; j < b.GetLength(1); j++)
   for (int k = 0; k < b.GetLength(0); k++)
     r[i, j] += a[i, k] * b[k, j];
   return r;
 }
 /*static void double[,] Multiplication(double[,] a, double angle)
 {
   /*double[,] r = new double[a.GetLength(0), b.GetLength(1)];
   for (int i = 0; i < a.GetLength(0); i++)
 for (int j = 0; j < b.GetLength(1); j++)
   for (int k = 0; k < b.GetLength(0); k++)
     r[i, j] += a[i, k] * b[k, j];
   return r;
 }*/
 /*private double[,] GetMatrix(int type, bool inv, double[] Arr)
 {
   double[,] Matrix = new double[4, 4] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } };
   double cos;
   double sin;
   int Mult = inv ? 1 : -1;  //скукожить-раскукожить
   switch (type)
   {
 case 1:  //Сдвиг
   Matrix[3, 0] = Mult * Arr[0];
   Matrix[3, 1] = Mult * Arr[1];
   Matrix[3, 2] = Mult * Arr[2];
   break;
 case 2:  //Скукоживание по Х
   cos = Math.Cos(Mult * Angle);
   sin = Math.Sin(Mult * Angle);
   Matrix[1, 1] = Matrix[2, 2] = cos;
   Matrix[1, 2] = sin;
   Matrix[2, 1] = -sin;
   break;
 case 3:  //Скукоживание по Y
   cos = Math.Cos(-Mult * Angle);
   sin = Math.Sin(-Mult * Angle);
   Matrix[0, 0] = Matrix[2, 2] = cos;
   Matrix[0, 2] = sin;
   Matrix[2, 0] = -sin;
   break;
 case 4:  //Скукоживание по Z
   cos = Math.Cos(Mult * Angle);
   sin = Math.Sin(Mult * Angle);
   Matrix[0, 0] = Matrix[1, 1] = cos;
   Matrix[0, 1] = sin;
   Matrix[1, 0] = -sin;
   break;
   }
   return Matrix;
 }*/
 public static LoTVPoint Translate(LoTVPoint points3D, LoTVPoint oldOrigin, LoTVPoint newOrigin)
 {
     LoTVPoint difference = new LoTVPoint(newOrigin.X - oldOrigin.X, newOrigin.Y - oldOrigin.Y, newOrigin.Z - oldOrigin.Z);
       points3D.X += difference.X;
       points3D.Y += difference.Y;
       points3D.Z += difference.Z;
       return points3D;
 }