Ejemplo n.º 1
0
XTreeBranch::XTreeBranch(XTree* tree_, XTreeBranch* previous_, uint width_, ofVec2f start_, ofVec2f end_) :
  m_tree(tree_),
  previous(previous_),
  m_age(0),
  m_active(false),
  m_start(start_),
  m_end(end_),
  m_currentStart(start_),
  m_currentEnd(start_),
  m_justActivated(true),
  m_growthTime(0.F),
  m_width(width_) {  
  m_length = ofDist(m_start.x, m_start.y, m_end.x, m_end.y);
  ofPoint thisStart(m_start.x, m_start.y, 0);
  ofPoint thisEnd(m_end.x, m_end.y, 0);
  m_rotation = ofAngle(thisStart, thisEnd);  
  m_startPosition.x = m_start.x + m_width/2 * sin(m_rotation);
  m_startPosition.y = m_start.y - m_width/2 * cos(m_rotation);
  this->m_level = (previous_ ? previous_->m_level + 1 : 0);
  m_image = g_images[(size_t)ofRandom(g_images.size())];
  m_growthTime = ofRandom(g_growthMin, g_growthMax);
  m_timer.set();
#ifndef XTREES_SCREENSAVER
  std::vector<float> msg;
  msg.push_back(m_growthTime);    // time
  msg.push_back(-45.f + 90.F * (float)m_start.x / (float)g_scene.width); // panning  
  InteractiveAudio::instance()->sendFloatList(kNewBranch, msg);
#endif
  m_timer.setAlarm(m_growthTime);  
  m_numChildren = 2 + (m_level + ofRandom(g_fertility)) / 3;
  m_positions.resize(m_numChildren);
  for (int i = 0; i < m_numChildren; ++i)
    m_positions[i] = i;
  std::random_shuffle(m_positions.begin(), m_positions.end());
  m_numLeaves = g_leavesFertility;
  stemProportions.resize(m_numLeaves);
  leaves.resize(m_numLeaves);
  usedLeaves.resize(m_numLeaves);
  leavesAngles.resize(m_numLeaves);
  for (int i = 0; i < m_numLeaves; ++i) {
    stemProportions[i] = ofRandom(m_length);
    leavesAngles[i] = .0f;// ofRandomuf() * M_PI/7.f;
    leaves[i] = NULL;
    usedLeaves[i] = false;
  }

}
Ejemplo n.º 2
0
float ofAngle(const ofVec3f & vec) {
    ofVec2f v(vec);
    return ofAngle(v);
}