About Store Forum Documentation Contact



Post Reply 
First Person by Default - AND ONLY :)
Author Message
pwsi Offline
Member

Post: #1
First Person by Default - AND ONLY :)
Been working with update camera to different views however want to try to run with FirstPerson cam by default and no switch option... Having trouble doing that... Would post code I've been screwing up but a little cumbersome. Anyone else have success in doing so?
09-06-2017 08:22 AM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #2
RE: First Person by Default - AND ONLY :)
Just take the first person camera from "14 - Camera Modes" tutorial and leave out the isometric and 3rd person one?

It sounds like you are secretly asking us how to program. grin If so, please ask.
(This post was last modified: 09-06-2017 11:33 AM by Tottel.)
09-06-2017 11:33 AM
Find all posts by this user Quote this message in a reply
pwsi Offline
Member

Post: #3
RE: First Person by Default - AND ONLY :)
Well.. I left a project was working on for quite some time in UE4 (with some headaches in regards to engine versions) and decided the stability and overall architecture of Esenthel is better. So excuse me if I got a bit used to form based options and that sort of thing.... In this case I did try to edit 14 - Camera Modes but wasn't sure what to keep/move exactly.
09-06-2017 01:34 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #4
RE: First Person by Default - AND ONLY :)
No worries, just wanted to know how familiar you are with programming. smile

Here is the tutorial with all other camera modes removed:

Code:
class Player : Game.Chr
{
   bool update()
   {
      if(action)
      {
         if(Kb.b(KB_W) || Kb.b(KB_S) || Kb.b(KB_A) || Kb.b(KB_D) || Kb.b(KB_Q) || Kb.b(KB_E))actionBreak();
      }

      if(!action)
      {
         // turn & move
         input.turn.x=Kb.b(KB_Q)-Kb.b(KB_E);
         input.turn.y=Kb.b(KB_T)-Kb.b(KB_G);
         input.move.x=Kb.b(KB_D)-Kb.b(KB_A);
         input.move.z=Kb.b(KB_W)-Kb.b(KB_S);
         input.move.y=Kb.b(KB_SPACE)-Kb.b(KB_LSHIFT);

         // dodge, crouch, walk, jump
         input.dodge = Kb.bd(KB_D)-Kb.bd(KB_A);
         input.crouch= Kb.b (KB_LSHIFT);
         input.walk  = Kb.b (KB_LCTRL );
         input.jump  =(Kb.bp(KB_SPACE ) ? 3.5 : 0);

         Flt max=DegToRad(900)*Time.d();
         angle.x-=Mid(Ms.d().x*1.7, -max, max);
         angle.y+=Mid(Ms.d().y*1.7, -max, max);
      }

      return super.update();
   }

   virtual uint drawPrepare()
   {
      uint draw_mask = 0xFFFFFFFF; // set all groups enabled by default
      FlagDisable(draw_mask, IndexToFlag(DG_CHR_HEAD)); // clear head draw group flag
      SetDrawMask(draw_mask); // set draw mask
      uint modes = super.drawPrepare(); // call default drawing after setting the mask
      SetDrawMask(); // reset default mask
      return modes;
   }
}
/******************************************************************************/
Game.ObjMap<Game.Item> Items;
Game.ObjMap<Player   > Players;
/******************************************************************************/
void InitPre()
{
   EE_INIT();
   Ms.hide();
   Ms.clip(null, 1);
   D.viewRange(30).shadowSoft(1);

   Cam.at.set(16, 0, 16);
   Cam.yaw   =-PI_4;
   Cam.pitch =-0.5;
   Cam.dist  =4;
}
/******************************************************************************/
bool Init()
{
   Physics.create(EE_PHYSX_DLL_PATH);

   Game.World.activeRange(D.viewRange())
             .setObjType (Players, OBJ_CHR)
             .New        (UID(4053788456, 1284500709, 3533893555, 3086486877));
   if(Game.World.settings().environment)Game.World.settings().environment->set();

   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
void UpdateCamera()
{
   // setup the camera
   if(Players.elms()) // if we have at least one player
   {
      C OrientP *head=Players[0].skel.getSlot(8"head"); // obtain player "head" skeleton slot (this was created in Object Editor)
      Cam.setPosDir(head.pos, head.dir, head.perp); // set camera from 'head' position, direction and perpendicular to direction

      // after setting camera position and angles:
      Cam.updateVelocities().set(); // update camera velocities and activate it
   }else // when no player on the scene
   {
      Cam.transformByMouse(0.1, 100, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT)); // default camera handling actions
   }
}
bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   Game.World.update(Cam.at);
   UpdateCamera();
   return true;
}
/******************************************************************************/
void Render()
{
   Game.World.draw();
}
void Draw()
{
   Renderer(Render);
   D.text  (0, 0.9, "Press Tab to switch camera modes");
}
/******************************************************************************/
09-06-2017 01:41 PM
Find all posts by this user Quote this message in a reply
pwsi Offline
Member

