Original Post
Anyone have a good, robust and somewhat simple third person camera system that I could use for my game demo/engine? It's just for learning purpose. Pseudo code is also appreciated. Thanks
void Camera::UpdatePosition(const Vector3 &vTargetPosition, const Vector3 &vTargetOrientation, float dt){ // Get the amount of rotation of the target as radians (rather than a vector). float fAngle = VectorAngle2v(vTargetOrientation, Vector3(0.0f, 0.0f, 1.0f)); // Adjust the desired camera rotation, accounting for the targets rotation. fAngle -= mfAzimuth; // Calculate the "desired" camera position. This is the position that the // camera would be in if it's weren't constrained by the spring system. The // spring system controls the camera motion towards this "desired" point. Vector3 vDesiredPosition; vDesiredPosition.x = mfDistance * sinf(fAngle) * sinf(mfAltitude + kHalfPi) + vTargetPosition.x; vDesiredPosition.y = mfDistance * cosf(mfAltitude + kHalfPi) + vTargetPosition.y; vDesiredPosition.z = mfDistance * cosf(fAngle) * sinf(mfAltitude + kHalfPi) + vTargetPosition.z; // The camera shouldn't move too quickly, so we need to get it to slowly // approach the "desired" camera position. This is achieved by moving the // camera a fixed percentage towards the desired camera position. The // greater the distance between the current camera position and the // desired camera position, the faster the camera moves. Vector3 vMovementDirection = vDesiredPosition - mvPosition; float fLength = vMovementDirection.Length(); float fDistanceToMove = mfTightness * (fLength * dt); vMovementDirection.Normalise(); // No we simply move the camera along our movement vector (vMovementDirection) // by the specified amount (fDistanceToMove). This places the camera at its // new position. mvPosition += vMovementDirection * fDistanceToMove; mvView = vTargetPosition; // We want to look at our target. // Recalculate the facing/cross vectors that are used for controlling the // avatar movement. mvFacing = mvView - mvPosition; mvFacing.Normalise(); mvCross = Vector3(mvFacing.z, 0.0f, -mvFacing.x); mvUp = Cross(mvFacing, mvCross); mvUp.Normalise();}This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more