PathPoint Path::update(Vector3<float> refPos, Vector3<float> playerPos) { float D_val; PathPoint current = getCurrent(); PathPoint previous = getPrevious(); float diffX = refPos.x - current.getPosition().x; float diffY = refPos.y - current.getPosition().y; float diffZ = refPos.z - current.getPosition().z; float playerDistFromPlane = 0; float firstDistFromPlane = 0; Vector3<float> vect1 (current.getPosition().x - previous.getPosition().x, current.getPosition().y - previous.getPosition().y, current.getPosition().z - previous.getPosition().z); Vector3<float> vect2 (current.getPosition().x + current.getUp().x, current.getPosition().y + current.getUp().y, current.getPosition().z + current.getUp().z); Vector3<float> normal; float distance = sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ); PathPoint firstChoice = getAt(current.getFirstID()); if (distance < RANGE_CHECK) { if (current.getNumberOfIDs() == 1) { setChoice(current.getFirstID()); return getCurrent(); } normal = vect1.Cross(vect2).Normalized(); D_val = (current.getPosition().x * normal.x + current.getPosition().y * normal.y + current.getPosition().z * normal.z) * -1.0f; playerDistFromPlane = (normal.x * playerPos.x) + (normal.y * playerPos.y) + (normal.z * playerPos.z) + D_val; if (abs(playerDistFromPlane) < MID_BUFFER_WIDTH && current.getNumberOfIDs() == 3) { setChoice(current.getThirdID()); return getCurrent(); } firstDistFromPlane = normal.x * firstChoice.getPosition().x + normal.y * firstChoice.getPosition().y + normal.z * firstChoice.getPosition().z + D_val; if (playerDistFromPlane / abs(playerDistFromPlane) == firstDistFromPlane / abs(firstDistFromPlane)) { setChoice(current.getFirstID()); return getCurrent(); } else { setChoice(current.getSecondID()); return getCurrent(); } } return getCurrent(); }
mx::e::PartGroupOrScorePartPtr convertPartGroup( const mx::e::PartGroupPtr& partGroup ) { auto enumPartGroup = mx::e::PartGroupOrScorePart::Choice::partGroup; auto pgosp = mx::e::makePartGroupOrScorePart(); pgosp->setChoice( enumPartGroup ); pgosp->setPartGroup( partGroup ); return pgosp; }
void DrListOption::setValueText(const QString &s) { m_current = findChoice(s); if(!m_current) { bool ok; int index = s.toInt(&ok); if(ok) setChoice(index); } }
DirectionTypePtr Direction::createDirectionType( std::ostream& message, xml::XElementIterator& subIter, xml::XElementIterator& subIterEnd, bool& isSuccess ) { auto directionType = makeDirectionType(); if( subIter == subIterEnd ) { message << "Direction: well thats weird - should not get here" << std::endl; isSuccess = false; return directionType; } if( subIter->getName() == "wedge" ) { directionType->setChoice( DirectionType::Choice::wedge ); isSuccess &= directionType->getWedge()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "dashes" ) { directionType->setChoice( DirectionType::Choice::dashes ); isSuccess &= directionType->getDashes()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "bracket" ) { directionType->setChoice( DirectionType::Choice::bracket ); isSuccess &= directionType->getBracket()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "pedal" ) { directionType->setChoice( DirectionType::Choice::pedal ); isSuccess &= directionType->getPedal()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "metronome" ) { directionType->setChoice( DirectionType::Choice::metronome ); isSuccess &= directionType->getMetronome()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "octave-shift" ) { directionType->setChoice( DirectionType::Choice::octaveShift ); isSuccess &= directionType->getOctaveShift()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "harp-pedals" ) { directionType->setChoice( DirectionType::Choice::harpPedals ); isSuccess &= directionType->getHarpPedals()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "damp" ) { directionType->setChoice( DirectionType::Choice::damp ); isSuccess &= directionType->getDamp()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "damp-all" ) { directionType->setChoice( DirectionType::Choice::dampAll ); isSuccess &= directionType->getDampAll()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "eyeglasses" ) { directionType->setChoice( DirectionType::Choice::eyeglasses ); isSuccess &= directionType->getEyeglasses()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "string-mute" ) { directionType->setChoice( DirectionType::Choice::stringMute ); isSuccess &= directionType->getStringMute()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "scordatura" ) { directionType->setChoice( DirectionType::Choice::scordatura ); isSuccess &= directionType->getScordatura()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "image" ) { directionType->setChoice( DirectionType::Choice::image ); isSuccess &= directionType->getImage()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "principal-voice" ) { directionType->setChoice( DirectionType::Choice::principalVoice ); isSuccess &= directionType->getPrincipalVoice()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "accordion-registration" ) { directionType->setChoice( DirectionType::Choice::accordionRegistration ); isSuccess &= directionType->getAccordionRegistration()->fromXElement( message, *subIter ); return directionType; } if( subIter->getName() == "other-direction" ) { directionType->setChoice( DirectionType::Choice::otherDirection ); isSuccess &= directionType->getOtherDirection()->fromXElement( message, *subIter ); return directionType; } std::string name = "rehearsal"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::rehearsal ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makeRehearsal(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getRehearsalSet().size() == 1 ) { directionType->addRehearsal( itemToAdd ); directionType->removeRehearsal( directionType->getRehearsalSet().cbegin() ); } else { directionType->addRehearsal( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end rehearsal name = "segno"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::segno ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makeSegno(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getSegnoSet().size() == 1 ) { directionType->addSegno( itemToAdd ); directionType->removeSegno( directionType->getSegnoSet().cbegin() ); } else { directionType->addSegno( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end segno name = "words"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::words ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makeWords(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getWordsSet().size() == 1 ) { directionType->addWords( itemToAdd ); directionType->removeWords( directionType->getWordsSet().cbegin() ); } else { directionType->addWords( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end words name = "coda"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::coda ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makeCoda(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getCodaSet().size() == 1 ) { directionType->addCoda( itemToAdd ); directionType->removeCoda( directionType->getCodaSet().cbegin() ); } else { directionType->addCoda( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end coda name = "dynamics"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::dynamics ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makeDynamics(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getDynamicsSet().size() == 1 ) { directionType->addDynamics( itemToAdd ); directionType->removeDynamics( directionType->getDynamicsSet().cbegin() ); } else { directionType->addDynamics( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end dynamics name = "percussion"; if( subIter->getName() == name ) { directionType->setChoice( DirectionType::Choice::percussion ); bool isFirstSubItemAdded = false; while( subIter != subIterEnd ) { if( subIter->getName() != name ) { message << "Direction: createDirectionType encountered an unexpected element '" << subIter->getName() << "' while parsing a collection of '" << name << "' elements" << std::endl; isSuccess = false; return directionType; } auto itemToAdd = makePercussion(); isSuccess &= itemToAdd->fromXElement( message, *subIter ); if( !isFirstSubItemAdded && directionType->getPercussionSet().size() == 1 ) { directionType->addPercussion( itemToAdd ); directionType->removePercussion( directionType->getPercussionSet().cbegin() ); } else { directionType->addPercussion( itemToAdd ); } isFirstSubItemAdded = true; ++subIter; } // end loop return directionType; } // end percussion return directionType; }