Ejemplo n.º 1
0
//--------------------------------------------------------------
CubeMapping::CubeMapping(){
    
    title="CubeMapping";
    
    shader.load("shaders/"+title);
    texture[0].load("textures/cubeMap/right.png");
    texture[1].load("textures/cubeMap/top.png");
    texture[2].load("textures/cubeMap/back.png");
    texture[3].load("textures/cubeMap/left.png");
    texture[4].load("textures/cubeMap/bottom.png");
    texture[5].load("textures/cubeMap/front.png");
    
    cube.set(100, 100, 100);
    cube.enableNormals();
    //sphere.mapTexCoordsFromTexture(texture[0].getTexture());
    
    cam.setDistance(250);
    
    
    gui.setup(title,"gui/"+title+".xml");
    gui.add(lightPos.set("lightPosition", ofVec3f(0,0,0), ofVec3f(-800,-800,-800), ofVec3f(800,800,800)));
    gui.add(baseColor.set("baseColor", ofVec3f(10,90,0), ofVec3f(0,0,0), ofVec3f(255,255,255)));
    gui.add(mixRatio.set("mixRatio", 0.5,0.0,1.0));
    gui.loadFromFile("gui/"+title+".xml");
    
   
    textureObjectID=1;
 
    //_ofEnable( GL_TEXTURE_CUBE_MAP_SEAMLESS );
    
    //create a texture object
  
    glGenTextures(1, &textureObjectID);
    glBindTexture(GL_TEXTURE_CUBE_MAP, textureObjectID);
    
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    
#ifndef TARGET_OPENGLES
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); // GL_TEXTURE_WRAP_R is not in the ES2 header, hmm..
#endif
    
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    
    
    unsigned char * data_px, * data_nx, * data_py, * data_ny, * data_pz, * data_nz;
    
    size = texture[0].getWidth();
    
    //cout << "ofxCubeMap::loadFromOfImages, size: " << size << "  bpp: " << pos_x.bpp << endl;
    
    //	data_px = new unsigned char [size * size * 3];
    //	data_py = new unsigned char [size * size * 3];
    //	data_pz = new unsigned char [size * size * 3];
    
    //	data_nx = new unsigned char [size * size * 3];
    //	data_ny = new unsigned char [size * size * 3];
    //	data_nz = new unsigned char [size * size * 3];
    
    data_px =  texture[0].getPixels();
    data_py =  texture[1].getPixels();
    data_pz =  texture[2].getPixels();
    
    data_nx =  texture[3].getPixels();
    data_ny =  texture[4].getPixels();
    data_nz =  texture[5].getPixels();

    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_px); // positive x
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_py); // positive y
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_pz); // positive z
    
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_nx); // negative x
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_ny); // negative y
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data_nz); // negative z
    
    
    //ofScale( _size, _size, _size );
    //ofScale( _size / 2.0f, _size / 2.0f, _size / 2.0f );
    
    float fExtent = 1.0f / 2.0f;
    
    
    
}
Ejemplo n.º 2
0
 ofVec3f toOf(glm::vec3 v){
     return ofVec3f(v.x, v.y, v.z);
 }
