Ejemplo n.º 1
0
Archivo: STL.cs Proyecto: rho24/OpenCAD
 private void LoadASCII(string filename)
 {
     Vect3 normal = null;
     var points = new Vect3[3];
     int i = 0;
     const NumberStyles style = NumberStyles.AllowExponent | NumberStyles.AllowLeadingSign | NumberStyles.Number;
     foreach (var split in File.ReadLines(filename).Select(line => line.Trim().ToLower().Split(' ')))
     {
         switch (split[0])
         {
             case "solid":
                 break;
             case "facet":
                 normal = new Vect3(Double.Parse(split[2], style), Double.Parse(split[3], style),
                                    Double.Parse(split[4], style));
                 break;
             case "outer":
                 break;
             case "vertex":
                 points[i++] = new Vect3(Double.Parse(split[1], style), Double.Parse(split[2], style),
                                         Double.Parse(split[3], style));
                 break;
             case "endloop":
                 break;
             case "endfacet":
                 Elements.Add(new STLElement { P1 = points[0], P2 = points[1], P3 = points[2], Normal = normal });
                 i = 0;
                 break;
             case "endsolid":
                 break;
         }
     }
 }
Ejemplo n.º 2
0
 public MainCamera()
 {
     Near = 1f;
     Far = 512.0f;
     Model = Mat4.Identity;
     Eye = Vect3.Zero;
     Target = Vect3.Zero;
     Up = Vect3.UnitY;
     Eye = new Vect3(0.0f, 0.0f, 5.0f);
 }
Ejemplo n.º 3
0
 public OrthographicCamera()
 {
     Near = -1000f;
     Far = 1000f;
     Target = Vect3.Zero;
     Up = Vect3.UnitY;
     Eye = new Vect3(0, 0, 20);
     Model = Mat4.Identity;
     View = Mat4.LookAt(Eye, Target, Up);
     Projection = Mat4.Identity;
     Scale = 15;
 }
Ejemplo n.º 4
0
 public DatumPlane(string name, Vect3 point1, Vect3 point2, Vect3 point3)
     : base(point1, point2, point3)
 {
     Name = name;
 }
Ejemplo n.º 5
0
 public DatumPlane(string name, Vect3 normal, Vect3 point)
     : base(normal, point)
 {
     Name = name;
 }
Ejemplo n.º 6
0
 public DatumPlane(string name, Vect3 normal, double distance)
     : base(normal, distance)
 {
     Name = name;
 }
Ejemplo n.º 7
0
 public MeshVertex(Vect3 position)
     : base(position)
 {
 }
Ejemplo n.º 8
0
 public double DistanceTo(Vect3 point)
 {
     return (A*point.X + B*point.Y + C*point.Y + Distance)/Normal.Length;
 }
Ejemplo n.º 9
0
 public Plane(Vect3 point1,Vect3 point2,Vect3 point3)
 {
     Normal = (point2 - point1).CrossProduct(point3 - point1).Normalize();
     Distance = -Normal.DotProduct(point1);
 }
Ejemplo n.º 10
0
 public static Mat4 LookAt(Vect3 eye, Vect3 target, Vect3 up)
 {
     var vector31 = (eye - target).Normalize();
     var right = up.CrossProduct(vector31).Normalize();
     var vector32 = vector31.CrossProduct(right).Normalize();
     return new Mat4(new[,]
         {
             {right.X, right.Y, right.Z, 0.0},
             {vector32.X, vector32.Y, vector32.Z, 0.0},
             {vector31.X, vector31.Y, vector31.Z, 0.0},
             {0.0, 0.0, 0.0, 1.0}
         }) * Translate(-eye);
 }
Ejemplo n.º 11
0
 public Cube(Vect3 position, double size)
 {
     Position = position;
     Size = size;
 }
Ejemplo n.º 12
0
 public Vect3(Vect3 v)
 {
     X = v.X;
     Y = v.Y;
     Z = v.Z;
 }
Ejemplo n.º 13
0
 public double DotProduct(Vect3 v)
 {
     return X*v.X + Y*v.Y + Z*v.Z;
 }
Ejemplo n.º 14
0
 public Vect3 CrossProduct(Vect3 v)
 {
     return new Vect3(Y*v.Z - Z*v.Y, Z*v.X - X*v.Z, X*v.Y - Y*v.X);
 }
Ejemplo n.º 15
0
 public static Vect3 Lerp(Vect3 start, Vect3 end, double percent)
 {
     return (start + percent * (end - start));
 }
Ejemplo n.º 16
0
 public Plane(Vect3 normal, double distance)
 {
     Normal = normal;
     Distance = distance;
 }
Ejemplo n.º 17
0
 public Plane(Vect3 normal, Vect3 point)
 {
     Normal = normal;
     Distance = -normal.DotProduct(point);
 }
Ejemplo n.º 18
0
 public static Mat4 Translate(Vect3 v)
 {
     return Translate(v.X, v.Y, v.Z);
 }
Ejemplo n.º 19
0
 public static Plane FromPoints(Vect3 p1, Vect3 p2, Vect3 p3)
 {
     var normal = (p2 - p1).CrossProduct(p3 - p1).Normalize();
     return new Plane(normal,normal.DotProduct(p1));
 }
Ejemplo n.º 20
0
Archivo: STL.cs Proyecto: rho24/OpenCAD
 private void LoadBinary(string filename)
 {
     using (var br = new BinaryReader(File.Open(filename, FileMode.Open)))
     {
         br.ReadBytes(80); //header
         var count = (int)br.ReadUInt32();
         for (var i = 0; i < count; i++)
         {
             var normal = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p1 = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p2 = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p3 = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             br.ReadUInt16(); //attrib
             Elements.Add(new STLElement { P1 = p1, P2 = p2, P3 = p3, Normal = normal });
         }
     }
 }
Ejemplo n.º 21
0
 public AxisAngle(Vect3 axis, Angle angle)
 {
     this.Axis = axis;
     this.Angle = angle;
 }
Ejemplo n.º 22
0
 public Vert(Vect3 position, Vect3 normal, Vect4 colour)
 {
     Position = position;
     Normal = normal;
     Colour = colour;
 }