Jump to content


Implementing 3rd person view in opengl


5 replies to this topic

#1 rogerdv

    Member

  • Members
  • PipPip
  • 99 posts

Posted 12 October 2005 - 11:46 AM

Im looking for some simple demo that implements a camera following a charater from behind. Can somebody give me an url or something? I would like to achieve something like WoW or Anarchy Online camera.

#2 awood

    Member

  • Members
  • PipPip
  • 33 posts

Posted 12 October 2005 - 02:54 PM

Have you looked at/used gluLookAt? This is what I use to achieve 3rd person view.

#3 rogerdv

    Member

  • Members
  • PipPip
  • 99 posts

Posted 12 October 2005 - 03:51 PM

Of course, but it covers just the basics. What I need to see is how to make the maths required to move and rotate the camera following the movement of character, given by the player using the arrow keys.

#4 zavie

    Member

  • Members
  • PipPip
  • 91 posts

Posted 12 October 2005 - 06:31 PM

There are much ways to do this.

A first very (very) basic way is to put your camera as in fps view, and then translate it both backward and upward. I guess it would result a bit annoying though. ;-) Then you could also manage distance from the character according to the context (I have no idea about this at the moment). It musn't be much more complicated in Tomb Raider (at least the three first ones - haven't seen the other ones ^_^).

#5 awood

    Member

  • Members
  • PipPip
  • 33 posts

Posted 12 October 2005 - 06:57 PM

This tutorial may be of help:
http://www.gamedev.n...article2160.asp

#6 corey

    Member

  • Members
  • PipPip
  • 78 posts

Posted 12 October 2005 - 08:56 PM

I believe your question is: How does the camera follow in that position, and how is the camera rotated and repositioned, right?

Well, essentially there is a fixed camera distance (most implementations do this although some detect viewing occlusion issues and compensate). The target can be at (0, 0, 0) and the camera translated to a different location (say behind and above) and then told to look at that position.

We have a basic camera controller that's in the style of a first-person game with simple camera follow according to keyboard input for movement and mouse movement for orientation/rotation. I'm pasting a sample of simple control below (obviously we have helper classes like CoordinateFrame and Vector3):

I personally think Nehe's tutorials are decently clear: Camera Class Tutorial


// Translation direction

Vector2 direction(userInput->getX(), userInput->getY());

direction.unitize();


// Translate forward

translation += (getLookVector() * direction.y + 

getStrafeVector() * direction.x) * elapsedTime * maxMoveRate;

    

Vector2 delta = userInput->mouseDXY() / 100.0;


// Turn rate limiter

if (G3D::abs(delta.x) > maxTurnRate) {

    delta.x = maxTurnRate * G3D::sign(delta.x);

}


if (G3D::abs(delta.y) > maxTurnRate) {

    delta.y = maxTurnRate * G3D::sign(delta.y);

}


yaw   += delta.x;

pitch += delta.y;


// Clamp pitch (looking straight up or down)

pitch = clamp(pitch, -G3D_PI / 2, G3D_PI / 2);


corey





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users