//---------------------------------------- void ofEasyCam::mousePressed(ofMouseEventArgs & mouse){ ofRectangle area = getControlArea(); if(area.inside(mouse.x, mouse.y)){ lastMouse = mouse; prevMouse = mouse; prevAxisX = getXAxis(); prevAxisY = getYAxis(); prevAxisZ = getZAxis(); prevPosition = ofCamera::getGlobalPosition(); prevOrientation = ofCamera::getGlobalOrientation(); if((bEnableMouseMiddleButton && mouse.button == OF_MOUSE_BUTTON_MIDDLE) || events->getKeyPressed(doTranslationKey) || mouse.button == OF_MOUSE_BUTTON_RIGHT){ bDoTranslate = true; bDoRotate = false; }else if(mouse.button == OF_MOUSE_BUTTON_LEFT){ bDoTranslate = false; bDoRotate = true; if(glm::length(glm::vec2(mouse.x - area.x - (area.width/2), mouse.y - area.y - (area.height/2))) < std::min(area.width/2, area.height/2)){ bInsideArcball = true; }else{ bInsideArcball = false; } } bApplyInertia = false; } }
void ofEasyCam::mousePressed(ofMouseEventArgs & mouse){ ofRectangle viewport = getViewport(this->viewport); if(viewport.inside(mouse.x, mouse.y)){ lastMouse = mouse; prevMouse = mouse; prevAxisX = getXAxis(); prevAxisY = getYAxis(); prevAxisZ = getZAxis(); prevPosition = ofCamera::getGlobalPosition(); prevOrientation = ofCamera::getGlobalOrientation(); if ((bEnableMouseMiddleButton && mouse.button == OF_MOUSE_BUTTON_MIDDLE) || events->getKeyPressed(doTranslationKey) || mouse.button == OF_MOUSE_BUTTON_RIGHT){ bDoTranslate = true; bDoRotate = false; }else if (mouse.button == OF_MOUSE_BUTTON_LEFT) { bDoTranslate = false; bDoRotate = true; if(ofVec2f(mouse.x - viewport.x - (viewport.width/2), mouse.y - viewport.y - (viewport.height/2)).length() < min(viewport.width/2, viewport.height/2)){ bInsideArcball = true; }else { bInsideArcball = false; } } bApplyInertia = false; } }
void ofEasyFingerCam::updateRotation() { rotationX += (targetXRot - rotationX) *.1; rotationY += (targetYRot - rotationY) *.1; rotationZ += (targetZRot - rotationZ) *.1; target.setOrientation(ofQuaternion(0,0,0,1)); //reset ofQuaternion p = ((getOrientationQuat() * ofQuaternion(-rotationY, getXAxis())) * ofQuaternion(-rotationX, getYAxis())) * ofQuaternion(-rotationZ, getZAxis()); target.setOrientation(p); }
//------------------------------------------------ void TravelingCam::update(ofEventArgs& a) { unsigned long long t = ofGetElapsedTimeMillis(); if (bTweening) { currentSpeed = tween.update(); } else if (pathLength < currentDistance + slowdownDist) { currentSpeed = ofMap(currentDistance, pathLength - slowdownDist, pathLength, 0, speed); } else { currentSpeed = speed; } unsigned long long dt = t - lastUpdateTime; currentDistance += currentSpeed * dt; ofPoint p = path.getPointAtLength(currentDistance); float inc = 10; if (pathLength < currentDistance + inc ) { inc = pathLength - currentDistance; } ofPoint p0 = path.getPointAtLength(currentDistance + inc); p.y *= heightMult; p0.y *= heightMult; //lookAt( p + (p - p0).normalize()); setPosition( p); dirVec = p + (p0 - p).normalize(); lookAt(dirVec, ofVec3f(0,1,0)); boom(altura); if(bMousePressed || bXenoRunning) { ofVec2f c (ofGetWidth()/2, ofGetHeight()/2); ofVec2f mouseNorm = mousePos - c; xenoPos = xenoPos + (mouseNorm- xenoPos)*xenoFactor; if ((mouseNorm - xenoPos).length() < 1) { xenoPos = mouseNorm; bXenoRunning = false; } // mouseNorm.x /= c.x; // mouseNorm.y /= c.y; rotate(ofMap(xenoPos.x, -c.x, c.x, 90, -90), getYAxis()); rotate(ofMap(xenoPos.y, -c.y, c.y, 60, -60), getXAxis()); } lastUpdateTime = t; }
//---------------------------------------- void ofEasyCam::updateTranslation(){ if (bApplyInertia) { moveX *= drag; moveY *= drag; moveZ *= drag; if (ABS(moveX) <= minDifference && ABS(moveY) <= minDifference && ABS(moveZ) <= minDifference) { bApplyInertia = false; bDoTranslate = false; } } move((getXAxis() * moveX) + (getYAxis() * moveY) + (getZAxis() * moveZ)); }
//---------------------------------------- void ofEasyCam::updateTranslation(){ if (bApplyInertia) { moveX *= drag; moveY *= drag; moveZ *= drag; if (ABS(moveX) <= minDifference && ABS(moveY) <= minDifference && ABS(moveZ) <= minDifference) { bApplyInertia = false; bDoTranslate = false; } move((getXAxis() * moveX) + (getYAxis() * moveY) + (getZAxis() * moveZ)); }else{ setPosition(prevPosition + ofVec3f(prevAxisX * moveX) + (prevAxisY * moveY) + (prevAxisZ * moveZ)); } }
//---------------------------------------- void ofLight::onOrientationChanged() { if(data->glIndex==-1) return; if(getIsDirectional()) { // if we are a directional light and not positional, update light position (direction) auto lookAtDir = glm::normalize(getGlobalOrientation() * glm::vec4(0,0,-1, 1)).xyz(); data->position = {lookAtDir.x,lookAtDir.y,lookAtDir.z,0.f}; ofGetGLRenderer()->setLightPosition(data->glIndex,data->position); }else if(getIsSpotlight() || getIsAreaLight()) { // determines the axis of the cone light auto lookAtDir = glm::normalize(getGlobalOrientation() * glm::vec4(0,0,-1, 1)).xyz(); data->direction = lookAtDir; ofGetGLRenderer()->setLightSpotDirection(data->glIndex, glm::vec4(data->direction, 0.0f)); } if(getIsAreaLight()){ data->up = getUpDir(); data->right = getXAxis(); } }
//---------------------------------------- void ofEasyCam::updateRotation(){ if (bApplyInertia) { xRot *=drag; yRot *=drag; zRot *=drag; if (ABS(xRot) <= minDifference && ABS(yRot) <= minDifference && ABS(zRot) <= minDifference) { bApplyInertia = false; bDoRotate = false; } curRot = ofQuaternion(xRot, getXAxis(), yRot, getYAxis(), zRot, getZAxis()); setPosition((getGlobalPosition()-target.getGlobalPosition())*curRot +target.getGlobalPosition()); rotate(curRot); }else{ curRot = ofQuaternion(xRot, prevAxisX, yRot, prevAxisY, zRot, prevAxisZ); setPosition((prevPosition-target.getGlobalPosition())*curRot +target.getGlobalPosition()); setOrientation(prevOrientation * curRot); } }
//---------------------------------------- void ofLight::onOrientationChanged() { if(data->glIndex==-1) return; // if we are a directional light and not positional, update light position (direction) if(getIsDirectional()) { // (tig) takes into account global orientation should node be parented. ofVec3f lookAtDir = ( getGlobalTransformMatrix().getInverse() * ofVec4f(0,0,-1, 1) ).getNormalized(); data->position = ofVec4f(lookAtDir.x,lookAtDir.y,lookAtDir.z,0); ofGetGLRenderer()->setLightPosition(data->glIndex,data->position); }else if(getIsSpotlight() || getIsAreaLight()) { // determines the axis of the cone light // // (tig) takes into account global orientation should node be parented. ofVec3f lookAtDir = ( getGlobalTransformMatrix().getInverse() * ofVec4f(0,0,-1, 1) ).getNormalized(); data->direction = ofVec3f(lookAtDir.x,lookAtDir.y,lookAtDir.z); ofGetGLRenderer()->setLightSpotDirection(data->glIndex,data->direction); } if(getIsAreaLight()){ data->up = getUpDir(); data->right = getXAxis(); } }
//---------------------------------------- void ofEasyCam::updateTranslation(){ if(bApplyInertia){ moveX *= drag; moveY *= drag; moveZ *= drag; if(ABS(moveZ) >= minDifference){ bIsBeingScrolled = true; } else { bIsBeingScrolled = false; } if(ABS(moveX) <= minDifference && ABS(moveY) <= minDifference && ABS(moveZ) <= minDifference){ bApplyInertia = false; bDoTranslate = false; } move((getXAxis() * moveX) + (getYAxis() * moveY) + (getZAxis() * moveZ)); }else if(bDoTranslate || bIsBeingScrolled){ setPosition(prevPosition + glm::vec3(prevAxisX * moveX) + (prevAxisY * moveY) + (prevAxisZ * moveZ)); bIsBeingScrolled = false; } }
int main(void) { wdt_enable(WDTO_1S); //odDebugInit(); //DBG1(0x00, 0, 0); /* debug output: main starts */ mouseInit(); usbInit(); usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ uchar i = 0; while(--i){ /* fake USB disconnect for > 250 ms */ wdt_reset(); _delay_ms(1); } usbDeviceConnect(); sei(); //DBG1(0x01, 0, 0); /* debug output: main loop starts */ for(;;){ /* main event loop */ //DBG1(0x02, 0, 0); /* debug output: main loop iterates */ wdt_reset(); usbPoll(); reportBuffer[0]=getXAxis(); reportBuffer[1]=getYAxis(); reportBuffer[2]=getZAxis(); if(usbInterruptIsReady()){ // called after every poll of the interrupt endpoint //DBG1(0x03, 0, 0); // debug output: interrupt report prepared usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer)); } } }
void ofxGameCamera::updateRotation(){ if(!applyRotation) return; // cout << "update rotation!" << endl; if(dampen){ rotationX += (targetXRot - rotationX) *.2; rotationY += (targetYRot - rotationY) *.2; rotationZ += (targetZRot - rotationZ) *.2; } else{ rotationX = targetXRot; rotationY = targetYRot; rotationZ = targetZRot; } setOrientation(ofQuaternion(0,0,0,1)); //reset setOrientation(getOrientationQuat() * ofQuaternion(-rotationZ, getZAxis())); setOrientation(getOrientationQuat() * ofQuaternion(-rotationX, getYAxis())); setOrientation(getOrientationQuat() * ofQuaternion(-rotationY, getXAxis())); targetNode.setOrientation(getOrientationQuat()); }
//---------------------------------------- void ofEasyCamExt::update(ofEventArgs & args) { if( isDoingMove ) { float tmpFraction = ofMap( ofGetElapsedTimef(), moveStartEndTimeParameters.getMin(), moveStartEndTimeParameters.getMax(), 0.0f, 1.0f ); if( tmpFraction >= 1.0f ) { isDoingMove = false; } tmpFraction = ofClamp( tmpFraction, 0.0f, 1.0f ); tmpFraction = EasingEquations::ease( tmpFraction, easeType ); ofVec3f newPos = positionEaseParameters.getMin().interpolate( positionEaseParameters.getMax(), tmpFraction ); //ofVec3f newLookAtDir = lookAtEaseParameters.getMin().interpolate( lookAtEaseParameters.getMax(), tmpFraction ); ofQuaternion newOrientation; newOrientation.slerp( tmpFraction, orientationEaseStart, orientationEaseEnd ); //resetTransform(); setPosition(newPos); //target.resetTransform(); //target.setPosition(newLookAtDir); //lookAt(target, getUpDir() ); setOrientation( newOrientation ); moveX = 0; moveY = 0; moveZ = 0; } else { if(!bDistanceSet && bAutoDistance) { setDistance(getImagePlaneDistance(viewport), true); } if(bMouseInputEnabled) { rotationFactor = sensitivityRot * 180 / min(viewport.width, viewport.height); if (bMouseInputEnabled) { updateMouse(); } if (bDoRotate) { updateRotation(); } else if (bDoTranslate) { updateTranslation(); } } if( dollyForwardKey != 0 ) { if( ofGetKeyPressed(dollyForwardKey) ) { dollyImpulse( -dollyImpulseAmount ); } } if( dollyBackwardKey != 0 ) { if( ofGetKeyPressed(dollyBackwardKey) ) { dollyImpulse( dollyImpulseAmount ); } } // if (bApplyInertia) { moveX *= drag; moveY *= drag; moveZ *= drag; if (ABS(moveX) <= minDifference && ABS(moveY) <= minDifference && ABS(moveZ) <= minDifference) { //bApplyInertia = false; bDoTranslate = false; } // } move((getXAxis() * moveX) + (getYAxis() * moveY) + (getZAxis() * moveZ)); } }
//---------------------------------------- void ofEasyCamExt::updateTranslation() { move((getXAxis() * moveX) + (getYAxis() * moveY) + (getZAxis() * moveZ)); }
//---------------------------------------- glm::vec3 ofNode::getSideDir() const { return getXAxis(); }
//---------------------------------------- void ofNode::tiltRad(float radians) { rotateRad(radians, getXAxis()); }
//---------------------------------------- void ofNode::tiltDeg(float degrees) { rotateDeg(degrees, getXAxis()); }
//---------------------------------------- void ofNode::truck(float amount) { move(getXAxis() * amount); }
//---------------------------------------- ofVec3f ofNode::getSideDir() const { return getXAxis(); }
/** Execute the algorithm. */ void ConjoinXRuns::exec() { const std::vector<std::string> inputs_given = getProperty(INPUT_WORKSPACE_PROPERTY); m_logEntry = getPropertyValue(SAMPLE_LOG_X_AXIS_PROPERTY); const std::string sampleLogsSum = getProperty(SampleLogsBehaviour::SUM_PROP); const std::string sampleLogsTimeSeries = getProperty(SampleLogsBehaviour::TIME_SERIES_PROP); const std::string sampleLogsList = getProperty(SampleLogsBehaviour::LIST_PROP); const std::string sampleLogsWarn = getProperty(SampleLogsBehaviour::WARN_PROP); const std::string sampleLogsWarnTolerances = getProperty(SampleLogsBehaviour::WARN_TOL_PROP); const std::string sampleLogsFail = getProperty(SampleLogsBehaviour::FAIL_PROP); const std::string sampleLogsFailTolerances = getProperty(SampleLogsBehaviour::FAIL_TOL_PROP); const std::string sampleLogsFailBehaviour = getProperty("FailBehaviour"); m_inputWS.clear(); for (const auto &input : RunCombinationHelper::unWrapGroups(inputs_given)) { MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(input); m_inputWS.push_back(ws); } auto first = m_inputWS.front(); SampleLogsBehaviour sampleLogsBehaviour = SampleLogsBehaviour( *first, g_log, sampleLogsSum, sampleLogsTimeSeries, sampleLogsList, sampleLogsWarn, sampleLogsWarnTolerances, sampleLogsFail, sampleLogsFailTolerances); auto it = m_inputWS.begin(); // Temporary workspace to carry the merged sample logs // This is cloned from the first workspace and does not have // the correct size to be the output, since the size is unknown // at this point. We can check only later which ones are going // to be skipped, to compute the size of the output respectively. MatrixWorkspace_uptr temp = first->clone(); size_t outBlockSize = (*it)->blocksize(); // First sequentially merge the sample logs for (++it; it != m_inputWS.end(); ++it) { // attempt to merge the sample logs try { sampleLogsBehaviour.mergeSampleLogs(**it, *temp); sampleLogsBehaviour.setUpdatedSampleLogs(*temp); outBlockSize += (*it)->blocksize(); } catch (std::invalid_argument &e) { if (sampleLogsFailBehaviour == SKIP_BEHAVIOUR) { g_log.error() << "Could not join workspace: " << (*it)->getName() << ". Reason: \"" << e.what() << "\". Skipping.\n"; sampleLogsBehaviour.resetSampleLogs(*temp); // remove the skipped one from the list m_inputWS.erase(it); --it; } else { throw std::invalid_argument(e); } } } if (m_inputWS.size() == 1) { g_log.warning() << "Nothing left to join [after skipping the workspaces " "that failed to merge the sample logs]."; // note, we need to continue still, since // the x-axis might need to be changed } if (!m_logEntry.empty()) { for (const auto &ws : m_inputWS) { m_axisCache[ws->getName()] = getXAxis(ws); } } // now get the size of the output size_t numSpec = first->getNumberHistograms(); m_outWS = WorkspaceFactory::Instance().create(first, numSpec, outBlockSize, outBlockSize); // copy over the merged sample logs from the temp m_outWS->mutableRun() = temp->run(); m_progress = make_unique<Progress>(this, 0.0, 1.0, numSpec); // Now loop in parallel over all the spectra and join the data PARALLEL_FOR_IF(threadSafe(*m_outWS)) for (int64_t index = 0; index < static_cast<int64_t>(numSpec); ++index) { PARALLEL_START_INTERUPT_REGION joinSpectrum(index); m_progress->report(); PARALLEL_END_INTERUPT_REGION } PARALLEL_CHECK_INTERUPT_REGION if (!m_logEntry.empty()) { std::string unit = first->run().getLogData(m_logEntry)->units(); try { m_outWS->getAxis(0)->unit() = UnitFactory::Instance().create(unit); } catch (Exception::NotFoundError &) { m_outWS->getAxis(0)->unit() = UnitFactory::Instance().create("Empty"); } } setProperty("OutputWorkspace", m_outWS); m_inputWS.clear(); m_axisCache.clear(); }
//---------------------------------------- void ofEasyCam::updateRotation(){ if(bApplyInertia){ xRot *=drag; yRot *=drag; zRot *=drag; if(ABS(xRot) <= minDifference && ABS(yRot) <= minDifference && ABS(zRot) <= minDifference){ xRot = 0; yRot = 0; zRot = 0; bApplyInertia = false; bDoRotate = false; } curRot = glm::angleAxis(zRot, getZAxis()) * glm::angleAxis(yRot, up()) * glm::angleAxis(xRot, getXAxis()); setPosition(curRot * (getGlobalPosition()-target.getGlobalPosition()) + target.getGlobalPosition()); rotate(curRot); }else if(bDoRotate){ curRot = glm::angleAxis(zRot, prevAxisZ) * glm::angleAxis(yRot, up()) * glm::angleAxis(xRot, prevAxisX); setPosition(curRot * (prevPosition-target.getGlobalPosition()) + target.getGlobalPosition()); setOrientation(curRot * prevOrientation); } }