本文整理汇总了C++中Gamepad类的典型用法代码示例。如果您正苦于以下问题:C++ Gamepad类的具体用法?C++ Gamepad怎么用?C++ Gamepad使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gamepad类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lua_Gamepad_getTriggerValue
int lua_Gamepad_getTriggerValue(lua_State* state)
{
// Get the number of parameters.
int paramCount = lua_gettop(state);
// Attempt to match the parameters to a valid binding.
switch (paramCount)
{
case 2:
{
if ((lua_type(state, 1) == LUA_TUSERDATA) &&
lua_type(state, 2) == LUA_TNUMBER)
{
// Get parameter 1 off the stack.
unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
Gamepad* instance = getInstance(state);
float result = instance->getTriggerValue(param1);
// Push the return value onto the stack.
lua_pushnumber(state, result);
return 1;
}
lua_pushstring(state, "lua_Gamepad_getTriggerValue - Failed to match the given parameters to a valid function signature.");
lua_error(state);
break;
}
default:
{
lua_pushstring(state, "Invalid number of parameters (expected 2).");
lua_error(state);
break;
}
}
return 0;
}
示例2: lua_Gamepad_isButtonDown
int lua_Gamepad_isButtonDown(lua_State* state)
{
// Get the number of parameters.
int paramCount = lua_gettop(state);
// Attempt to match the parameters to a valid binding.
switch (paramCount)
{
case 2:
{
if ((lua_type(state, 1) == LUA_TUSERDATA) &&
(lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL))
{
// Get parameter 1 off the stack.
Gamepad::ButtonMapping param1 = (Gamepad::ButtonMapping)lua_enumFromString_GamepadButtonMapping(luaL_checkstring(state, 2));
Gamepad* instance = getInstance(state);
bool result = instance->isButtonDown(param1);
// Push the return value onto the stack.
lua_pushboolean(state, result);
return 1;
}
lua_pushstring(state, "lua_Gamepad_isButtonDown - Failed to match the given parameters to a valid function signature.");
lua_error(state);
break;
}
default:
{
lua_pushstring(state, "Invalid number of parameters (expected 2).");
lua_error(state);
break;
}
}
return 0;
}
示例3: LinuxJoystickPoll
Gamepad LinuxJoystickPoll(const Gamepad &oldGamepad) {
Gamepad newGamepad = oldGamepad;
LinuxJoystickEvent lje;
Int bytesRead = 0;
do {
bytesRead = read(newGamepad.GetDeviceInfo().mHandle,
&lje, sizeof(LinuxJoystickEvent));
if (0 < bytesRead) {
switch (lje.mType & ~JS_EVENT_INIT) {
case JS_EVENT_AXIS: {
switch (lje.mNumber % 3) {
case 0:
newGamepad.SetStickXAxis(
lje.mNumber / 3, lje.mValue);
break;
case 1:
newGamepad.SetStickYAxis(
lje.mNumber / 3, lje.mValue);
break;
case 2:
newGamepad.SetStickOtherAxis(
lje.mNumber / 3, lje.mValue);
break;
default:
break;
}
break;
}
case JS_EVENT_BUTTON:
lje.mValue ? newGamepad.PressButton(lje.mNumber) :
newGamepad.ReleaseButton(lje.mNumber);
break;
default:
// TODO: Error
break;
}
}
} while (0 < bytesRead);
return newGamepad;
}
示例4: page
void NavigatorGamepad::pageVisibilityChanged()
{
// Inform the embedder whether it needs to provide gamepad data for us.
bool visible = page()->visibilityState() == PageVisibilityStateVisible;
if (visible && (m_hasEventListener || m_gamepads))
startUpdating();
else
stopUpdating();
if (!visible || !m_hasEventListener)
return;
// Tell the page what has changed. m_gamepads contains the state before we became hidden.
// We create a new snapshot and compare them.
GamepadList* oldGamepads = m_gamepads.release();
gamepads();
GamepadList* newGamepads = m_gamepads.get();
ASSERT(newGamepads);
for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) {
Gamepad* oldGamepad = oldGamepads ? oldGamepads->item(i) : 0;
Gamepad* newGamepad = newGamepads->item(i);
bool oldWasConnected = oldGamepad && oldGamepad->connected();
bool newIsConnected = newGamepad && newGamepad->connected();
bool connectedGamepadChanged = oldWasConnected && newIsConnected && oldGamepad->id() != newGamepad->id();
if (connectedGamepadChanged || (oldWasConnected && !newIsConnected)) {
oldGamepad->setConnected(false);
m_pendingEvents.append(oldGamepad);
}
if (connectedGamepadChanged || (!oldWasConnected && newIsConnected)) {
m_pendingEvents.append(newGamepad);
}
}
if (!m_pendingEvents.isEmpty())
m_dispatchOneEventRunner.runAsync();
}
示例5: handle_button_states_stub
void VRPN_CALLBACK Gamepad::handle_button_states_stub(void* userData, const vrpn_BUTTONSTATESCB b)
{
Gamepad *gamepad = static_cast<Gamepad*>(userData);
gamepad->handle_button_states(NULL, b);
}
示例6: printf
/**
* Periodic code for teleop mode should go here.
*
* Use this method for code which will be called periodically at a regular
* rate while the robot is in teleop mode.
*/
void RobotDemo::TeleopPeriodic()
{
drive->TeleopDrive(driverPad->GetLeftY() *DRIVER_LEFT_DIRECTION, driverPad->GetRightY() *DRIVER_RIGHT_DIRECTION);
shooter->handle();
shooter->debug();
//shooter->setShooterPower(operatorPad->GetRightY());
if((intakeMode == IN_INTAKE_MANUAL_MODE) && operatorPad->GetNumberedButton(INTAKE_AUTO_MODE_BUTTON))
{
intakeMode = IN_INTAKE_AUTO_MODE;
printf ("set into auto roller mode");
intake->setExtenderMode(IN_INTAKE_AUTO_MODE);
}
//sets intake mode to auto if previously in manual and operator presses auto button
else if((intakeMode == IN_INTAKE_AUTO_MODE) && operatorPad->GetNumberedButton(INTAKE_MANUAL_MODE_BUTTON))
{
intakeMode = IN_INTAKE_MANUAL_MODE;
printf ("set into manual roller mode");
intake->setExtenderMode(IN_INTAKE_MANUAL_MODE);
}
intake->handle();
if(intakeMode == IN_INTAKE_MANUAL_MODE)
{
intake->move(operatorPad->GetLeftY()*OPERATOR_LEFT_DIRECTION);
}
else
{
//Extender DPad control
curPadDir = operatorPad->GetDPad();
if(lastPadDir != curPadDir)
{
switch(curPadDir)
{
case Gamepad::kUp:
intake->setExtenderTarget(FULL_EXTEND_DISTANCE);
break;
case Gamepad::kDown:
intake->setExtenderTarget(FULL_RETRACT_DISTANCE);
break;
default:
break;
}
}
lastPadDir = curPadDir;
}
//intake->spinRoller(operatorPad->GetRightY()*OPERATOR_RIGHT_DIRECTION);
intake->getCurrentPosition();
//if operator taps in button roller continually spins inward
if(operatorPad->GetNumberedButton(ROLLER_IN_BUTTON))
{
intakeCont = INTAKE_ROLLER_IN_STATE;
}
//if operator taps stop button roller stops continually
else if(operatorPad->GetNumberedButton(ROLLER_OFF_BUTTON))
{
intakeCont = INTAKE_ROLLER_STOP_STATE;
}
//if operator holds spit button roller spins backwards no matter what
if(operatorPad->GetNumberedButton(ROLLER_OUT_BUTTON))
{
intake->spinRoller(INTAKE_ROLLER_SPIT_POWER);
}
//not holding spit button
else
{
//roller either spins or is stopped depending on previous code
if(intakeCont)
{
intake->spinRoller(INTAKE_ROLLER_IN_POWER);
}
else
{
intake->spinRoller(INTAKE_ROLLER_STOP_POWER);
}
}
if(operatorPad->GetNumberedButton(RIGHT_TRIGGER_BUTTON)) // low shot = Right Trigger
{
shooter->initShot(SHOT_LOW_ANGLE, SHOT_LOW_SPEED);
printf("test button 1 is pressed");
}
else if(operatorPad->GetNumberedButton(LEFT_TRIGGER_BUTTON)) // pass = Left Trigger
{
//.........这里部分代码省略.........
示例7: SetLogicalInputs
void GamepadController::AdvanceFrame(WorldTime /*delta_time*/) {
went_down_ = went_up_ = 0;
Gamepad gamepad = input_system_->GetGamepad(controller_id_);
SetLogicalInputs(LogicalInputs_Up,
gamepad.GetButton(Gamepad::kUp).is_down());
SetLogicalInputs(LogicalInputs_Down,
gamepad.GetButton(Gamepad::kDown).is_down());
SetLogicalInputs(LogicalInputs_Left,
gamepad.GetButton(Gamepad::kLeft).is_down());
SetLogicalInputs(LogicalInputs_Right,
gamepad.GetButton(Gamepad::kRight).is_down());
SetLogicalInputs(LogicalInputs_ThrowPie,
gamepad.GetButton(Gamepad::kUp).is_down() ||
gamepad.GetButton(Gamepad::kButtonA).is_down());
SetLogicalInputs(LogicalInputs_Deflect,
gamepad.GetButton(Gamepad::kDown).is_down() ||
gamepad.GetButton(Gamepad::kButtonB).is_down());
SetLogicalInputs(LogicalInputs_Select,
gamepad.GetButton(Gamepad::kButtonA).is_down());
SetLogicalInputs(LogicalInputs_Cancel,
gamepad.GetButton(Gamepad::kButtonB).is_down());
}
示例8: TeleopPeriodic
void TeleopPeriodic() {
//Target * target = GetLatestTarget();
//Begin DRIVER input section
if(driverGamepad->GetDPad()==Gamepad::kUp)
lc->setMode(1);
else if(driverGamepad->GetDPad()==Gamepad::kDown)
lc->setMode(6);
else
lc->setMode(0);
if(driverGamepad->GetDPad() == Gamepad::kRight)
{
cameraLight->Set(Relay::kOff);
}
else if(driverGamepad->GetDPad() == Gamepad::kLeft)
{
cameraLight->Set(Relay::kOn);
}
if(driverGamepad->GetB())
{
cout << "Resetting the gyro! :D" << endl;
//driveGyro->Reset();
magicBox->resetGyro();
}
bool modifySpeed = driverGamepad->GetRightBumper();
bool halfSpeed = driverGamepad->GetLeftBumper();
/*
try {
std::string temp = SmartDashboard::GetString("TargetInfo");
cout << "temp: " << endl;
} catch (exception ex) {
cout << "bah! " << ex.what() << endl;
}*/
//Target t = GetLatestTarget();
/*
if (t.IsValid()) {
cout << "Valid target (" << (t.IsCenter() ? "center" : "side") << "):" << t.Distance() << " ft, " << t.X() << "," << t.Y() << endl;
} else {
//cout << "No valid target." << endl;
} */
if(driverGamepad->GetBack())
{
cout << "Now driving in relation to the robot" << endl;
myDrive->setGyroDrive(false);
}
if(driverGamepad->GetStart())
{
cout << "Now driving in relation to the field (gyro)" << endl;
myDrive->setGyroDrive(true);
}
// If the driver is holding the X button
/*
if (driverGamepad->GetX()) {
// Stop using the joysticks to drive the robot, and let this function do it
PointAtTarget(t);
} else { */
// We aren't auto-targeting. Reset the sequence.
target_state = RA13Robot::READY;
// Drive based on joysticks.
myDrive->Drive(driverGamepad->GetLeftX(), driverGamepad->GetLeftY(),
driverGamepad->GetRightX(), magicBox->getGyroAngle(), modifySpeed,halfSpeed);
//}
//End DRIVER input section
Gamepad::DPadDirection dir = operatorGamepad->GetDPad();
if (dir != lastdir) {
switch(dir) {
case Gamepad::kUp:
manualAngle += 1;
break;
case Gamepad::kDown:
manualAngle -= 1;
break;
case Gamepad::kRight:
manualAngle += 0.25;
break;
case Gamepad::kLeft:
manualAngle -= 0.25;
break;
default:
break;
}
}
//cout << "Current target angle: " << manualAngle << endl;
//Begin OPERATOR input section
if(operatorGamepad->GetBack())
{
myShooter->ResetShooterProcess(); // Re-homes the shooter
}
//.........这里部分代码省略.........
示例9: indexAttrGetter
static v8::Handle<v8::Value> indexAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
Gamepad* imp = V8Gamepad::toNative(info.Holder());
return v8UnsignedInteger(imp->index(), info.GetIsolate());
}
示例10: main
int main(int argc, char ** argv) {
std::cout << "Starting Controller Mouse Emulator" << std::endl;
float mouseSpeed = 15;
float scrollSpeed = 25;
MouseInput mouseInput;
Gamepad gamepad;
int dx, dy;
int sy;
while (true) {
gamepad.update();
dx = (int)(gamepad.getLThumbX() * mouseSpeed);
dy = (int)(-gamepad.getLThumbY() * mouseSpeed);
sy = (int)(gamepad.getRThumbY() * scrollSpeed);
mouseInput.moveMouse(dx, dy);
mouseInput.scrollWheel(sy);
if (gamepad.aPressed())
mouseInput.setLeftMouseDown(true);
else if (gamepad.aReleased())
mouseInput.setLeftMouseDown(false);
if (gamepad.bPressed())
mouseInput.setRightMouseDown(true);
else if (gamepad.bReleased())
mouseInput.setRightMouseDown(false);
if (gamepad.rsPressed())
mouseInput.setMiddleMouseDown(true);
else if (gamepad.rsReleased())
mouseInput.setMiddleMouseDown(false);
if (gamepad.rbPressed() && mouseSpeed < MAX_MOUSE_SPEED) {
mouseSpeed += SPEED_INCREMENT;
std::cout << "Mouse speed: " << mouseSpeed << std::endl;
}
if (gamepad.lbPressed() && mouseSpeed > SPEED_INCREMENT) {
mouseSpeed -= SPEED_INCREMENT;
std::cout << "Mouse speed: " << mouseSpeed << std::endl;
}
gamepad.updateInput();
Sleep(15);
}
return 0;
}
示例11: get_PICH
uint16_t get_PICH(Gamepad mando) {
uint16_t anglePICH;
float leftStic_Y = mando.LeftStick_Y();
anglePICH = mando.float_UINT16(leftStic_Y);
return anglePICH;
}
示例12: get_YAW
//Funciones para obtener YAW,PITCH y ROLL con valores UINT16
uint16_t get_YAW(Gamepad mando) {
uint16_t angleYaw;
float leftStic_X = mando.LeftStick_X();
angleYaw = mando.float_UINT16(leftStic_X);
return angleYaw;
}
示例13: StartOfCycleMaintenance
/**
* Periodic code for teleop mode should go here.
*
* Use this method for code which will be called periodically at a regular
* rate while the robot is in teleop mode.
*/
void RA14Robot::TeleopPeriodic() {
StartOfCycleMaintenance();
//Input Acquisition
DriverLeftY = DriverGamepad->GetLeftY();
DriverRightY = DriverGamepad->GetRightY();
DriverLeftBumper = DriverGamepad->GetLeftBumper(); // Reads state of left bumper
DriverRightBumper = DriverGamepad->GetRightBumper(); // Gets state of right bumper
RingLightButton = OperatorGamepad->GetY();
ShouldFireButton = DriverGamepad->GetRightTrigger();
BallCollectPickupButton = DriverGamepad->GetBack();
DriverDPad = DriverGamepad->GetDPad();
OperatorDPad = OperatorGamepad->GetDPad();
//End Input Acquisition
//Current Sensing
//myCurrentSensor->Toggle(DriverGamepad->GetStart());
//End Current Sensing
//Target Processing
target->Parse(server->GetLatestPacket());
/*
if (target->IsValid()) {
cout << "\tx = " << target->GetX() << ", y = " << target->GetY() << ", distance = " << target->GetDistance() << "ft";
cout << "\tside = " << (target->IsLeft() ? "LEFT" : "RIGHT") << ", hot = " << (target->IsHot() ? "HOT" : "NOT") << endl;
}
else {
cout << "No Target Received..." << endl;
}
*/
//End Target Processing
//Ball Collection
/*
if(BallCollectPickupButton)
{
myCollection->Collect();
}
else
{
myCollection->ResetPosition();
}
*/
float spinSpeed = Config::GetSetting("intake_roller_speed", 1);
int armPosition = 0;
int rollerPosition = 0;
switch (OperatorDPad) {
case Gamepad::kCenter:
armPosition = 0;
rollerPosition = 0;
break;
case Gamepad::kUp:
armPosition = -1;
break;
case Gamepad::kUpLeft:
armPosition = -1;
rollerPosition = -1;
break;
case Gamepad::kUpRight:
armPosition = -1;
rollerPosition = 1;
break;
case Gamepad::kDown:
armPosition = 1;
break;
case Gamepad::kDownLeft:
armPosition = 1;
rollerPosition = -1;
break;
case Gamepad::kDownRight:
armPosition = 1;
rollerPosition = 1;
break;
case Gamepad::kLeft:
rollerPosition = -1;
break;
case Gamepad::kRight:
rollerPosition = 1;
break;
}
if (DriverGamepad->GetLeftTrigger()) {
armPosition = 0;
rollerPosition = -1;
}
//.........这里部分代码省略.........
示例14: handle_analog_stub
void VRPN_CALLBACK Gamepad::handle_analog_stub(void* userData, const vrpn_ANALOGCB a)
{
Gamepad *gamepad = static_cast<Gamepad*>(userData);
gamepad->handle_analog(NULL, a);
}
示例15: LOGI
void SamplesGame::initialize()
{
LOGI(">SamplesGame::initialize ()");
LOGI(">SamplesGame::initialize FileSystem::getAssetPath() = '%s'", FileSystem::getAssetPath());
LOGI(">SamplesGame::initialize FileSystem::getResourcePath() = '%s'", FileSystem::getResourcePath());
Bundle* bundle = Bundle::create("res/ui/arial.gpb");
LOGI(">SamplesGame::initialize bundle=%p", bundle);
_font = bundle->loadFont(bundle->getObjectId(0));
LOGI(">SamplesGame::initialize _font=%p", _font);
_font = Font::create("res/ui/arial.gpb");
LOGI(">SamplesGame::initialize _font=%p", _font);
for (size_t i = 0; i < _categories->size(); ++i)
{
std::sort((*_samples)[i].begin(), (*_samples)[i].end());
}
// Load camera script
getScriptController()->loadScript("res/common/camera.lua");
// Create the selection form
_sampleSelectForm = Form::create("sampleSelect", NULL, Layout::LAYOUT_VERTICAL);
_sampleSelectForm->setWidth(220);
_sampleSelectForm->setHeight(1, true);
_sampleSelectForm->setScroll(Container::SCROLL_VERTICAL);
const size_t size = _samples->size();
LOGI(">SamplesGame::initialize _samples->size()=%d", size);
for (size_t i = 0; i < size; ++i)
{
Label* categoryLabel = Label::create((*_categories)[i].c_str());
categoryLabel->setFontSize(22);
categoryLabel->setText((*_categories)[i].c_str());
_sampleSelectForm->addControl(categoryLabel);
categoryLabel->release();
SampleRecordList list = (*_samples)[i];
const size_t listSize = list.size();
for (size_t j = 0; j < listSize; ++j)
{
SampleRecord sampleRecord = list[j];
Button* sampleButton = Button::create(sampleRecord.title.c_str());
sampleButton->setText(sampleRecord.title.c_str());
sampleButton->setWidth(1, true);
sampleButton->setHeight(50);
sampleButton->addListener(this, Control::Listener::CLICK);
_sampleSelectForm->addControl(sampleButton);
sampleButton->release();
}
}
_sampleSelectForm->setFocus();
// Disable virtual gamepads.
unsigned int gamepadCount = getGamepadCount();
for (unsigned int i = 0; i < gamepadCount; i++)
{
Gamepad* gamepad = getGamepad(i, false);
if (gamepad->isVirtual())
{
gamepad->getForm()->setEnabled(false);
}
}
/*
for (size_t i = 0; i < size; ++i)
{
SampleRecordList list = (*_samples)[i];
const size_t listSize = list.size();
for (size_t j = 0; j < listSize; ++j)
{
SampleRecord sampleRecord = list[j];
// TODO if (sampleRecord.title.compare(control->getId()) == 0)
{
_sampleSelectForm->setEnabled(false);
runSample(sampleRecord.funcPtr);
LOGI("<SamplesGame::initialize _activeSample=%lx", (long )_activeSample);
return;
}
}
}
*/
LOGI("<SamplesGame::initialize _activeSample=%lx", (long )_activeSample);
}