コード例 #1
0
void TDragger::drag()
{
    projector.setViewVolume(this->getViewVolume());
    projector.setWorkingSpace(this->getLocalToWorldMatrix());

    SbVec3f hitPoint = projector.project(getNormalizedLocaterPosition());
    SbVec3f startingPoint = getLocalStartingPoint();
    SbVec3f localMovement = hitPoint - startingPoint;
    
    //scale the increment to match local space.
    float scaledIncrement = static_cast<float>(translationIncrement.getValue()) / autoScaleResult.getValue();
    
    localMovement = roundTranslation(localMovement, scaledIncrement);
    //when the movement vector is null either the appendTranslation or
    //the setMotionMatrix doesn't work. either way it stops translating
    //back to its initial starting point.
    if (localMovement.equals(SbVec3f(0.0, 0.0, 0.0), 0.00001f))
    {
        setMotionMatrix(getStartMotionMatrix());
        //don't know why I need the following but if I don't have it
        //it won't return to original position.
        this->valueChanged();
    }
    else
        setMotionMatrix(appendTranslation(getStartMotionMatrix(), localMovement));
    
    Base::Quantity quantity(
      static_cast<double>(translationIncrementCount.getValue()) * translationIncrement.getValue(), Base::Unit::Length);
    
    QString message(QObject::tr("Translation: "));
    message += quantity.getUserString();
    getMainWindow()->showMessage(message, 3000);
}