Exemplo n.º 1
0
        public override bool visitLeaf(CS_Leaf leaf)
        {
            DX_Transformation transf = leaf.getTransformation();

            List <DXMEV> mev = new List <DXMEV>();

            foreach (DXMEV m in V)
            {
                DXMEV mp = new DXMEV();
                mp.P = transf.apply(m.P);
                mp.P = new Vector4(mp.P.X, mp.P.Z, mp.P.Y, 1);
                mev.Add(mp);

                BBox.Maximum = Vector3.Max(BBox.Maximum, new Vector3(mp.P.X, mp.P.Y, mp.P.Z));
                BBox.Minimum = Vector3.Min(BBox.Minimum, new Vector3(mp.P.X, mp.P.Y, mp.P.Z));
            }

            int c = Vertices2[LEAFLEVEL].Count;

            foreach (int k in I)
            {
                Indices2[LEAFLEVEL].Add(c + k);
            }

            Vertices2[LEAFLEVEL].AddRange(mev);

            return(true);
        }
Exemplo n.º 2
0
        private void MakeDiscPoints(int vCount)
        {
            for (int i = 0; i < vCount; i++)
            {
                float   a = (float)(i * Math.PI * 2 / vCount);
                Vector4 p = new Vector4((float)Math.Sin(a), 0, (float)Math.Cos(a), 1);

                if (a < Math.PI)
                {
                    p.X -= leaffunc(a);
                }
                else if (a > Math.PI)
                {
                    p.X += leaffunc((float)(2 * Math.PI - a));
                }

                p.X *= _width;
                p.Y *= _width;
                p.Z  = (_stemLength + p.Z + 1) * _length;

                DXMEV m = new DXMEV();
                m.P = p;
                Vertices.Add(m);
            }

            for (int i = 0; i < vCount - 2; i++)
            {
                Indices.Add(0); Indices.Add(i + 1); Indices.Add(i + 2);
            }
        }
