示例#1
0
void Branch::spawnSubBranches(const int level, const double length, const double thickness)
{
  if (level == recursiveDepth) return;

  // Spawn subbranches (make more as we get smaller)
  int numBranches = rand(0.2, 0.8, (level == 0 ? 2 : level) * initialBranches);
  for (int i = 0; i < numBranches; i++) {
    add_child(new Branch("SubBranch", level + 1,
                         nextThickness(thickness, level),
                         nextLength(length, level)));
    totalBranches++;
  }

  // Tree branches seem to split in two at the ends so simulate that.

  add_child(new Branch("SplitBranch", level + 1, nextThickness(thickness, level), 
                       nextLength(length, level), length, -30.0, 0.0));
  add_child(new Branch("SplitBranch", level + 1, nextThickness(thickness, level), 
                       nextLength(length, level), length, 30.0, 0.0));
  // Two branches coming out of the top looks a little weird so add a sphere.
  Sphere* p_sphere = new Sphere();
  GeometryNode* sphere = new GeometryNode("BranchTop", p_sphere);
  sphere->set_material(&wood);

  sphere->translate(Vector3D(0.0, 0.0, length));
  sphere->scale(Vector3D(thickness, thickness, thickness));

  add_child(sphere);

  totalBranches += 3;
}
示例#2
0
void Branch::createGeometryNode(const double length, const double thickness, const double upDist,
                                const double upAngle, const double zAngle)
{  
  Cylinder* c_branch= new Cylinder;
  GeometryNode* branch = new GeometryNode("TreeTrunk", c_branch);
  branch->set_material(&wood);

  this->rotate('z', zAngle);
  this->translate(Vector3D(0.0, 0.0, upDist));
  this->rotate('y', upAngle);
  branch->scale(Vector3D(thickness, thickness, length));

  add_child(branch);
}