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; } } }
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); }
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; }
public DatumPlane(string name, Vect3 point1, Vect3 point2, Vect3 point3) : base(point1, point2, point3) { Name = name; }
public DatumPlane(string name, Vect3 normal, Vect3 point) : base(normal, point) { Name = name; }
public DatumPlane(string name, Vect3 normal, double distance) : base(normal, distance) { Name = name; }
public MeshVertex(Vect3 position) : base(position) { }
public double DistanceTo(Vect3 point) { return (A*point.X + B*point.Y + C*point.Y + Distance)/Normal.Length; }
public Plane(Vect3 point1,Vect3 point2,Vect3 point3) { Normal = (point2 - point1).CrossProduct(point3 - point1).Normalize(); Distance = -Normal.DotProduct(point1); }
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); }
public Cube(Vect3 position, double size) { Position = position; Size = size; }
public Vect3(Vect3 v) { X = v.X; Y = v.Y; Z = v.Z; }
public double DotProduct(Vect3 v) { return X*v.X + Y*v.Y + Z*v.Z; }
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); }
public static Vect3 Lerp(Vect3 start, Vect3 end, double percent) { return (start + percent * (end - start)); }
public Plane(Vect3 normal, double distance) { Normal = normal; Distance = distance; }
public Plane(Vect3 normal, Vect3 point) { Normal = normal; Distance = -normal.DotProduct(point); }
public static Mat4 Translate(Vect3 v) { return Translate(v.X, v.Y, v.Z); }
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)); }
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 }); } } }
public AxisAngle(Vect3 axis, Angle angle) { this.Axis = axis; this.Angle = angle; }
public Vert(Vect3 position, Vect3 normal, Vect4 colour) { Position = position; Normal = normal; Colour = colour; }