コード例 #1
0
pair<Vec3, Vec3> RotateDesktopGesture::calculateCameraPosition()
{
	// Right Direction
	Vec3 referenceDirection(-1.0f, 0.0f, 0.0f);
	Vec3 position, direction;
	Vec3 startPosition, endPosition;
	Vec3 startDirection, endDirection;
	int startWallIndex, endWallIndex;
	float ratio = 1.0f;
	
	Vec3 camDirection(cam->getDir().x, cam->getDir().z, 0.0f);
	Vec3 camPosition(cam->getEye().x, cam->getEye().z, 0.0f);
	float angle = getAngleBetween(camDirection, referenceDirection);
	
	if (camDirection.y > 0.0f)
	{
		// The camera is pointing in the upper quadrants
		if (angle < 90.0f)
		{
			//first quadrant
			ratio = angle / 90.0f;
			startWallIndex = 2;
			endWallIndex = 0;
		}
		else if (angle >= 90.0f && angle <= 180.0f)
		{
			//second quadrant
			ratio = (angle - 90.0f) / 90.0f;
			startWallIndex = 0;
			endWallIndex = 3;
		}
	}
	else
	{
		// The camera is pointing in the lower quadrants
		if (angle < 90.0f)
		{
			//fourth quadrant
			ratio = angle / 90.0f;
			startWallIndex = 2;
			endWallIndex = 1;
		}
		else if (angle >= 90.0f && angle <= 180.0f)
		{
			//third quadrant
			ratio = (angle - 90.0f) / 90.0f;
			startWallIndex = 1;
			endWallIndex = 3;
		}
	}
	
	// Find the two points in the world to interpolate between
	cam->lookAtWall(GLOBAL(Walls)[startWallIndex], startPosition, startDirection);
	cam->lookAtWall(GLOBAL(Walls)[endWallIndex], endPosition, endDirection);
	position = lerp(startPosition, endPosition, ratio);
	direction = lerp(startDirection, endDirection, ratio);

	return make_pair(position, direction);
}
コード例 #2
0
ファイル: testApp.cpp プロジェクト: damiannz/openFrameworks
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
	
	//let's move the camera when you move the mouse
	float rotateAmount = ofMap(ofGetMouseY(), 0, ofGetHeight(), 0, 360);

	
	//move the camera around the mesh
	ofVec3f camDirection(0,0,1);
	ofVec3f centre(vidGrabber.getWidth()/2.f,vidGrabber.getHeight()/2.f, 255/2.f);
	ofVec3f camDirectionRotated = camDirection.rotated(rotateAmount, ofVec3f(1,0,0));
	ofVec3f camPosition = centre + camDirectionRotated * extrusionAmount;
	
	cam.setPosition(camPosition);
	cam.lookAt(centre);
	
}
コード例 #3
0
int RotateDesktopGesture::getWallCameraIsFacing()
{
	Vec3 camDirection(cam->getDir().x, cam->getDir().z, 0.0f);
	Vec3 camPosition(cam->getEye().x, cam->getEye().z, 0.0f);
	Vec3 referenceDirection(-1.0f, 0.0f, 0.0f);

	float angle = getAngleBetween(camDirection, referenceDirection);
	Vec3 desktopDims = GetDesktopBox().GetExtents();
	
	if (camDirection.y > 0.0f)
	{
		float frontLeftAngle = getAngleBetween(Vec3(desktopDims.x, desktopDims.z, 0.0f) - camPosition, referenceDirection);
		float frontRightAngle = getAngleBetween(Vec3(-desktopDims.x, desktopDims.z, 0.0f) - camPosition, referenceDirection);
		if (angle < frontRightAngle)
		{
			return 2;
		}
		else if (angle >= frontRightAngle && angle < frontLeftAngle)
		{
			return 0;
		}
		else if (angle >= frontLeftAngle)
		{
			return 3;
		}
	}
	else
	{
		float backRightAngle = getAngleBetween(Vec3(-desktopDims.x, -desktopDims.z, 0.0f) - camPosition, referenceDirection);
		float backLeftAngle = getAngleBetween(Vec3(desktopDims.x, -desktopDims.z, 0.0f) - camPosition, referenceDirection);
		if (angle < backRightAngle)
		{
			return 2;
		}
		else if (angle >= backRightAngle && angle < backLeftAngle)
		{
			return 1;
		}
		else if (angle >= backLeftAngle)
		{
			return 3;
		}
	}
	return -1;
}
コード例 #4
0
//--------------------------------------------------------------
void testApp::update(){
	//grab a new frame
	vidGrabber.update();
	
	//update the mesh if we have a new frame
	if (vidGrabber.isFrameNew()){
		//this determines how far we extrude the mesh
		for (int i=0; i<vidGrabber.getWidth()*vidGrabber.getHeight(); i++){

			ofFloatColor sampleColor(vidGrabber.getPixels()[i*3]/255.f,				// r
									 vidGrabber.getPixels()[i*3+1]/255.f,			// g
									 vidGrabber.getPixels()[i*3+2]/255.f);			// b
			
			//now we get the vertex aat this position
			//we extrude the mesh based on it's brightness
			ofVec3f tmpVec = mainMesh.getVertex(i);
			tmpVec.z = sampleColor.getBrightness() * extrusionAmount;
			mainMesh.setVertex(i, tmpVec);

			mainMesh.setColor(i, sampleColor);
		}
	}
	
	//let's move the camera when you move the mouse
	float rotateAmount = ofMap(ofGetMouseY(), 0, ofGetHeight(), 0, 360);

	
	//move the camera around the mesh
	ofVec3f camDirection(0,0,1);
	ofVec3f centre(vidGrabber.getWidth()/2.f,vidGrabber.getHeight()/2.f, 255/2.f);
	ofVec3f camDirectionRotated = camDirection.rotated(rotateAmount, ofVec3f(1,0,0));
	ofVec3f camPosition = centre + camDirectionRotated * extrusionAmount;
	
	cam.setPosition(camPosition);
	cam.lookAt(centre);
}
コード例 #5
0
ファイル: ofApp.cpp プロジェクト: haotian91/CC-Lab-OF
//--------------------------------------------------------------
void ofApp::update() {
    
    float t = (ofGetElapsedTimef()) * 0.9f;
    float div = 250.0;
    
    for (int i=0; i<NUM_BILLBOARDS; i++) {
        
        // noise
        ofVec3f vec(ofSignedNoise(t, billboards.getVertex(i).y/div, billboards.getVertex(i).z/div),
                    ofSignedNoise(billboards.getVertex(i).x/div, t, billboards.getVertex(i).z/div),
                    ofSignedNoise(billboards.getVertex(i).x/div, billboards.getVertex(i).y/div, t));
        
        vec *= 10 * ofGetLastFrameTime();
        billboardVels[i] += vec;
        billboards.getVertices()[i] += billboardVels[i];
        billboardVels[i] *= 0.94f;
        billboards.setNormal(i,ofVec3f(12 + billboardSizeTarget[i] * ofNoise(t+i),0,0));
    }
    
    
    // move the camera around
    float mx = (float)mouseX/(float)ofGetWidth();
    float my = (float)mouseY/(float)ofGetHeight();
    ofVec3f des(mx * 360.0, my * 360.0, 0);
    cameraRotation += (des-cameraRotation) * 0.03;
    zoom += (zoomTarget - zoom) * 0.03;
    
    //grab a new frame
    vidGrabber.update();
    
    //update the mesh if we have a new frame
    if (vidGrabber.isFrameNew()){
        //this determines how far we extrude the mesh
        for (int i=0; i<vidGrabber.getWidth()*vidGrabber.getHeight(); i++){
            
            ofFloatColor sampleColor(vidGrabber.getPixels()[i*3]/255.f,				// r
                                     vidGrabber.getPixels()[i*3+1]/255.f,			// g
                                     vidGrabber.getPixels()[i*3+2]/255.f);			// b
            
            //now we get the vertex aat this position
            //we extrude the mesh based on it's brightness
            ofVec3f tmpVec = mainMesh.getVertex(i);
            tmpVec.z = sampleColor.getBrightness() * extrusionAmount;
            mainMesh.setVertex(i, tmpVec);
            
            mainMesh.setColor(i, sampleColor);
        }
    }
    
    //let's move the camera when you move the mouse
    float rotateAmount = ofMap(ofGetMouseY(), 0, ofGetHeight(), 0, 360);
    
    
    //move the camera around the mesh
    ofVec3f camDirection(0,0,1);
    ofVec3f centre(vidGrabber.getWidth()/2.f,vidGrabber.getHeight()/2.f, 255/2.f);
    ofVec3f camDirectionRotated = camDirection.rotated(rotateAmount, ofVec3f(1,0,0));
    ofVec3f camPosition = centre + camDirectionRotated * extrusionAmount;
    
    cam.setPosition(camPosition);
    cam.lookAt(centre);

    
}