Exemple #1
0
void ofApp::moveArm(){
    
    // assign the target pose to the current robot pose
    if(parameters.bCopy){
        parameters.bCopy = false;
        parameters.targetTCP.rotation = ofQuaternion(90, ofVec3f(0, 0, 1));
        parameters.targetTCP.rotation*=ofQuaternion(90, ofVec3f(1, 0, 0));
        
        // get the robot's position
        parameters.targetTCP.position = parameters.actualTCP.position;
        parameters.targetTCP.rotation*=parameters.actualTCP.rotation;
        
        tcpNode.setPosition(parameters.targetTCP.position*1000);
        tcpNode.setOrientation(parameters.targetTCP.rotation);
        gizmo.setNode(tcpNode);
        // update GUI params
        parameters.targetTCPPosition = parameters.targetTCP.position;
        parameters.targetTCPOrientation = ofVec4f(parameters.targetTCP.rotation.x(), parameters.targetTCP.rotation.y(), parameters.targetTCP.rotation.z(), parameters.targetTCP.rotation.w());
        
    }
    // follow a user-defined position and orientation
    if(parameters.bFollow){
        
        parameters.targetTCP.position.interpolate(tcpNode.getPosition()/1000.0, parameters.followLerp);
        parameters.targetTCP.rotation = tcpNode.getOrientationQuat();
        parameters.targetTCPOrientation = ofVec4f(parameters.targetTCP.rotation.x(), parameters.targetTCP.rotation.y(), parameters.targetTCP.rotation.z(), parameters.targetTCP.rotation.w());
        
    }
}
Exemple #2
0
void UserPointCloud::initBones() {
	
	// First retrieve the points of the user
	PointCloud::update();
	
	ofVec3f zAxis = ofVec3f(0.0f, 0.0f, 1.0f);
	
	ofQuaternion qDefault	= ofQuaternion( 0	 , zAxis);
	ofQuaternion qLeft		= ofQuaternion(-90.0 , zAxis);
	ofQuaternion qRight		= ofQuaternion( 90.0 , zAxis);
	ofQuaternion qNeck		= ofQuaternion( 180.0, zAxis);
	
	bones[TORSO]		 .init( XN_SKEL_TORSO,			qDefault);
	bones[WAIST]		 .init( XN_SKEL_WAIST,			qDefault);
	bones[LEFT_SHOULDER] .init( XN_SKEL_LEFT_SHOULDER,	qLeft);
	bones[LEFT_ELBOW]	 .init( XN_SKEL_LEFT_ELBOW,		qLeft);
	bones[RIGHT_SHOULDER].init( XN_SKEL_RIGHT_SHOULDER,	qRight);
	bones[RIGHT_ELBOW]	 .init( XN_SKEL_RIGHT_ELBOW,	qRight);
	bones[LEFT_HIP]		 .init( XN_SKEL_LEFT_HIP,		qDefault);
	bones[RIGHT_HIP]	 .init( XN_SKEL_RIGHT_HIP,		qDefault);
	bones[LEFT_KNEE]	 .init( XN_SKEL_LEFT_KNEE,		qDefault);
	bones[RIGHT_KNEE]	 .init( XN_SKEL_RIGHT_KNEE,		qDefault);
	bones[NECK]			 .init( XN_SKEL_NECK,			qNeck);
	
	// Update the bones
	updateBones();
	
	for(int i=0; i<kNumTestNodes; i++) bones[i].updateCalibPose();
	
	setBonesLengths();
	
	initVerticesWeights();
	
	bBonesInit = true;
}
void demoAdvanced::setup( ) {

    ofSetFrameRate( 60 );
    
    stringstream ss;
    ss << "Tweens, advanced interpolations demo";
    ofSetWindowTitle( ss.str() );
    
    _tweener = new tween::Tweener( 100 );
    _tweener->addListener( this );
    
    lognum = 4;
    logs = new string[ lognum ];
    logi = 0;
    
    // quaternion
    quaternion.makeRotate( ofRandomf() * 180, ofRandomf(), ofRandomf(), ofRandomf() );
    tween::TweenConfig<ofQuaternion> qcf(
        ofQuaternion( PI, -1,0,1 ),
        ofQuaternion( -PI, 1,0.5,1 ),
        tween::TWEEN_INTERPOLATION_ELASTIC_OUT,
        500, 2000, true
    );
    qcf.forever( true );
    _tweener->addTween( qcf, &quaternion );
    
    // matrix
    mat.makeIdentityMatrix();
    mat.rotate( ofRandomf() * 180, ofRandomf(), ofRandomf(), ofRandomf() );
    mat.translate( -200, 0, 0 );
    mat.scale(  1,2,0.2  );
    
    ofMatrix4x4 mmin;
    mmin.makeIdentityMatrix();
    mmin.rotate( -90, 1, 0, 0.2 );
    mmin.translate( -300, 0, 0 );
    
    ofMatrix4x4 mmax;
    mmax.makeIdentityMatrix();
    mmax.rotate( 90, 1, 0, 0 );
    mmax.translate( 300, 0, 0 );
    mmax.scale(  1,3,3  );
    
//    mat = mmax;
    
    tween::TweenConfig<ofMatrix4x4> mcf(
        mmin,
        mmax,
        tween::TWEEN_INTERPOLATION_ELASTIC_OUT,
        200, 3000, true
    );
    mcf.forever( true );
    _tweener->addTween( mcf, &mat );
    
    _tweener->start();
    
}
Exemple #4
0
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);
}
Exemple #5
0
vector<PxActor*> World::addWorldBox(const ofVec3f &leftTopFar, const ofVec3f& rightBottomNear)
{
	vector<PxActor*> result;

	result.push_back(addPlane(ofVec3f(leftTopFar.x, 0, 0)));
	result.push_back(addPlane(ofVec3f(rightBottomNear.x, 0, 0), ofQuaternion(180, ofVec3f(0, 1, 0))));

	result.push_back(addPlane(ofVec3f(0, rightBottomNear.y, 0), ofQuaternion(90, ofVec3f(0, 0, -1))));
	result.push_back(addPlane(ofVec3f(0, leftTopFar.y, 0), ofQuaternion(90, ofVec3f(0, 0, 1))));

	result.push_back(addPlane(ofVec3f(0, 0, rightBottomNear.z), ofQuaternion(90, ofVec3f(0, 1, 0))));
	result.push_back(addPlane(ofVec3f(0, 0, leftTopFar.z), ofQuaternion(90, ofVec3f(0, -1, 0))));

	return result;
}
Exemple #6
0
void StencilWaves::updateMeshes(){
    mainWaveMesh.clear();
    strokeMesh.clear();
    for (int i = 0; i < waves[0].polyline.getVertices().size(); i++) {
        ofVec2f p = waves[0].polyline.getVertices()[i];
        ofVec2f p2 = ofVec2f(p.x, ofGetHeight());
        ofVec3f dir = waves[0].polyline.getTangentAtIndex(i);
        float angle = atan2(dir.x, dir.y)*(180)/pi;
        
        ofColor col = ofColor::lightSkyBlue;
        ofColor cc = ofColor::darkBlue;
        col.setBrightness((int)ofMap(angle, 90, 120, 0, 255)%255);
        col.setHueAngle(ofMap(angle, 90, 120, 0, 360, true));
        
        mainWaveMesh.addVertex(p);
        mainWaveMesh.addColor(col);
        mainWaveMesh.addVertex(p2);
        mainWaveMesh.addColor(cc);
        
        ofNode node;
        ofNode child;
        child.setParent(node);

        child.setPosition(ofVec3f(0, ofMap(angle, 90, 120, 0, 20)+cos(ofGetFrameNum()/20.0)*10, 0));

        node.setPosition(p);
        ofQuaternion q = ofQuaternion(0, ofVec3f(1, 0, 0), 0, ofVec3f(0, 1, 0), angle, ofVec3f(0, 0, 1));
        node.setOrientation(q);

        strokeMesh.addVertex(node.getGlobalPosition());
        strokeMesh.addVertex(child.getGlobalPosition());
    }
}
void LeapToCameraCalibrator::resetProjector()
{
	//position = ofVec3f(1.0f,1.0f,1.0f);//cam.getPosition();
	throwRatio = 1.62f;
	lensOffset = ofVec2f(0.0f,0.5f);
    
	ofQuaternion rotation;
	auto rotationQuat = ofQuaternion(rotationX, ofVec3f(1, 0, 0), rotationZ, ofVec3f(0, 0, 1), rotationY, ofVec3f(0, 1, 0));
	ofMatrix4x4 pose = ofMatrix4x4(rotationQuat);
	pose(3,0) = translationX;
	pose(3,1) = translationY;
	pose(3,2) = translationZ;
	projector.setView(pose);
    
	ofMatrix4x4 projection;
	projection(0,0) = throwRatioX;
	projection(1,1) = -throwRatioY;
	projection(2,3) = 1.0f;
	projection(3,3) = 0.0f;
	projection.postMultTranslate(-lensOffsetX, -lensOffsetY, 0.0f);
	projector.setProjection(projection);
    
	projector.setWidth(resolution.x);
	projector.setHeight(resolution.y);
}
Exemple #8
0
void gradientWaves::drawSpikes(){
    for (int i = 0; i < waves.size(); i++) {
        ofPolyline *line = &waves[i].polyline;
        float index  = 5.0;
        for (int j = 0; j < 50; j++) {
            index = ofMap(ofNoise(ofGetElapsedTimef()/j + j*100.0 + i*10.0), 0.2, 0.8, 0, waves[0].amount );
            ofVec2f p = line->getPointAtIndexInterpolated(index);
            ofVec3f dir = line->getTangentAtIndex(index);
            float angle = atan2(dir.x, dir.y)*(180)/pi;
            ofSetColor(ofColor::white);
            ofSetLineWidth(ofNoise(index/20.0)*5);
            ofNode node;
            ofNode child;
            child.setParent(node);
            child.setPosition(-ofNoise(index/2.)*20, 0, 0);
            
            node.setPosition(p);
            ofQuaternion q = ofQuaternion(0, ofVec3f(1, 0, 0), 0, ofVec3f(0, 1, 0), angle, ofVec3f(0, 0, 1));
            node.setOrientation(q);
            float vel = 0;
//            for(auto &t: IM->targets){
//                if(p.distance(t.pos)<30){
//                    vel = t.vel.y;
//                }
//            }
            ofSetColor(255, 255);
            ofDrawCircle(ofVec2f(p.x, p.y+vel*10), ofMap(p.y, 0, screenH, 10, 1, true));
        }
    }
}
Exemple #9
0
void gradientWaves::drawCircles(ofPolyline *line, int i){
    int index  = 5;
    while (index < waves[0].amount) {
        ofVec2f p = line->getPointAtIndexInterpolated(index);
        ofVec3f dir = line->getTangentAtIndex(index);
        float angle = atan2(dir.x, dir.y)*(180)/pi;
        ofNode node;
        ofNode child;
        child.setParent(node);
        child.setPosition(-ofNoise(index/2.)*300, 0, 0);
        
        node.setPosition(p);
        ofQuaternion q = ofQuaternion(0, ofVec3f(1, 0, 0), 0, ofVec3f(0, 1, 0), angle, ofVec3f(0, 0, 1));
        node.setOrientation(q);
        
        ofSetLineWidth(ofNoise(index/20.0)*5);
        ofSetColor(ofColor::gray);
        ofVec2f pos = node.getGlobalPosition()+ofVec2f(0, cos(ofGetElapsedTimef()*i)*40+100);
        float size = ofNoise(index/2.)*100;
        if(i!=waves.size()-1)
            ofDrawCircle(pos, size);
        
        index += ofNoise((i*index)/20.01)*60;
    }
}
Exemple #10
0
ofMatrix4x4 headTracking::getLastHeadView(ofMatrix4x4 headView)
{
    if (!mTracker.isReady()) {
        return headView;
    }

    ofOrientation fooRot = ofGetOrientation();
    double rotation = 0.0;

    if (fooRot == OF_ORIENTATION_DEFAULT) {
        rotation = 0.0;
    } else if (fooRot == OF_ORIENTATION_90_LEFT) {
        rotation = 90.0;
    } else if (fooRot == OF_ORIENTATION_90_RIGHT) {
        rotation = 180.0;
    } else {
        rotation = 270.0;
    }

    if (fooRot != mDisplayRotation) {
        mDisplayRotation = fooRot;

        mSensorToDisplay.makeRotationMatrix(
            ofQuaternion(0.0, ofVec3f(1, 0, 0), -rotation, ofVec3f(0, 0, 1),
                         0.0, ofVec3f(0, 1, 0)));
        mEkfToHeadTracker.makeRotationMatrix(
            ofQuaternion(0.0, ofVec3f(1, 0, 0), rotation, ofVec3f(0, 0, 1),
                         0.0, ofVec3f(0, 1, 0)));
    }

    double secondsSinceLastGyroEvent = (ofGetElapsedTimeMicros() -
                                        mLastGyroEventTimeNanos) * 1E-6;


    double secondsToPredictForward = secondsSinceLastGyroEvent + 0.0166666666;
    mTmpHeadView = mTracker.getPredictedGLMatrix(secondsToPredictForward);
    mTmpHeadView2.makeFromMultiplicationOf(mSensorToDisplay, mTmpHeadView);
    headView.makeFromMultiplicationOf(mTmpHeadView2, mEkfToHeadTracker);

    if (mNeckModelEnabled) {
        mTmpHeadView.makeFromMultiplicationOf(mNeckModelTranslation, headView);
        mTmpHeadView.translate(ofVec3f(0, 0.075, 0.0));
        headView = mTmpHeadView;
    }

    return headView;
}
Exemple #11
0
ofQuaternion ofxURDriver::convertAxisAngle(double rx, double ry, double rz) {
    float angle = ofVec3f(rx, ry, rz).normalize().length();
    double s = sin(angle/2);
    float x = (rx) * s;
    float y = (ry) * s;
    float z = (rz) * s;
    float w = cos(angle/2);
    return ofQuaternion(x, y, z, w);
}
void ofxRGBDCaptureGui::objectDidRelease(ofxMSAInteractiveObject* object, int x, int y, int button){
 	if(object == btnSetDirectory){
		loadDirectory();
	}
	else if(object == btnCalibrateTab){
		currentTab = TabCalibrate; 
        currentTabObject = btnCalibrateTab;
        btnRecordBtn->setLabel("Capture Chessboard");
	}
	else if(object == btnRecordTab){
		currentTab = TabRecord;
        currentTabObject = btnRecordTab;
    	btnRecordBtn->setLabel("Toggle Record");
	}
	else if(object == btnPlaybackTab){
		currentTab = TabPlayback;
        currentTabObject = btnPlaybackTab;
    	btnRecordBtn->setLabel("Reset Camera");
	}
	else if(object == btnRecordBtn){
		if(currentTab == TabRecord){
			toggleRecord();
		}
		else if(currentTab == TabCalibrate){
			captureCalibrationImage();
		}
		else if(currentTab == TabPlayback){
			cam.targetNode.setPosition(0, 0, 0);
            cam.targetNode.setOrientation(ofQuaternion());
            cam.targetXRot = cam.targetYRot = cam.targetZRot = 0;
		}
	}
	else if(object == btnRenderBW){
		currentRenderMode = RenderBW;
        currentRenderModeObject = btnRenderBW;
	}
	else if(object == btnRenderRainbow){
		currentRenderMode = RenderRainbow;
        currentRenderModeObject = btnRenderRainbow;
	}
	else if(object == btnRenderPointCloud){
		currentRenderMode = RenderPointCloud;
        currentRenderModeObject = btnRenderPointCloud;
	}
	else {
		for(int i = 0; i < btnTakes.size(); i++){
			if(object == btnTakes[i].button){
				loadSequenceForPlayback( i );                
                for(int b = 0; b < btnTakes.size(); b++){
                	btnTakes[b].isSelected = b == i;
                }
                break;
			}
		}
	}
}
void ofxBvh::updateJoint(int& index, const FrameData& frame_data, ofxBvhJoint *joint)
{
	ofVec3f translate;
	ofQuaternion rotate;
	
	for (int i = 0; i < joint->channel_type.size(); i++)
	{
		float v = frame_data[index++];
		ofxBvhJoint::CHANNEL t = joint->channel_type[i];
		
		if (t == ofxBvhJoint::X_POSITION)
			translate.x = v;
		else if (t == ofxBvhJoint::Y_POSITION)
			translate.y = v;
		else if (t == ofxBvhJoint::Z_POSITION)
			translate.z = v;
		else if (t == ofxBvhJoint::X_ROTATION)
			rotate = ofQuaternion(v, ofVec3f(1, 0, 0)) * rotate;
		else if (t == ofxBvhJoint::Y_ROTATION)
			rotate = ofQuaternion(v, ofVec3f(0, 1, 0)) * rotate;
		else if (t == ofxBvhJoint::Z_ROTATION)
			rotate = ofQuaternion(v, ofVec3f(0, 0, 1)) * rotate;
	}
	
	translate += joint->initial_offset;
	
	joint->matrix.makeIdentityMatrix();
	joint->matrix.glTranslate(translate);
	joint->matrix.glRotate(rotate);
	
	joint->global_matrix = joint->matrix;
	joint->offset = translate;
	
	if (joint->parent)
	{
		joint->global_matrix.postMult(joint->parent->global_matrix);
	}
	
	for (int i = 0; i < joint->children.size(); i++)
	{
		updateJoint(index, frame_data, joint->children[i]);
	}
}
Exemple #14
0
//----------------------------------------
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);
	}
}
Exemple #15
0
//--------------------------------------------------------------
void Cube::update()
{	
	
	auto now = ofGetElapsedTimef();
	
	if (isRotating) {
		auto endTime = initTime + duration;
		auto currentRotation = ofxeasing::map_clamp(now, initTime, endTime, initRotation, targetRotation, &ofxeasing::linear::easeIn);
		auto diffRotation = currentRotation - lastRotation;
		box.setOrientation(ofQuaternion(currentRotation, axis));
		plane.setOrientation(ofQuaternion(currentRotation, axis));
		plane.rotateAround(diffRotation, axis, ofVec3f(boxPosition.x, boxPosition.y, 0));

		lastRotation = currentRotation;

		if (currentRotation == targetRotation) {
			isRotating = false;
			logoShown = targetRotation != 180.0f;
		}
	}
}
//----------------------------------------
void ofxViewportCam::tumble(float yaw, float pitch)
{
    const float tumbleAmount = 0.25f;
    this->tiltAmount += pitch * tumbleAmount;
    this->panAmount += yaw * tumbleAmount;
        
    if(this->isTargetSet)
    {
        // Move to tumble point.
        const ofVec3f targetPos(target.getGlobalPosition());
        setPosition(targetPos);

        // Reset orientation to identity.
        setOrientation(ofQuaternion(0, 0, 0, 1));

        // Apply tumble.
        pan(this->panAmount);
        tilt(this->tiltAmount);

        // Re-apply pre-existing track and zoom.
        dolly(this->distance);
        truck(this->truckAmount);
        boom(this->boomAmount);
    }
    else
    {
        // Move to tumble point.
        dolly(-this->distance);

        // Reset orientation to identity.
        setOrientation(ofQuaternion(0, 0, 0, 1));

        // Apply tumble.
        pan(this->panAmount);
        tilt(this->tiltAmount);

        // Move back.
        dolly(this->distance);
    }
}
Exemple #17
0
//--------------------------------------------------------------
void testApp::keyPressed(int key){
//    azeqsdd
    float da=360./32.;
    ofQuaternion rot;
    switch(key) {
        case 97:
            rot= ofQuaternion(da, ofVec3f(0,0,1));
            curRot *= rot;
            break;
        case 122:
            rot= ofQuaternion(da, ofVec3f(0,-1,0));
            curRot *= rot;
            break;
        case 101:
            rot= ofQuaternion(da, ofVec3f(0,0,-1));
            curRot *= rot;
            break;
        case 113:
            rot= ofQuaternion(da, ofVec3f(-1,0,0));
            curRot *= rot;
            break;
        case 115:
            rot= ofQuaternion(da, ofVec3f(0,1,0));
            curRot *= rot;
            break;
        case 100:
            rot= ofQuaternion(da, ofVec3f(1,0,0));
            curRot *= rot;
            break;
        default:
            break;
            
    }
}
Exemple #18
0
//--------------------------------------------------------------
void testApp::keyPressed(int key) {
	ofVec3f mouseLoc = camera.screenToWorld( ofVec3f((float)ofGetMouseX(), (float)ofGetMouseY(), 0) );
	ofVec3f gravity = world.getGravity();
	ofQuaternion startRot = ofQuaternion(1., 0., 0., PI);
	float rsize = ofRandom(.3, 1.8);
	mouseLoc.z += 15;
	switch (key) {
		case 'd':
			bDrawDebug = !bDrawDebug;
			break;
		case 'o':
			logos.push_back( new ofxBulletCustomShape() );
			logos[logos.size()-1]->init( (btCompoundShape*)logos[0]->getCollisionShape(), logos[0]->getCentroid() );
			logos[logos.size()-1]->create( world.world, mouseLoc, startRot, 3. );
			logos[logos.size()-1]->add();
			break;
		case 's':
			shapes.push_back( new ofxBulletSphere() );
			((ofxBulletSphere*)shapes[shapes.size()-1])->create( world.world, mouseLoc, rsize*.2, rsize );
			((ofxBulletSphere*)shapes[shapes.size()-1])->setSphereResolution( 16 );
			((ofxBulletSphere*)shapes[shapes.size()-1])->setActivationState( DISABLE_DEACTIVATION );
			shapes[shapes.size()-1]->add();
			break;
		case 'b':
			shapes.push_back( new ofxBulletBox() );
			((ofxBulletBox*)shapes[shapes.size()-1])->create( world.world, mouseLoc, rsize*.2, rsize*2, rsize*2, rsize*2 );
			((ofxBulletBox*)shapes[shapes.size()-1])->setActivationState( DISABLE_DEACTIVATION );
			shapes[shapes.size()-1]->add();
			break;
		case ' ':
			bDropBox = true;
			break;
		case OF_KEY_UP:
			gravity.y -= 5.;
			world.setGravity( gravity );
			break;
		case OF_KEY_DOWN:
			gravity.y += 5.;
			world.setGravity( gravity );
			break;
		case OF_KEY_RIGHT:
			gravity.x += 5.;
			world.setGravity( gravity );
			break;
		case OF_KEY_LEFT:
			gravity.x -= 5.;
			world.setGravity( gravity );
			break;
		default:
			break;
	}
}
// ---------------------------------------------------------------------------------------------------------------------------------------------------
//
void ofxOculusRift::readSensorIfNeededThisFrame()
{
	if( needSensorReadingThisFrame )
	{
		Vector3f tmpAcc = FusionResult.GetAcceleration();
		acc.set( ofVec3f(tmpAcc.x, tmpAcc.y, tmpAcc.z) );
		
		Quatf quaternion = FusionResult.GetOrientation();
		setOrientation( ofQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w) ); // sets the orientation quat in ofNode
		
		needSensorReadingThisFrame = false;
	}
}
void ofxGameCamera::reset(){
 	rotationX = 0.0f;
	rotationY = 0.0f;
	rotationZ = 0.0f;
    
	targetXRot = 0.0f;
	targetYRot = 0.0f;
	targetZRot = 0.0f;
    
    targetNode.setPosition(ofVec3f(0,0,0));
    targetNode.setOrientation(ofQuaternion());

}
Exemple #21
0
//----------------------------------------
void ofEasyFingerCam::reset()
{
    rotationX = 0.0f;
    rotationY = 0.0f;
    rotationZ = 0.0f;
    targetXRot = 0.0f;
    targetYRot = 0.0f;
    targetZRot = 0.0f;
    target.resetTransform();
    setDistance(lastDistance, false);
    rotation = ofQuaternion(0,0,0,1);
    distanceScaleVelocity = 0;
}
Exemple #22
0
//--------------------------------------------------------------
void testApp::setup(){
    
    ofSetFrameRate(60);
    ofSetVerticalSync(true);
    ofBackground(255*.15);
    
    //set up a standard timeline with a default duration to begin with
    timeline.setup();
    timeline.getColors().load("defaultColors.xml");
	timeline.setOffset(ofVec2f(0,0));
    timeline.setDurationInFrames(300);
    timeline.setPageName("Main");
    
    //set up a video timeline element so we can see the video frames
    timeline.addTrack("Video", &videoTrack);
    timeline.addTrack("Depth", &depthTrack);
	
//	timeline.addCurves("xshift", "xshift.xml", ofRange(-.15, .15));
//  timeline.addCurves("yshift", "yshift.xml", ofRange(-.15, .15));
//  timeline.addCurves("farclip", "farclip.xml", ofRange(500, 6000));
	
	panel.setup("options");
	panel.add(showDepthProjection.setup("show depth projection", ofxParameter<bool>()));
	panel.add(showDepthWireframe.setup("show wireframe", ofxParameter<bool>()));
	panel.add(showRGBProjection.setup("show rgb projection", ofxParameter<bool>()));
	panel.add(rgbTextureSlider.setup("rgb texture projection", ofxParameter<float>(), 0, 1));
//	panel.add(xShift.setup("x shift",ofxParameter<float>(), -.15, .15));
//	panel.add(yShift.setup("y shift",ofxParameter<float>(), -.15, .15));

	xShift = 0.0045;
	yShift = 0.03;
	rgbTextureSlider = 0;
	
	
    //set up the game camera
    cam.setup();
	cam.dampen = true;
    cam.speed = 20;
    cam.autosavePosition = true;
    cam.targetNode.setPosition(ofVec3f());
    cam.targetNode.setOrientation(ofQuaternion());
    cam.targetXRot = -180;
    cam.targetYRot = 0;
    cam.rotationZ = 0;    

	player.updateVideoPlayer = false;
    //load 
    loadDefaultScene();
	
 	ofToggleFullscreen();
}
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());
}
Exemple #24
0
//--------------------------------------------------------------
void testApp::setup(){
	
	g_Rotation = ofQuaternion(0.0f, 0.0f, 0.0f, 1.0f);
	g_RotateStart = ofQuaternion(0.0f, 0.0f, 0.0f, 1.0f);
	g_LightDirection.set(-0.57735f, -0.57735f, -0.57735f);
	
	// Create some 3D objects (stored in display lists)
    glNewList(SHAPE_TEAPOT, GL_COMPILE);
    glutSolidTeapot(1.0);
    glEndList();
    glNewList(SHAPE_TORUS, GL_COMPILE);
    glutSolidTorus(0.3, 1.0, 16, 32);
    glEndList();
    glNewList(SHAPE_CONE, GL_COMPILE);
    glutSolidCone(1.0, 1.5, 64, 4);
    glEndList();
	
	
	float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
    float angle = 0.8f;

    // Init rotation
    SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
    SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);
	
	//TWEAK BAR
	bar.init("TweakBar", 200, 400, 200, 200, 200, 100);
	bar.enable();
	
	bar.addParam("Zoom", &g_Zoom, " min=0.01 max=500.0 step=1.0 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ", false);
	bar.addParam("ObjRotation", &g_Rotation, " label='Object rotation' open help='Change the object orientation.' ", false);	
	bar.addParam("Multiplier", &g_LightMultiplier, " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ", false);
	bar.addParam("LightDir", &g_LightDirection, " label='Light direction' open help='Change the light direction.' ", false);
	bar.addSeparator("separator");
	bar.addParam("Ambient", g_MatAmbient, " group='Material' ", false, TW_TYPE_COLOR3F);
	bar.addParam("Diffuse", g_MatDiffuse, " group='Material' ", false, TW_TYPE_COLOR3F);
}
Exemple #25
0
//--------------------------------------------------------------
void testApp::update(){
	
	while(receiver.hasWaitingMessages()){
		
		ofxOscMessage message;
		receiver.getNextMessage(&message);
		
		string address= message.getAddress();
		if(address=="/attitude"){
			
			ofQuaternion quaternion= ofQuaternion(message.getArgAsFloat(0),
												  message.getArgAsFloat(1),
												  message.getArgAsFloat(2),
												  message.getArgAsFloat(3));
			
			quaternion=	quaternion*
						ofQuaternion(kDefaultRotateZ, ofVec3f(0.0f, 0.0f, 1.0f))*
						ofQuaternion(kDefaultRotateX, ofVec3f(1.0f, 0.0f, 0.0f));
			
			quaternion.getRotate(angle, vec);
		}
	}
	
}
//----------------------------------------
void ofEasyCamExt::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, ofCamera::getXAxis(), yRot, ofCamera::getYAxis(), zRot, ofCamera::getZAxis());
	setPosition((ofCamera::getGlobalPosition()-target.getGlobalPosition())*curRot +target.getGlobalPosition());
	rotate(curRot);
}
//--------------------------------------------------------------
void testApp::initMetaio(){
		/* --- BEGIN INTITALIZE METAIO SDK ---------------------------------------- */
	// GETTING CUSTOM IMAGE FOR PROCESSING - NEEDS PRO LICENSE
	
	camWidth 		= 1280;	// try to grab at this size. 
	camHeight 		= 720;
	vidGrabber.setVerbose(true);
	vidGrabber.initGrabber(camWidth,camHeight);
	videoMirror 	= new unsigned char[camWidth*camHeight*3];
	blah 	= new unsigned char[camWidth*camHeight*3];
	videoTexture.allocate(camWidth,camHeight, GL_RGB);	

	videoPx = new metaio::ImageStruct(videoInverted, camWidth, camHeight, metaio::common::ECF_R8G8B8, true);

	int u0=0, v0=0;
	//int wndWidth=1280, wndHeight=1024;
	int wndWidth=camWidth, wndHeight=camHeight;
	// create the SDK
	m_metaioSDK = metaio::CreateMetaioSDKWin32();
	
	//m_metaioSDK->initializeRenderer(wndWidth, wndHeight, u0, v0,  handler, metaio::ERENDER_SYSTEM_NULL );
	m_metaioSDK->initializeRenderer(wndWidth, wndHeight, metaio::ESCREEN_ROTATION_0, (HWND)0, metaio::ERENDER_SYSTEM_NULL);
	m_sensors = metaio::CreateSensorsComponent();
	m_metaioSDK->registerSensorsComponent( m_sensors );
	// set the callback to this class
	m_metaioSDK->registerCallback( this );
	// activate 1st camera
	//m_metaioSDK->startCamera( 0 );
	//m_metaioSDK->setCameraParameters("camParams.xml");

	// load your favorite configuration
	bool result = m_metaioSDK->setTrackingConfiguration( "TrackingData_MarkerlessFast.xml" );
	cout << "tracking data loaded:" << result;
	/* --- END INTITALIZE METAIO SDK ---------------------------------------- */
	arPos.set(0,0,0);
	camTex.allocate(wndWidth, wndHeight, GL_RGB);
	metaio_foundObject = false;
	selTr = 0;

	metaio_found = new bool[num_trackers];
	metaio_pos = new ofVec3f[num_trackers];
	metaio_rot = new ofQuaternion[num_trackers];
	for(int j = 0; j < num_trackers; j++) {
		metaio_found[j] = false;
		metaio_pos[j] = ofVec3f(0,0,0);
		metaio_rot[j] = ofQuaternion(0, 0, 0, 0);
	}
}
//--------------------------------------------------------------
void testApp::setup(){
    
    ofSetFrameRate(60);
    ofSetVerticalSync(true);
    ofBackground(25);
    
    //set up the game camera
    cam.setup();
    cam.speed = 20;
    cam.autosavePosition = true;
    cam.targetNode.setPosition(ofVec3f());
    cam.targetNode.setOrientation(ofQuaternion());
    cam.targetXRot = -180;
    cam.targetYRot = 0;
    cam.rotationZ = 0;    
    cam.setScale(1,-1,1);

    xshift = 0;
    yshift = 0;
    maxFeatures = 500;
    featureQuality = .5;
	minDistance = 10;
	
    
    gui.setup("tests");
    gui.add(loadNew.setup("load new scene"));

    gui.add(xshift.setup("xshift", ofxParameter<float>(), -.15, .15));
    gui.add(yshift.setup("yshift", ofxParameter<float>(), -.15, .15));
    gui.add(farClip.setup("far clip", ofxParameter<float>(),1000, 4500));

    gui.add(lightX.setup("lightX", ofxParameter<float>(),-1000, 1000));
    gui.add(lightY.setup("lightY", ofxParameter<float>(),-1000, 1000));
    gui.add(lightZ.setup("lightZ", ofxParameter<float>(),400, 2000));

    gui.add(maxFeatures.setup("max features", ofxParameter<int>(),100, 5000));
    gui.add(featureQuality.setup("feature quality", ofxParameter<float>(),.0000001, .01));
    gui.add(minDistance.setup("min distance", ofxParameter<float>(), .0, 200));
	gui.add(renderMode.setup("render", ofxParameter<bool>()));

    gui.loadFromFile("defaultSettings.xml");
    renderMode = false;
    
    calculateRects();
    
    //attemping to load the last scene
    loadDefaultScene();
}
Exemple #29
0
		void update(){
			
			if(_age>0){
				if(int(_age)%4 == 0){
					auto p = std::shared_ptr<flower::Petal>(new flower::Petal(_petalMaterial, _petalMaxAge));
					const auto x = ofRandom(-5, 5);
					const auto y = ofRandom(-5, 5);
					const auto z = ofRandom(-5, 5);
					p->position(ofVec3f(x, y, z) + position())
						.orientation(ofQuaternion(ofRandom(-PI, PI)*100.0f, ofVec3f(x, y, z).normalized()));
					_petals.push_back(p);

				}
				_age-=1.0;
			}else{
				shouldDie = true;
			}
		}
