About Store Forum Documentation Contact



Post Reply 
Camera mode tutorial from EE
Author Message
RedcrowProd Offline
Member

Post: #1
Camera mode tutorial from EE
hey just wanna point out, that the "Camera Modes" turorial is broken, it is missing the end of it wink
12-03-2016 07:00 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Camera mode tutorial from EE
wow, many thanks, don't know what happened.
This will be fixed in next release, here's the full code if you need it now:
Code:
/******************************************************************************

   Here we'll present how to properly use different camera modes

/******************************************************************************/
// Define viewing modes:
enum VIEW_MODE // Viewing Mode
{
   VIEW_FPP, // First Person
   VIEW_TPP, // Third Person
   VIEW_ISO, // Isometric
   VIEW_NUM, // number of view modes
}
VIEW_MODE View=VIEW_TPP; // current VIEW_MODE
/******************************************************************************/
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);

         // mouse turn
         if(View!=VIEW_ISO) // don't use mouse turning when in Isometric mode
         {
            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
      bool hide_head=(View==VIEW_FPP && mesh); // disable drawing head when we're in FPP mode
      if(hide_head)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()
{
   // set next camera mode when Tab pressed
   if(Kb.bp(KB_TAB))
   {
      View=VIEW_MODE((View+1)%VIEW_NUM);

      if(View==VIEW_ISO) // when set to isometric view
      {
         Cam.dist =   10; // set bigger camera distance at start
         Cam.pitch=-PI_4; // set starting camera pitch angle
      }
   }

   // 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].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
         }break;

         case VIEW_TPP:
         {
            Cam.dist=Max(1.0, Cam.dist*ScaleFactor(Ms.wheel()*-0.1)); // update camera distance according to mouse wheel
            Cam.setSpherical(Players[0].ctrl.center()+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;

         default: // VIEW_ISO
         {
            Cam.yaw  -=Ms.d().x; // update camera yaw   angle according to mouse delta x
            Cam.pitch+=Ms.d().y; // update camera pitch angle according to mouse delta y
            Clamp(Cam.pitch, -PI_2, 0); // clamp to possible camera pitch angle
            Cam.dist  =Max(1.0, Cam.dist*ScaleFactor(Ms.wheel()*-0.1)); // update camera distance according to mouse wheel
            Cam.setSpherical(Players[0].pos(), Cam.yaw, Cam.pitch, 0, Cam.dist); // set spherical camera looking at player using camera angles
         }break;
      }

      // 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");
}
/******************************************************************************/
12-03-2016 08:35 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #3
RE: Camera mode tutorial from EE
ahah i'm sure you forgot, but its still not fixed in latest version pfft just a reminder ( redoing some camera stuff, i like to check the tutos every time i start redoing something so i realised this again aha)
03-11-2017 04:48 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Camera mode tutorial from EE
Hi and thank you.
I remember about fixing this problem already, it looks like it re-appeared all over again.
I'm wondering what could be the cause of this.
However I've just reuploaded the fix, and double checked that it's okay now.
03-11-2017 07:35 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: Camera mode tutorial from EE
This problem happened to me again in a different tutorial file.
I think the culprit was GitHub trying to merge some binary file as a text file.
I've made some changes to GitHub configuration, I hope this will be enough.
05-25-2017 04:26 AM
Find all posts by this user Quote this message in a reply
Post Reply