void DaisyWheelTool::frame(void) { if(active) { /* Update the selection ray: */ selectionRay=calcInteractionRay(); /* Calculate the intersection point of selection ray and daisy wheel: */ Ray wheelRay=selectionRay; wheelRay.inverseTransform(wheelTransform); if(wheelRay.getDirection()[1]!=Scalar(0)) { Scalar lambda=(Scalar(0)-wheelRay.getOrigin()[1])/wheelRay.getDirection()[1]; if(lambda>=Scalar(0)) { Point wheelPoint=wheelRay(lambda); /* Calculate the zoom angle and zoom strength: */ zoomStrength=(Geometry::mag(wheelPoint)-factory->innerRadius)*Scalar(0.5)/(factory->outerRadius-factory->innerRadius); if(zoomStrength<Scalar(0)) zoomStrength=Scalar(0); else if(zoomStrength>Scalar(0.75)) zoomStrength=Scalar(0.75); if(zoomStrength>Scalar(0)) { zoomAngle=Math::atan2(wheelPoint[0],wheelPoint[2]); if(zoomAngle<Scalar(0)) zoomAngle=Scalar(2)*Math::Constants<Scalar>::pi+zoomAngle; } } } } }
void PlaneSnapInputDeviceTool::buttonCallback(int,InputDevice::ButtonCallbackData* cbData) { if(cbData->newButtonState) // Button has just been pressed { /* Try activating the tool: */ if(interactionDevice->isRayDevice()) { /* Pick a virtual input device using ray selection: */ activate(calcInteractionRay()); } else { /* Pick a virtual input device using point selection: */ activate(getInteractionPosition()); } /* Check if the tool was activated: */ if(isActive()) { /* Check if there are currently three selected points: */ if(numSelectedPoints==3) { /* Snap the selected virtual input device to the plane defined by the three selected points: */ Vector y=Geometry::cross(selectedPoints[1]-selectedPoints[0],selectedPoints[2]-selectedPoints[0]); Scalar offset=(selectedPoints[0]*y+selectedPoints[1]*y+selectedPoints[2]*y)/Scalar(3); Vector x=Geometry::normal(y); Point devicePos=getInverseNavigationTransformation().transform(getGrabbedDevice()->getPosition()); Scalar lambda=(offset-devicePos*y)/Geometry::sqr(y); devicePos+=y*lambda; NavTransform dt=NavTransform(devicePos-Point::origin,NavTransform::Rotation::fromBaseVectors(x,y),Scalar(1)); dt.leftMultiply(getNavigationTransformation()); getGrabbedDevice()->setTransformation(TrackerState(dt.getTranslation(),dt.getRotation())); } /* Deactivate the tool again: */ deactivate(); } else { /* Start dragging another selection point: */ if(numSelectedPoints==3) numSelectedPoints=0; draggingPoint=true; ++numSelectedPoints; } } else // Button has just been released { /* Stop dragging a selection point: */ draggingPoint=false; } }
void RayInputDeviceTool::frame(void) { if(isActive()) { /* Update the interaction ray: */ interactionRay=calcInteractionRay(); /* Drag the box dragger: */ dragger.drag(interactionRay); /* Set the grabbed device's position and orientation: */ getGrabbedDevice()->setTransformation(dragger.getCurrentTransformation()); } }