About Store Forum Documentation Contact



Post Reply 
Can't get the light to work!
Author Message
tibiartist Offline
Member

Post: #1
Can't get the light to work!
Hi, I've been trying to implement lights to my game... But Adding to the world in world editor wont work... Here's the code:
Code:
/******************************************************************************/
#include "stdafx.h"
#include "../../../../../data/enum/_enums.h"
Sound sound;
Image skybox;
Marker marker;
/******************************************************************************

   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_NUM, // number of view modes
};
UInt View; // current VIEW_MODE
/******************************************************************************/
struct Item : Game::Item // extend game items
{
   Game::LightPoint light_point; // point light

   virtual void create(Game::ObjParams &obj); // extend creation
   virtual void draw  (       );              // extend drawing
   virtual void save  (File &f);              // extend saving
   virtual Bool load  (File &f);              // extend loading
};

void Item::draw()
{
   if(0) // optionally you can disable shadow casting of the item, when the item is the light source
   {
      if(Renderer()==RM_SHD_MAP && CurrentLight.src==&light_point)return; // if in shadowing mode and current light source is 'light_point' then don't draw anything
   }

   __super ::  draw(              ); // default draw
   light_point.draw(actor.matrix()); // draw light with item's matrix
}
/******************************************************************************/
void Item::save(File &f)
{
   __super::save(f); // save default data

   light_point.save(f); // save point light
}
Bool Item::load(File &f)
{
   if(__super::load(f)) // load default data
   {
      light_point.load(f); // load point light
      return true;
   }
   return false;
}

struct Player : Game::Chr
{
   virtual Bool update();
  
   virtual void draw(); // extend drawing to disable head rendering in FPP mode
};
/******************************************************************************/
Game::ObjMemx<Game::Static> Statics; // container for static objects
Game::ObjMemx<Game::Item  > Items  ; // container for item   objects
Game::ObjMemx<Game::LightPoint> LightPoints; // container for point light objects
Game::ObjMemx<      Player> Players; // container for player objects
/******************************************************************************/
void Startersound(){


    if(::sound.playing()) // if already playing
      {
          ::sound.del(); // delete sound
      }else
      {
          ::sound.play("people020.wav",false); // play with loop option enabled
      }

};

Bool Player::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.anglei.x=Kb.b(KB_Q)-Kb.b(KB_E);
      input.anglei.y=Kb.b(KB_T)-Kb.b(KB_G);
      input.diri  .x=Kb.b(KB_D)-Kb.b(KB_A);
      input.diri  .z=Kb.b(KB_W)-Kb.b(KB_S);
      input.diri  .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 ) ? 10 : 0);
         if(Kb.bp(KB_H))
   {
      speed++;
   }
      

      // mouse turn

      {
         Flt  max=DegToRad(900)*Tm.d(),
              dx =Ms.dir_ds.x*1.7,
              dy =Ms.dir_ds.y*1.7*Ms.inv();
         angle.x-=Mid(dx,-max,max);
         angle.y+=Mid(dy,-max,max);
      }

      // ready stance change
      ready^=Kb.bp(KB_R);
   }

   return __super::update();
}

void Player::draw()
{
   Bool disable_head_draw=(View==VIEW_FPP && Renderer()!=RM_SHD_MAP && mesh); // disable drawing head when we're in FPP mode and we're not in shadowing mode (if this isn't included player will cast head-less shadows)

   if(disable_head_draw)mesh->hide("head"); // hide "head" mesh part in 'mesh'

   __super::draw(); // call default drawing

   if(disable_head_draw)mesh->show("head"); // un-hide "head" mesh part, so other objects which use the same mesh will have the head rendered properly
}
/******************************************************************************/
void InitPre()
{   App.name("Camera Modes");
   App.flag=APP_MS_EXCLUSIVE|APP_MAXIMIZABLE;
   IOPath("../data");
   PakAdd("engine.pak");
   D.full(false).ambPower(0.4).hpRt(true).hwDepthBuffer(true).mtnMode(MTN_LOW).shdF​ade(0.4).hdr(true);
   ViewportFull.range=60;
}
/******************************************************************************/
Bool Init()
{
       void Startersound();
       Startersound();
   Physics.create();
   Sky    .set   ();
      // sun
   {
    

      Sun &sun=Suns.New();                 // create a new sun in 'Suns' container
      sun.set(*Images("gfx/sky/sun.gfx")); // set image
      sun.pos=!Vec(1,1,1);                 // set custom position
   }
   Water.set(*Images("gfx/water/0.gfx"),*Images("gfx/water/0.n.gfx"),Images("gfx/fx/reflection.gfx")); // set water from textures

   // create the world
   Game::World.init()
              .setType(Statics,OBJ_STATIC)
              .setType(Players,OBJ_CHR   )
              .setType(LightPoints,OBJ_LGT_PNT)
              .setItem(Items  ,OBJ_ITEM  )
              .New("world/beta"        );
                
   Water.plane(Water.plane() + Vec(0,-3,0));

   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Main()
{
   if(Kb.bp(KB_ESC))return false;
   Game::World.update(Cam.at);

   // set next camera mode when Tab pressed
   if(Kb.bp(KB_TAB))
   {
      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:
         {
            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;
        
         case VIEW_TPP:
         {
            Cam.dist=Max(1.0f,Cam.dist*ScaleFactor(Ms.wheel()*-0.1)); // update camera distance according to mouse wheel
            Cam.setSpherical(Players[0].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;
        
         default: // VIEW_ISO
         {
            Cam.yaw  -=Ms.ds.x; // update camera yaw   angle according to mouse smooth delta x
            Cam.pitch+=Ms.ds.y; // update camera pitch angle according to mouse smooth delta y
            Clamp(Cam.pitch,-PI_2,0); // clamp to possible camera pitch angle
            Cam.dist  =Max(1.0f,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
   {
      CamHandle(0.1,100,CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT)); // default camera handling actions
   }
Water.update(Vec2(0.2,0.2));




   return true;
}
/******************************************************************************/
void Render()
{
    Game::World.draw();
    switch(Renderer()){
  
      case RM_SOLID  :
      case RM_SOLID_M:
      break;

    }
}
void Draw()
{
   Renderer(Render);
   D.text  (0,0.9,"Version 1.0.8");
}
/******************************************************************************/
06-14-2009 05:50 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: Can't get the light to work!
please try to look at the tutorial with world editor lights
06-14-2009 07:11 PM
Find all posts by this user Quote this message in a reply
Post Reply