Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to improve upon my first person camera implementation and extend it to, so the user can toggle between third person/first person view.

My current setup: draw()::

glPushMatrix();
    m_pCamera->ApplyCameraTransform();

    // Render gameObjects
glPopMatrix();

Camera is strongly coupled to the player, so much so, that it is a friend of player. This is what the Camera::ApplyCameraTransform looks like:

glm::mat4 l_TransformationMatrix;
m_pPlayer->m_pTransformation->GetTransformation(l_TransformationMatrix, false);

l_TransformationMatrix = glm::core::function::matrix::inverse(l_TransformationMatrix);
glMultMatrixf(glm::value_ptr(l_TransformationMatrix));

So, I take the player's transformation matrix and invert it to yield First person camera view.


Since, Third person camera view is just a 'translated' first person view behind the player; what would be a good way to improve upon this (keeping in mind that I will be extending it to Third person camera as well.

Thanks

share|improve this question
    
it says someone answered, but i can't see the answer. I've tried three different browsers, but it shows up on none ? –  brainydexter Feb 5 '11 at 6:31
    
I have this issue as well –  Ray Dey Feb 5 '11 at 14:09
    
For posterity, here's a link to the relevant meta discussion: meta.gamedev.stackexchange.com/questions/380/… –  Josh Petrie Feb 5 '11 at 19:05
add comment

1 Answer 1

Not entirely sure what kind of improvements you're after here, so I will suggest two different kinds:

  1. I don't see that it's necessary to strongly-couple the camera and the player object, certainly not to the point where they grant friendship. All it seems like you're doing in this example is grabbing the transform of the player, which is something I would expect you could do via the player's public interface -- in fact, I would expect it to be something you could do via a more generalized interface -- any entity with a position. For improved code health, I would suggest decoupling these two.

  2. If the only different between your first-person and third-person camera is a transformation tweak to place the camera behind the target object, I think you'll notice some unpleasantly jerky camera dynamics in response to user input in 3rd person mode. Many 3rd person camera's implement a spring-like system to damp their movements in response to player input (example here), so you might consider implementing damping constraints that you can have applied separately for both camera modes.

share|improve this answer
    
Good answer. You also may need to look at raycasting to keep out of terrain. Have a look at this question gamedev.stackexchange.com/questions/10388/… which talks about how complex this issue can get. –  tenpn Mar 31 '11 at 8:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.