- Home /
Setting up point sets for a procedural tree
While creating a set of lines.
                     points=new Vector3[num];
                 points[0]=new Vector3(0,0,0);
                 for(int tt=1; tt<num; tt++)
                 {
                     d_a=Quaternion.AngleAxis(seed*num*tt*13%(39+tt),Vector3.up)*d_a;
                     direction=Quaternion.AngleAxis(seed*num*tt*(tt*13%39)%(15+tt),d_a)*direction;
                     dirs[tt-1]=direction;
                     points[tt]=points[tt-1]+(direction*(num/20f));
                     Debug.DrawLine(points[tt],points[tt-1],Color.blue,91);
                 }
a set of points form a ring around each point on the line set
         for(int tt=0; tt<num; tt++)
         {    
             int it=num-tt;
             it=Mathf.RoundToInt(it/3)*3;
             if(it==0 && tt!=num-1)
             {
                 it=3;
             }
             if(tt==num-1)
             {
                 it=1;
             }
             vert_at_point[tt]=it;
             for(int i=0; i<it; i++)
             {
                 Quaternion q=Quaternion.AngleAxis((360f/(it))*i,dirs[tt]);
                 Vector3 dd=q*Vector3.forward;
                 dd=dd.normalized;
                 int ttt=tt;
                 if(ttt<3)
                 {
                     ttt=3;
                 }
                 dd*=((num-ttt)/(float)num)*(num/10f);
             
                 Vector3 castfrom=points[tt]+dd;//+(dirs[tt]);//Vector3.Normalize(dd));
                 Debug.DrawLine(castfrom,castfrom+(Vector3.up*.1f),Color.red,91);
                 trees[slot].vertices.Add(castfrom);
             }
         } 
the points for the rings are put in a list for vertices points

OR

The problem is the more of an angle the ring is the smaller it is, as is the direction vector doesn't == 1 total, I'm not sure how to fix this, any speculative comments appreciated.
One thing I noticed is the center of the ring is offset from the point.
I did a test and the direction vectors are all approximately 1 in distance, so the angle is off.
Answer by Benjames · May 10, 2015 at 09:19 PM
So I looked up how to find a perpendicular vector http://docs.unity3d.com/Manual/ComputingNormalPerpendicularVector.html
Then modified my code a little. It took a little over an hour to figure out.
             for(int i=0; i<it; i++)
             {
                 Vector3 qq=Vector3.Cross(dirs[tt],Vector3.up);//dirs[tt]-Vector3.Project(dirs[tt],Vector3.up);//Quaternion.AngleAxis(90,dirs[tt])*dirs[tt];
                 qq=qq.normalized;
                 Quaternion q=Quaternion.AngleAxis((360f/(it))*i,dirs[tt]);
                 Vector3 dd=q*qq;
                 int ttt=tt;
                 if(ttt<3)
                 {
                     ttt=3;
                 }
                 dd*=((num-ttt)/(float)num)*(num/10f);
             
                 Vector3 castfrom=points[tt]+dd;//+(dirs[tt]);//Vector3.Normalize(dd));
                 Debug.DrawLine(castfrom,castfrom+(Vector3.up*.1f),Color.red,91);
                 trees[slot].vertices.Add(castfrom);
             }

Also if anyone cares here is what I was trying to accomplish.


Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                