| 199 | } |
| 200 | |
| 201 | void CameraManager::updateCameraFrameTime(const Ogre::Real frameTime) |
| 202 | { |
| 203 | if (!isCameraMovingAtAll()) |
| 204 | return; |
| 205 | |
| 206 | // Carry out the acceleration/deceleration calculations on the camera translation. |
| 207 | Ogre::Real speed = mTranslateVector.normalise(); |
| 208 | mTranslateVector *= static_cast<Ogre::Real>(std::max(0.0, speed - (0.75 + (speed / MOVE_SPEED)) |
| 209 | * MOVE_SPEED_ACCELERATION * frameTime)); |
| 210 | mTranslateVector += mTranslateVectorAccel * static_cast<Ogre::Real>(frameTime * 2.0); |
| 211 | |
| 212 | // If we have sped up to more than the maximum moveSpeed then rescale the |
| 213 | // vector to that length. We use the squaredLength() in this calculation |
| 214 | // since squaring the RHS is faster than sqrt'ing the LHS. |
| 215 | if (mTranslateVector.squaredLength() > MOVE_SPEED * MOVE_SPEED) |
| 216 | { |
| 217 | speed = mTranslateVector.length(); |
| 218 | mTranslateVector *= MOVE_SPEED / speed; |
| 219 | } |
| 220 | |
| 221 | // Get the camera's current position. |
| 222 | Ogre::Vector3 newPosition = getActiveCameraNode()->getPosition(); |
| 223 | |
| 224 | // Get a quaternion which will rotate the "camera relative" x-y values |
| 225 | // for the translateVector into the global x-y used to position the camera. |
| 226 | Ogre::Vector3 viewTarget = getCameraViewTarget(); |
| 227 | |
| 228 | Ogre::Vector3 viewDirection = viewTarget - newPosition; |
| 229 | |
| 230 | viewDirection.z = 0.0; |
| 231 | |
| 232 | Ogre::Quaternion viewDirectionQuaternion = Ogre::Vector3::UNIT_Y.getRotationTo(viewDirection); |
| 233 | |
| 234 | // Adjust the newPosition vector to account for the translation due |
| 235 | // to the movement keys on the keyboard (the arrow keys and/or WASD). |
| 236 | if (mZChange != 0) |
| 237 | { |
| 238 | newPosition.z += static_cast<Ogre::Real>(mZChange * frameTime * ZOOM_SPEED); |
| 239 | // We also stow and stop the movement here, as the keyboard release events |
| 240 | // and mouse wheel event are otherwise colliding on handling the zoom. |
| 241 | if (mZChange > 0) |
| 242 | mZChange -= MOVE_SPEED; |
| 243 | else if (mZChange < 0) |
| 244 | mZChange += MOVE_SPEED; |
| 245 | } |
| 246 | |
| 247 | // Update the position for the other axices. |
| 248 | newPosition += (viewDirectionQuaternion * mTranslateVector); |
| 249 | |
| 250 | // Prevent camera from moving down into the tiles or too high. |
| 251 | if (newPosition.z <= MIN_CAMERA_Z) |
| 252 | newPosition.z = MIN_CAMERA_Z; |
| 253 | else if (newPosition.z >= MAX_CAMERA_Z) |
| 254 | newPosition.z = MAX_CAMERA_Z; |
| 255 | |
| 256 | // Prevent the tilting to show a reversed world or looking too high. |
| 257 | if (mRotateLocalVector.x != 0) |
| 258 | { |
no test coverage detected