void YesNoObjectSoft::startFaceingToCam(ofxCamera* cam, ofxVec3f offset) { ofxVec3f faceCentroid = yesORno->getFaceCentroid(incomingSMSFaceID); ofxVec3f _objCentroid = yesORno->getBodyCentroid(); if (isnan(_objCentroid.x) || isnan(_objCentroid.y) || isnan(_objCentroid.z)) { _objCentroid = preservedObjCentroid; } ofxVec3f camPos = cam->getPosition()-offset; ofxVec3f center = _objCentroid; ofxVec3f tar = camPos; ofxVec3f normal = tar - center; normal.normalize(); ofxVec3f forward = _objCentroid - faceCentroid; forward.normalize(); ofxVec3f axis = normal.crossed(forward); axis.normalize(); float angle = normal.angle(forward); quatTween.setParameters(quatEasing, ofxTween::easeIn, 0.0, 1.0, 950, 0); ofAddListener(quatTween.end_E, this, &YesNoObjectSoft::addSMSCompleted); from = ofxQuaternion(prevFacingAxis.x, prevFacingAxis.y, prevFacingAxis.z, ofDegToRad(prevFaceAngle)); to = ofxQuaternion(axis.x, axis.y, axis.z, ofDegToRad(angle)); prevFaceAngle = angle; prevFacingAxis = axis; ofNotifyEvent(notifyStartCamOrbit, YesOrNo); }
void Particle::update() { ofxQuaternion force, bforce, mforce, dforce; // normalization is just for visualization forceCentroid /= forceCount; // find the spherical centroid bforce.makeRotate(getVectorPosition(), forceCentroid); bforce.slerp(relativeRadius, ofxQuaternion(), bforce); // reduces add-glitches force *= bforce; float curDirection = meanderDirection + ofSignedNoise(noiseOffset + meanderJitter * baseJitter * age) * PI * meanderRange; mforce.makeRotate( 0, xunit, sinf(curDirection) * meanderForce, yunit, cosf(curDirection) * meanderForce, zunit); force *= mforce; dforce.slerp(-velocityDamping, ofxQuaternion(), velocity); force *= dforce; velocity *= force; // mass = 1 velocity /= velocity.length(); // keep velocity stable float velocityMagnitude = acosf(xunit.dot(velocity * xunit)); if(velocityMagnitude > velocityMax) velocity.slerp(velocityMax / velocityMagnitude, ofxQuaternion(), velocity); float faceAngle = ofSignedNoise(noiseOffset + angleJitter * baseJitter * age) * PI * angleRange; setAngle(faceAngle); // apply velocity to position position *= velocity; position /= position.length(); // keep position stable if(animateFaces) { face.next(); // kill faces before they loop if(face.curImage > (face.dirSize - deathTime)) kill(); } age++; }
//-------------------------------------------------------------- void flockApp::keyPressed(int key) { switch (key) { case OF_KEY_ESC: exit(); break; case OF_KEY_UP: wrld_rot = wrld_rot * ofxQuaternion(ofDegToRad(5.0), ofxVec3f(1.0, 0.0, 0.0)); break; case OF_KEY_DOWN: wrld_rot = wrld_rot * ofxQuaternion(ofDegToRad(-5.0), ofxVec3f(1.0, 0.0, 0.0)); break; case OF_KEY_LEFT: wrld_rot = wrld_rot * ofxQuaternion(ofDegToRad(5.0), ofxVec3f(0.0, 1.0, 0.0)); break; case OF_KEY_RIGHT: wrld_rot = wrld_rot * ofxQuaternion(ofDegToRad(-5.0), ofxVec3f(0.0, 1.0, 0.0)); break; } }
//-------------------------------------------------------------- void flockApp::update() { for (int i = 0; i < MAX_FLOCKS; i++) { Flocks[i]->Update(); } if(inMouseDrag) { ofxVec3f screenVec(mouseX-mouseDownX,mouseY-mouseDownY,0.0); screenVec.limit(ofGetHeight()/2); float angle = (10.0 / 60.0) * screenVec.length() / (ofGetHeight()/2); screenVec.normalize(); screenVec.set(screenVec.y,screenVec.x,0.0); wrld_rot = wrld_rot * ofxQuaternion(ofDegToRad(angle), screenVec); } }
/// Set the elements of the Quat to represent a rotation of angle /// (radians) around the axis (x,y,z) void ofxQuaternion::makeRotate( float angle, float x, float y, float z ) { const float epsilon = 0.0000001f; float length = sqrtf( x * x + y * y + z * z ); if (length < epsilon) { // ~zero length axis, so reset rotation to zero. *this = ofxQuaternion(); return; } float inversenorm = 1.0f / length; float coshalfangle = cosf( 0.5f * angle ); float sinhalfangle = sinf( 0.5f * angle ); _v[0] = x * sinhalfangle * inversenorm; _v[1] = y * sinhalfangle * inversenorm; _v[2] = z * sinhalfangle * inversenorm; _v[3] = coshalfangle; }
void ofxQuaternionExtra::rotate(ofxAxisAngle aa) { (*this) *= ofxQuaternion(aa.angle,aa.axis); }
//-------------------------------------------------------------- void testApp::setup(){ ofSetDataPathRoot("../Resources/"); ofDisableArbTex(); ofEnableAlphaBlending(); ofEnableSmoothing(); ofBackground(255, 255, 255); cam.setup(this, 700); // defaultShader.setup("default"); // showDepthShader.setup("showdepth"); ssaoShader.setup("ssao"); dofShader.setup("dof"); depthFBO.setup(ofGetWidth(), ofGetHeight()); colorFBO.setup(ofGetWidth(), ofGetHeight()); ssaoFBO.setup(ofGetWidth(), ofGetHeight()); ofxSetSphereResolution(100); numObj = 200; for (int i = 0; i < numObj; i++) { float x = ofRandom(ofGetWidth()/2-200, ofGetWidth()/2+200); float y = ofRandom(ofGetHeight()/2-200, ofGetHeight()/2+200); float z = ofRandom(-100, 500); ofxVec3f pos = ofxVec3f(x,y,z); float r = ofRandom(0.0, 255.0); float g = ofRandom(0.0, 255.0); float b = ofRandom(0.0, 255.0); float a = ofRandom(200.0, 255.0); ofxVec4f col = ofxVec4f(r,g,b,a); int size = ofRandom(10, 50); ofxQuaternion qua = ofxQuaternion(ofRandomf(), ofRandomf(), ofRandomf(), ofRandomf()); int typ = ofRandom(1, 3); objPos.push_back(pos); objRot.push_back(qua); objCol.push_back(col); objSize.push_back(size); objType.push_back(typ); } //.setNewColumn(true); gui.addTitle("SSAO Setting"); gui.addSlider("camerarangex", camerarangex, 0, 10000); gui.addSlider("camerarangey", camerarangey, 0, 10000); gui.addSlider("aoCap", aoCap, 0.0, 2.0); gui.addSlider("aoMultiplier", aoMultiplier, 0.0, 20000.0); gui.addSlider("depthTolerance", depthTolerance, 0.000, 0.002); gui.addSlider("aorange", aorange, 0.0, 2.0); gui.addSlider("readDepthVal", readDepthVal, 0.0, 20.0); gui.addTitle("DOF Setting").setNewColumn(true); gui.addSlider("focus", focus, 0.0, 2.0); gui.addSlider("aspectratiox", aspectratiox, 0.0, ofGetWidth()); gui.addSlider("aspectratioy", aspectratioy, 0.0, ofGetHeight()); gui.addSlider("blurclamp", blurclamp, 0.0, 1.0); gui.addSlider("bias", bias, 0.0, 1.0); gui.loadFromXML(); gui.show(); camerarangex = 6113.28; camerarangey = 4121.09; aoCap = 1.8795; aoMultiplier = 1523.5625; depthTolerance = 0.0001130; aorange = 0.285156; readDepthVal = 2.0; focus = 0.808594; aspectratiox = ofGetWidth(); aspectratioy = ofGetHeight(); blurclamp = 0.0253910; bias = 0.041016; }