About Store Forum Documentation Contact



Post Reply 
First Person -> Third Person
Author Message
Dwight Offline
Member

Post: #1
First Person -> Third Person
Dear members,

My team has difficulty implementing a third person view and first person view in the mmo.

The basic idea is this: press F to go to the First Person View and F again to switch to Third Person View again. (Lateron, when in first person view, a crosshair will be drawn in the center, and you will be able to actually aim when in first person mode).

I looked at the tutorials, and came up with the following chunks of code that I added to the MMO source. It compiles without errors, though it does not work. I most likely forgot something...

So here goes:

Main.h
Code:
struct Chr;
struct Player;
typedef Game::Obj Obj;

#include "../data/enum/_enums.h"
#include "../Shared/Main.h"
#include "Interpolator.h"
#include "Intro.h"
#include "Item.h"
#include "Inventory.h"
#include "Inventory Gui.h"
#include "Chr.h"
#include "Peer.h"
#include "Player.h"
#include "Game.h"
#include "Server.h"
#include "Select Server.h"
#include "Login.h"
#include "Select Character.h"
#include "Background Loader.h"
#include "Options.h"
#include "Controls.h"
#include "Messages.h"

void SetGuiSkin(Int skin);

// Define viewing modes:
enum VIEW_MODE // Viewing Mode
{
   VIEW_FPP, // First Person
   VIEW_TPP, // Third Person
   VIEW_NUM, // number of view modes
};
extern UInt View; // current VIEW_MODE

extern Game::ObjMemx<Player> Players;
Here was added the //Define viewing modes and onwards.

Second, in Main.cpp
Code:
// Camera update for Third person to First person and visa versa
void UpdateCamera()
{
   // set next camera mode when the F key is pressed
   if(Kb.bp(KB_F))
   {
      View=(View+1)%VIEW_NUM;
   }

   // setup the camera
   if(Players.elms()) // if we have at least one player
   {
      // set camera depending on current view mode
      switch(View)
      {
         case VIEW_FPP:
         {
            C OrientP &head=Players[0].cskel.getPoint("Head"); // obtain player "Head" skeleton point (this was created in Mesh Editor)
            Cam.setPosDir(head.pos,head.dir,head.perp); // set camera from 'head' position, direction and perpendicular to direction
         }break;

         default: // VIEW_TPP
         {
            Cam.dist=Max(1.0f,Cam.dist*ScaleFactor(Ms.wheel()*-0.1f)); // update camera distance according to mouse wheel
            Cam.setSpherical(Players[0].ctrl_pos+Vec(0,0.5,0), Players[0].angle.x, Players[0].angle.y, 0, Cam.dist); // set spherical camera looking at player position with given player angles
         }break;
      }

      // after setting camera position and angles:
      Cam.updateVelocities().set(); // update camera velocities and activate it
   }
   else // when no player on the scene
   {
      CamHandle(0.1f,100,CAMH_ZOOM|(Ms.b(1)? CAMH_MOVE:CAMH_ROT)); // default camera handling actions
   }
}
Exactly the same as in the tutorial, except for the TAB going to F, and "head" to "Head"

Third, in Main.cpp
Code:
Bool Update()
{
    // set fog parameters
   Sky.frac                      (    __noop()    )
      .atmosphericDensityExponent(1.21f)
      .atmosphericHorizonColor(Vec4(0,255,0));
   Game::World.update(Cam.at);
   UpdateCamera(); // Update the camera function
   return true;
}
UpdateCamera() and Game::World.update(Cam.at) was added

Fourth, in Player.cpp
Code:
Int Player::drawPrepare()
{
   Bool hide_head=(View==VIEW_FPP && mesh); // disable drawing Head when we're in FPP mode

   if(hide_head)mesh->hide("Head"); // hide "Head" mesh part in 'mesh'

   UInt modes=__super::drawPrepare(); // call default drawing

   if(hide_head)mesh->show("Head"); // un-hide "Head" mesh part, so other objects which use the same mesh will have the head rendered properly
   return modes;
}
Again straight from the tutorials

Lastly, in Player.h
Code:
virtual UInt drawPrepare(); // extend drawing to disable head rendering in FPP mode
This line was added.

I changed nothing except for the above, and now when I am typing this, I get the feeling even more than I forgot something...

Could someone give us some guidance in the right direction please? We would very much appreciate it!

Thanks in advance!

SnowCloud Entertainment - We are recruiting!
http://www.sc-entertainment.com
01-31-2011 05:06 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: First Person -> Third Person
Do you have this line in Main.cpp?

Code:
UInt View; // current VIEW_MODE

You say it doesn't work, but what exactly does it do? Just stays on one type of view mode?
01-31-2011 09:45 PM
Find all posts by this user Quote this message in a reply
Dwight Offline
Member

Post: #3
RE: First Person -> Third Person
Thank you for your reply!

So I checked a couple of things out, and decided to use the search function... I got it to work now. I failed to place the camupdate in the UpdateGame() in Game.cpp.

Now the toggling works, but now when I am in third person view, the cam can move out of the terrain again... (I tried to fix this too, but when entering first person view again, it kinda zoomed in on the characters behind... now it was a nice effect to see, but fullly unintentionally...)

Moving on! smile

I will keep this thread updated with the progress of how I get the aim to work in first person view!

SnowCloud Entertainment - We are recruiting!
http://www.sc-entertainment.com
01-31-2011 09:55 PM
Find all posts by this user Quote this message in a reply
MikeyUchiha Offline
Member

Post: #4
RE: First Person -> Third Person
Did you ever got this to work fully? I'm having the same issue.
07-25-2011 07:03 PM
Find all posts by this user Quote this message in a reply
Post Reply