/** * Returns a normalised Quaternion with the Joystick movements. */ MTQuaternion getQuaternion(MTVec3D jawAxis, MTVec3D turnAxis, double minJawAngle, double maxJawAngle, double factor) { short a,b; /* Right now, we are only interested in these two axes. If you want to use more * than these two, just add some short variables and read the axis-values accordingly. Easy. */ if (!( getAxisValue(0, &a) && getAxisValue(1, &b) )) { printf("ERROR reading an axis value!\n"); MTQuaternion q; return q; } double angle = posToAngle(b, factor); angle = (angle > 0.0 && angle < minJawAngle) ? 0.0 : angle; angle = (angle < 0.0 && angle > maxJawAngle) ? 0.0 : angle; MTQuaternion qB = mtCreateQuaternion(jawAxis, angle); MTQuaternion qA = mtCreateQuaternion(turnAxis, -posToAngle(a, factor)); MTQuaternion qRes = mtAddQuaternionQuaternion(&qA, &qB); mtNormQuaternion(&qRes); return qRes; }
short getTranslationAxisValue(int axis) { if (axis <= 5) { short v; if (!getAxisValue(axis, &v)) { printf("ERROR reading a translation axis value!\n"); return 0; } return v; } printf("ERROR wrong axis value\n"); return 0; }
void ofxGamepad::draw(int x, int y) { int curX=0; int highestY; ofPushMatrix(); ofTranslate(x, y); ofSetColor(255); ofPushMatrix(); ofRotate(90); ofDrawBitmapString(name+" ("+ofToString(id)+")", 0, 0); ofPopMatrix(); curX=17; int margin=3; ofRectangle axisSize(curX,0,85, 17); for(int i=0; i<getNumAxis(); i++) { ofSetColor(70); ofRect(axisSize); ofSetColor(255); float x = ofMap(getAxisValue(i), -1, 1, axisSize.x, axisSize.width+axisSize.x); ofLine(x, axisSize.y, x, axisSize.y+axisSize.height); ofSetColor(20); ofDrawBitmapString(ofToString(i), axisSize.x, axisSize.y+axisSize.height-1); axisSize.y+=axisSize.height+margin; if(axisSize.y>highestY) highestY=axisSize.y; } curX+=axisSize.width+margin; ofRectangle btnSize(curX,0,17,17); for(int i=0; i<getNumButtons(); i++) { if(getButtonValue(i)) ofSetColor(255); else ofSetColor(70); ofRect(btnSize); btnSize.y+=btnSize.height+margin; ofSetColor(20); ofDrawBitmapString(ofToString(i), btnSize.x, btnSize.y-4); if(btnSize.y>highestY) highestY=axisSize.y; } curX+=btnSize.width; ofPopMatrix(); drawSize.x=curX; drawSize.y=highestY; }
void getJoyStickState(unsigned int index, SimJoyStick::State& state, const AxisMaps& maps) { if (index >= kMaxControllers) { state.is_initialized = false; return; } if (controllers_[index] == nullptr) { controllers_[index].reset(new DirectInputJoyStick()); if (!controllers_[index]->initialize(index)) { state.is_initialized = false; state.message = controllers_[index]->getState(false).message; return; } state.is_initialized = true; } const DirectInputJoyStick::JoystickState& di_state = controllers_[index]->getState(); const DirectInputJoyStick::JoystickInfo& joystick_info = controllers_[index]->getJoystickInfo(); state.is_valid = di_state.is_valid; state.left_x = getAxisValue(AxisMap::AxisType::LeftX, maps.left_x, di_state, joystick_info.pid_vid); state.left_y = getAxisValue(AxisMap::AxisType::LeftY, maps.left_y, di_state, joystick_info.pid_vid); state.right_x = getAxisValue(AxisMap::AxisType::RightX, maps.right_x, di_state, joystick_info.pid_vid); state.right_y = getAxisValue(AxisMap::AxisType::RightY, maps.right_y, di_state, joystick_info.pid_vid); state.right_z = getAxisValue(AxisMap::AxisType::RightZ, maps.right_z, di_state, joystick_info.pid_vid); state.left_z = getAxisValue(AxisMap::AxisType::LeftZ, maps.left_z, di_state, joystick_info.pid_vid); state.slider0 = di_state.slider0; state.slider1 = di_state.slider1; state.pov0 = di_state.pov0; state.pov1 = di_state.pov1; state.pov2 = di_state.pov2; state.pov3 = di_state.pov3; state.pid_vid = joystick_info.pid_vid; state.buttons = 0; for (int i = 0; i < sizeof(int)*8; ++i) { state.buttons |= ((di_state.buttons[i] & 0x80) == 0 ? 0 : 1) << i; } }