Example #1
0
 public Sphere(vect3d pos, double r, Shader shader)
 {
     this.shader = shader;
     this.radius = r;
     this.radius2 = r * r;
     this.pos = pos;
 }
Example #2
0
        public Plane(vect3d p0, vect3d p1, vect3d p2, Shader shader)
        {
            this.shader = shader;
            this.pos = p0;

            z = (p1 - p0) % (p2 - p0);
            z.normalize();

            x = p2 % z;
            x.normalize();

            y = z % x;
        }
Example #3
0
        vect3d norm; // unit normal for getting plane intersection

        public Triangle(vect3d p0, vect3d p1, vect3d p2, Shader shader)
        {
            this.shader = shader;

            this.p0 = p0;
            this.p1 = p1;
            this.p2 = p2;

            N = (p1 - p0) % (p2 - p0);
            N /= N * N;

            norm = N;
            norm.normalize();

            n0 = n1 = n2 = norm;
        }
Example #4
0
        static GroupList load_obj(string fn, Shader shader)
        {
            var mesh = new GroupList();

            List<vect3d> verts = new List<vect3d>();
            List<vect3d> norms = new List<vect3d>();
            List<vect3d> texc = new List<vect3d>();

            using (TextReader reader = File.OpenText(fn))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var toks = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    if (toks.Count() == 0)
                        continue;

                    if (toks[0] == "v")
                    {
                        verts.Add(new vect3d(double.Parse(toks[1]), double.Parse(toks[2]), double.Parse(toks[3])));
                    }
                    else if (toks[0] == "vt")
                    {
                        texc.Add(new vect3d(double.Parse(toks[1]), double.Parse(toks[2]), 0));
                    }
                    else if (toks[0] == "vn")
                    {
                        norms.Add(new vect3d(double.Parse(toks[1]), double.Parse(toks[2]), double.Parse(toks[3])));
                    }
                    else if (toks[0] == "f")
                    {
                        var vals0 = toks[1].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                        var vals1 = toks[2].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                        var vals2 = toks[3].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                        int i0 = int.Parse(vals0[0]) - 1;
                        int i1 = int.Parse(vals1[0]) - 1;
                        int i2 = int.Parse(vals2[0]) - 1;

                        var t = new Triangle(verts[i0], verts[i1], verts[i2], shader);

                        if (texc.Count() != 0)
                        {
                            int j0 = int.Parse(vals0[1]) - 1;
                            int j1 = int.Parse(vals1[1]) - 1;
                            int j2 = int.Parse(vals2[1]) - 1;

                            t.t0 = texc[j0];
                            t.t1 = texc[j1];
                            t.t2 = texc[j2];
                        }
                        if (norms.Count() != 0)
                        {
                            int k0 = int.Parse(vals0[2]) - 1;
                            int k1 = int.Parse(vals1[2]) - 1;
                            int k2 = int.Parse(vals2[2]) - 1;

                            t.n0 = norms[k0];
                            t.n1 = norms[k1];
                            t.n2 = norms[k2];
                        }

                        mesh.add(t);
                    }
                }
            }

            return mesh;
        }
Example #5
0
        public GroupTree(List<Occluder> list, Shader s)
        {
            shader = s;

            //// randomize list
            //for (int i = list.Count - 1; i > 1; i--)
            //{
            //    int r = Custom.Rand.rand.Next(i - 1);
            //    var t = list[i];
            //    list[i] = list[r];
            //    list[r] = t;
            //}

            // calculate bounds of whole volume
            box3d bounds = new box3d();
            bounds.xh = bounds.yh = bounds.zh = Double.MinValue;
            bounds.xl = bounds.yl = bounds.zl = Double.MaxValue;

            foreach (var v in list)
            {
                box3d b = v.bounds();

                if (b.xl < bounds.xl)
                    bounds.xl = b.xl;
                if (b.yl < bounds.yl)
                    bounds.yl = b.yl;
                if (b.zl < bounds.zl)
                    bounds.zl = b.zl;
                if (b.xh > bounds.xh)
                    bounds.xh = b.xh;
                if (b.yh > bounds.yh)
                    bounds.yh = b.yh;
                if (b.zh > bounds.zh)
                    bounds.zh = b.zh;
            }

            // build the tree
            tree = new KDTreeOccluder(list, bounds, 0, Double.MaxValue);
        }