void TouchDial::mouseMoveEvent(QMouseEvent *event) { if(m_readOnly) return; const int w = width(); const int h = height(); const int d = qMin(w, h); const int r = d / 2; const int xoff = (w - d) / 2; const int yoff = (h - d) / 2; QPointF localPos = event->localPos(); double x = (localPos.x() - xoff - r); double y = (localPos.y() - yoff - r); double angle = atan(y / x); if(x < 0.0) angle += M_PI; else if(y < 0.0) angle += 2 * M_PI; else angle -= M_PI / 4; double value = angleToValue(angle) * (m_maximumValue - m_minimumValue) + m_minimumValue; // Correct dead zone if(angle < (3.0 * M_PI) / 4.0 && angle > M_PI / 2.0 && value > 0.5) value = m_minimumValue; setValue(value); update(); }
/* * Set Angle for Joint * In: Joint, angle in dgr * Returns angle that has been set */ float setAngle(Joint joint, float angle) { //Variables u32 value, realValue; float realAngle; //Convert angle to value value = angleToValue(joint, angle); // Set Value realValue = setValue(joint, value); //Compute Real angle realAngle = valToAngle(joint, realValue); //Return return realAngle; }
/* * Move to Absolute Angle */ float moveToAbsAngle(Joint joint, float dgr) { //Variables u32 val, realVal; float angle; //Get final steps val = angleToValue(joint, dgr); //Move realVal = moveTo(joint, val); //Get Current Angle angle = valToAngle(joint, realVal); //Return return angle; }