Exemplo n.º 1
0
        public override Vector3[] getSectionPoints(bool start = true)
        {
            CS_Params      par  = segment.par;
            CS_LevelParams lpar = segment.lpar;

            int pt_cnt = lpar.mesh_points;

            Vector3[]         points;
            DX_Transformation trf = getTransformation(); //segment.getTransformation().translate(pos.sub(segment.getLowerPosition()));

            // if radius = 0 create only one point -> that's a problem for me
            if (false /*rad < -0.000001*/)
            {
                points    = new Vector3[1];
                points[0] = trf.apply(new Vector3(0, 0, 0));
            }
            else
            { //create pt_cnt points
                points = new Vector3[pt_cnt];
                //stem.DBG("MESH+LOBES: lobes: %d, depth: %f\n"%(self.tree.Lobes, self.tree.LobeDepth))

                for (int i = 0; i < pt_cnt; i++)
                {
                    float angle = i * 360.0f / pt_cnt;
                    // for Lobes ensure that points are near lobes extrema, but not exactly there
                    // otherwise there are to sharp corners at the extrema
                    if (lpar.level == 0 && par.Lobes != 0)
                    {
                        angle -= 10.0f / par.Lobes;
                    }

                    // create some point on the unit circle
                    Vector3 pt = new Vector3((float)Math.Cos(angle * Math.PI / 180), (float)Math.Sin(angle * Math.PI / 180), 0);
                    // scale it to stem radius
                    if (lpar.level == 0 && (par.Lobes != 0 || par._0ScaleV != 0))
                    {
                        float rad1 = rad * (1 +
                                            par.random.uniform(-par._0ScaleV, par._0ScaleV) /
                                            segment.getSubsegmentCount());
                        pt = pt * (rad1 * (1.0f + par.LobeDepth * (float)Math.Cos(par.Lobes * angle * Math.PI / 180.0)));
                    }
                    else
                    {
                        pt = pt * rad; // faster - no radius calculations
                    }
                    // apply transformation to it
                    // (for the first trunk segment transformation shouldn't be applied to
                    // the lower meshpoints, otherwise there would be a gap between
                    // ground and trunk)
                    // FIXME: for helical stems may be/may be not a random rotation
                    // should applied additionally?

                    pt        = trf.apply(pt);
                    points[i] = pt;
                }
            }

            return(points);
        }
Exemplo n.º 2
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.º 3
0
        public override bool visitLeaf(CS_Leaf leaf)
        {
            DXSKV             v0, v1;
            DX_Transformation transf = leaf.getTransformation();


            // the tree is caculated in openGL coordinates with Z "up" so...
            v0.P = new Vector3(0, 0, 0);
            v1.P = new Vector3(0, 0, _csParams.LeafScale);
            v0.P = transf.apply(v0.P); v0.P = new Vector3(v0.P.X, v0.P.Z, v0.P.Y);
            v1.P = transf.apply(v1.P); v1.P = new Vector3(v1.P.X, v1.P.Z, v1.P.Y);
            v0.C = colors[5];
            v1.C = colors[5];

            BBox.Maximum = Vector3.Max(BBox.Maximum, v0.P);
            BBox.Maximum = Vector3.Max(BBox.Maximum, v1.P);
            BBox.Minimum = Vector3.Min(BBox.Minimum, v0.P);
            BBox.Minimum = Vector3.Min(BBox.Minimum, v1.P);

            Vertices2[LEAFLEVEL].Add(v0);
            Vertices2[LEAFLEVEL].Add(v1);

            return(true);
        }
Exemplo n.º 4
0
        /**
         * Make subsegments for a segment with helical curving.
         * They curve around with 360° from base to top of the
         * segment
         *
         * @param cnt the number of subsegments, should be higher
         *        when a smooth curve is needed.
         */

        private void makeHelix(int cnt)
        {
            float angle = (float)(Math.Abs(lpar.nCurveV) / 180 * Math.PI);
            // this is the radius of the helix
            float rad = (float)(Math.Sqrt(1.0 / (Math.Cos(angle) * Math.Cos(angle)) - 1) * length / Math.PI / 2.0);

            /*
             *      if (Console.debug())
             *              stem.DBG("Segment.make_helix angle: "+angle+" len: "+length+" rad: "+rad);
             */

            //self.stem.DBG("HELIX: rad: %f, len: %f\n" % (rad,len))
            for (int i = 1; i < cnt + 1; i++)
            {
                Vector3 pos = new Vector3(rad * (float)Math.Cos(2 * Math.PI * i / cnt) - rad, rad * (float)Math.Sin(2 * Math.PI * i / cnt), i * length / cnt);
                //self.stem.DBG("HELIX: pos: %s\n" % (str(pos)))
                // this is the stem radius
                float srad = stem.stemRadius(index * length + i * length / cnt);
                addSubsegment(new CS_SubsegmentImpl(transf.apply(pos), srad, i * length / cnt, this));
            }
        }
        private void MakeDiscPoints(int vCount, DX_Transformation transf)
        {
            List <DXBaseArbaroTreeMesh.DXVertex> dxvv = new List <DXBaseArbaroTreeMesh.DXVertex>();

            // Create vertices
            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;

                p = transf.apply(p);

                DXBaseArbaroTreeMesh.DXVertex dxv = _mesh.Vertices.Add(new DXArbaroVertexTrait(new Vector3(p.X, p.Y, p.Z)));
                dxvv.Add(dxv);
            }

            // create faces
            for (int i = 0; i < vCount - 2; i++)
            {
                //Console.WriteLine(dxvv[0].Index + " " + dxvv[i + 1].Index + " " + dxvv[i + 2].Index);
                _mesh.Faces.Add(dxvv[0], dxvv[i + 1], dxvv[i + 2]);
            }
        }