コード例 #1
0
ファイル: NewAxis.cpp プロジェクト: dos5gw/TMeter
void CNewAxis::SetScale(double m,double M)
{
	maxRange=M;
	minRange=m;
	nSteps=0;
	ScaleAxis();
}
コード例 #2
0
ファイル: NBodyWnd.cpp プロジェクト: adhage/Galaxy-Renderer
//------------------------------------------------------------------------------
void NBodyWnd::OnProcessEvents(uint8_t type)
{
    switch (type)
    {
    case SDL_MOUSEBUTTONDOWN:
        break;

    case SDL_KEYDOWN:
        switch (m_event.key.keysym.sym)
        {
        case SDLK_1:
            m_camOrient = 0;
            break;

        case SDLK_2:
            m_camOrient = 1;
            break;

        case SDLK_3:
            m_camOrient = 2;
            break;

        case SDLK_q:
            m_galaxy.SetExInner(m_galaxy.GetExInner() + 0.05);
            break;

        case SDLK_a:
            m_galaxy.SetExInner(std::max(m_galaxy.GetExInner() - 0.05, 0.0));
            break;

        case SDLK_w:
            m_galaxy.SetExOuter(m_galaxy.GetExOuter() + 0.05);
            break;

        case SDLK_s:
            m_galaxy.SetExOuter(std::max(m_galaxy.GetExOuter() - 0.05, 0.0));
            break;

        case SDLK_e:
            m_galaxy.SetAngularOffset(m_galaxy.GetAngularOffset()+0.0001);
            break;

        case SDLK_d:
            m_galaxy.SetAngularOffset(m_galaxy.GetAngularOffset()-0.0001);
            break;

        case SDLK_r:
            if (m_galaxy.GetRad()>m_galaxy.GetCoreRad()+500)
            {
                m_galaxy.SetCoreRad(m_galaxy.GetCoreRad()+500);
            }
            std::cout << "Bulge radius " << m_galaxy.GetCoreRad() << "\n";
            break;

        case SDLK_f:
            m_galaxy.SetCoreRad(std::max(m_galaxy.GetCoreRad()-500, 0.0));
            std::cout << "Bulge radius " << m_galaxy.GetCoreRad() << "\n";
            break;

        case SDLK_t:
            m_galaxy.SetRad(m_galaxy.GetRad()+1000);
            break;

        case SDLK_g:
            m_galaxy.SetRad(std::max(m_galaxy.GetRad()-1000, 0.0));
            break;

        case SDLK_z:
        case SDLK_y:
            m_galaxy.SetSigma(m_galaxy.GetSigma()+0.05);
            break;

        case SDLK_h:
            m_galaxy.SetSigma(std::max(m_galaxy.GetSigma()-0.05, 0.05));
            break;

        case  SDLK_F1:
            std::cout << "Display:  help screen" << ((m_flags & dspHELP) ? "off" : "on") << "\n";
            m_flags ^= dspHELP;
            m_flags &= ~dspSTAT;
            break;

        case  SDLK_F2:
            std::cout << "Display:  statistic" << ((m_flags & dspSTAT) ? "off" : "on") << "\n";
            m_flags ^= dspSTAT;
            m_flags &= ~dspHELP;
            break;

        case  SDLK_F3:
            std::cout << "Display:  Toggling stars " << ((m_flags & dspSTARS) ? "off" : "on") << "\n";
            if (m_starRenderType==2)
            {
                m_starRenderType=0;
                m_flags &= ~dspSTARS;
            }
            else
            {
                m_starRenderType++;
                m_flags |= dspSTARS;
            }
            break;

        case  SDLK_F4:
            std::cout << "Display:  Toggling dust " << ((m_flags & dspDUST) ? "off" : "on") << "\n";
            m_flags ^= dspDUST;
            break;

        case  SDLK_F5:
            std::cout << "Display:  Toggling h2 regions " << ((m_flags & dspH2) ? "off" : "on") << "\n";
            m_flags ^= dspH2;
            break;

        case SDLK_F6:
            std::cout << "Display:  Density waves axis " << ((m_flags & dspDENSITY_WAVES) ? "off" : "on") << "\n";
            m_flags ^= dspDENSITY_WAVES;
            break;

        case SDLK_F7:
            std::cout << "Display:  Axis" << ((m_flags & dspAXIS) ? "off" : "on") << "\n";
            m_flags ^= dspAXIS;
            break;

        case SDLK_F8:
            std::cout << "Display:  Radii" << ((m_flags & dspRADII) ? "off" : "on") << "\n";
            m_flags ^= dspRADII;
            break;

        case  SDLK_p:
            std::cout << "Display:  Toggling Velocity graph " << ((m_flags & dspVELOCITY) ? "off" : "on") << "\n";
            m_flags ^= dspVELOCITY;
            break;

        case  SDLK_PAUSE:
            std::cout << "Simulation:  pause " << ((m_flags & dspPAUSE) ? "off" : "on") << "\n";
            m_flags ^= dspPAUSE;
            break;


//          case SDLK_p:
//               SaveToTGA();
//               break;

        case SDLK_KP1:
            m_galaxy.Reset(12000,    // radius of the galaxy
                           4000,     // radius of the core
                           0.0004,   // angluar offset of the density wave per parsec of radius
                           0.75,      // excentricity at the edge of the core
                           0.9,      // excentricity at the edge of the disk
                           0.5,
                           200,      // orbital velocity at the edge of the core
                           300,      // orbital velovity at the edge of the disk
                           30000);   // total number of stars
            break;

        case SDLK_KP2:
            m_galaxy.Reset(13000,    // radius of the galaxy
                           4000,     // radius of the core
                           0.0004,   // angluar offset of the density wave per parsec of radius
                           0.9,      // excentricity at the edge of the core
                           0.9,      // excentricity at the edge of the disk
                           0.5,
                           200,      // orbital velocity at the edge of the core
                           300,      // orbital velovity at the edge of the disk
                           30000);   // total number of stars
            break;
        case SDLK_KP3:
            m_galaxy.Reset(13000,    // radius of the galaxy
                           4000,     // radius of the core
                           0.0004,   // angluar offset of the density wave per parsec of radius
                           1.35,      // excentricity at the edge of the core
                           1.05,      // excentricity at the edge of the disk
                           0.5,
                           200,      // orbital velocity at the edge of the core
                           300,      // orbital velovity at the edge of the disk
                           40000);   // total number of stars
            break;

        // Typ Sa
        case SDLK_KP4:
            m_galaxy.Reset(20000,    // radius of the galaxy
                           4000,     // radius of the core
                           0.0004,   // angluar offset of the density wave per parsec of radius
                           0.75,      // excentricity at the edge of the core
                           1.0,      // excentricity at the edge of the disk
                           0.5,
                           200,      // orbital velocity at the edge of the core
                           300,      // orbital velovity at the edge of the disk
                           40000);   // total number of stars
            break;

        // Typ SBb
        case SDLK_KP5:
            m_galaxy.Reset(15000,    // radius of the galaxy
                           4000,     // radius of the core
                           0.0003,   // angluar offset of the density wave per parsec of radius
                           1.45,     // excentricity at the edge of the core
                           1.0,      // excentricity at the edge of the disk
                           0.5,
                           400,      // orbital velocity at the edge of the core
                           420,      // orbital velovity at the edge of the disk
                           40000);   // total number of stars
            break;

        // zum debuggen
        case SDLK_KP6:
            m_galaxy.Reset(15000,    // radius of the galaxy
                           4000,     // radius of the core
                           0.0003,   // angluar offset of the density wave per parsec of radius
                           1.45,     // excentricity at the edge of the core
                           1.0,      // excentricity at the edge of the disk
                           0.5,
                           400,      // orbital velocity at the edge of the core
                           200,      // orbital velovity at the edge of the disk
                           40000);   // total number of stars
            break;

        // für Wikipedia: realistische Rotationskurve
        case SDLK_KP7:
            m_galaxy.Reset(12000,    // radius of the galaxy
                           2000,     // radius of the core
                           0.0004,   // angluar offset of the density wave per parsec of radius
                           0.75,      // excentricity at the edge of the core
                           0.9,      // excentricity at the edge of the disk
                           0.5,
                           400,      // orbital velocity at the edge of the core
                           420,      // orbital velovity at the edge of the disk
                           30000);   // total number of stars
            break;


        case SDLK_KP8:
            m_galaxy.Reset(12000,    // radius of the galaxy
                           2000,     // radius of the core
                           0.0004,   // angluar offset of the density wave per parsec of radius
                           0.75,      // excentricity at the edge of the core
                           0.9,      // excentricity at the edge of the disk
                           0.5,
                           400,      // orbital velocity at the edge of the core
                           150,      // orbital velovity at the edge of the disk
                           30000);   // total number of stars
            break;


        case SDLK_KP0:
            m_galaxy.Reset(15000,    // radius of the galaxy
                           4000,     // radius of the core
                           0.000306, // angluar offset of the density wave per parsec of radius
                           0.8,      // excentricity at the edge of the core
                           0.85,     // excentricity at the edge of the disk
                           0.5,
                           200,      // orbital velocity at the edge of the core
                           220,      // orbital velovity at the edge of the disk
                           40000);   // total number of stars
            break;

        case SDLK_F12:
            m_bDumpImage ^= true;
            m_idxSnapshot = 0;
            std::cout << "Image dumping is " << ((m_bDumpImage) ? "enabled" : "disabled") << std::endl;
            break;

        case SDLK_PLUS:
        case SDLK_KP_PLUS:
            ScaleAxis(0.9);
            SetCameraOrientation(Vec3D(0,1,0));
            break;


        case SDLK_MINUS:
        case SDLK_KP_MINUS:
            ScaleAxis(1.1);
            SetCameraOrientation(Vec3D(0,1,0));
            break;

        default:
            break;

        }

        break;
    }
}
コード例 #3
0
ファイル: WindowsGamepad.cpp プロジェクト: LordJZ/gecko-dev
bool
WindowsGamepadService::HandleRawInput(HRAWINPUT handle)
{
  if (!mHID) {
    return false;
  }

  // First, get data from the handle
  UINT size;
  GetRawInputData(handle, RID_INPUT, nullptr, &size, sizeof(RAWINPUTHEADER));
  nsTArray<uint8_t> data(size);
  data.SetLength(size);
  if (GetRawInputData(handle, RID_INPUT, data.Elements(), &size,
                      sizeof(RAWINPUTHEADER)) == kRawInputError) {
    return false;
  }
  PRAWINPUT raw = reinterpret_cast<PRAWINPUT>(data.Elements());

  Gamepad* gamepad = nullptr;
  for (unsigned i = 0; i < mGamepads.Length(); i++) {
    if (mGamepads[i].type == kRawInputGamepad
        && mGamepads[i].handle == raw->header.hDevice) {
      gamepad = &mGamepads[i];
      break;
    }
  }
  if (gamepad == nullptr) {
    return false;
  }

  // Second, get the preparsed data
  nsTArray<uint8_t> parsedbytes;
  if (!GetPreparsedData(raw->header.hDevice, parsedbytes)) {
    return false;
  }
  PHIDP_PREPARSED_DATA parsed =
    reinterpret_cast<PHIDP_PREPARSED_DATA>(parsedbytes.Elements());

  // Get all the pressed buttons.
  nsTArray<USAGE> usages(gamepad->numButtons);
  usages.SetLength(gamepad->numButtons);
  ULONG usageLength = gamepad->numButtons;
  if (mHID.mHidP_GetUsages(HidP_Input, kButtonUsagePage, 0, usages.Elements(),
                     &usageLength, parsed, (PCHAR)raw->data.hid.bRawData,
                     raw->data.hid.dwSizeHid) != HIDP_STATUS_SUCCESS) {
    return false;
  }

  bool buttons[kMaxButtons] = { false };
  usageLength = std::min<ULONG>(usageLength, kMaxButtons);
  for (unsigned i = 0; i < usageLength; i++) {
    buttons[usages[i] - 1] = true;
  }

  if (gamepad->hasDpad) {
    // Get d-pad position as 4 buttons.
    ULONG value;
    if (mHID.mHidP_GetUsageValue(HidP_Input, gamepad->dpadCaps.UsagePage, 0, gamepad->dpadCaps.Range.UsageMin, &value, parsed, (PCHAR)raw->data.hid.bRawData, raw->data.hid.dwSizeHid) == HIDP_STATUS_SUCCESS) {
      UnpackDpad(static_cast<LONG>(value), gamepad, buttons);
    }
  }

  for (unsigned i = 0; i < gamepad->numButtons; i++) {
    if (gamepad->buttons[i] != buttons[i]) {
      NewButtonEvent(gamepad->id, i, buttons[i]);
      gamepad->buttons[i] = buttons[i];
    }
  }

  // Get all axis values.
  for (unsigned i = 0; i < gamepad->numAxes; i++) {
    double new_value;
    if (gamepad->axes[i].caps.LogicalMin < 0) {
LONG value;
      if (mHID.mHidP_GetScaledUsageValue(HidP_Input, gamepad->axes[i].caps.UsagePage,
                                   0, gamepad->axes[i].caps.Range.UsageMin,
                                   &value, parsed,
                                   (PCHAR)raw->data.hid.bRawData,
                                   raw->data.hid.dwSizeHid)
          != HIDP_STATUS_SUCCESS) {
        continue;
      }
      new_value = ScaleAxis(value, gamepad->axes[i].caps.LogicalMin,
                            gamepad->axes[i].caps.LogicalMax);
    }
    else {
      ULONG value;
      if (mHID.mHidP_GetUsageValue(HidP_Input, gamepad->axes[i].caps.UsagePage, 0,
                             gamepad->axes[i].caps.Range.UsageMin, &value,
                             parsed, (PCHAR)raw->data.hid.bRawData,
                             raw->data.hid.dwSizeHid) != HIDP_STATUS_SUCCESS) {
        continue;
      }

      new_value = ScaleAxis(value, gamepad->axes[i].caps.LogicalMin,
                            gamepad->axes[i].caps.LogicalMax);
    }
    if (gamepad->axes[i].value != new_value) {
      NewAxisMoveEvent(gamepad->id, i, new_value);
      gamepad->axes[i].value = new_value;
    }
  }

  return true;
}