void BasicScreenObject::_update(ofEventArgs &e){ if(!isupdating) return; if(age == 1) firstUpdate(); // TODO: use Animation elements equal to Positioners Animator.h // Update Animations based on Tweening if (isMoveTweening) setPosition(tweenx, tweeny, tweenz); if (isScaleTweening) setScale(tweenscalex, tweenscaley, tweenscalez); if (isColorTweening) setColor(tweenr,tweeng,tweenb); if (isSizeTweening) setSize(tweenWidth, tweenHeight); if (isRotationTweening) { ofQuaternion nowquat=getOrientationQuat(); nowquat.slerp(tweenrotslerp, startquat, endquat); setOrientation(nowquat); } // Animations based on Forces and Attractionpoints doRotate(); doMove(); if(isorderbyz) doOrderChildrenByZ(); update(); if(positioners.size()>0){ for(positioner = positioners.begin(); positioner != positioners.end(); positioner++) { IPositioner* p = positioner->second; p->restrict(this); } } age++; }
void WaypointCamera::setOriginTarget(){ originTarNode.resetTransform(); originTarNode.setPosition(getPosition()); pan(-180); // Fix for camera orientation originTarNode.setOrientation(getOrientationQuat()); pan(180); // Fix for camera orientation }
ofVec3f BasicScreenObject::getOrientationAxisAngles() { ofVec3f result; ofQuaternion q = getOrientationQuat(); double x = q.x(); double y = q.y(); double z = q.z(); double w = q.w(); double sqw = w * w; double sqx = x * x; double sqy = y * y; double sqz = z * z; double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor double test = x * y + z * w; if (test > 0.499 * unit) { // singularity at north pole result.y = 2 * atan2(x, w); result.z = PI / 2; result.x = 0; } else if (test < -0.499 * unit) { // singularity at south pole result.y = -2 * atan2(x, w); result.z = -PI / 2; result.x = 0; } else { result.y = atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); result.z = asin(2 * test / unit); result.x = atan2(2 * x * w - 2 * y * z, -sqx + sqy - sqz + sqw); } return result; }
Transform * const Transform::lookAt(glm::vec3 _pos, glm::vec3 _up, float _interpolation){ Transform t; t.parents.push_back(this); glm::mat4 m = glm::lookAt(_pos, t.getWorldPos(), _up); glm::quat q(glm::transpose(m)); setOrientation(glm::slerp(getOrientationQuat(), q, _interpolation)); return this; }
void BasicScreenObject::doRotate(){ rotationspeed *= rotationdrag; if (rotationspeed.length() > 0) { addRotation(rotationspeed.x, rotationspeed.y, rotationspeed.z); } if(rotationattractionforce > 0){ ofQuaternion betweenquat = rotationattractionquat-getOrientationQuat(); float betweenangle; ofVec3f dirvec(1,0,0); betweenquat.getRotate(betweenangle, dirvec); ofQuaternion nowquat = getOrientationQuat(); nowquat.slerp(rotationattractionforce, nowquat, rotationattractionquat); setOrientation(nowquat); } }
void BasicScreenObject::rotateTo(ofQuaternion _quat, float _slerptime, float (ofxTransitions::*ease) (float,float,float,float), float delay) { rotationspeed.set(0,0,0); stopRotationAttraction(); tweenrotslerp = 0.0; endquat = _quat; startquat = getOrientationQuat(); Tweener.addTween(tweenrotslerp, 1.0, _slerptime/1000.0, ease, delay/1000.0); isRotationTweening = true; }
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 BoneNode::update() { if (parent) { // update orientation const ofQuaternion& parentOrientation = parent->getDerivedOrientationQuat(); if (mInheritOrientation) { // Combine orientation with that of parent //mDerivedOrientation = parentOrientation * getOrientationQuat(); mDerivedOrientation = getOrientationQuat() * parentOrientation; } else { mDerivedOrientation = getOrientationQuat(); } // update scale const ofVec3f& parentScale = parent->getDerivedScale(); if (mInheritScale) { mDerivedScale = parentScale * getScale(); } else { mDerivedScale = getScale(); } // change position vector based on parent's orientation & scale mDerivedPosition = parentOrientation * (parentScale * getPosition()); // add altered position vector to parent's mDerivedPosition += parent->getDerivedPosition(); } else { // root node, no parent mDerivedOrientation = getOrientationQuat(); mDerivedPosition = getPosition(); mDerivedScale = getScale(); } }
void BasicScreenObject::addRotation(float _xangle, float _yangle, float _zangle){ qx.makeRotate(_xangle, ofVec3f(1,0,0)); qy.makeRotate(_yangle, ofVec3f(0,1,0)); qz.makeRotate(_zangle, ofVec3f(0,0,1)); ofQuaternion nowquat = getOrientationQuat(); nowquat *= qx*qy*qz; nowquat.normalize(); setOrientation(nowquat); }
void WaypointCamera::setSnapToTarget(bool snap){ if(snap == true){ camState = WAYPOINT_CAM_STATE_TARGET; // Update the prev target node preTarNode.resetTransform(); preTarNode.setPosition(getPosition()); pan(-180); // Fix for camera orientation preTarNode.setOrientation(getOrientationQuat()); pan(180); // Fix for camera orientation }else{ camState = WAYPOINT_CAM_STATE_FREE; } }
WaypointCamera::WaypointCamera(){ // Initialize the current and previous targets for cam curTarNode.setPosition(getPosition()); pan(-180); // Fix for camera orientation curTarNode.setOrientation(getOrientationQuat()); pan(180); // Fix for camera orientation preTarNode = curTarNode; // The camrea origin starts off as the default camera positoin. originTarNode = preTarNode; arrivedAtTarget = false; isMoving = false; }
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 Player::drawEditor() { if(movePlayer) { ofVec3f forward = ofVec3f(0,0,1) * getOrientationQuat(); ofVec3f sideways = ofVec3f(1,0,0) * getOrientationQuat(); if( ofGetKeyPressed('w') ) setPosition( getPosition() + (-forward * movementSpeed) ); if( ofGetKeyPressed('s') ) setPosition( getPosition() + ( forward * movementSpeed) ); if( ofGetKeyPressed('a') ) setPosition( getPosition() + (-sideways * movementSpeed) ); if( ofGetKeyPressed('d') ) setPosition( getPosition() + ( sideways * movementSpeed) ); ofPoint mouse = ofPoint(ofGetMouseX(), ofGetMouseY()); ofPoint mouseVel = mouse - lastMouse; pan(mouseVel.x/4); lastMouse = mouse; } draw(); }
void Creature::slerp(const ofVec3f& target, const ofVec3f& upVector) { ofVec3f zaxis = (getPosition() - target).normalized(); ofVec3f xaxis = upVector.getCrossed(zaxis).normalized(); ofVec3f yaxis = zaxis.getCrossed(xaxis); ofMatrix4x4 m; m._mat[0].set(xaxis.x, xaxis.y, xaxis.z, 0); m._mat[1].set(yaxis.x, yaxis.y, yaxis.z, 0); m._mat[2].set(zaxis.x, zaxis.y, zaxis.z, 0); ofQuaternion targetQuat = m.getRotate(); ofQuaternion currentQuat = getOrientationQuat(); currentQuat.slerp(0.1, currentQuat, targetQuat); setOrientation(currentQuat); }
//---------------------------------------- void ofEasyCamExt::startMove( ofVec3f _posEnd, ofQuaternion _orientationEnd, float _timeToTake, float _delay, EasingEquations::EaseType _easeType ) { startMove( getPosition(), getOrientationQuat(), _posEnd, _orientationEnd, _timeToTake, _delay, _easeType ); }