Exemplo n.º 3
0
        private void MakeSpherePoints()
        {
            float s = (float)((Math.Sqrt(5) - 1) / 2 * Math.Sqrt(2 / (5 - Math.Sqrt(5))) / 2);
            float t = (float)(Math.Sqrt(2 / (5 - Math.Sqrt(5))) / 2);

            DXMEV m;

            m = new DXMEV(); m.P = new Vector4(0, s, -t + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(t, 0, -s + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(-s, t, 0 + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(0, s, t + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(-t, 0, -s + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(-s, -t, 0 + 0.5f, 1); Vertices.Add(m);

            m = new DXMEV(); m.P = new Vector4(0, -s, -t + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(t, 0, s + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(s, t, 0 + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(0, -s, t + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(-t, 0, s + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(s, -t, 0 + 0.5f, 1); Vertices.Add(m);

            for (int i = 0; i < Vertices.Count; i++)
            {
                DXMEV mev = Vertices[i];
                mev.P.X    *= _width;
                mev.P.Y    *= _width;
                mev.P.Z     = (_stemLength + mev.P.Z) * _length;
                Vertices[i] = mev;
            }

            Indices.AddRange(new int[] { 0, 1, 6 });
            Indices.AddRange(new int[] { 0, 6, 4 });
            Indices.AddRange(new int[] { 1, 8, 7 });
            Indices.AddRange(new int[] { 1, 7, 11 });
            Indices.AddRange(new int[] { 2, 3, 8 });

            Indices.AddRange(new int[] { 2, 0, 3 });

            Indices.AddRange(new int[] { 3, 9, 7 });
            Indices.AddRange(new int[] { 3, 10, 9 });
            Indices.AddRange(new int[] { 4, 10, 2 });
            Indices.AddRange(new int[] { 4, 5, 10 });
            Indices.AddRange(new int[] { 5, 6, 11 });
            Indices.AddRange(new int[] { 5, 11, 9 });

            Indices.AddRange(new int[] { 0, 8, 1 });
            Indices.AddRange(new int[] { 6, 1, 11 });
            Indices.AddRange(new int[] { 6, 5, 4 });
            Indices.AddRange(new int[] { 0, 4, 2 });

            Indices.AddRange(new int[] { 7, 8, 3 });
            Indices.AddRange(new int[] { 10, 3, 2 });
            Indices.AddRange(new int[] { 10, 5, 9 });
            Indices.AddRange(new int[] { 9, 11, 7 });
        }
Exemplo n.º 4
0
        private void AddRangeVector3(Vector3[] v, int level, bool isFirst)
        {
            int N = Vertices2[level].Count - 1;
            int C = v.Count();

            foreach (Vector3 v3 in v)
            {
                DXMEV p = new DXMEV();
                p.P = new Vector4(v3.X, v3.Z, v3.Y, 1);
                Vertices2[level].Add(p);

                BBox.Maximum = Vector3.Max(BBox.Maximum, new Vector3(p.P.X, p.P.Y, p.P.Z));
                BBox.Minimum = Vector3.Min(BBox.Minimum, new Vector3(p.P.X, p.P.Y, p.P.Z));
            }

            if (isFirst)
            {
            }
            else
            {
                // Create the triangles
                for (int i = 0; i < C; i++)
                {
                    // first triangle for the "quad"
                    Indices2[level].Add(N - C + 1 + i); Indices2[level].Add(N + i + 1);
                    if (i == C - 1)
                    {
                        Indices2[level].Add(N - C + 1);
                    }
                    else
                    {
                        Indices2[level].Add(N - C + 2 + i);
                    }

                    // second triangle for the "quad"
                    if (i == C - 1)
                    {
                        Indices2[level].Add(N - C + 1);
                    }
                    else
                    {
                        Indices2[level].Add(N - C + 2 + i);
                    }
                    Indices2[level].Add(N + i + 1);
                    if (i == C - 1)
                    {
                        Indices2[level].Add(N + 1);
                    }
                    else
                    {
                        Indices2[level].Add(N + 2 + i);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void MakeDiscPoints(int vCount)
        {
            for (int i = 0; i < vCount; i++)
            {
                float a = (float)(i * Math.PI * 2 / vCount);
                Vector4 p = new Vector4((float)Math.Sin(a), 0, (float)Math.Cos(a), 1);

                if (a < Math.PI)
                {
                    p.X -= leaffunc(a);
                }
                else if (a > Math.PI)
                {
                    p.X += leaffunc((float)(2 * Math.PI - a));
                }

                p.X *= _width;
                p.Y *= _width;
                p.Z = (_stemLength + p.Z + 1) * _length;

                DXMEV m = new DXMEV();
                m.P = p;
                Vertices.Add(m);
            }

            for (int i = 0; i < vCount - 2; i++)
            {
                Indices.Add(0); Indices.Add(i + 1); Indices.Add(i + 2);
            }
        }
Exemplo n.º 6
0
        private void MakeSpherePoints()
        {
            float s = (float)((Math.Sqrt(5) - 1) / 2 * Math.Sqrt(2 / (5 - Math.Sqrt(5))) / 2);
            float t = (float)(Math.Sqrt(2 / (5 - Math.Sqrt(5))) / 2);

            DXMEV m;
            m = new DXMEV(); m.P = new Vector4(0, s, -t + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(t, 0, -s + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(-s, t, 0 + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(0, s, t + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(-t, 0, -s + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(-s, -t, 0 + 0.5f, 1); Vertices.Add(m);

            m = new DXMEV(); m.P = new Vector4(0, -s, -t + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(t, 0, s + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(s, t, 0 + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(0, -s, t + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(-t, 0, s + 0.5f, 1); Vertices.Add(m);
            m = new DXMEV(); m.P = new Vector4(s, -t, 0 + 0.5f, 1); Vertices.Add(m);

            for (int i = 0; i < Vertices.Count; i++)
            {
                DXMEV mev = Vertices[i];
                mev.P.X *= _width;
                mev.P.Y *= _width;
                mev.P.Z = (_stemLength + mev.P.Z) * _length;
                Vertices[i] = mev;
            }

            Indices.AddRange(new int[] { 0, 1, 6 });
            Indices.AddRange(new int[] { 0, 6, 4 });
            Indices.AddRange(new int[] { 1, 8, 7 });
            Indices.AddRange(new int[] { 1, 7, 11 });
            Indices.AddRange(new int[] { 2, 3, 8 });

            Indices.AddRange(new int[] { 2, 0,3 });

            Indices.AddRange(new int[] { 3, 9, 7 });
            Indices.AddRange(new int[] { 3, 10, 9 });
            Indices.AddRange(new int[] { 4, 10, 2 });
            Indices.AddRange(new int[] { 4, 5, 10 });
            Indices.AddRange(new int[] { 5, 6, 11 });
            Indices.AddRange(new int[] { 5, 11, 9 });

            Indices.AddRange(new int[] { 0, 8, 1 });
            Indices.AddRange(new int[] { 6, 1, 11 });
            Indices.AddRange(new int[] { 6, 5, 4 });
            Indices.AddRange(new int[] { 0, 4, 2 });

            Indices.AddRange(new int[] { 7, 8, 3 });
            Indices.AddRange(new int[] { 10, 3, 2 });
            Indices.AddRange(new int[] { 10, 5, 9 });
            Indices.AddRange(new int[] { 9, 11, 7 });
        }
Exemplo n.º 7
0
        private void AddRangeVector3(Vector3[] v, int level, bool isFirst)
        {
            int N = Vertices2[level].Count - 1;
            int C = v.Count();

            foreach (Vector3 v3 in v)
            {
                DXMEV p = new DXMEV();
                p.P = new Vector4(v3.X, v3.Z, v3.Y, 1);
                Vertices2[level].Add(p);

                BBox.Maximum = Vector3.Max(BBox.Maximum, new Vector3(p.P.X, p.P.Y, p.P.Z));
                BBox.Minimum = Vector3.Min(BBox.Minimum, new Vector3(p.P.X, p.P.Y, p.P.Z));
            }

            if (isFirst) { }
            else
            {
                // Create the triangles
                for (int i = 0; i < C; i++)
                {
                    // first triangle for the "quad"
                    Indices2[level].Add(N - C + 1 + i); Indices2[level].Add(N + i + 1);
                    if (i == C - 1) Indices2[level].Add(N - C + 1); else Indices2[level].Add(N - C + 2 + i);

                    // second triangle for the "quad"
                    if (i == C - 1) Indices2[level].Add(N - C + 1); else Indices2[level].Add(N - C + 2 + i);
                    Indices2[level].Add(N + i + 1);
                    if (i == C - 1) Indices2[level].Add(N + 1); else Indices2[level].Add(N + 2 + i);
                }
            }
        }
Exemplo n.º 8
0
        public override bool visitLeaf(CS_Leaf leaf)
        {
            DX_Transformation transf = leaf.getTransformation();

            List<DXMEV> mev = new List<DXMEV>();
            foreach(DXMEV m in V) {
                DXMEV mp = new DXMEV();
                mp.P = transf.apply(m.P);
                mp.P = new Vector4(mp.P.X, mp.P.Z, mp.P.Y, 1);
                mev.Add(mp);

                BBox.Maximum = Vector3.Max(BBox.Maximum, new Vector3(mp.P.X, mp.P.Y, mp.P.Z));
                BBox.Minimum = Vector3.Min(BBox.Minimum, new Vector3(mp.P.X, mp.P.Y, mp.P.Z));
            }

            int c = Vertices2[LEAFLEVEL].Count;
            foreach (int k in I)
            {
                Indices2[LEAFLEVEL].Add(c + k);
            }

            Vertices2[LEAFLEVEL].AddRange(mev);

            return true;
        }