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!