Ejemplo n.º 1
0
bool RabidEngine::OnInitialize(int argc, char** argv)
{
  LOG_START("rabid_log.html");

  g_fileSystem = (IFileSystem*)new FileSystem();
  g_fileSystem->AddPath();

  g_defMgr = new DefMgr();

  g_cvarSystem = new CVarSystem();
  g_cvarSystem->Initialize();
  CVar::RegisterStaticCVars();

  g_console = new Console();
  g_console->SetScreenDimensions(GetWidth(), GetHeight());

  g_commandSystem = new CommandSystem();
  g_commandSystem->Initialize();

  g_common = new Common();

  g_renderer = CreateRenderer("GL");
  g_renderer->SetViewport(0,0, GetWidth(), GetHeight());

  g_common->Print("\x009### Rabid Hardware Radiosity Engine");
  g_common->Print("\x009### Based on the Catharsis Game Engine");
  g_common->Print("\x009### Christopher Olsen");
  g_common->Print("\x005### \x007SPACE\x005 distributes light ###");
  g_common->Print("\x005### \x007TAB\x005 switches light view modes ###");
  g_common->Print("\x005### \x007""B\x005 toggles the brightest surface ###");

  LoadMap("test.map");

  cl_camrotx.SetFloat(0.0);
  cl_camroty.SetFloat(0.0);
  cl_camrotz.SetFloat(0.0);

  logo = g_materialSystem->GetMaterial("logo");

  return true;
}
Ejemplo n.º 2
0
bool RabidEngine::OnMouseMove(int dx, int dy)
{
  if(!g_console->Active())
  {
    {
      cl_camroty.SetFloat(cl_camroty.GetFloat() - dx);
      cl_camrotx.SetFloat(cl_camrotx.GetFloat() - dy);

      while(cl_camroty.GetFloat() > 360.0f)
        cl_camroty.SetFloat(cl_camroty.GetFloat() - 360.0f);
      while(cl_camroty.GetFloat() < 0.0f)
        cl_camroty.SetFloat(cl_camroty.GetFloat() + 360.0f);

      if(cl_camrotx.GetFloat() > 90)
        cl_camrotx.SetFloat(90.0);
      if(cl_camrotx.GetFloat() < -90)
        cl_camrotx.SetFloat(-90.0);
    }

    
    return true;
  }

  return false;
}
Ejemplo n.º 3
0
void RabidEngine::OnIdle()
{
  g_timer.Update();
  const float dt = g_timer.GetTimeChange();

  g_console->Update(dt);




  Transformation view;
  view.Rotate().FromEulerXYZ(cl_camrotx.GetFloat(),
                             cl_camroty.GetFloat(),
                             cl_camrotz.GetFloat());

  // move
  const Vector3f forward = -view.Rotate().GetColumn(2);
  const Vector3f right   =  view.Rotate().GetColumn(0);

  const float vel = 50.0 * dt;
  if(keyState[B_FORWARD])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + forward.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + forward.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + forward.z * vel);
  }
  if(keyState[B_BACKWARD])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + -forward.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + -forward.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + -forward.z * vel);
  }
  if(keyState[B_RIGHT])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + right.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + right.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + right.z * vel);
  }
  if(keyState[B_LEFT])
  {
    cl_camx.SetFloat(cl_camx.GetFloat() + -right.x * vel);
    cl_camy.SetFloat(cl_camy.GetFloat() + -right.y * vel);
    cl_camz.SetFloat(cl_camz.GetFloat() + -right.z * vel);
  }
  if(keyState[B_RENDER])
  {
    done.Set("0");
    keyState[B_RENDER] = 0;
  }
  if(keyState[B_LIGHT_MODE])
  {
    if(r_resid.GetBool())
      r_resid.Set("0");
    else
      r_resid.Set("1");
    keyState[B_LIGHT_MODE] = 0;
  }
  if(keyState[B_TOGGLE_BRIGHTEST])
  {
    if(r_showbrightest.GetBool())
      r_showbrightest.Set("0");
    else
      r_showbrightest.Set("1");
    keyState[B_TOGGLE_BRIGHTEST] = 0;
  }






  static int pass;
  static int surf = -1;
  static int brightest;
  static int patches;
  if(done.GetBool())
  {
  }
  else
  {
    if(pass == 0)
    {
      // clear accumulation buffers
      for(unsigned int i = 0; i < surfaces.Size(); i++)
      {
//          if(surfaces[i]->GetType() != S_LIGHT)
//            surfaces[i]->ClearAccum();
      }
    }


    if(surf >= (int)surfaces.Size())
    {
      surf = -2;
      pass++;
      done.Set("1");
    }
    else if(surf == -1)
    {
      // Find Brightest Surface
      float maxPower = 0.0;
      for(unsigned int i = 0; i < surfaces.Size(); i++)
      {
        float p = surfaces[i]->GetPower();
        if(p > maxPower)
        {
          brightest = i;
          maxPower = p;
        }
      }

      for(int i = 0; i < lights.Size(); i++)
        delete lights[i];
      lights.Resize(0);

      surfaces[brightest]->CreateLights(lights);
    }
    else
    {
      Surface* lsurf = surfaces[surf];

      bool skip = false;
      // lights can't receive light
      if(lsurf->GetType() == S_LIGHT)
        skip = true;

      // surface can light itself
      if(!skip && surf == brightest)
      {
        if(r_resid.GetBool())
          lsurf->CopyResidualToLightMap();
        skip = true;
      }



      if(!skip)
      {
        // Render each sub-light's contribution
        for(unsigned int l = 0; l < lights.Size(); l++)
        {
          Vector3f& p = lights[l]->p;
          Vector3f& d = lights[l]->d;
          float     I = lights[l]->I;

          // light is on wrong side of surface
          if(Dot(p - lsurf->c, lsurf->N) < 0.1)
            continue;

          g_renderer->SetLight(0, p.x, p.y, p.z);
          g_renderer->SetLightDir(0, d.x, d.y, d.z);
          g_renderer->SetLightIntensity(0, I);
          g_renderer->SetLightFraction(0, 1.0 / (float)lights.Size());

          lsurf->Frame(p);
          lsurf->CreateLightMap(p, d, surfaces);
          lsurf->AccumulateResidualLight();
          lsurf->AccumulateLight();
          g_renderer->SetViewMatrix(0);
          patches += lsurf->GetNumPatches();
        }

        r_resid.Set(r_resid.GetBool() ? "1" : "0");
      }
    }
    surf++;
  }


  if(r_resid.Changed())
  {
    for(int i = 0; i < surfaces.Size(); i++)
    {
      Surface* lsurf = surfaces[i];
      lsurf->Frame(lsurf->c + lsurf->N*10.0);

      if(r_resid.GetBool())
        lsurf->CopyResidualToLightMap();
      else
        lsurf->CopyAccumToLightMap();
    }
  }






  // Render normal view
  view.Translate() = Vector3f(cl_camx.GetFloat(),
                              cl_camy.GetFloat(),
                              cl_camz.GetFloat());

  view = view.Inverse();
  g_renderer->SetViewport(0,0, GetWidth(),GetHeight());
  g_renderer->SetViewMatrix(view);
  g_renderer->SetProjectionMatrix(0);
  g_renderer->SetClearColor(0.25f, 0.25f, 0.35f, 1.0f);
  g_renderer->BindMaterial(0);
  g_renderer->Clear(R_COLOR_BUFFER | R_DEPTH_BUFFER);
  g_renderer->SetColor(1,1,1);


  int bsurf = 0;
  float maxPower = 0.0;
  for(unsigned int i = 0; i < surfaces.Size(); i++)
  {
    float p = surfaces[i]->GetPower();
    if(p > maxPower)
    {
      bsurf = i;
      maxPower = p;
    }
  }


  // draw all surfaces normally
  for(unsigned int i = 0; i < surfaces.Size(); i++)
  {
    if(r_showbrightest.GetBool())
    {
      if(i == bsurf)
        g_renderDevice->SetColor(1.0, 1.0, 0.7);
      else
        g_renderDevice->SetColor(1,1,1);
    }
    surfaces[i]->Render();
  }

  g_console->Draw(g_renderer);

  g_renderer->DrawTextP(15, 50, 16, r_resid.GetBool() ? "Residual" : "Accumulation");
  g_renderer->DrawTextP(15, 30, 16, "Step: %d", pass);
  g_renderer->DrawTextP(15, 10, 16, "Patches: %d", patches);
  g_materialSystem->BindMaterial(logo);
  g_renderer->DrawRect(GetWidth()-200, 0, 200, 50, 0,0,1,1);

  g_renderer->Flip();
}