Exemple #30
0
void ofxFBXScene::parseRotationCurve(ofxFBXNode & node, FbxAnimLayer * pAnimLayer, FbxNode* fbxNode, FbxPropertyT<FbxDouble3> &rotation){
	node.originalRotation = ofQuaternion(rotation.Get().mData[0], ofVec3f(1, 0, 0), rotation.Get().mData[1], ofVec3f(0, 1, 0), rotation.Get().mData[2], ofVec3f(0, 0, 1));
	node.getNode().setOrientation(node.originalRotation);
	ofLogVerbose("ofxFBXScene") << "original rotation " << endl << node.originalRotation << endl;

	if(!rotation.GetCurve(pAnimLayer)) return;
	FbxAnimCurve* lAnimCurveX = rotation.GetCurve(pAnimLayer,"X");
	FbxAnimCurve* lAnimCurveY = rotation.GetCurve(pAnimLayer,"Y");
	FbxAnimCurve* lAnimCurveZ = rotation.GetCurve(pAnimLayer,"Z");


    int xKeyCount = lAnimCurveX ? lAnimCurveX->KeyGetCount() : 0;
    int yKeyCount = lAnimCurveY ? lAnimCurveY->KeyGetCount() : 0;
    int zKeyCount = lAnimCurveZ ? lAnimCurveZ->KeyGetCount() : 0;

	FbxTime   lKeyTime;
	int     lCount;
	FbxTime lXKeyTime,lYKeyTime,lZKeyTime;
	for(lCount = 0; lCount < max(max(xKeyCount,yKeyCount),zKeyCount); lCount++)
	{
		if(lCount<xKeyCount){
			lXKeyTime  = lAnimCurveX->KeyGetTime(lCount);
		}
		if(lCount<yKeyCount){
			lYKeyTime  = lAnimCurveY->KeyGetTime(lCount);
		}
		if(lCount<zKeyCount){
			lZKeyTime  = lAnimCurveZ->KeyGetTime(lCount);
		}
		lKeyTime = min(min(lXKeyTime,lYKeyTime),lZKeyTime);
		lKeyTime = lXKeyTime;

		FbxAMatrix & matrix = fbxNode->EvaluateLocalTransform(lKeyTime);
		ofxFBXKey<ofQuaternion> key;
		ofVec3f t,s;
		ofQuaternion so;
		ofMatrix4x4 m = toOf(matrix);
		m.decompose(t,key.value,s,so);
		key.timeMillis = lKeyTime.GetMilliSeconds();
		node.rotationKeys.push_back(key);
	}
}