Post: #5
RE: First Person by Default - AND ONLY :)
The issue I was having was around line 114 of Camera Mode Demo and taking out the switch VIEW_FPP... As well as virtual uint drawPrepare() I see taking out bool hide_head is the way to go and adding FlagDisable... Thanks for the response!!!
09-06-2017 02:05 PM
Find all posts by this user Quote this message in a reply
pwsi Offline
Member

Post: #6
RE: First Person by Default - AND ONLY :)
Now I am asking for programming help... Basically trying to get First Person working in your Visual Event System. A couple things going on here... Was able to get first person showing up by placing the First Person code in Main ONLY. (That was first step to get it working, but interaction wasn't working and was afraid it was called to Player.cpp from other places..
So decided to place
Code:
virtual UInt drawPrepare();
   {
      uint draw_mask = 0xFFFFFFFF; // set all groups enabled by default
      FlagDisable(draw_mask, IndexToFlag(DG_CHR_HEAD)); // clear head draw group flag
      SetDrawMask(draw_mask); // set draw mask
      uint modes = super.drawPrepare(); // call default drawing after setting the mask
      SetDrawMask(); // reset default mask
      return modes;
   }
...in player.

In MAIN I changed the void UpdateCamera() to reflect required for first person camera.

NOW, what is happening I am getting an error showing character not allowed as an identifier and I think its in drawPrepare. I am at a loss.
admittedly.
09-06-2017 09:19 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #7
RE: First Person by Default - AND ONLY :)
For now, you can just go into the Camera class, and replace the four lines that set the camera in the update with these two:

Code:
C OrientP *head=Players[0].skel.getSlot(8"head"); // obtain player "head" skeleton slot (this was created in Object Editor)
         Cam.setPosDir(head.pos + finalOffset, head.dir, head.perp); // set camera from 'head' position, direction and perpendicular to direction

Also go into Interact, and replace the update with this:

Code:
void Interact::update()
{
   clear();
  
   if(Players.elms())
   {
      Player &player = Players[0];
      
      if(!valid)
      {  
         C OrientP *head=Players[0].skel.getSlot(8"head"); // obtain player "head" skeleton slot (this was created in Object Editor)
         Vec dir = head.dir;
         Vec pos = head.pos + (dir * 0.5f);
        
         PhysHit hit;
         if(Physics.ray(pos, dir*10, &hit))
         {
            valid = true;
            obj = hit.obj;
            pos = hit.plane.pos;
            
            // Set the mesh to be highlighted
            highlight = true;
            
            // Clicked on the object
            if(Ms.bp(0))
            {
                    if(ButtonObject  *temp = CAST(ButtonObject, hit.obj)) temp.Activate();
               else if(Item          *temp = CAST(        Item, hit.obj)) temp.PickedUp();
            
               Ms.eat(0); // Eat the mouse operation (this mouse click does not count for anything else in the project)
            }
         }
      }
   }
}

You don't have to bother with the drawPrepare for now.. Eventually, you will want to do it to hide the face while in FPP, but for now, it'll work fine (To use it, you have to assign body groups to your player character. My project doesn't have that set up, the tutorial does for the Warrior character).
Also, I'm preparing yet another update where you can toggle the camera between first person, third person, or looking at things with an event. So, the code I just gave you is temporary (but works fine for just first person only)
09-07-2017 08:24 AM
Find all posts by this user Quote this message in a reply
Post Reply