public Sphere(Vector position, double radius, Material material) : base(material) { this.Position = position; this.Radius = radius; box = createBoundingBox(); }
private void readPolygons(StreamTokenizer lex, Scene scene, List<Vector> vertices, Material shapeMaterial, Matrix shapeMatrix) { int startLevel = lex.BracketLevel; while (!lex.EndOfStream) { double i1 = 0; if (lex.TryReadDouble(out i1)) { // read polyline till -1 double iPreLast = lex.ReadDouble(); double iLast = lex.ReadDouble(); while (iLast != -1) { scene.addObject(new Triangle(shapeMaterial, shapeMatrix * vertices[(int)i1], shapeMatrix * vertices[(int)iPreLast], shapeMatrix * vertices[(int)iLast])); iPreLast = iLast; iLast = lex.ReadDouble(); } } if (lex.BracketLevel <= startLevel) return; } }
public Triangle(Material material, params Vector[] vertices) : base(material) { if (vertices.Length != 3) { throw new ArgumentException(string.Format("Cannot construct triangle from {0} vertices", vertices.Length)); } else { this.Vertices = new Vector[3]; vertices.CopyTo(this.Vertices, 0); plane = new Plane(vertices, material); double test = vertices[0].Dot(plane.Normal) + plane.D; test = vertices[1].Dot(plane.Normal) + plane.D; test = vertices[2].Dot(plane.Normal) + plane.D; double x = test; bounds = new BoundingPlane[3]; Vector n; // get bounding plane containing v1, v0 // normal must be perpendicular to v1 - v0 n = plane.Normal.Cross(vertices[1] - vertices[0]); bounds[0].Normal = n; // shift plane so that v0 (thus also v1) lies in the plane bounds[0].d = -vertices[0].Dot(n); test = vertices[0].Dot(bounds[0].Normal) + bounds[0].d; test = vertices[1].Dot(bounds[0].Normal) + bounds[0].d; // make plane positive side face inside of the triangle if (vertices[2].Dot(n) + bounds[0].d < 0) bounds[0].Invert(); n = plane.Normal.Cross(vertices[2] - vertices[1]); bounds[1].Normal = n; bounds[1].d = -vertices[1].Dot(n); test = vertices[2].Dot(bounds[1].Normal) + bounds[1].d; test = vertices[1].Dot(bounds[1].Normal) + bounds[1].d; if (vertices[0].Dot(n) + bounds[1].d < 0) bounds[1].Invert(); n = plane.Normal.Cross(vertices[0] - vertices[2]); bounds[2].Normal = n; bounds[2].d = -vertices[2].Dot(n); test = vertices[0].Dot(bounds[2].Normal) + bounds[2].d; test = vertices[2].Dot(bounds[2].Normal) + bounds[2].d; if (vertices[1].Dot(n) + bounds[2].d < 0) bounds[2].Invert(); double y = test; box = createBoundingBox(); } }
private void readShapeObject(StreamTokenizer lex, Scene scene, Matrix shapeMatrix) { int startLevel = lex.BracketLevel; List<Vector> shapeVertices = null; Material shapeMaterial = new Material(Color.Black, 0, 0); while (!lex.EndOfStream) { lex.NextWord(); if (lex.BracketLevel <= startLevel) return; if (lex.Word == "diffuseColor") { double r = lex.ReadDouble(); double g = lex.ReadDouble(); double b = lex.ReadDouble(); shapeMaterial.Color = new Color(r, g, b, 1.0); } if (lex.Word == "transparency") { Color shapeColor = shapeMaterial.Color; shapeColor.A = 1 - lex.ReadDouble(); shapeMaterial.Color = shapeColor; } if (lex.Word == "shininess") { shapeMaterial.Reflectance = lex.ReadDouble(); shapeMaterial.Specular = shapeMaterial.Reflectance; } if (lex.Word == "point") { shapeVertices = readShapeVertices(lex); } if (lex.Word == "coordIndex") { scene.addMaterial(shapeMaterial); readPolygons(lex, scene, shapeVertices, shapeMaterial, shapeMatrix); } if (lex.BracketLevel <= startLevel) return; } }
public void addMaterial(Material material) { this.materials.Add(material); }
public Plane(Vector[] vertices, Material material) : base(material) { initFromVertices(vertices); }
public Plane(Vector normal, double d, Material material) : base(material) { this.Normal = normal; this.D = d; }
public BoxPrimitive(Vector leftTopFront, Vector rightBottomBack, Material mat) : base(mat) { box = new BoundingBox(leftTopFront, rightBottomBack); center = Vector.Combine(leftTopFront, 1.0, (rightBottomBack - leftTopFront), 0.5); }
public Primitive(Material material) { this.material = material; }