About Store Forum Documentation Contact



Post Reply 
Sun problem
Author Message
tipforeveryone Offline
Bronze Supporter

Post: #1
Sun problem
https://youtu.be/GaEWEjOjjp8

Here is my code, I cant find the problem

Code:
Game.ObjMap<Game.Item> Items;
Game.ObjMap<Game.Item> Weapons;


class Player : Game.Chr // extend character class by defining a player class based on the character
{
   virtual Bool update() // here we'll update the player (please note that this is a virtual method)
   {
      // here we update character input according to mouse and keyboard
      // before we set the input, we need to check if the character isn't controlled by an automatic action
      if(action)
      {
         // if it's controlled by an action we leave the input with no changes,
         // however we can optionally break that action, by pressing for example movement keys
         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) // if the character isn't controlled by an automatic action, we can set the input
      {
         // turn & move
         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
         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(); // call Game.Chr.update on which Player is based on
   }
}
/******************************************************************************/
Player player; // player
/******************************************************************************/
void InitPre()
{
   EE_INIT();
   Ms.hide();
   Ms.clip(null, 1);
   Cam.dist=2;
}
/******************************************************************************/
bool Init()
{
   Physics.create();
  
   player.create(*ObjectPtr(UID(3881591406, 1159942933, 3235648136, 485124123))); // create player from object parameters
  
   Game.World.New(UID(4079117345, 1148274901, 4202549426, 3268749690)); // create the world by giving path to world
   Game.World.setObjType(Items, Props);
   Game.World.setObjType(Weapons, Gun);
   Game.World.settings().environment->set(); // setup world's environment
   Game.World.update(Cam.at); // which updates world to use only terrain and objects at given position, here camera position is used

   return true;
}
/******************************************************************************/
void Shut()
{
   Game.World.del(); // worlds need to be manually deleted
}
/******************************************************************************/
bool Update()
{
   if(Kb.bp(KB_ESC))return false;

   Physics.startSimulation().stopSimulation();

   player.update(); // update player
  
   //C OrientM *head = player.skel.getSlot("eyes");

   Cam.updateBegin()
      //.setPosDir(head.pos, head.dir, head.perp)
      
      .setSpherical(player.skel.getSlot("eyes").pos,
         player.angle.x,
         player.angle.y,
         0,
         0)
         //Cam.dist*ScaleFactor(Ms.wheel()*-0.2))
      .updateEnd()
      .set();
      
      
   // update camera according to player angles and mouse wheel
  
   Game.World.update(Cam.at); // update the world to given position
  
   if(Kb.bp(KB_R)) // on space
   {
      ObjectPtr obj=UID(2552926861, 1117558837, 264905372, 2361802078); // get barrel object parameters
      Game.World.objCreate(*obj, Matrix(obj->scale3(), Vec(0, 4, 0))); // create new object at (16, 4, 16) position and give objects default scaling
   }
  
   return true;
}
/******************************************************************************/
void Render()
{
   Game.World.draw(); // draw world (this is done outside of 'switch(Renderer())' because world automatically detects active rendering mode)
   switch(Renderer())
   {
      case RM_PREPARE:
      {
         player.drawPrepare();

         LightDir(!(Cam.matrix.x-Cam.matrix.y+Cam.matrix.z)).add();
      }break;
   }
  
}
void Draw()
{
   Renderer(Render);
   Renderer.setDepthForDebugDrawing();
}
/******************************************************************************/
(This post was last modified: 06-14-2020 09:19 AM by tipforeveryone.)
06-14-2020 09:17 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Sun problem
What's the problem?

Sun light direction?

You're using this code:
LightDir(!(Cam.matrix.x-Cam.matrix.y+Cam.matrix.z)).add();
which depends on camera
06-14-2020 02:55 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #3
RE: Sun problem
You're also casting it to a bool with "!". Probably not something you want either.
06-14-2020 03:16 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Sun problem
! operator for Vec's means normalization in EE
06-14-2020 03:19 PM
Find all posts by this user Quote this message in a reply
tipforeveryone Offline
Bronze Supporter

Post: #5
RE: Sun problem
Ah yes, comment out that line solved problem of sunlight direction, I just copy/paste those lines of code!
Thanks for pointing this out.
06-14-2020 04:50 PM
Find all posts by this user Quote this message in a reply
Post Reply