void wyVirtualJoystick::adjustRockerPosition(float x, float y) { // to node space wyPoint p = wyp(x, y); p = worldToNodeSpace(p); wyPoint center = wyp(m_width / 2, m_height / 2); // check position, if in rocker radius, just set it // if not, connect position to center and pick the intersect point float distance = wypDistance(p, center); if(distance > m_rockerRangeRadius) { float ratio = m_rockerRangeRadius / distance; float rX = p.x - m_width / 2; float rY = p.y - m_height / 2; p.x = m_width / 2 + rX * ratio; p.y = m_height / 2 + rY * ratio; } // save position m_rockerX = p.x; m_rockerY = p.y; // set rocker position if(m_rocker) { m_rocker->setPosition(p.x, p.y); } // change degree m_degree = wypToDegree(wypSub(p, center)); if(m_degree < 0) m_degree += 360; }
bool wySlider::touchesCancelled(wyMotionEvent& e) { if(m_dragging) { m_dragging = false; setValueFromLocation(worldToNodeSpace(wyp(e.x[0], e.y[0]))); } return true; }
bool wySlider::touchesBegan(wyMotionEvent& e) { // thumb clicked? if(m_thumb) { m_dragging = m_thumb->hitTest(e.x[0], e.y[0]); } // if not dragging, means it clicks other parts if(!m_dragging) { setValueFromLocation(worldToNodeSpace(wyp(e.x[0], e.y[0]))); } return true; }
wyPoint wyNode::worldToNodeSpaceAR(wyPoint p) { p = worldToNodeSpace(p); return wypSub(p, wyp(m_anchorPointX, m_anchorPointY)); }