It is currently Thu Apr 27, 2017 9:55 am

All times are UTC - 5 hours




 Page 1 of 1 [ 2 posts ] 
Author Message
 Post subject: GameDev VMK 44 - 3rd Person Camera
PostPosted: Fri Dec 10, 2010 9:23 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
YouTube VideoImage


VMK 44A and 44B - To prepare for the swap over from the 1st person camera to the 3rd person camera controls, we replace the old camera class with a new one that uses the gluLookAt function.

VMK 44C - We separate the Player class from the Camera class and attached a 3D model of the player to our movement controls. The player is rendered in front of the camera as we move around the world. A little bit of 3D math is involved to figure out where to position our "pivot" point so that when we rotate the camera, our scene/view updates correctly while keeping the 3D model at the correct spot.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 44 - 3rd Person Camera
PostPosted: Sat Jan 07, 2012 1:55 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
I successfully was able to switch between 3rd person view to first person view by clicking the Middle Mouse Button. It took some time but the trick was simple.

In the scene class I added a private bool variable _b3rdPerson, I set this to true inside of the scene's constructor. I created a public function in the scene class: void SwitchCameraView(). All this function does is negate our member variable. This function is called in GameOGL's Message Handler Inside the Middle Mouse Button Down Section.

For this to work properly I encased the players transform inside an if statement inside the Update Function.

it now looks like this.

if ( _b3rdPerson ) {
      _pPlayerTransform->_bVisible = true;
      if ( _pPlayerTransform ) {
         // Update Player's Position
         _Camera.Get3rdPersonLocation( _pPlayerTransform->_v3Translate, _pPlayerTransform->_fRotateAngle );
      }
   } else {
      _pPlayerTransform->_bVisible = false;
   }


When you click the middle mouse button, it triggers the transform of this object's _bVisible variable. After checking to see if _b3rdPerson is true We still have to make our transform's visible parameter true just to make sure it is true before we try to update the transforms position, otherwise, if _b3rdPerson is false our _bVisible will always be false. I hope this helps anyone who has reached this point and would like the ability to switch between views.

If you want the ability to use the mouse's wheel to scroll the camera closer to the player's model it would take a little more work. Im not to familiar with programming a mouse wheel's functionality, but I am sure that you would have to regulate the mouse wheel's polling speed then sync it with the distance between the player and camera's location.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron