void Camera::initialize() { Vector3d goalPos = getGoalPosition(); Quaternion goalOrient = getGoalOrientation(); mSceneNode->setPosition(toOgre(goalPos, mScene->getOffset())); mSceneNode->setOrientation(toOgre(goalOrient)); setMode(FirstPerson); }
/** * detecting simple deadlocks */ void detectDeadSquare(vector<string> &ground) { vector<Position> goal; getGoalPosition(ground, goal); vector<string> mark = ground; for (int i = 0; i < goal.size(); ++i) { for (int j = 0; j < 4; ++j) { Position person(goal[i].x + direction[j][0], goal[i].y + direction[j][1]); pullAndMark(mark, goal[i], person); } } for (int i = 0; i < ground.size(); ++i) { for (int j = 0; j < ground[i].size(); ++j) { if (!isWall(ground[i][j]) && !isPerson(ground[i][j]) && !isBox(ground[i][j]) && mark[i][j] != 'V') { ground[i][j] = 'X'; } } } }
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)); }