void Lightning::newBranch(glm::vec3 begin, int percentChance, bool isBranchOff,int amountOfBranches) { //get branch length, add it to the up value, then rotate it between 90 and 270 degrees in either x or Z axis. float len = BranchLength(); glm::vec3 en = begin + glm::vec3(0,len,0); float Angle; int randVal = rand() % 2; if(!isBranchOff){ Angle = util::randF(90.0f,270.0f); if(randVal == 0) { en = util::rotateZaxisByPoint(begin,Angle,en); } else { en = util::rotateXaxisByPoint(begin,Angle,en); } } else { //en += lightningStrike[lightningStrike.size()].getDirection(); int randVal2 = rand() % 2; //Angle = util::randF(90.0f,270.0f); if(randVal2 == 1){ Angle = util::randF(90.0f,140.0f); }else{ Angle = util::randF(220.0f,270.0f); } if(randVal == 0) { en = util::rotateZaxisByPoint(begin,Angle,en); } else { en = util::rotateXaxisByPoint(begin,Angle,en); } } bool branchC = BranchChance(percentChance); //Add our new branch. LightningBranch *t_bBranch = new LightningBranch(begin,en,len,branchC); t_bBranch->setIsBranchOff(isBranchOff); t_bBranch->setAmountOfBranches(amountOfBranches); t_bBranch->setAngle(Angle); if(!isBranchOff) { predessingIndex = lightningStrike.size(); }/*else{ t_bBranch->setEnd(t_bBranch->getEnd() + lightningStrike[lightningStrike.size()].getDirection()); }*/ lightningStrike.push_back(*t_bBranch); //if the end y is ground level then it's hit the ground. if(en.y <= 0.0f) { hitGround = true; } }
BranchLength OptimizedParameter::getOptimizedBranch() const { // auto result = _branch.toBlDummy(); // result.setLength(_zCur); auto result = BranchLength(_branch, InternalBranchLength(_zCur)); if(not BoundsChecker::checkBranch(result)) BoundsChecker::correctBranch(result); // tout << "optimized branch: " << _zCur << std::endl; return result; }
void OptimizedParameter::setToTypicalBranch(double typicalAbsLen, TreeAln& traln ) { #if 0 auto b = BranchLength(0,0); b.setConvertedInternalLength(traln, _param, typicalAbsLen); if(BoundsChecker::checkBranch(b)) BoundsChecker::correctBranch(b); _zCur = b.getLength(); #else _zCur = 0.9; #endif }