public Branch(Branch parent, float weight, int sibling, Vector3 light, float light_intensity) { this.parent = parent; this.level = parent.level + 1; this.weight = weight; this.child = new List <Branch>(); this.sprig = new List <Branch>(); this.angle = parent.angle; this.length = parent.length; this.color = parent.color; this.pos = parent.pos + parent.dir; //calc angle this.dir = Quaternion.Euler(0.0f, 0.0f, (-1 * (angle / 2.0f) + (this.angle / (sibling - 1) * parent.child.Count)) * Random.Range(0.6f, 1.0f)) * (parent.dir); if (light != Vector3.zero) { this.weight *= (1 + Mathf.Pow(Mathf.Cos(Vector3.Angle(this.dir, light * -1) / 2.0f * Mathf.PI / 180.0f), light_intensity)); } this.dir = this.dir.normalized * this.length * this.weight * Random.Range(1.0f, 1.5f); this.tree = parent.tree; }
// trunk public Branch(YulanTree tree, Vector3 direction, float length, float angle) { this.parent = null; this.level = 0; this.weight = 1; this.child = new List <Branch>(); this.pos = Vector3.zero; this.dir = direction.normalized * length; this.length = length; this.angle = angle; this.tree = tree; this.color = Color.white; if (tree.light != Vector4.zero) { this.weight *= (1 + Mathf.Pow(Mathf.Cos(Vector3.Angle(this.dir, (Vector3)tree.light * -1) / 2.0f * Mathf.PI / 180.0f), tree.light.z)); } this.dir *= this.weight * Random.Range(1.0f, 2.0f); }
public void Generate() { tree = new YulanTree(Vector3.up, intensity, duration, angle, this.sun.forward, this.sun_intensity, this.sprig); //tree = new YulanTree(Vector3.up, intensity, duration, angle, Vector3.zero, 0.0f); tree.MakeCompleteTree(); }