Ejemplo n.º 3
0
//--------------------------------------------------------------
bool ofxBulletCustomShape::addMesh( ofMesh a_mesh, ofVec3f a_localScaling, bool a_bUseConvexHull ) {
	if(a_mesh.getMode() != OF_PRIMITIVE_TRIANGLES) {
		ofLog( OF_LOG_ERROR, "ofxBulletCustomShape :: addMesh : mesh must be set to OF_PRIMITIVE_TRIANGLES!! aborting");
		return false;
	}
	if(_bAdded == true) {
		ofLog( OF_LOG_ERROR, "ofxBulletCustomShape :: addMesh : can not call after calling add()" );
		return false;
	}
	
	btVector3 localScaling( a_localScaling.x, a_localScaling.y, a_localScaling.z );
	vector <ofIndexType>	indicies = a_mesh.getIndices();
	vector <ofVec3f>		verticies = a_mesh.getVertices();
	
	btVector3 centroid = btVector3(0, 0, 0);
	
	if(!a_bUseConvexHull) {
		for(int i = 0; i < verticies.size(); i++) {
			btVector3 tempVec = btVector3(verticies[i].x, verticies[i].y, verticies[i].z);
			tempVec *= localScaling;
			centroid += tempVec;
		}
		centroid /= (float)verticies.size();
		
		vector<btVector3> newVerts;
		for ( int i = 0; i < indicies.size(); i++) {
			btVector3 vertex( verticies[indicies[i]].x, verticies[indicies[i]].y, verticies[indicies[i]].z);
			vertex *= localScaling;
			vertex -= centroid;
			newVerts.push_back(vertex);
		}
		
		btConvexHullShape* convexShape = new btConvexHullShape(&(newVerts[0].getX()), newVerts.size());
		convexShape->setMargin( 0.01f );
		shapes.push_back( convexShape );
		centroids.push_back( ofVec3f(centroid.getX(), centroid.getY(), centroid.getZ()) );
	} else {
		// HULL Building code from example ConvexDecompositionDemo.cpp //
		btTriangleMesh* trimesh = new btTriangleMesh();
		
		for ( int i = 0; i < indicies.size()/3; i++) {
			int index0 = indicies[i*3];
			int index1 = indicies[i*3+1];
			int index2 = indicies[i*3+2];
			
			btVector3 vertex0( verticies[index0].x, verticies[index0].y, verticies[index0].z );
			btVector3 vertex1( verticies[index1].x, verticies[index1].y, verticies[index1].z );
			btVector3 vertex2( verticies[index2].x, verticies[index2].y, verticies[index2].z );
			
			vertex0 *= localScaling;
			vertex1 *= localScaling;
			vertex2 *= localScaling;
			
			trimesh->addTriangle(vertex0, vertex1, vertex2);
		}
		
		//cout << "ofxBulletCustomShape :: addMesh : input triangles = " << trimesh->getNumTriangles() << endl;
		//cout << "ofxBulletCustomShape :: addMesh : input indicies = " << indicies.size() << endl;
		//cout << "ofxBulletCustomShape :: addMesh : input verticies = " << verticies.size() << endl;
		
		btConvexShape* tmpConvexShape = new btConvexTriangleMeshShape(trimesh);
		
		//create a hull approximation
		btShapeHull* hull = new btShapeHull(tmpConvexShape);
		btScalar margin = tmpConvexShape->getMargin();
		hull->buildHull(margin);
		tmpConvexShape->setUserPointer(hull);
		
		centroid = btVector3(0., 0., 0.);
		for (int i = 0; i < hull->numVertices(); i++) {
			centroid += hull->getVertexPointer()[i];
		}
		centroid /= (float)hull->numVertices();
		
		//printf("ofxBulletCustomShape :: addMesh : new hull numTriangles = %d\n", hull->numTriangles());
		//printf("ofxBulletCustomShape :: addMesh : new hull numIndices = %d\n", hull->numIndices());
		//printf("ofxBulletCustomShape :: addMesh : new hull numVertices = %d\n", hull->numVertices());
		
		btConvexHullShape* convexShape = new btConvexHullShape();
		for (int i=0;i<hull->numVertices();i++) {
			convexShape->addPoint(hull->getVertexPointer()[i] - centroid);
		}
		
		delete tmpConvexShape;
		delete hull;
		
		shapes.push_back( convexShape );
		centroids.push_back( ofVec3f(centroid.getX(), centroid.getY(), centroid.getZ()) );
	}
	return true;
}
Ejemplo n.º 4
0
void ofApplication::processOscMessages()
{
    while (oscIn.hasWaitingMessages())
    {
        ofxOscMessage m;
        oscIn.getNextMessage(&m);
        
        string a = m.getAddress();
        
        // ------ FLAGS/SWITCHES -------
        if (a == "/oF/drawUser/")
        {
            bDrawUserOutline = m.getArgAsFloat(0) != 0.0f;
        }
        else if (a == "/of/drawUserTrails")
        {
            bTrailUserOutline = m.getArgAsFloat(0) != 0.0f;
        }
        else if (a == "/oF/drawPoi")
        {
            bDrawPoi = m.getArgAsFloat(0) != 0.0f;
        }
        else if (a == "/oF/drawPoiTrails")
        {
            bTrailPoi = m.getArgAsFloat(0) != 0.0f;
        }
        
        // ------- BACKGROUND ---------
        else if (a == "/oF/bgBrightFade")
        {
            bgBrightnessFade = m.getArgAsFloat(0);
        }
        else if (a == "/oF/bgSpotSize")
        {
            bgSpotRadius = ofMap(m.getArgAsFloat(0), 0.0f, 1.0f, 1.0f, ofGetHeight(), true);
        }
        
        // ------- USER OUTLINE -------
        else if (a == "/oF/drawUser")
        {
            bDrawUserOutline = m.getArgAsFloat(0) != 0.0f;
        }
        else if (a == "/oF/drawUserTrails")
        {
            bTrailUserOutline = m.getArgAsFloat(0) != 0.0f;
        }
        
        // -------- POI --------
        else if (a == "/oF/poiHue")
        {
            poiSpriteColorHSB.h = ofMap(m.getArgAsFloat(0), 0.0f, 1.0f, 0.0f, 254.0f, true);
        }
        
        // ------- TOUCH PAD ------
        else if (a.find("/oF/multiPad/") != string::npos)
        {
            handleTouchPadMessage(m);
        }
        
        // ------- EFFECTS ------
        
        else if (a == "/oF/strobeRate")
        {
            strobeIntervalMs = ofMap(m.getArgAsFloat(0), 0.0f, 1.0f, 10.0f, 250.0f, true);
        }
        else if (a == "/oF/trailVelocity")
        {
            // swap X and Y from touchOSC in landscape
            trailVelocity.set(ofVec3f(m.getArgAsFloat(1),m.getArgAsFloat(0))*300.0f);
        }
        else if (a == "/oF/trailZoom")
        {
            float oscv = m.getArgAsFloat(0);
            trailZoom = powf(fabs(oscv), 3.0f) * (oscv >= 0.0f ? 1.0f : -1.0f) * 10.0f;
        }
        else if (a == "/oF/trailAlphaFade")
        {
            trailAlphaDecay = toOnePoleTC(m.getArgAsFloat(0), 10, 10000);
        }
        else if (a == "/oF/trailColorFade")
        {
            trailColorDecay = toOnePoleTC(m.getArgAsFloat(0), 10, 10000);
        }
        else if (a == "/oF/trailMinAlpha")
        {
            trailMinAlpha = ofMap((float)m.getArgAsFloat(0), 0.0f, 1.0f, 0.02f, 0.15f);
        }
        
        // ------- AUDIO SENSITIVITY ------
        else if (a == "/oF/audioSensitivity")
        {
            audioSensitivity = ofMap(m.getArgAsFloat(0), 0.0f, 1.0f, 0.5f, 2.0f, true);
        }
    }
}
//--------------------------------------------------------------
//
//  Used to draw the faces to screen in 2D, usually to debug.
//	The code would look something like:
//
//  for( int i = 0; i < 6; i++ )
//  {
// 	   myFboCubeMap.drawFace( GL_TEXTURE_CUBE_MAP_POSITIVE_X + i , i * 100, 0, 100, 100 );
//  }
//
void ofxCubeMap::drawFace( GLuint _face, float _x, float _y, float _w, float _h )
{
	// create a rect with the correct 3D texture coordinates, draw to screen
	scratchVertices.clear();
	scratchTexCoords.clear();
	scratchIndices.clear();
	
	switch ( _face )
	{
		case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
			
			scratchTexCoords.push_back( ofVec3f( 1.0f, -1.0f,  1.0f) );
			scratchTexCoords.push_back( ofVec3f( 1.0f,  1.0f,  1.0f) );
			scratchTexCoords.push_back( ofVec3f( 1.0f,  1.0f, -1.0f) );
			scratchTexCoords.push_back( ofVec3f( 1.0f, -1.0f, -1.0f) );
			
			break;
			
		case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
			
			scratchTexCoords.push_back( ofVec3f( -1.0f, -1.0f, -1.0f) );
			scratchTexCoords.push_back( ofVec3f( -1.0f,  1.0f, -1.0f) );
			scratchTexCoords.push_back( ofVec3f( -1.0f,  1.0f,  1.0f) );
			scratchTexCoords.push_back( ofVec3f( -1.0f, -1.0f,  1.0f) );
			
			break;
			
		case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
			
			scratchTexCoords.push_back( ofVec3f( -1.0f,  1.0f,  1.0f) );
			scratchTexCoords.push_back( ofVec3f( -1.0f,  1.0f, -1.0f) );
			scratchTexCoords.push_back( ofVec3f(  1.0f,  1.0f, -1.0f) );
			scratchTexCoords.push_back( ofVec3f(  1.0f,  1.0f,  1.0f) );
			
			break;
			
		case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
			
			scratchTexCoords.push_back( ofVec3f( -1.0f, -1.0f, -1.0f) );
			scratchTexCoords.push_back( ofVec3f( -1.0f, -1.0f,  1.0f) );
			scratchTexCoords.push_back( ofVec3f(  1.0f, -1.0f,  1.0f) );
			scratchTexCoords.push_back( ofVec3f(  1.0f, -1.0f, -1.0f) );
			
			break;
			
		case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
			
			scratchTexCoords.push_back( ofVec3f( -1.0f, -1.0f,  1.0f) );
			scratchTexCoords.push_back( ofVec3f( -1.0f,  1.0f,  1.0f) );
			scratchTexCoords.push_back( ofVec3f(  1.0f,  1.0f,  1.0f) );
			scratchTexCoords.push_back( ofVec3f(  1.0f, -1.0f,  1.0f) );
			
			break;
			
		case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
			
			scratchTexCoords.push_back( ofVec3f(  1.0f, -1.0f, -1.0f) );
			scratchTexCoords.push_back( ofVec3f(  1.0f,  1.0f, -1.0f) );
			scratchTexCoords.push_back( ofVec3f( -1.0f,  1.0f, -1.0f) );
			scratchTexCoords.push_back( ofVec3f( -1.0f, -1.0f, -1.0f) );
			
			break;
			
		default:
			
			ofLogError() << "ofxCubeMap::drawFace, passed in invalid face.";
			
			break;
	}
	
	scratchVertices.push_back( ofVec3f( _x, 		_y + _h, 	0.0f ) );
	scratchVertices.push_back( ofVec3f( _x, 		_y, 		0.0f ) );
	scratchVertices.push_back( ofVec3f( _x + _w, 	_y, 		0.0f ) );
	scratchVertices.push_back( ofVec3f( _x + _w, 	_y + _h, 	0.0f ) );
	
	scratchIndices.push_back( 0 );
	scratchIndices.push_back( 1 );
	scratchIndices.push_back( 2 );
	
	scratchIndices.push_back( 0 );
	scratchIndices.push_back( 2 );
	scratchIndices.push_back( 3 );
	
	// swap all this for an ofMesh when it supports ofVec3f tex coordinates
	
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer( 	3, GL_FLOAT, sizeof(ofVec3f), &scratchVertices.data()->x );
	
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glTexCoordPointer( 	3, GL_FLOAT, sizeof(ofVec3f), &scratchTexCoords.data()->x );
	
	bind();
	
#ifdef TARGET_OPENGLES
	glDrawElements( GL_TRIANGLES, scratchIndices.size(), GL_UNSIGNED_SHORT, 	scratchIndices.data() );
#else
	glDrawElements( GL_TRIANGLES, scratchIndices.size(), GL_UNSIGNED_INT, 		scratchIndices.data() );
#endif
	
	unbind();
	
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	
}
Ejemplo n.º 6
0
// ------------------------------------------------------------------------------------------------------
//
void ofApp::setup()
{
	ofBackground( ofColor::white );
	
	ofSetLogLevel(OF_LOG_VERBOSE);
	
	fontSmall.loadFont("Fonts/DIN.otf", 8 );
	
	currAppMode = APP_MODE_LIVE;

	ofxGuiSetFont( "Fonts/DIN.otf", 8 );
	ofxGuiSetDefaultWidth( 260 );

	// Set up UI
	string xmlSettingsPath = "Settings/Main.xml";
	gui.setup( "Main", xmlSettingsPath );
	
	gui.add( kinectPointCloudScale.set( "Kinect Point Cloud Scale", 0.05, 0.0, 1.0 ) );
	gui.add( kinectPointCloudOffset.set( "Kinect Point Cloud Offset", ofVec3f(0,0,0), ofVec3f(-500,-500,-500), ofVec3f(500,500,500) ) );
	
	gui.add( globalAmbient.set("Global Ambient", ofColor(50,50,50), ofColor(0,0,0,0), ofColor(255,255,255,255)) );
	gui.add( light1Position.set( "Light 1 Position", ofVec3f(-5,50,0), ofVec3f(-200,0,-200), ofVec3f(200,400,200) ) );
	gui.add( light1Diffuse.set("Light 1 Diffuse",   ofColor(50,50,50), ofColor(0,0,0,0), ofColor(255,255,255,255)) );
	gui.add( light1Ambient.set("Light 1 Ambient",   ofColor(50,50,50), ofColor(0,0,0,0), ofColor(255,255,255,255)) );
	gui.add( light1Specular.set("Light 1 Specular", ofColor(255,255,255), ofColor(0,0,0,0), ofColor(255,255,255,255)) );

	gui.add( drawPointCloud.set( "Draw Point Cloud", false ) );

	//gui.add( testPos.set( "Test Pos", ofVec3f(-5,50,0), ofVec3f(-200,0,-200), ofVec3f(200,400,200) ) );

	gui.loadFromFile( xmlSettingsPath );
	gui.minimizeAll();
	
	kinectManager.init();
	
	particles.init(); // number of particles is (texSize * texSize)
	
	ofVec2f guiPos = gui.getPosition();
	particles.gui.setPosition( guiPos + ofVec2f( gui.getWidth() + 10, 0) );
	
	// Give us a starting point for the camera
	camera.setNearClip( 0.01f );
	camera.setPosition( 0, 50, 100.0 );
	camera.setMovementMaxSpeed( 1.0f );
	
	pointCloudMesh.setMode( OF_PRIMITIVE_POINTS );
	
	time = 0.0f;
	timeStep = 1.0f / 60.0f;
	
	light[0].enable();

	opticalFlowDebugDrawer.init();
	opticalFlowDebugDrawer.getGui()->setPosition( gui.getPosition() + ofVec2f( 0, gui.getHeight() + 10) );
	
	ofSetLogLevel(OF_LOG_NOTICE);
	
	drawUI = false;
	
	//ofHideCursor();
}
//--------------------------------------------------------------
static inline ofVec3f aiVecToOfVec(const aiVector3D& v){
	return ofVec3f(v.x,v.y,v.z);
}
Ejemplo n.º 8
0
//--------------------------------------------------------------
ofVec3f ofxBulletWorldSoft::getGravity() {
	if(!checkWorld()) return ofVec3f(0,0,0);
	btVector3 g = world->getGravity();
	return ofVec3f(g.getX(), g.getY(), g.getZ());
}
Ejemplo n.º 9
0
void ofCairoRenderer::setupScreenPerspective(float width, float height, ofOrientation orientation, bool vFlip, float fov, float nearDist, float farDist){
	if(!b3D) return;
	if(width == 0) width = ofGetWidth();
	if(height == 0) height = ofGetHeight();
	if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation();

	float viewW = ofGetViewportWidth();
	float viewH = ofGetViewportHeight();

	float eyeX = viewW / 2;
	float eyeY = viewH / 2;
	float halfFov = PI * fov / 360;
	float theTan = tanf(halfFov);
	float dist = eyeY / theTan;
	float aspect = (float) viewW / viewH;

	if(nearDist == 0) nearDist = dist / 10.0f;
	if(farDist == 0) farDist = dist * 10.0f;

	projection.makePerspectiveMatrix(fov,aspect,nearDist,farDist);
	modelView.makeLookAtViewMatrix(ofVec3f(eyeX,eyeY,dist),ofVec3f(eyeX,eyeY,0),ofVec3f(0,1,0));


	//note - theo checked this on iPhone and Desktop for both vFlip = false and true
	switch(orientation) {
		case OF_ORIENTATION_180:
			modelView.glRotate(-180,0,0,1);
			if(vFlip){
				modelView.glScale(-1,-1,1);
				modelView.glTranslate(width,0,0);
			}else{
				modelView.glTranslate(width,-height,0);
			}

			break;

		case OF_ORIENTATION_90_RIGHT:
			modelView.glRotate(-90,0,0,1);
			if(vFlip){
				modelView.glScale(1,1,1);
			}else{
				modelView.glScale(1,-1,1);
				modelView.glTranslate(-width,-height,0);
			}
			break;

		case OF_ORIENTATION_90_LEFT:
			modelView.glRotate(90,0,0,1);
			if(vFlip){
				modelView.glScale(1,1,1);
				modelView.glTranslate(0,-height,0);
			}else{

				modelView.glScale(1,-1,1);
				modelView.glTranslate(0,0,0);
			}
			break;

		case OF_ORIENTATION_DEFAULT:
		default:
			if(vFlip){
				modelView.glScale(-1,-1,1);
				modelView.glTranslate(-width,-height,0);
			}
			break;
	}
};
//---------------------------------
void GeneratedMesh::setup(ofxBulletWorldRigid &world, ofVec3f position, string url, ofVec3f ModelScale){
    type = ShapeTypeAnimatedMesh;
    collisionTime = -120;
    ModelPath = url;
    this->position = position;
    this->world = &world;
	
    //rotation = btQuaternion(btVector3(0,1,0), ofDegToRad(-90));
    
    //TODO to try with ofBtGetCylinderCollisionShape, for improve collision detection
    
    
    anisotropy = 4.;
    
    float fboDiv = 4.f;
    //    ofSetMinMagFilters( GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR );
    fbo.allocate( (float)ofGetWidth() / fboDiv, (float)ofGetWidth() / fboDiv, GL_RGB, 4 );
    fbo.begin(); {
        ofClear(0, 0, 0, 255 );
        ofSetColor( 11,90,121, 255);
        ofRect(0, 0, ofGetWidth(), ofGetHeight() );
        ofSetColor(120, 140, 150, 255);
        
        int numIterations = 4;
        float inc = (float)fbo.getWidth() / ((float)numIterations);
        for( int i = 0; i < numIterations; i++ ) {
            float tx = (float)i*inc + inc;
            float ty = (float)i*inc + inc;
            
            ofSetColor(152,197,190, 255);
            ofSetLineWidth( 1.5 );
            if( i % 2 == 0 ) ofSetLineWidth( 0.5 );
            
            ofLine( tx, 0, tx, fbo.getHeight() );
            ofLine( 0, ty, fbo.getWidth(), ty );
        }
        
    } fbo.end();
    
    ofSetLineWidth( 1 );
    
    fbo.getTextureReference().bind();
    glGenerateMipmap( fbo.getTextureReference().texData.textureTarget);
    ofSetMinMagFilters( GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR );
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);
    //    glSamplerParameterf( fbo.getTextureReference().texData.textureTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2 );
    fbo.getTextureReference().unbind();

    
    omesh = ofMesh::plane( 70, 70, 14, 14, OF_PRIMITIVE_TRIANGLES );
    ofQuaternion rquat;
    rquat.makeRotate( 90, 1, 0, 0);
    ofSeedRandom();
    float rseed = ofRandom(0, 10000);
    vector< ofVec3f >& verts = omesh.getVertices();
    for( int i = 0; i < verts.size(); i++ ) {
        verts[i] = rquat * verts[i];
        verts[i].y = ofSignedNoise( verts[i].x*0.02, verts[i].y*0.02 + verts[i].z*0.02, ofGetElapsedTimef() * 0.1 + rseed ) * 3;
    }
    
    vector< ofVec2f >& tcoords = omesh.getTexCoords();
    for( int i = 0; i < tcoords.size(); i++ ) {
        tcoords[i].x *= 4.f;
        tcoords[i].y *= 4.f;
    }
    mesh = omesh;
    
    
    //ofEnableSeparateSpecularLight();
    
	//save init values
	initScale = scale;
    // create ofxBullet shape
    //body.create(world.world, position, 0); // we set m=0 for kinematic body
    body.create( world.world, mesh, position, 0.f, ofVec3f(-10000, -10000, -10000), ofVec3f(10000,10000,10000) );
    body.add();
    body.enableKinematic();
    body.setActivationState( DISABLE_DEACTIVATION );
    
    
    bAnimate = true;

    body.add();
    
	
    //body.setProperties(1., 0.); // .25 (more restituition means more energy) , .95 ( friction )
    // to add force to the ball on collision set restitution to > 1
	
	body.setProperties(3, .95); // restitution, friction
	body.setDamping( .25 );
    
	
	//Set Rotation Objects
	setupRot();
	
    body.activate();
	
	setDefaultZ();
    

    
    
    
}
Ejemplo n.º 11
0
void Particle::applyForce(float x, float y)
{
	applyForce( ofVec3f(x, y) );
}
Ejemplo n.º 12
0
void Particles::setup(){

    settings.setName("Particles");
    
    
    
    
    noReset = false;
  
#ifdef PIMG
    int partRes = 100 ;
//    partImg.allocate(partRes,partRes,OF_IMAGE_COLOR_ALPHA);
    ofVec2f center(partRes/2);
//    for(int i = 0 ; i<partRes;i++){
//        for(int j = 0 ; j<partRes;j++){
//            ofVec2f curp(i,j);
//            ofColor cc(0,0,255*max(0.,1-curp.distance(center)*1.0/partRes),255);
//            partImg.setColor(i,j,cc);
//        }
//    }

    partImg.loadImage("photos/fire.jpg");

#endif


    //GLOBAL
    
    
    settings.setName("particles");
    
    
    MYPARAM(timeStep , 1.f,0.f,30.f);

    
    MYPARAM(numParticles , 100000,100,1000000);
    lastnumParticles = numParticles;
    
    //Appearence
    MYPARAM(particleSize, 3.0f,0.f,30.f);
    MYPARAM(alphaColor,255,0,255);
    MYPARAM(color, ofVec3f(0,0,1.),ofVec3f(0.),ofVec3f(255.));
    MYPARAM(gradtype , 2,0,3);
    MYPARAM(gradNum,0,0,20);
    MYPARAM(mingrad,0.f,-1.f,1.f);
    MYPARAM(maxgrad,1,-1.f,3.f);
    MYPARAM(map2blob,true,false,true);

#ifdef PMOD
    MYPARAM(origintype,1,0,2);

#endif
    


    forces.push_back(new Force("netw"));
    forces[forces.size()-1]->addParameter("k",.030f,0.f,.2f);
    forces[forces.size()-1]->addParameter("l0",1.0f,0.f,20.0f);
    forces[forces.size()-1]->addParameter("l0max",1.0f,0.f,20.0f);
    forces[forces.size()-1]->addParameter("z",.0f,0.f,2.f);
    forces[forces.size()-1]->addParameter("size",2,1,10);
    
    forces.push_back(new Force("neth"));
    forces[forces.size()-1]->addParameter("k",.030f,0.f,.2f);
    forces[forces.size()-1]->addParameter("l0",1.0f,0.f,20.f);
    forces[forces.size()-1]->addParameter("l0max",1.0f,0.f,20.0f);
    forces[forces.size()-1]->addParameter("z",.0f,0.f,2.f);
    forces[forces.size()-1]->addParameter("size",2,1,10);
    
    forces.push_back(new Force("origin"));
    forces[forces.size()-1]->addParameter("k",.10f,0.f,.25f);
    forces[forces.size()-1]->addParameter("z",.01f,0.f,.5f);
    forces[forces.size()-1]->addParameter("freeze",0.f,0.f,.80f);
    forces[forces.size()-1]->addParameter("freezemin",0.f,0.f,.30f);
    forces[forces.size()-1]->addParameter("damp",0.9f,0.5f,1.0f);
    
    forces.push_back(new Force("rotation",true));
    forces[forces.size()-1]->addParameter("type",0,0,1);
    forces[forces.size()-1]->addParameter("r",0.2f,0.f,.5f);
    forces[forces.size()-1]->addParameter("speed",0.f,0.f,0.5f);
    forces[forces.size()-1]->addParameter("orientation",ofVec3f(0,1,0),ofVec3f(0),ofVec3f(1));
    
    forces.push_back(new Force("gravity",true));
    forces[forces.size()-1]->addParameter("r",.50f,0.f,.5f);
    forces[forces.size()-1]->addParameter("mass",.001f,-.0002f,.02f);
    forces[forces.size()-1]->addParameter("rin",.50f,0.f,.5f);
    forces[forces.size()-1]->addParameter("massin",.00f,-.0002f,.0002f);
    forces[forces.size()-1]->addParameter("damp",1.f,.60f,1.0f);

    forces.push_back(new Force("smoothyGrav",true));
    forces[forces.size()-1]->addParameter("r",.50f,0.f,1.f);
    forces[forces.size()-1]->addParameter("mass",.1f,-.2f,.5f);
    forces[forces.size()-1]->addParameter("rin",.50f,0.f,.5f);
    forces[forces.size()-1]->addParameter("minattr",.0f,-.2f,.2f);
    forces[forces.size()-1]->addParameter("damp",1.f,.60f,1.0f);

    
    forces.push_back(new Force("spring",true));
    forces[forces.size()-1]->addParameter("k",.030f,-.2f,1.f);
    forces[forces.size()-1]->addParameter("l0",.010f,0.f,.1f);
    forces[forces.size()-1]->addParameter("z",.0f,-.5f,.5f);    
    forces[forces.size()-1]->addParameter("mode",1,0,1);
    
    forces.push_back(new Force("fieldForce"));
    forces[forces.size()-1]->addParameter("k",.030f,-.3f,.3f);
    forces[forces.size()-1]->addParameter("velouty",.030f,-.1f,.1f);
    forces[forces.size()-1]->addParameter("veloutz",.030f,-.1f,.1f);
    forces[forces.size()-1]->addParameter("veloutborder",.00f,-.1f,.1f);
    forces[forces.size()-1]->addParameter("minv",.10f,0.f,1.f);
    forces[forces.size()-1]->addParameter("maxv",.80f,0.f,1.f);
    forces[forces.size()-1]->addParameter("fin",1.f,0.5f,1.3f);
    forces[forces.size()-1]->addParameter("fout",1.f,0.5f,1.3f);
    
    
    forces.push_back(new Force("globalForce"));
    forces[forces.size()-1]->addParameter("f",1.f,0.8f,1.f);
    forces[forces.size()-1]->addParameter("fmin",1.f,0.f,1.3f);
    forces[forces.size()-1]->addParameter("vmax",1.0f,0.f,1.f);
    forces[forces.size()-1]->addParameter("vmin",.0f,0.f,1.f);


    
    

    


    

}
Ejemplo n.º 13
0
void Particles::initFbo(int w,int h){
    
    // Seting the textures where the information ( position and velocity ) will be
//    textureResx*textureResy = numParticles;
//    textureResx/textureResy = scrw/scrh;
 
    textureRes2.x = (int)sqrt((float)numParticles* w/ h);
    textureRes2.y = (int)numParticles/textureRes2.x;
    
    textureRes = (int)sqrt((float)numParticles);
    numParticles = textureRes* textureRes;
    
    // Load this information in to the FBO´s texture
if(!noReset){
        posPingPong.allocate(textureRes, textureRes,GL_RGB32F);

    
    // Load this information in to the FBO´s texture
    velPingPong.allocate(textureRes, textureRes,GL_RGB32F);
    origins.allocate(textureRes, textureRes,GL_RGB32F);
    
    
    // 1. Making arrays of float pixels with position information
    float * pos = new float[numParticles*3];
    for (int x = 0; x < textureRes; x++){
        for (int y = 0; y < textureRes; y++){
            int i = textureRes * y + x;
            
            pos[i*3 + 0] = x*1.0/textureRes;
            pos[i*3 + 1] = y*1.0/(textureRes);
            pos[i*3 + 2] = 0.5;
        }
    }
    

    posPingPong.src->getTextureReference().loadData(pos, textureRes, textureRes, GL_RGB);
    posPingPong.dst->getTextureReference().loadData(pos, textureRes, textureRes, GL_RGB);
       
    
    origins.getTextureReference().loadData(pos, textureRes, textureRes, GL_RGB);
    
    delete [] pos;    // Delete the array
    
    
    
    
    
    // 2. Making arrays of float pixels with velocity information and the load it to a texture
    float * vel = new float[numParticles*3];
    for (int i = 0; i < numParticles; i++){
        vel[i*3 + 0] = 0.0;
        vel[i*3 + 1] = 0.0;
        vel[i*3 + 2] = 0.0;//i*1.0/numParticles ;
    }

    velPingPong.src->getTextureReference().loadData(vel, textureRes, textureRes, GL_RGB);
    velPingPong.dst->getTextureReference().loadData(vel, textureRes, textureRes, GL_RGB);
    delete [] vel; // Delete the array
    

    }
    else{
        
            posPingPong.src->allocate(textureRes, textureRes,GL_RGB32F);
            posPingPong.src->begin();
            posPingPong.dst->draw(0,0);
            posPingPong.src->end();
            posPingPong.dst->allocate(textureRes,textureRes,GL_RGB32F);
       
    }
    partVbo.clear();
    partVbo.disableColors();
    partVbo.disableNormals();
    partVbo.disableTexCoords();
    partVbo.disableIndices();
    vector<ofVec3f> initPos (numParticles);
    for(int x = 0 ; x < textureRes ; x++){
        for(int y = 0 ; y < textureRes ; y++){
            initPos[x*textureRes+y] = ofVec3f(x,y,0);
        }
    }
    partVbo.setVertexData(&initPos[0],numParticles,GL_STATIC_DRAW);

 
}
Ejemplo n.º 14
0
void CloudsRGBDVideoPlayer::swapAndPlay(){

    if(!clipPrerolled){
        ofLogError("CloudsRGBDVideoPlayer::swapAndPlay") << "No clip prerolled for swap";
        return;
    }
    
	cout << "*** SWAPPING CLIP" << endl;

	if(!nextClipIsVO){
		
		ofxXmlSettings XML;
		if ( !XML.loadFile(nextCalibrationXML) ){
			ofLogError("CloudsRGBDVideoPlayer::setup") << "XML Path " << nextCalibrationXML << " failed to load";
			return;
		}
		
		colorPrincipalPoint.x = XML.getValue("colorIntrinsics:ppx", 971.743835449);
		colorPrincipalPoint.y = XML.getValue("colorIntrinsics:ppy", 546.945983887);
		colorFOV.x = XML.getValue("colorIntrinsics:fovx", 923.500793457);
		colorFOV.y = XML.getValue("colorIntrinsics:fovy", 921.060791016);
		colorRect.x = 0.0f;
		colorRect.y = 0.0f;
		colorRect.width = XML.getValue("colorIntrinsics:width", 1920.000000000);
		colorRect.height = XML.getValue("colorIntrinsics:height", 1080.000000000);
		
		float depthToRGBRotation[9];
		float depthToRGBTranslation[3];
		for (int i = 0; i < 9; i++) {
			depthToRGBRotation[i] = XML.getValue("extrinsics:rotation:r"+ofToString(i), 1.0f);
		}
		
		for (int i = 0; i < 3; i++) {
			depthToRGBTranslation[i] = XML.getValue("extrinsics:translation:t"+ofToString(i), 1.0f);
		}
		
		for (int i = 0; i < 3; i++) {
			distortionK[i] = XML.getValue("colorIntrinsics:dK:k"+ofToString(i), 1.0f);
		}
		
		for (int i = 0; i < 2; i++) {
			distortionP[i] = XML.getValue("colorIntrinsics:dP:p"+ofToString(i), 1.0f);
		}
		
		headPosition = ofVec3f(-XML.getValue("face:x", 0.0),
							   -XML.getValue("face:y", 0.0),
							    XML.getValue("face:z", 0.0));
		
		//cout << "head position " << headPosition << endl;
		
		float mat4x4[16] = {
			depthToRGBRotation[0],depthToRGBRotation[1],depthToRGBRotation[2],0,
			depthToRGBRotation[3],depthToRGBRotation[4],depthToRGBRotation[5],0,
			depthToRGBRotation[6],depthToRGBRotation[7],depthToRGBRotation[8],0,
			depthToRGBTranslation[0],depthToRGBTranslation[1],depthToRGBTranslation[2],1
		};
		
		extrinsics = ofMatrix4x4(mat4x4);
		
		//	cout << "extrinsic matrix: " << endl << extrinsics << endl;
		
		//adjustment
		adjustTranslate.x = XML.getValue("adjustment:translate:x", 0.0);
		adjustTranslate.y = XML.getValue("adjustment:translate:y", 0.0);
		adjustTranslate.z = XML.getValue("adjustment:translate:z", 0.0);
		
		adjustRotate.x = XML.getValue("adjustment:rotate:x", 0.0);
		adjustRotate.y = XML.getValue("adjustment:rotate:y", 0.0);
		adjustRotate.z = XML.getValue("adjustment:rotate:z", 0.0);
		
		adjustScale.x = XML.getValue("adjustment:scale:x", 1.0);
		adjustScale.y = XML.getValue("adjustment:scale:y", 1.0);
		
		depthPrincipalPoint.x = XML.getValue("depthIntrinsics:ppx", 320.0);
		depthPrincipalPoint.y = XML.getValue("depthIntrinsics:ppy", 240.0);
		depthFOV.x = XML.getValue("depthIntrinsics:fovx", 570.34);
		depthFOV.y = XML.getValue("depthIntrinsics:fovy", 570.34);
		
		depthRect.x = 0.0;      //  TODO: do this automatically
		depthRect.y = 720.0;    //
		depthRect.width = XML.getValue("depthIntrinsics:width", 640.0);
		depthRect.height = XML.getValue("depthIntrinsics:height", 480.0);
		
		normalRect.x = 640.0;       //  TODO: do this automatically
		normalRect.y = 720.0;       //
		normalRect.width = 640.0;
		normalRect.height = 480.0;
		
		nearClip = minDepth = XML.getValue("adjustment:depth:min", 1.0f);
		farClip = maxDepth = XML.getValue("adjustment:depth:max", 6000.0f);
		
		////////-----NO LONGER USED
		//this describes the face features: eyes, mouth, and skin
		faceFeatureRect = ofRectangle(depthRect.x, depthRect.getMaxY(), 640, 360);
		//this describes the change each frame
		deltaChangeRect = ofRectangle(normalRect.x, normalRect.getMaxY(), 640, 360);
		////////////
		
		hasSkinSettings = XML.tagExists("skin");
		skinSampleColor.r = XML.getValue("skin:targetR", 0.);
		skinSampleColor.g = XML.getValue("skin:targetG", 0.);
		skinSampleColor.b = XML.getValue("skin:targetB", 0.);
		skinWeights.x = XML.getValue("skin:hueWeight", 0.);
		skinWeights.y = XML.getValue("skin:satWeight", 0.);
		skinWeights.z = XML.getValue("skin:brightWeight", 0.);
		skinThreshold.min = XML.getValue("skin:lowerThreshold", .0);
		skinThreshold.max = XML.getValue("skin:upperThreshold", 1.0);
		
//		cout << "HAS SKIN? " << hasSkinSettings << endl;

		//	float colorWidth  = getPlayer().getWidth();
		//	float colorHeight = getPlayer().getHeight();
		float colorWidth  = 1280;
		float colorHeight = 1560;
		colorScale.x = colorWidth / colorRect.width;
		colorScale.y = float(colorHeight - (depthRect.height + faceFeatureRect.height) ) / float(colorRect.height);
		useFaces = true;
	}
    
    bClipJustFinished = false;
    
    cout << "*** STARTING PLAYER FROM SWAP" << endl;
    
    currentPlayer->stop();
    currentClipVolumeAdjustment = nextClipVolumeAdjustment;
    
    //JG dont' need this anymore without directshow player
    //    if(!nextClipIsVO){
    //        nextPlayer->setUseTexture(true);
    //    }
    
    swap(currentPlayer,nextPlayer);
    swap(currentSubtitles, nextSubtitles);
    
    currentClipHasSubtitles = nextClipHasSubtitles;
    currentPlayer->play();
    currentPlayer->setLoopState(OF_LOOP_NONE);
    
    playingVO = nextClipIsVO;
    playingVideo = !nextClipIsVO;
    
    clipPrerolled = false;
    playerPaused = false;
    //if our player has
    bCurrentClipLoading = bNextClipLoading;
    bNextClipLoading = false;
    
}
// Nico ZOOM & DRAG
void ofxComposer::_mouseDragged(ofMouseEventArgs &e){
    //ofVec3f mouse = ofVec3f(e.x, e.y,0);
    //ofVec3f mouseLast = ofVec3f(ofGetPreviousMouseX(),ofGetPreviousMouseY(),0);
    
    ofVec3f mouse = ofVec3f(e.x, e.y, 0.0)*this->getGlobalTransformMatrix();
    
    // si el mouse esta siendo arrastrado y no hay un nodo/link/nodeInput abajo
    if ( disabledPatches && !draggingGrip && !draggingHGrip && (!isAnyLinkHit()) && (!gui->getOtherSelected()) ) {
        // si apreto el boton izquierdo muevo todos los nodos
//        if(e.button == 0){
//            movePatches(mouse - mouseLast);
//        }
        
        // si es el boton izquierdo hago multiple selection
        if(e.button == 0){
            multipleSelectRectangle.width = mouse.x - multipleSelectFromX;
            multipleSelectRectangle.height = mouse.y - multipleSelectFromY;
        }
        
        // si apreto el boton derecho, hago zoom in/out
        if(e.button == 2){
//            scalePatches(mouse.y - mouseLast.y);
        }
    } else {
        int activePatch = isAnyPatchHit(mouse.x, mouse.y, mouse.z);
        if (activePatch != -1) {
        
            patch* p = patches[activePatch];
            verticalAlign1 = 0;
            verticalAlign2 = 0;
            verticalAlign3 = 0;
            horizontalAlign1 = 0;
            horizontalAlign2 = 0;
            horizontalAlign3 = 0;
            
            for(map<int,patch*>::iterator it = patches.begin(); it != patches.end(); it++ ){
                
                if (it->second != p) {
                    if ((int)it->second->getCoorners()[0].x == (int)p->getCoorners()[0].x or
                        (int)it->second->getCoorners()[1].x == (int)p->getCoorners()[0].x) {
                        verticalAlign1 = p->getCoorners()[0].x ;
                    }
                    if ((int)(it->second->getCoorners()[0].x + it->second->getBox().width/2) == (int)(p->getCoorners()[0].x + p->getBox().width/2)) {
                        verticalAlign2 = (p->getCoorners()[0].x + p->getBox().width/2);
                    }
                    if ((int)it->second->getCoorners()[0].x == (int)p->getCoorners()[1].x or
                        (int)it->second->getCoorners()[1].x == (int)p->getCoorners()[1].x ) {
                        verticalAlign3 = p->getCoorners()[1].x;
                    }
                    
                    if ((int)it->second->getCoorners()[1].y == (int)p->getCoorners()[1].y or
                        (int)it->second->getCoorners()[3].y == (int)p->getCoorners()[1].y) {
                        horizontalAlign1 = p->getCoorners()[1].y ;
                    }
                    if ((int)(it->second->getCoorners()[1].y + it->second->getBox().height/2) == (int)(p->getCoorners()[1].y + p->getBox().height/2)) {
                        horizontalAlign2 = (p->getCoorners()[1].y + p->getBox().height/2);
                    }
                    if ((int)it->second->getCoorners()[1].y == (int)p->getCoorners()[3].y or
                        (int)it->second->getCoorners()[3].y == (int)p->getCoorners()[3].y ) {
                        horizontalAlign3 = p->getCoorners()[3].y;
                    }
                }
            }
        }
    }
}
Ejemplo n.º 16
0
//--------------------------------------------------------------
void testApp::setup(){
		
    radius = 400;
    max = 60;
    
    glEnable(GL_DEPTH_TEST); //make sure we test depth for 3d
    
		ofSetVerticalSync(true);
    ofEnableLighting();
    ofEnableAlphaBlending();
    ofEnableSmoothing();
    ofEnableBlendMode(ofBlendMode(OF_BLENDMODE_ALPHA));
    
    mesh.addVertex(ofPoint(0,0,0)); // add center vertex
    mesh.addColor(ofColor(137,137,140,255)); // center is same as bg
    mesh.addNormal(ofVec3f(0,0,1)); // center normal points up
    
    zfreq = 3.;
    zamt = .3;
    
    //loop around and make verts in a circle, with a bit of a z-wave
    for (int i = 0; i < max; i++){
        float step = 2*PI/max; // step size around circle
        float theta = ofMap(i, 0, max-1, 0, 2*PI - step); //map i as circle divisions to actual radian values around the circle (note we don't go quite all the way around by one step, because it will be the same as where we started, so we'll just index that starting vertex when we make faces)
 
        float prevTheta = theta - step; //one step back
        float nextTheta = theta + step; // one step forward
        
        // create vertices in polar coordinates, plus a sine wave for z
        ofVec3f p(radius*cos(theta),radius*sin(theta), radius*zamt*sin(zfreq*theta) );
        // add this vertex
        mesh.addVertex(p);
        
        // we need these for calculating normals
        ofVec3f prev(radius*cos(prevTheta),radius*sin(prevTheta),radius*zamt*sin(zfreq*prevTheta) );        
        ofVec3f next(radius*cos(nextTheta),radius*sin(nextTheta),radius*zamt*sin(zfreq*nextTheta) );
        
        // our normals for each triangle face is the cross product of the two vectors making up that sliver 
        ofVec3f previousFaceNormal = prev.crossed(p);
        ofVec3f nextFaceNormal = p.crossed(next);
        
        /* notice here we go in the same direction: previous->current,current->next;
           we could similarly go next->current,current-prev, which would flip all of our normals;
           this might not be the best idea, but its certainly better than going previous->current,next->current, which would end up being quite awful.
           This is the concept of an "orientable mesh" or "face winding order", to be googled for more information.
         */
        
        // since we want smooth normals, we'll sum the two adjacent face normals, then normalize (since usually, only the direction and not the magnitude of the normal is what matters)
        mesh.addNormal((previousFaceNormal + nextFaceNormal).normalize());
        
        //add a color too
        ofColor c;
        c.setHsb(40 + 30*sin(2*theta+PI),255,255,255);        
        mesh.addColor(c);
    }
    
    //index our verts/normals/colors as a triangle fan
    for (int i=0, j = max-1; i < max; j=i++){
        mesh.addIndex(0);
        mesh.addIndex(i+1);
        mesh.addIndex(j+1);
    }
    
    // light the scene to show off why normals are important
    light.enable();
    light.setPointLight();
    light.setPosition(0,0,300);
		
}
Ejemplo n.º 17
0
//--------------------------------------------------------------
void ofApp::setup(){
    ofSetVerticalSync(false);
    ofBackground(0, 0, 0);
    ofDisableAlphaBlending();
    
    cam.setupPerspective();
    
    //パーティクルの数を設定

    particleNum = 1000000;
    texRes = ceil(sqrt(particleNum));
    
    // レンダリング用シェーダーの読み込み

    render.load("shaders/render");

    // アップデート用シェーダーの読み込み

    updatePos.load("","shaders/update.frag");
    
    // パーティクルの初期設定

    particles.setMode(OF_PRIMITIVE_POINTS);
    for(int i=0;i<texRes;i++){
        for(int j=0;j<texRes;j++){
            int index = i * texRes + j;
            if(index < particleNum){
                particles.addVertex(ofVec3f(0,0,0));
                particles.addTexCoord(ofVec2f(i, j)); // Fboのテクスチャー内で、データを読み出す位置を設定
                particles.addColor(ofFloatColor(1.0,1.0,1.0,0.5));
            }
        }
    }
    
    // パーティクルの座標・加速度の保存用Fbo
    // RGBA32Fの形式で2つのColorbufferを用意

    pingPong.allocate(texRes, texRes, GL_RGBA32F, 2);
    
    // パーティクルの位置と経過時間の初期設定
    
	float * posAndAge = new float[texRes * texRes * 4];
    for (int x = 0; x < texRes; x++){
        for (int y = 0; y < texRes; y++){
            int i = texRes * y + x;
            posAndAge[i*4 + 0] = ofRandom(-1.0,1.0);
            posAndAge[i*4 + 1] = ofRandom(-1.0,1.0);
            posAndAge[i*4 + 2] = ofRandom(-1.0,1.0);
            posAndAge[i*4 + 3] = 0;
        }
    }
    //pingPongBufferに初期値を書き込み

    pingPong.src->getTextureReference(0).loadData(posAndAge, texRes, texRes, GL_RGBA);
    delete [] posAndAge;
    
    // パーティクルの速度と生存期間の初期設定
    
	float * velAndMaxAge = new float[texRes * texRes * 4];
    for (int x = 0; x < texRes; x++){
        for (int y = 0; y < texRes; y++){
            int i = texRes * y + x;
            velAndMaxAge[i*4 + 0] = 0.0;
            velAndMaxAge[i*4 + 1] = 0.0;
            velAndMaxAge[i*4 + 2] = 0.0;
            velAndMaxAge[i*4 + 3] = ofRandom(1,150);
        }
    }

    //pingPongBufferに初期値を書き込み

    pingPong.src->getTextureReference(1).loadData(velAndMaxAge, texRes, texRes, GL_RGBA);
    delete [] velAndMaxAge;

	showTex = false;
}
Ejemplo n.º 18
0
//--------------------------------------------------------------
void ofApp::setup() {
	ofSetFrameRate(60);
	ofSetVerticalSync(true);
	ofBackground( 255, 255, 255);
	
    camPosx = 0;
    camPosy = -7;
    camPosz = -10;
    
    camA = 0;
    camB = 0;
    camC = 0;
    
    
    
	camera.setPosition(ofVec3f(camPosx, camPosy, camPosz));
	camera.lookAt(ofVec3f(camA, camB, camC), ofVec3f(0, -1, 0));

	world.setup();
	world.enableGrabbing();
	world.enableDebugDraw();
	world.setCamera(&camera);
	
	sphere = new ofxBulletSphere();
	sphere->create(world.world, ofVec3f(0, 0, 0), 0.1, 3);
	sphere->add();
	
		
	ground.create( world.world, ofVec3f(0., 5.5, 0.), 0., 100.f, 1.f, 100.f );
	ground.setProperties(.25, .95);
	ground.add();
    
    
    
    
    //CSV parse
    currentIndex = 0;
    
    //Path to the comma delimited file
    string filePath = "earthquakes.csv";
    
    //Load file placed in bin/data
    ofFile file(filePath);
    
    if(!file.exists()){
        ofLogError("The file " + filePath + " is missing");
    }
    ofBuffer buffer(file);
    
    //Read file line by line
    
    for (ofBuffer::Line it = buffer.getLines().begin(), end = buffer.getLines().end(); it != end; ++it) {
        string line = *it;
        
        //Split line into strings
        vector<string> words = ofSplitString(line, ",");
        
        //add elements to longlatVector
        temp.longitude = ofToDouble(words[1]);
        temp.latitude = ofToDouble(words[2]);
//        cout << words[14].substr(0,11) <<endl;
        if ((words[14].substr(0,11)).compare(" California")){
            
            temp.cali = true;
        }
        else {
            temp.cali = false;
        }
        
        
        longlatVector.push_back(temp);
        
    }
    
    cout << longlatVector.size() << endl;
    
    for(int i = 0; i < longlatVector.size(); i++){
        //cout << longlatVector[i].longitude << " longitude" << endl;
        testPoint = placePoint(longlatVector[i].latitude, longlatVector[i].longitude, sphere->getRadius());
        //cout << testPoint << " testPoint" << endl;
        earthquakePoints.push_back(testPoint); //vector of 3d vectors
        
    }
    
    //now we can draw them

    
    
    
}
Ejemplo n.º 19
0
// ------------------------------------------------------------------------------------------------------
//
void ofApp::update()
{
	// Update time, this let's us hit space and slow down time, even reverse it.
	if( ofGetKeyPressed(' ') ) { timeStep = ofLerp( timeStep, ofMap( ofGetMouseX(), 0, ofGetWidth(), -(1.0f/60.0f), (1.0f/60.0f) ), 0.1f );} else { timeStep = ofLerp( timeStep, 1.0f / 60.0f, 0.1f ); }
	time += timeStep;
	
	float mx = ofMap( ofGetMouseX(), 0, ofGetWidth()-1,  0, 1 );
	float my = ofMap( ofGetMouseY(), 0, ofGetHeight()-1, 0, 1 );
	
	ofSetGlobalAmbientColor( globalAmbient.get() );

	light[0].setAmbientColor( light1Ambient.get() ); // If you're having trouble passing an 'ofParameter<ClassX>' into something that expects a 'ClassX' use .get()
	light[0].setDiffuseColor( light1Diffuse.get() );
	light[0].setSpecularColor( light1Specular.get() );

	light[0].setPosition( light1Position );
	

	if( currAppMode == APP_MODE_LIVE  )
	{
		kinectToWorld.makeIdentityMatrix();
		kinectToWorld.scale( ofVec3f(kinectPointCloudScale) );
		kinectToWorld.scale( ofVec3f(1,-1,-1) );
		kinectToWorld.translate( kinectPointCloudOffset );
		
		worldToKinect = kinectToWorld.getInverse();
		
		particles.setWorldToFlowParameters( worldToKinect );
		
		
		// Copy the points and colors every frame for now, can be optimized
		kinectManager.getCurrentPointCloud( pointCloudPoints, pointCloudColors );
		
		if( pointCloudPoints.size() != pointCloudColors.size() ) ofLogError() << "ofApp::update() pointCloudPoints.size() != pointCloudColors.size()";
		
		
		//ofVec3f kinectCoordinateCorrection(1,-1,1);
		
		pointCloudMesh.clear();
		for( int i = 0; i < pointCloudPoints.size(); i++ )
		{
			//pointCloudMesh.addVertex( ((pointCloudPoints.at(i) * kinectPointCloudScale) * kinectCoordinateCorrection) + kinectPointCloudOffset );
			pointCloudMesh.addVertex( pointCloudPoints.at(i) * kinectToWorld );
			pointCloudMesh.addColor( pointCloudColors.at(i) );
		}
		
		// Spawn positions
		bool haveNewData = pointCloudMesh.getNumVertices() > 2; // We'll be grabbing the vertices from the mesh, a bit hacky but the rescaled data is right there
		if( haveNewData )
		{
			// Fill in the span buffer for the particles with random point cloud locations
			int tmpIndex = 0;
			for( int y = 0; y < particles.textureSize; y++ )
			{
				for( int x = 0; x < particles.textureSize; x++ )
				{
					int randomIndex = (int)ofRandom(pointCloudMesh.getNumVertices()-1);
					ofVec3f spawnPos = pointCloudMesh.getVertex( randomIndex );
					
					particles.spawnPosBuffer.getPixels()[ (tmpIndex * 3) + 0 ] = spawnPos.x;
					particles.spawnPosBuffer.getPixels()[ (tmpIndex * 3) + 1 ] = spawnPos.y;
					particles.spawnPosBuffer.getPixels()[ (tmpIndex * 3) + 2 ] = spawnPos.z;
					
					tmpIndex++;
				}
			}
			particles.spawnPosTexture.loadData( particles.spawnPosBuffer );
		}
		
		// Optical Flow
		
		ofxCv::FlowFarneback& flowObj = kinectManager.getFlowObject();
		int targetNumChannels = 3;
		
		if( particles.opticalFlowBuffer.getWidth() != flowObj.getWidth() ||
		   particles.opticalFlowBuffer.getHeight() != flowObj.getHeight() )
		{
			particles.opticalFlowBuffer.allocate( flowObj.getWidth(), flowObj.getHeight(), targetNumChannels );
			
			particles.opticalFlowTexture.allocate( flowObj.getWidth(), flowObj.getHeight(), GL_RGB32F, false );
			
			cout << "** Alocating flow " << particles.opticalFlowBuffer.getWidth() << ", " << particles.opticalFlowBuffer.getHeight() << "  " << particles.opticalFlowBuffer.getNumChannels() << endl;
		}
		
		// We are going to copy the flow data into am RGB texture rather than RG, having trouble getting that working,
		// otherwise it would (without filtering) just be ofxCv::toOf( flowObj.getFlow(), particles.opticalFlowBuffer );
		
		int numChannels = particles.opticalFlowBuffer.getNumChannels();
		
		int w = particles.opticalFlowBuffer.getWidth();
		int h = particles.opticalFlowBuffer.getHeight();
		int tmpIndex = 0;
		int windowSize = 4;
		int windowSizeHalf = windowSize / 2;
		for( int y = windowSize; y < h - windowSize; y++ )
		{
			for( int x = windowSize; x < w - windowSize; x++ )
			{
				tmpIndex = ((y*w) + x) * numChannels;
				//ofVec2f flowOffset = flowObj.getFlowOffset( x, y );
				ofVec2f flowOffset = flowObj.getAverageFlowInRegion( ofRectangle( x-windowSizeHalf, y-windowSizeHalf, windowSize, windowSize) );
				particles.opticalFlowBuffer.getPixels()[ tmpIndex + 0 ] = flowOffset.x;
				particles.opticalFlowBuffer.getPixels()[ tmpIndex + 1 ] = flowOffset.y;
				particles.opticalFlowBuffer.getPixels()[ tmpIndex + 2 ] = 0;
			}
		}
		
		particles.opticalFlowTexture.loadData( particles.opticalFlowBuffer );
		
		particles.setAverageFlow( kinectManager.getAverageFlowSmoothed() );
		
	}
	else if ( currAppMode == APP_MODE_TOUCH_SETUP )
	{
		
	}
	
}
Ejemplo n.º 20
0
//--------------------------------------------------------------
void testApp::setup(){
    ofSetFrameRate(24);
    ofBackground(0);
    ofSetSmoothLighting(true);
    
    bDrawWireframe = false;
    
    
    // Point lights emit light in all directions //
    pointLight.setPointLight();
    
    // set the diffuse color, color reflected from the light source //
    pointLight.setDiffuseColor(ofColor(255, 255, 255));
    
    // specular color, the highlight/shininess color //
	pointLight.setSpecularColor(ofColor(0, 0, 255));
    
    pointLight.enable();
    
    
    
    // turn the light into spotLight, emit a cone of light //
    spotLight.setSpotlight();
    spotLight.setDiffuseColor( ofColor(255.f, 0.f, 0.f));
	spotLight.setSpecularColor( ofColor(255.f, 255.f, 255.f));
    
    // size of the cone of emitted light, angle between light axis and side of cone //
    // angle range between 0 - 90 in degrees //
    spotLight.setSpotlightCutOff( 45 );
    
    // rate of falloff, illumitation decreases as the angle from the cone axis increases //
    // range 0 - 128, zero is even illumination, 128 is max falloff //
    spotLight.setSpotConcentration( 0 );
    
    spotLight.enable();
    
    
    // Load the font
    string filename = "planet_kosmos.ttf";
    int fontSize = 90;
    bool bAntiAliased = false;
    bool bFullCharacterSet = true;
    bool makeContours = true;
    float simplifyAmt = 30; // uses ofPolyline::simplify
    font.loadFont(filename, fontSize, bAntiAliased, bFullCharacterSet, makeContours, simplifyAmt);
    font.setLineHeight(fontSize+10);
    
    
    
    // Get the bounding box of the text
    text = "Kitchen\nTable\nCoders";
    bb = font.getStringBoundingBox(text, 0, 0);
    
    float depth = 20;
    float halfDepth = depth/2;
    
    // Create a bunch of Letter objects
    vector<ofPath> letters = font.getStringAsPoints(text);
    for(int i=0; i<letters.size(); i++)
    {
        // Tessellation is subdividing a concave polygon into convex polygons.
        ofMesh front = letters[i].getTessellation();
        ofMesh back = front;
        ofMesh side;
        
        // Loop through all of the vertices in the "back" mesh
        // and move them back in on the "z" axis
        vector<ofPoint>& f = front.getVertices();
        vector<ofPoint>& b = back.getVertices();
        for(int j=0; j< f.size(); j++)
        {
            f[j].z += halfDepth;
            b[j].z -= halfDepth;
        }
        
        // NORMALS!
        for(int i=0; i<front.getNumVertices(); i++)
        {
            front.addNormal(ofVec3f(0, 0, 1));
        }
        
        for(int i=0; i<back.getNumVertices(); i++)
        {
            back.addNormal(ofVec3f(0, 0, -1));
        }
        
        // TIP - class heirarchy
        // an ofPath is basically a container for a bunch of ofPolyLines
        // an ofPolyline is a single, continuous line that has lots of useful functions
        // such as getSmoothed, getResampledBySpacing, getClosestPoint
        
        vector<ofPolyline> lines = letters[i].getOutline();
        for(int j=0; j<lines.size(); j++)
        {
            vector<ofPoint>& points = lines[j].getVertices();
            for(int k=0; k<points.size(); k++)
            {
                ofPoint p1 = points[(k+0)%points.size()];
                ofPoint p2 = points[(k+1)%points.size()];
                
                side.addVertex(ofPoint(p1.x, p1.y, p1.z+halfDepth));
                side.addVertex(ofPoint(p2.x, p2.y, p2.z+halfDepth));
                side.addVertex(ofPoint(p1.x, p1.y, p1.z-halfDepth));
                
                side.addColor(ofColor::white);
                side.addColor(ofColor::white);
                side.addColor(ofColor::white);
                
                side.addVertex(ofPoint(p1.x, p1.y, p1.z-halfDepth));
                side.addVertex(ofPoint(p2.x, p2.y, p2.z-halfDepth));
                side.addVertex(ofPoint(p2.x, p2.y, p2.z+halfDepth));
                
                side.addColor(ofColor::white);
                side.addColor(ofColor::white);
                side.addColor(ofColor::white);
            }
        }

        
        meshes.push_back(side);
        meshes.push_back(front);
        meshes.push_back(back);
    }
}
Ejemplo n.º 21
0
//--------------------------------------------------------------
void vbo::update(){
    
    if (timer % 80 == 0) {
        
        if (y < HEIGHT) {
            if(x < WIDTH) {
                
                xValue = pixels[y*WIDTH*3+x*3];
                yValue = pixels[y*WIDTH*3+x*3+1];
                zValue = pixels[y*WIDTH*3+x*3+2];
                                
                x++;

            }else{
                x = 0;
                y++;
            }
            
        }else{
            y = 0;
        }

    }
    
    
    if (timer < lastingTime) {
        timer++;
    }else{
        
        timer = 0;
        resetImg();
        resetVerts();
        
    }


    if (!overdose) {
    
        for (int i = 0; i < WIDTH; i++) {
            for (int j = 0; j < HEIGHT; j++) {

                myVerts[j*WIDTH+i].x += (vec[j*WIDTH+i].x * vecLength[j*WIDTH+i]/10000);
                myVerts[j*WIDTH+i].y += (vec[j*WIDTH+i].y * vecLength[j*WIDTH+i]/10000);
                myVerts[j*WIDTH+i].z += (vec[j*WIDTH+i].z * vecLength[j*WIDTH+i]/20000);
                
                if(vecLength[j*WIDTH+i] > 100){
                    vec[j*WIDTH+i].normalize();
                }

            }
        }

        vec[longestVec] = myVerts[longestVec] - ofVec3f(0,0,0);
        if(vec[longestVec].length() > initialLength * 200){
            resetVerts();
        }
        
    }

    myVbo.updateVertexData(myVerts, NUM_PARTICLES);

}
Ejemplo n.º 22
0
//--------------------------------------------------------------
void testApp::setup(){
    particleSize = 30.0f;
    timeStep = 0.005f;
    numParticles = 1000;
    
    // Width and Heigth of the windows
    width = ofGetWindowWidth();
    height = ofGetWindowHeight();
    
    string shadersFolder;
    if(ofGetGLProgrammableRenderer()){
    	shadersFolder="shaders_programmable";
    }else{
    	shadersFolder="shaders";
    }

    // Loading the Shaders
    updatePos.load("",shadersFolder+"/posUpdate.frag");// shader for updating the texture that store the particles position on RG channels
    updateVel.load("",shadersFolder+"/velUpdate.frag");// shader for updating the texture that store the particles velocity on RG channels
    
    // Frag, Vert and Geo shaders for the rendering process of the spark image
    updateRender.setGeometryInputType(GL_POINTS);
	updateRender.setGeometryOutputType(GL_TRIANGLE_STRIP);
	updateRender.setGeometryOutputCount(6);
    updateRender.load(shadersFolder+"/render.vert",shadersFolder+"/render.frag",shadersFolder+"/render.geom");
    
    // Seting the textures where the information ( position and velocity ) will be
    textureRes = (int)sqrt((float)numParticles);
    numParticles = textureRes * textureRes;
    
    // 1. Making arrays of float pixels with position information
    float * pos = new float[numParticles*3];
    for (int x = 0; x < textureRes; x++){
        for (int y = 0; y < textureRes; y++){
            int i = textureRes * y + x;
            
            pos[i*3 + 0] = ofRandom(1.0); //x*offset;
            pos[i*3 + 1] = ofRandom(1.0); //y*offset;
            pos[i*3 + 2] = 0.0;
        }
    }
    // Load this information in to the FBO�s texture
    posPingPong.allocate(textureRes, textureRes,GL_RGB32F);
    posPingPong.src->getTextureReference().loadData(pos, textureRes, textureRes, GL_RGB);
    posPingPong.dst->getTextureReference().loadData(pos, textureRes, textureRes, GL_RGB);
    delete [] pos;    // Delete the array
    
    
    // 2. Making arrays of float pixels with velocity information and the load it to a texture
    float * vel = new float[numParticles*3];
    for (int i = 0; i < numParticles; i++){
        vel[i*3 + 0] = ofRandom(-1.0,1.0);
        vel[i*3 + 1] = ofRandom(-1.0,1.0);
        vel[i*3 + 2] = 1.0;
    }
    // Load this information in to the FBO�s texture
    velPingPong.allocate(textureRes, textureRes,GL_RGB32F);
    velPingPong.src->getTextureReference().loadData(vel, textureRes, textureRes, GL_RGB);
    velPingPong.dst->getTextureReference().loadData(vel, textureRes, textureRes, GL_RGB);
    delete [] vel; // Delete the array
    
    // Loading and setings of the variables of the textures of the particles
    sparkImg.loadImage("spark.png");
    imgWidth = sparkImg.getWidth();
    imgHeight = sparkImg.getHeight();
    
    // Allocate the final 
    renderFBO.allocate(width, height, GL_RGB32F);
    renderFBO.begin();
    ofClear(0, 0, 0, 255);
    renderFBO.end();


    mesh.setMode(OF_PRIMITIVE_POINTS);
    for(int x = 0; x < textureRes; x++){
        for(int y = 0; y < textureRes; y++){
            mesh.addVertex(ofVec3f(x,y));
            mesh.addTexCoord(ofVec2f(x, y));
        }
    }

}
Ejemplo n.º 23
0
ofVec3f ConvertProjectiveToRealWorld(float x, float y, float z) {
	return ofVec3f((x/Xres-.5f) * z * XtoZ,
								 (.5f-y/Yres) * z * YtoZ,
								 z);
}
Ejemplo n.º 24
0
void testApp::setup(){
    Particle* p;
    //Particles_Container* g;
    //ofSetFrameRate(1);
    ofSetVerticalSync(true);
    ofEnableSmoothing();
    // 15 pixels given for particle regular grid distance
    //mouseWave.min_dist = regularGrid_interactions_system.grid_ds*2;
    //mouseWaveGenerator.setup();
    mouse.startThread(true, false);
    managerInterface.start(&world);
    
    p = world.create_particle("MP_RegGrid");

    if(strncmp("MP_RegGrid","MP_",3) == 0){
        managerInterface.update_availableItems_names(&(managerInterface.group_name),"C_MP_RegGrid");
    }




    Tag* t0 = world.create_tag();

    t0->add_particles(world.particles.get_itemsByName("P_Circle"));
    t0->add_behavior("B_GravityGlue");

    p = world.create_particle("P_Circle");
    
    Tag* t1 = world.create_tag();

    t1->add_behavior("B_MouseTracking");
    Interaction* i0 = t1->add_interaction("I_ElectRepulsion");
    i0->add_tag(t0);

    t1->add_particle(p);

    cout << "hello dynamicWorld!!" << endl;
    // testing remove particle
    world.remove_particle(p);

    p = world.create_particle("P_Circle");
    *(p->ofColorPtr_map["color"]) = ofColor(255,0,0);
    *(p->ofVec3fPtr_map["loc"]) = ofVec3f(ofGetWindowWidth()/2,ofGetWindowHeight()/2,0);
    *(p->intPtr_map["rad"]) = 10;

    t1->add_particle(p);


    //p->behaviors.add_itemByName("B_MouseTracking",p);

    //p->set_var( b->name+"_loc", *(p->ofVec3fPtr_map["loc"]) );
    //ofVec3f* v_ptr;
    //p->get_var( b->name+"_loc",v_ptr);

//    g = world.create_group("G_dancers");
//    managerInterface.update_availableItems_names(&(managerInterface.group_name),"G_dancers");
//    g->add(p,false);

    //world.remove_particle(p);
    //for (u_int i=0; i<world.groups.itemsVector.size(); i++){
    //    cout<<world.groups.itemsVector[i]->id;
    //}

}
//--------------------------------------------------------------
void ofxCubeMap::setupSkyBoxVertices()
{
	
	//ofScale( _size, _size, _size );
	//ofScale( _size / 2.0f, _size / 2.0f, _size / 2.0f );
	
	float fExtent = 1.0f / 2.0f;
	
	
	
	///////////////////////////////////////////////
	//  Postive X
	cubemapTexCoords.push_back( ofVec3f(1.0f, -1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, -fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, -1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, -fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, 1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f(1.0f, -1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, -fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, 1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, 1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, fExtent, fExtent) );
	
	
	//////////////////////////////////////////////
	// Negative X
	cubemapTexCoords.push_back( ofVec3f( -1.0f, -1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent , -fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, -1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, -fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, 1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, -1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent , -fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, 1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, 1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, fExtent, -fExtent) );
		
	//////////////////////////////////////////////////
	// Positive Y
	cubemapTexCoords.push_back( ofVec3f( -1.0f, 1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, 1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, 1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, 1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, 1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, 1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, fExtent, -fExtent) );
	
	///////////////////////////////////////////////////
	// Negative Y
	cubemapTexCoords.push_back( ofVec3f( -1.0f, -1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, -fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, -1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, -fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, -1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, -fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, -1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, -fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, -1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, -fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, -1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, -fExtent, fExtent) );
	
	
	////////////////////////////////////////////////
	// Positive Z
	cubemapTexCoords.push_back( ofVec3f( 1.0f, -1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, -fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, -1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, -fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, 1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, -1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, -fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, 1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, fExtent, fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, 1.0f, 1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, fExtent, fExtent) );
	
	
	////////////////////////////////////////////////
	// Negative Z
	cubemapTexCoords.push_back( ofVec3f( -1.0f, -1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, -fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, -1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, -fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, 1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, -1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, -fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( -1.0f, 1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(-fExtent, fExtent, -fExtent) );
	
	cubemapTexCoords.push_back( ofVec3f( 1.0f, 1.0f, -1.0f) );
	cubemapVertices.push_back( ofVec3f(fExtent, fExtent, -fExtent) );
	
}
Ejemplo n.º 26
0
void ofxChartCreate3dRect(ofMesh *m, ofVec3f xyz, ofVec3f dimensions, ofColor color)
{
m->clear();

//if not filled (no background), just show the line loops

float w = dimensions.x, h =dimensions.y, z = dimensions.z;

float vx =xyz.x, vy=xyz.y, vz=xyz.z;


for(int i=0; i< 36;i++)
{
    m->addColor(color);
}
    // bottom (-z)
    m->addVertex(ofVec3f(        vx, vy, vz-z));
    m->addVertex(ofVec3f(        vx,  vy+h, vz-z));
    m->addVertex(ofVec3f(        vx+w, vy, vz-z));
    m->addVertex(ofVec3f(        vx+w, vy, vz-z));
    m->addVertex(ofVec3f(        vx,  vy+h, vz-z));
    m->addVertex(ofVec3f(        vx+w,  vy+h, vz-z));

    // top (+z)
    m->addVertex(ofVec3f(        vx, vy,  vz));
    m->addVertex(ofVec3f(        vx+w, vy,  vz));
    m->addVertex(ofVec3f(        vx,  vy+h,  vz));
    m->addVertex(ofVec3f(        vx,  vy+h,  vz));
    m->addVertex(ofVec3f(        vx+w, vy,  vz));
    m->addVertex(ofVec3f(        vx+w,vy+h,  vz));


    // right (+x)
    m->addVertex(ofVec3f(        vx+w, vy, vz-z));
    m->addVertex(ofVec3f(        vx+w,  vy+h, vz-z));
    m->addVertex(ofVec3f(        vx+w, vy,  vz));
    m->addVertex(ofVec3f(        vx+w, vy,  vz));
    m->addVertex(ofVec3f(        vx+w,  vy+h, vz-z));
    m->addVertex(ofVec3f(        vx+w,  vy+h,  vz));
    
    // left (-x)
    m->addVertex(ofVec3f(        vx, vy, vz-z));
    m->addVertex(ofVec3f(       vx, vy,  vz));
    m->addVertex(ofVec3f(        vx,  vy+h, vz-z));
    m->addVertex(ofVec3f(        vx,  vy+h, vz-z));
    m->addVertex(ofVec3f(       vx, vy,  vz));
    m->addVertex(ofVec3f(       vx,  vy+h,  vz));
    
    // front (+y)
    m->addVertex(ofVec3f(        vx, vy, vz-z));
    m->addVertex(ofVec3f(        vx+w, vy, vz-z));
    m->addVertex(ofVec3f(        vx, vy,  vz));
    m->addVertex(ofVec3f(        vx, vy,  vz));
    m->addVertex(ofVec3f(        vx+w, vy, vz-z));
    m->addVertex(ofVec3f(        vx+w, vy,  vz));
    
    // back (-y
    m->addVertex(ofVec3f(        vx,  vy+h, vz-z));
    m->addVertex(ofVec3f(        vx,  vy+h,  vz));
    m->addVertex(ofVec3f(        vx+w,  vy+h, vz-z));
    m->addVertex(ofVec3f(        vx+w,  vy+h, vz-z));
    m->addVertex(ofVec3f(       vx,  vy+h,  vz));
    m->addVertex(ofVec3f(        vx+w,  vy+h,  vz));
    
    m->setMode(OF_PRIMITIVE_TRIANGLES);

}
Ejemplo n.º 27
0
ofVec3f KinectGrabber::getStatBuffer(int x, int y){
    float* statBufferPtr = statBuffer+3*(x + y*width);
    return ofVec3f(statBufferPtr[0], statBufferPtr[1], statBufferPtr[2]);
}
void ofxComposer::customDraw(){
    ofPushView();
    ofPushStyle();
    ofPushMatrix();

    ofEnableAlphaBlending();
    
#ifdef USE_OFXGLEDITOR
    //  Draw the GLEditor if it�s not inside a Patch
    //
    if (bEditMode && !bGLEditorPatch){
        ofPushMatrix();
        ofRotate(180, 1, 0, 0);
        ofTranslate(0, -ofGetWindowHeight());
        ofSetColor(editorFgColor);
        editorFbo.draw(0, 0);
        ofPopMatrix();
    }
#endif
    
    //  Draw Patches
    //
    for(map<int,patch*>::iterator it = patches.begin(); it != patches.end(); it++ ){
        it->second->customDraw();
    }
    
    //  Draw active line
    //
    //mili
    ofVec3f mouse_transformed = ofVec3f(ofGetMouseX(), ofGetMouseY(), 0.0)*this->getGlobalTransformMatrix();
    //
    if (selectedDot >= 0){
        ofLine(patches[selectedDot]->getOutPutPosition(), ofPoint(mouse_transformed.x,mouse_transformed.y));
    }
    
    //mili - nodes aligned
    ofVec3f scale = ((ofCamera*)this->getParent())->getScale();
    if (verticalAlign1) {
        ofSetColor(255, 208, 111);
        ofLine(verticalAlign1, 0, verticalAlign1, ofGetHeight()*scale.y);
    }
    if (verticalAlign2) {
        ofSetColor(255, 208, 111);
        ofLine(verticalAlign2, 0, verticalAlign2, ofGetHeight()*scale.y);
    }
    if (verticalAlign3) {
        ofSetColor(255, 208, 111);
        ofLine(verticalAlign3, 0, verticalAlign3, ofGetHeight()*scale.y);
    }
    if (horizontalAlign1) {
        ofSetColor(255, 208, 111);
        ofLine(0, horizontalAlign1, ofGetWidth()*scale.x, horizontalAlign1);
    }
    if (horizontalAlign2) {
        ofSetColor(255, 208, 111);
        ofLine(0, horizontalAlign2, ofGetWidth()*scale.x, horizontalAlign2);
    }
    if (horizontalAlign3) {
        ofSetColor(255, 208, 111);
        ofLine(0, horizontalAlign3, ofGetWidth()*scale.x, horizontalAlign3);
    }
    //
        
    //  Draw Help screen
    //
    if (bHelp){
        ofSetColor(255);
        ofDrawBitmapString(helpScreen, 20, ofGetWindowHeight()*0.5- 11.0*15.0);
    }
    
    ofDisableBlendMode();
    ofEnableAlphaBlending();

    ofPopMatrix();
    ofPopStyle();
    ofPopView();
    
    
    // nico multipleSelect
    ofPushMatrix();
        ofNoFill();
        ofRect(multipleSelectRectangle);
    ofPopMatrix();
    
}
Ejemplo n.º 29
0
//--------------------------------------------------------------
ofMatrix4x4 ofxCubeMap::getLookAtMatrixForFace( GLuint _face )
{
    ofMatrix4x4 lookAt;
    
    switch ( _face )
    {
        case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
            lookAt.makeLookAtViewMatrix( ofVec3f( 0.0f, 0.0f, 0.0f), ofVec3f(  1.0f,  0.0f,  0.0f), ofVec3f(  0.0f, -1.0f,  0.0f) );
            break;
        case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
            lookAt.makeLookAtViewMatrix( ofVec3f( 0.0f, 0.0f, 0.0f), ofVec3f( -1.0f,  0.0f,  0.0f), ofVec3f(  0.0f, -1.0f,  0.0f) );
            break;
        case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
            lookAt.makeLookAtViewMatrix( ofVec3f( 0.0f, 0.0f, 0.0f), ofVec3f(  0.0f,  1.0f,  0.0f), ofVec3f(  0.0f,  0.0f,  1.0f) );
            break;
        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
            lookAt.makeLookAtViewMatrix( ofVec3f( 0.0f, 0.0f, 0.0f), ofVec3f(  0.0f, -1.0f,  0.0f), ofVec3f(  0.0f,  0.0f, -1.0f) );
            break;
        case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
            lookAt.makeLookAtViewMatrix( ofVec3f( 0.0f, 0.0f, 0.0f), ofVec3f(  0.0f,  0.0f,  1.0f), ofVec3f(  0.0f, -1.0f,  0.0f) );
            break;
        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
            lookAt.makeLookAtViewMatrix( ofVec3f( 0.0f, 0.0f, 0.0f), ofVec3f(  0.0f,  0.0f, -1.0f), ofVec3f(  0.0f, -1.0f,  0.0f) );
            break;
        default:
            ofLogError() << "ofxCubeMap::getLookAtMatrixForFace, passed in invalid face.";
            break;
    }
    
    //lookAt.translate( cubeMapCamerasRenderPosition.x, cubeMapCamerasRenderPosition.y, cubeMapCamerasRenderPosition.z );
    lookAt.glTranslate( -cubeMapCamerasRenderPosition.x, -cubeMapCamerasRenderPosition.y, -cubeMapCamerasRenderPosition.z );
    
    return lookAt;
}
Ejemplo n.º 30
0
ofVec3f Joint::getVelocity() {
	return ofVec3f(0.0, 0.0, 0.0);
}