Ejemplo n.º 1
0
//--------------------------------------------------------------
// initialize application
void DontHitMe::appInit()
{
  // get the important directories
  mgString shaderDir;
  m_options.getFileName("shaderDir", m_options.m_sourceFileName, "docs/shaders", shaderDir);
  mgString uiDir;
  m_options.getFileName("uiDir", m_options.m_sourceFileName, "docs/ui", uiDir);
  mgString fontDir;
  m_options.getFileName("fontDir", m_options.m_sourceFileName, "docs/fonts", fontDir);

  mgInitDisplayServices(shaderDir, fontDir);

  mgDisplay->setFOV(m_options.getDouble("FOV", 60.0));
  mgDisplay->setDPI(m_options.getInteger("DPI", 0));

  // load cursor pattern
  loadCursor();
  setDeskMode(true);

  initMovement();

  // load the shaders we might use
  mgVertex::loadShader("litTexture");
  mgVertex::loadShader("unlitTexture");
  mgVertex::loadShader("litTextureCube");
  mgVertex::loadShader("unlitTextureCube");
  mgVertexTA::loadShader("litTextureArray");
  mgVertexTA::loadShader("unlitTextureArray");

  m_sky = new StarrySky(m_options);
  m_sky->enableSkyBox(true);
  m_sky->enableStars(true);
  m_sky->enableSun(true);

  mgPoint3 lightDir(0, 1, 1);
  lightDir.normalize();
  m_sky->setSunDir(lightDir);

  mgDisplay->setLightDir(lightDir);

  m_saucer = new Saucer(m_options);
  m_planet = new Planet(m_options);

  m_wreck = new Wreck(m_options);
  m_tower1 = new Tower(m_options, false);
  m_tower2 = new Tower(m_options, false);

  mgString fileName;
  m_options.getFileName("tube", m_options.m_sourceFileName, "tube.jpg", fileName);
  m_tubeTexture = mgDisplay->loadTexture(fileName);

  initTrack();
  initBall();
  updateBallPt();

  m_intro = new Intro(m_options, m_ballOrigin);
  m_showingIntro = false;

  m_lastAnimate = mgOSGetTime();  // now!
}
Ejemplo n.º 2
0
//--------------------------------------------------------------------
// initialize application
void GuiTestAll::appInit()
{
  // get the important directories
  mgString shaderDir;
  m_options.getFileName("shaderDir", m_options.m_sourceFileName, "docs/shaders", shaderDir);
  mgString uiDir;
  m_options.getFileName("uiDir", m_options.m_sourceFileName, "docs/ui", uiDir);
  mgString fontDir;
  m_options.getFileName("fontDir", m_options.m_sourceFileName, "docs/fonts", fontDir);

  mgInitDisplayServices(shaderDir, fontDir);

  mgDisplay->setDPI(m_options.getInteger("dpi", 0));
  mgDisplay->setFOV(m_options.getDouble("FOV", 60.0));

  mgString title;
  title.format("%s, %s", mgProgramName, mgProgramVersion);
  mgPlatform->setWindowTitle(title);

  // load the shaders we use
  mgVertex::loadShader("litTexture");
  mgVertexTA::loadShader("litTextureArray");

  // load cursor pattern
  loadCursor();
  setDeskMode(true);

  initMovement();
  m_lastAnimate = mgOSGetTime();  // now!

  // rotation angle for cube
  m_angle = 0.0;

  // load texture patterns
  loadTextures();

  // create vertex and index buffers
  m_cubeIndexes = NULL;
  m_cubeVertexes = NULL;
  m_floorVertexes = NULL;

  m_surface = mgDisplay->createOverlaySurface();

  mgString fileName;
  m_options.getFileName("helpFile", m_options.m_sourceFileName, "help.xml", fileName);
  m_ui = new SampleUI(m_surface, fileName);
}
Ejemplo n.º 3
0
//--------------------------------------------------------------
// initialize application
void Crafty::appInit()
{
  MovementApp::appInit();

  mgPlatform->setWindowTitle("Crafty, Part 58");

  // get lighting and material
  m_options.getPoint("matColor", mgPoint3(1,1,1), m_matColor);
  m_options.getPoint("sunlightColor", mgPoint3(0.8, 0.8, 0.8), m_sunlightColor);
  m_options.getPoint("moonlightColor", mgPoint3(0.1, 0.1, 0.1), m_moonlightColor);
  m_options.getPoint("torchlightColor", mgPoint3(0.5, 0.5, 0.5), m_torchlightColor);

  // since the view list goes up as the cube of distance, limit it
  int viewDistance = m_options.getInteger("viewDistance", 300);
  viewDistance = min(450, viewDistance);
  m_fogMaxDist = viewDistance;

  // create the sky
  m_lightDir = mgPoint3(0.0, 0.5, 1.0);
  m_sky = new StarrySky(m_options);
  m_sky->setMoonDir(m_lightDir);
  m_sky->setSunDir(m_lightDir);
  m_sky->setFogInten(1.0, 1.0);
  m_sky->setFogDist(1000.0, m_fogMaxDist);

  m_world = new ChunkWorld(m_options);
  m_world->setTorchColor(m_torchlightColor);
  m_world->setFogHeight(FOG_BOT_HEIGHT, FOG_TOP_HEIGHT);
  m_world->setFogInten(1.0, 1.0);
  m_world->setFogDist(m_fogMaxDist);

  setDaylight(true);
  setFoggy(true);

  m_eyePt =  mgPoint3(721, 72, -179);

  m_eyeRotX = -1.32; // -33;
  m_eyeRotY = -111.56; // -29;
  m_eyeRotZ = 0;

  setDeskMode(true);

  // create the help pane
  m_help = new HelpUI(m_options);
  setUI(m_help);
}
Ejemplo n.º 4
0
//--------------------------------------------------------------
// initialize application
void SeaOfMemes::appInit()
{
  // get the important directories
  mgString shaderDir;
  m_options.getFileName("shaderDir", m_options.m_sourceFileName, "docs/shaders", shaderDir);
  mgString uiDir;
  m_options.getFileName("uiDir", m_options.m_sourceFileName, "docs/ui", uiDir);
  mgString fontDir;
  m_options.getFileName("fontDir", m_options.m_sourceFileName, "docs/fonts", fontDir);

  mgInitDisplayServices(shaderDir, fontDir);

  mgDisplay->setDPI(m_options.getInteger("dpi", 0));
  mgDisplay->setFOV(m_options.getDouble("FOV", 60.0));

  // load cursors
  loadCursor();

  setDeskMode(true);

  // take units from option
  m_unitsMetric = m_options.getBoolean("metricUnits", true);

  // create the sky
  m_matColor = mgPoint3(1, 1, 1);
  m_lightDir = mgPoint3(1.0, 0.25, 0.0);
  m_lightDir.normalize();

  m_sky = new NebulaSky(m_options);
  m_sky->setSunDir(m_lightDir);

  m_world = new SolarSystem(m_options);

  m_helpUI = new HelpUI(m_options);
  m_helpUI->setDebugApp(this);

  m_speedUI = new SpeedUI(m_options);
  m_speedUI->setUnits(m_unitsMetric ? UNITS_KM : UNITS_MILES);

  appCreateBuffers();

  // initialize movement
  initMovement();
  m_lastAnimate = 0.0;
}
Ejemplo n.º 5
0
//--------------------------------------------------------------
// initialize application
void MovementApp::appInit()
{
  // get the important directories
  mgString shaderDir;
  m_options.getFileName("shaderDir", m_options.m_sourceFileName, "docs/shaders", shaderDir);
  mgString uiDir;
  m_options.getFileName("uiDir", m_options.m_sourceFileName, "docs/ui", uiDir);
  mgString fontDir;
  m_options.getFileName("fontDir", m_options.m_sourceFileName, "docs/fonts", fontDir);

  mgInitDisplayServices(shaderDir, fontDir);

  mgDisplay->setDPI(m_options.getInteger("dpi", 0));
  mgDisplay->setFOV(m_options.getDouble("FOV", 60.0));

  // load cursor pattern
  loadCursor();
  setDeskMode(true);

  initMovement();
  m_lastAnimate = mgOSGetTime();  // now!
}
Ejemplo n.º 6
0
//-----------------------------------------------------------------------------
// key press
void DontHitMe::appKeyDown(
  int keyCode,
  int modifiers)
{
  switch (keyCode)
  {
    case MG_EVENT_KEY_ESCAPE: 
      setDeskMode(!m_deskMode);
      break;

    case MG_EVENT_KEY_F1:
//      showHelp();
      break;

    case MG_EVENT_KEY_F5:
      mgDebug("break");
      break;

    case 'F':
      m_flying = !m_flying;
      m_eyeChanged = true;
      break;

    case 'W':
    case MG_EVENT_KEY_UP:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
        if (m_forwardSince == INVALID_TIME)
          m_forwardSince = mgOSGetTime();
      break;

    case 'S':
    case MG_EVENT_KEY_DOWN:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_backwardSince == INVALID_TIME)
        m_backwardSince = mgOSGetTime();
      break;

    case 'A':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_leftSince == INVALID_TIME)
        m_leftSince = mgOSGetTime();
      break;

    case 'D':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_rightSince == INVALID_TIME)
        m_rightSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEUP:
    case ' ':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_upSince == INVALID_TIME)
        m_upSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEDN:
    case 'X':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_downSince == INVALID_TIME)
        m_downSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_LEFT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnLeftSince == INVALID_TIME)
        m_turnLeftSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_RIGHT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnRightSince == INVALID_TIME)
        m_turnRightSince = mgOSGetTime();
      break;
  }
}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------
// key press
void GuiTestAll::appKeyDown(
  int keyCode,
  int modifiers)
{
  if (m_ui != NULL && m_ui->hasKeyFocus())
  {
    m_ui->m_top->surfaceKeyDown(keyCode, modifiers);
    return;
  }

  switch (keyCode)
  {
    case MG_EVENT_KEY_F1:
      m_ui->toggleHelp();
      break;

    case MG_EVENT_KEY_F2:
      m_ui->toggleConsole();
      break;

    case MG_EVENT_KEY_ESCAPE: 
      setDeskMode(!m_deskMode);
      break;

    case 'W':
    case MG_EVENT_KEY_UP:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
        if (m_forwardSince == INVALID_TIME)
          m_forwardSince = mgOSGetTime();
      break;

    case 'S':
    case MG_EVENT_KEY_DOWN:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_backwardSince == INVALID_TIME)
        m_backwardSince = mgOSGetTime();
      break;

    case 'A':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_leftSince == INVALID_TIME)
        m_leftSince = mgOSGetTime();
      break;

    case 'D':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_rightSince == INVALID_TIME)
        m_rightSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEUP:
    case ' ':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_upSince == INVALID_TIME)
        m_upSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEDN:
    case 'X':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_downSince == INVALID_TIME)
        m_downSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_LEFT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnLeftSince == INVALID_TIME)
        m_turnLeftSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_RIGHT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnRightSince == INVALID_TIME)
        m_turnRightSince = mgOSGetTime();
      break;
  }
}
Ejemplo n.º 8
0
//-----------------------------------------------------------------------------
// key press
void SeaOfMemes::appKeyDown(
  int keyCode,
  int modifiers)
{
  switch (keyCode)
  {
    case MG_EVENT_KEY_ESCAPE: 
      setDeskMode(!m_deskMode);
      break;

    case MG_EVENT_KEY_F1:
      if (m_helpUI != NULL)
        m_helpUI->toggleHelp();
      break;

    case MG_EVENT_KEY_F6:
    {
      mgDebug("debug");
      break;
    }

    case 'W':
    case MG_EVENT_KEY_UP:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
        if (m_forwardSince == INVALID_TIME)
          m_forwardSince = mgOSGetTime();
      break;

    case 'S':
    case MG_EVENT_KEY_DOWN:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_backwardSince == INVALID_TIME)
        m_backwardSince = mgOSGetTime();
      break;

    case 'A':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_leftSince == INVALID_TIME)
        m_leftSince = mgOSGetTime();
      break;

    case 'D':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_rightSince == INVALID_TIME)
        m_rightSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEUP:
    case ' ':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_upSince == INVALID_TIME)
        m_upSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEDN:
    case 'X':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_downSince == INVALID_TIME)
        m_downSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_LEFT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnLeftSince == INVALID_TIME)
        m_turnLeftSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_RIGHT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnRightSince == INVALID_TIME)
        m_turnRightSince = mgOSGetTime();
      break;

    case 'L':
      setLandingMode(!m_landingMode);
      break;

    case 'K':
      setUnits(!m_unitsMetric);
      break;

    case '=': 
    case '+':
    {
      m_avatarSpeed = m_avatarSpeed * 2.0;
      m_avatarSpeed = min(MAX_AVATAR_SPEED, m_avatarSpeed);
      if (m_speedUI != NULL)
        m_speedUI->setSpeed(m_avatarSpeed);
/*
      if (m_landingMode)
        m_avatarSpeed = min(MAX_LAND_SPEED, m_avatarSpeed);
      else m_avatarSpeed = min(MAX_SPACE_SPEED, m_avatarSpeed);
      showSpeed();
*/
      break;
    }
      
    case '-':
    {
      m_avatarSpeed = m_avatarSpeed / 2.0;
      m_avatarSpeed = max(MIN_AVATAR_SPEED, m_avatarSpeed);
      if (m_speedUI != NULL)
        m_speedUI->setSpeed(m_avatarSpeed);
/*
      if (m_landingMode)
        m_avatarSpeed = max(MIN_LAND_SPEED, m_avatarSpeed);
      else m_avatarSpeed = max(MIN_SPACE_SPEED, m_avatarSpeed);
      showSpeed();
*/
      break;
    }
  }
}
Ejemplo n.º 9
0
//-----------------------------------------------------------------------------
// key press
void SeaOfMemes::appKeyDown(
  int keyCode,
  int modifiers)
{
  switch (keyCode)
  {
    case MG_EVENT_KEY_F1:
      if (m_helpUI != NULL)
        m_helpUI->toggleHelp();
      break;

    case MG_EVENT_KEY_F2:
      if (m_helpUI != NULL)
        m_helpUI->toggleConsole();
      break;

    case MG_EVENT_KEY_F6:
    {
      mgDebug("debug");
      break;
    }
  }

  // if UI open, give it keys
  if (m_helpUI != NULL && m_helpUI->hasKeyFocus())
  {
    m_helpUI->getTop()->surfaceKeyDown(keyCode, modifiers);
    return;
  }

  switch (keyCode)
  {
    case MG_EVENT_KEY_ESCAPE: 
      setDeskMode(!m_deskMode);
      break;

    case 'W':
    case MG_EVENT_KEY_UP:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
        if (m_forwardSince == INVALID_TIME)
          m_forwardSince = mgOSGetTime();
      break;

    case 'S':
    case MG_EVENT_KEY_DOWN:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_backwardSince == INVALID_TIME)
        m_backwardSince = mgOSGetTime();
      break;

    case 'A':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_leftSince == INVALID_TIME)
        m_leftSince = mgOSGetTime();
      break;

    case 'D':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_rightSince == INVALID_TIME)
        m_rightSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEUP:
    case ' ':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_upSince == INVALID_TIME)
        m_upSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEDN:
    case 'X':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_downSince == INVALID_TIME)
        m_downSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_LEFT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnLeftSince == INVALID_TIME)
        m_turnLeftSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_RIGHT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnRightSince == INVALID_TIME)
        m_turnRightSince = mgOSGetTime();
      break;
  }
}