예제 #1
0
void Camera::tick(const Time& t, const Duration& dt) {
    if (!haveGoal()) return;

    Vector3d goalPos = getGoalPosition();
    Quaternion goalOrient = getGoalOrientation();

    Vector3d pos;
    Quaternion orient;

    if (mMode == FirstPerson) {
        // In first person mode we are tied tightly to the position of
        // the object.
        pos = goalPos;
        orient = goalOrient;
    }
    else {
        // In third person mode, the target is offset so we'll be behind and
        // above ourselves and we need to interpolate to the target.
        // Offset the goal.
        BoundingSphere3f following_bounds = getGoalBounds();
        goalPos += Vector3d(following_bounds.center());
        // > 1 factor gets us beyond the top of the object
        goalPos += mOffset * (following_bounds.radius());
        // Restore the current values from the scene node.
        pos = fromOgre(mSceneNode->getPosition(), mScene->getOffset());
        orient = fromOgre(mSceneNode->getOrientation());
        // And interpolate.
        Vector3d toGoal = goalPos-pos;
        double toGoalLen = toGoal.length();
        if (toGoalLen < 1e-06) {
            pos = goalPos;
            orient = goalOrient;
        } else {
            double step = exp(-dt.seconds()*2.f);
            pos = goalPos - (toGoal/toGoalLen)*(toGoalLen*step);
            orient = (goalOrient*(1.f-step) + orient*step).normal();
        }
    }

    mSceneNode->setPosition(toOgre(pos, mScene->getOffset()));
    mSceneNode->setOrientation(toOgre(orient));
}
예제 #2
0
 Vector3f getScale() const {
     return fromOgre(mSceneNode->getScale());
 }
예제 #3
0
Quaternion Camera::getOrientation() const {
    return fromOgre(mSceneNode->getOrientation());
}
예제 #4
0
Vector3d Camera::getPosition() const {
    return fromOgre(mSceneNode->getPosition(), mScene->getOffset());
}
예제 #5
0
 Vector3d getOgrePosition() const {
     return fromOgre(mSceneNode->getPosition(), getScene()->getOffset());
 }
예제 #6
0
 Quaternion getOgreOrientation() const {
     return fromOgre(mSceneNode->getOrientation());
 }