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)); }
Vector3f getScale() const { return fromOgre(mSceneNode->getScale()); }
Quaternion Camera::getOrientation() const { return fromOgre(mSceneNode->getOrientation()); }
Vector3d Camera::getPosition() const { return fromOgre(mSceneNode->getPosition(), mScene->getOffset()); }
Vector3d getOgrePosition() const { return fromOgre(mSceneNode->getPosition(), getScene()->getOffset()); }
Quaternion getOgreOrientation() const { return fromOgre(mSceneNode->getOrientation()); }