vector<meshy> ofTessellator::tessellateToMesh( const vector<ofPolyline>& polylines, int polyWindingMode, bool bIs2D ) {
#else
static ofMesh ofTessellator::tessellateToMesh( const vector<ofPolyline>& polylines, int polyWindingMode, bool bIs2D ) {
#endif

	mutex.lock();
	
	clear();
#ifdef DRAW_WITH_MESHIES
	resultMeshies.clear();
#else
	resultMesh = ofMesh();
#endif

	performTessellation( polylines, polyWindingMode, true /* filled */, bIs2D );
	
	mutex.unlock();
	
#ifdef DRAW_WITH_MESHIES
	return resultMeshies;
#else
	return resultMesh;
#endif
		
}
//--------------------------------------------------------------
ofMesh ofCylinderPrimitive::getBottomCapMesh() const {
    if(getMesh().getMode() != OF_PRIMITIVE_TRIANGLE_STRIP) {
        ofLogWarning("ofCylinderPrimitive") << "getBottomCapMesh(): must be in triangle strip mode";
        return ofMesh();
    }
    return getMesh().getMeshForIndices( strides[2][0], strides[2][0]+strides[2][1],
                             vertices[2][0], vertices[2][0]+vertices[2][1] );
}
//--------------------------------------------------------------
ofMesh ofConePrimitive::getCapMesh() const {
    int startIndex  = strides[1][0];
    int endIndex    = startIndex + strides[1][1];
    
    int startVertIndex  = vertices[1][0];
    int endVertIndex    = startVertIndex + vertices[1][1];
    if(getMesh().getMode() != OF_PRIMITIVE_TRIANGLE_STRIP) {
        ofLogWarning("ofConePrimitive") << "getCapMesh(): must be in triangle strip mode";
        return ofMesh();
    }
    return getMesh().getMeshForIndices( startIndex, endIndex, startVertIndex, endVertIndex );
}
//-------------------------------------------
ofMesh ofxAssimpModelLoader::getCurrentAnimatedMesh(int num){
	if((int)modelMeshes.size()<=num){
		ofLog(OF_LOG_ERROR,"couldn't find mesh " + ofToString(num) + " there's only " + ofToString(scene->mNumMeshes));
		return ofMesh();
	}
	if(!modelMeshes[num].validCache){
		modelMeshes[num].cachedMesh.clearVertices();
		modelMeshes[num].cachedMesh.clearNormals();
		modelMeshes[num].cachedMesh.addVertices(aiVecVecToOfVecVec(modelMeshes[num].animatedPos));
		modelMeshes[num].cachedMesh.addNormals(aiVecVecToOfVecVec(modelMeshes[num].animatedNorm));
		modelMeshes[num].validCache = true;
	}
	return modelMeshes[num].cachedMesh;
}
//-------------------------------------------
ofMesh ofxAssimpModelLoader::getCurrentAnimatedMesh(int num){
	if((int)modelMeshes.size()<=num){
		ofLogError("ofxAssimpModelLoader") << "getCurrentAnimatedMesh(): mesh id: " << num
			<< "out of range for total num meshes: " << scene->mNumMeshes;
		return ofMesh();
	}
	if(!modelMeshes[num].validCache){
		modelMeshes[num].cachedMesh.clearVertices();
		modelMeshes[num].cachedMesh.clearNormals();
		modelMeshes[num].cachedMesh.addVertices(aiVecVecToOfVecVec(modelMeshes[num].animatedPos));
		modelMeshes[num].cachedMesh.addNormals(aiVecVecToOfVecVec(modelMeshes[num].animatedNorm));
		modelMeshes[num].validCache = true;
	}
	return modelMeshes[num].cachedMesh;
}
Exemple #6
0
Radar::Radar() {
  debug = false;
  subdivisions = 10;
  point_count = 8;
  thetaRate = 1/150.0;
  axis_length = 220;

  x = 100;
  y = 0;
  w = 400;
  h = 400;
  alphaSub = 0;

  absolute_center = ofPoint(300,200);

  time = 0;
  minTheta = 0;
  maxTheta = 2;
  change_index = 3;

  thetaStep = 6.28/point_count;
  index_update_rate = thetaStep / thetaRate;

  radialSplineShader.setGeometryInputType(GL_LINES);
	radialSplineShader.setGeometryOutputType(GL_TRIANGLE_STRIP);
	radialSplineShader.setGeometryOutputCount(4);
  radialSplineShader.load("shadersGL3/lines.vert", "shadersGL3/radialFade.frag", "shadersGL3/lines.geom");
  axisShader.setGeometryInputType(GL_LINES);
	axisShader.setGeometryOutputType(GL_TRIANGLE_STRIP);
	axisShader.setGeometryOutputCount(4);
  axisShader.load("shadersGL3/lines.vert", "shadersGL3/null.frag", "shadersGL3/lines.geom");
//  axisShader.load("shadersGL3/null.vert", "shadersGL3/radialFade.frag");

  axisMesh = ofMesh();
  axisMesh.setMode(OF_PRIMITIVE_LINES);
  for (int i = 0; i < axis_length; i += 10) {
    axisMesh.addVertex(ofPoint(i,0));
  }

  init_aframe();

  cam = ofEasyCam();
  cam.setTarget(ofVec3f(0,0,0));
  cam.setDistance(600);

  if (!debug)
    cam.disableMouseInput();
}
//-------------------------------------------
ofMesh ofxAssimpModelLoader::getCurrentAnimatedMesh(string name){
	for(int i=0; i<(int)modelMeshes.size(); i++){
		if(string(modelMeshes[i].mesh->mName.data)==name){
			if(!modelMeshes[i].validCache){
				modelMeshes[i].cachedMesh.clearVertices();
				modelMeshes[i].cachedMesh.clearNormals();
				modelMeshes[i].cachedMesh.addVertices(aiVecVecToOfVecVec(modelMeshes[i].animatedPos));
				modelMeshes[i].cachedMesh.addNormals(aiVecVecToOfVecVec(modelMeshes[i].animatedNorm));
				modelMeshes[i].validCache = true;
			}
			return modelMeshes[i].cachedMesh;
		}
	}

	ofLogError("ofxAssimpModelLoader") << "getCurrentAnimatedMesh(): couldn't find mesh: \"" + name << "\"";
	return ofMesh();

}
Exemple #8
0
void ofApp::regenHelper() {
	meshNode.setPosition(0, 0, 0);
	ofVec3f s = size;
	ofVec3f g = grid;
	switch (shapeType) {
	case 0:
		mesh = ofMesh::plane(s.x, s.y, g.x, g.y);
		break;
	case 1:
		mesh = ofMesh::sphere(s.x, g.x);
		break;
	case 2:
		mesh = ofMesh::box(s.x, s.y, s.z, g.x, g.y, g.z);
		break;
	}

	shadow = ofMesh(mesh);
}
Exemple #9
0
void Radar::compute_lines_from_bezier() {
  // From the bezier_segments, subdivide the bezier to create line segments
  // Place line segments in bezierLineMesh
  bezierLineMesh = ofMesh();
  bezierLineMesh.setMode(OF_PRIMITIVE_LINE_STRIP);

  float t_step = 1/subdivisions;

  for (int i = 0; i < bezier_segments.size(); i++) {
    bezier b = bezier_segments[i];
    vector<ofPoint> points = bezier_to_points(b);
    for (float t = 0; t <= 1; t+= t_step) {
      ofPoint p = rec_de_casteljau(points, t);
      bezierLineMesh.addVertex(p);
    }
  }
  // Connect end and start
  bezierLineMesh.addVertex(bezier_segments[0].start);
}
void Tunnel::init(Audio440& aud,Kinect440& kin,ColorTheme& the){

	audio = &aud;
	kinect = &kin;
	theme = &the;
	mesh = ofMesh();
	age = 0;
	mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
	scan = Scanlines();
	direction = ofVec3f(0,0,200);
	tunnell.allocate(ofGetWidth(),ofGetHeight());
	tunnelr.allocate(ofGetWidth(),ofGetHeight());
	anaglyphFbo.allocate(ofGetWidth(),ofGetHeight());
	offset = 0;
	prevamp = 0;
	basic.load("shaders/default");
	bulge.load("shaders/bulge");
	anaglyph.load("shaders/fullscreenQuad");
	circle.loadImage("images/softy.png");
	generate();
	light.setup();
	light.setPointLight();
	light.setPosition(ofGetWidth()/2,ofGetHeight()/2,-100);
	
	flash.loadImage("images/flashorb.png");
	flash.resize(ofGetHeight(),ofGetHeight());

	rangeX = 500;
	rangeY = 500;

	FullscreenQuad::setup(anaglyph.getAttributeLocation("a_vertex"), anaglyph.getAttributeLocation("a_texCoord"));
 
	cout << anaglyph.getAttributeLocation("a_vertex") << ", " <<  anaglyph.getAttributeLocation("a_texCoord") << endl;

	kinectHandSize = 100;
} 
Exemple #11
0
namespace GrabScene {
	//---------
	ofMesh Handles::Rotate::fill = ofMesh();
	ofMesh Handles::Rotate::line = ofMesh();
	
	//---------
	Handles::Rotate::Rotate(Axis axis) : BaseHandle(axis) {

	}
	
	//---------
	void Handles::Rotate::init() {
		const float radius = GRABSCENE_HANDLES_RADIUS_1;
		const float width = GRABSCENE_HANDLES_RADIUS_2;
		
		const int resolution = 48.0f;
		
		float theta;
		
		////
		//vertices
		
		//inner ring
		for (int i=0; i<resolution; i++) {
			theta = (float) i / (float) resolution * TWO_PI;
			line.addVertex(ofVec3f(radius * cos(theta), radius * sin(theta), 0.0f));
		}
						   
		//outer ring
		for (int i=0; i<resolution; i++) {
			theta = ((float) i + 0.5f) / (float) resolution * TWO_PI;
			line.addVertex(ofVec3f((radius + width) * cos(theta), (radius + width) * sin(theta), 0.0f));
		}
		
		fill.addVertices(line.getVertices());
		//
		////
		
		
		////
		//indices
		
		//line
		
		//inner ring
		for (int i=0; i<resolution; i++) {
			line.addIndex(i);
			line.addIndex((i+1) % resolution);
		}

		//inner ring
		for (int i=0; i<resolution; i++) {
			line.addIndex(i + resolution);
			line.addIndex(((i+1) % resolution) + resolution);
		}
		
		
		//fill
		for (int i=0; i<resolution+1; i++) {
			fill.addIndex(i % resolution);
			fill.addIndex((i % resolution) + resolution);
		}
		//
		////
		
		////
		//styles
		line.setMode(OF_PRIMITIVE_LINES);
		fill.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
		//
		////
	}
	
	//---------
	void Handles::Rotate::draw() const {
		if (parent == 0 || !this->enabled)
			return;
		
		GLboolean hadLighting;
		glGetBooleanv(GL_LIGHTING, &hadLighting);
		if (hadLighting)
			ofDisableLighting();
		
		parent->getNode().transformGL();
		ofPushMatrix();
		ofScale(scale, scale, scale);
		
		ofPushStyle();
		shader("fixed").begin();
		
		this->rotateAxis();
		this->setStyleFill();
		fill.draw();
		this->setStyleLine();
		line.draw();
		
		shader("fixed").end();
		
		ofSetColor(255);
		if (this->rollover) {
			ofTranslate(0, GRABSCENE_HANDLES_RADIUS_1 + GRABSCENE_HANDLES_RADIUS_2 * 2);
			ofSetDrawBitmapMode(OF_BITMAPMODE_MODEL_BILLBOARD);
			ofDrawBitmapString(this->getReading(), ofPoint());
		}
		
		ofPopStyle();
		
		ofPopMatrix();
		parent->getNode().restoreTransformGL();
		
		if (hadLighting)
			ofEnableLighting();
	}
	
	//---------
	void Handles::Rotate::drawStencil() const {
		if (parent == 0 || !this->enabled)
			return;
		
		parent->getNode().transformGL();
		ofPushMatrix();
		ofScale(scale, scale, scale);
		
		this->rotateAxis();
		fill.draw();
		
		ofPopMatrix();
		parent->getNode().restoreTransformGL();
	}
	
	//---------
	void Handles::Rotate::cursorDragged(const MovingCursor & cursor) {
		if (this->parent == 0)
			return;
		
		ofNode & node(this->parent->getNode());
		ofVec3f center = node.getPosition();
		ofVec3f direction = this->getDirection() * node.getOrientationQuat();
		
		//find element of vector perpendicular to direction
		ofVec3f perp = cursor.worldViewFrameDifference;
		perp -= perp.dot(direction) * direction;
		
		ofVec3f v1, v2;
		v1 = (cursor.startWorld - center).normalized();
		v2 = (cursor.startWorld + perp - center).normalized();
		ofQuaternion rotation;
		rotation.makeRotate(v1,v2);
		
		float angle;
		ofVec3f direction2;
		rotation.getRotate(angle, direction2);
		if (direction2.dot(direction) < 0.0f)
			angle *= -1.0f;
		
		node.rotate(angle, direction);
	}
	
	//---------
	string Handles::Rotate::getReading() const {
		if (this->parent == 0)
			return "";
		
		ofNode & node(this->parent->getNode());
		
		return ofToString(node.getOrientationEuler().dot(this->getDirection()), 2);
	}
}
Exemple #12
0
namespace GrabScene {
	//---------
	ofMesh Handles::Rotate::fill = ofMesh();
	
	//---------
	Handles::Rotate::Rotate(Axis axis) : BaseHandle(axis) {

	}
	
	//---------
	void Handles::Rotate::init() {
		const float radius = GRABSCENE_HANDLES_RADIUS_1;
		const float width = GRABSCENE_HANDLES_RADIUS_2;
		
		const int resolution = 48.0f;
		
		float theta;
		
		////
		//vertices
		
		//inner ring
		for (int i=0; i<resolution; i++) {
			theta = (float) i / (float) resolution * TWO_PI;
			fill.addVertex(ofVec3f(radius * cos(theta), radius * sin(theta), 0.0f));
		}
						   
		//outer ring
		for (int i=0; i<resolution; i++) {
			theta = ((float) i + 0.5f) / (float) resolution * TWO_PI;
			fill.addVertex(ofVec3f((radius + width) * cos(theta), (radius + width) * sin(theta), 0.0f));
		}
		//
		////
		
		
		////
		//indices
		for (int i=0; i<resolution+1; i++) {
			fill.addIndex(i % resolution);
			fill.addIndex((i % resolution) + resolution);
		}
		//
		////
		
		////
		//styles
		fill.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
		//
		////
	}
	
	//---------
	void Handles::Rotate::draw() const {
		if (parent == 0 || !this->enabled)
			return;
		
		GLboolean hadLighting;
		glGetBooleanv(GL_LIGHTING, &hadLighting);
		if (hadLighting)
			ofDisableLighting();
		
		ofPushMatrix();
		this->doTransform();
		
		ofPushStyle();
		shader("fixed").begin();
		
		this->rotateAxis();
		this->setStyleFill();
		fill.draw();
		
		shader("fixed").end();
		
		ofSetColor(255);
		if (this->rollover) {
			ofTranslate(0, GRABSCENE_HANDLES_RADIUS_1 + GRABSCENE_HANDLES_RADIUS_2 * 2);
			ofSetDrawBitmapMode(OF_BITMAPMODE_MODEL_BILLBOARD);
			ofDrawBitmapString(this->getReading(), ofPoint());
		}
		
		ofPopStyle();
		
		ofPopMatrix();
		
		if (hadLighting)
			ofEnableLighting();
	}
	
	//---------
	void Handles::Rotate::drawStencil() const {
		if (parent == 0 || !this->enabled)
			return;
		
		ofPushMatrix();
		this->doTransform();
		
		this->rotateAxis();
		fill.draw();
		
		ofPopMatrix();
	}
	
	//---------
	void Handles::Rotate::cursorDragged(const MovingCursor & cursor) {
		if (this->parent == 0) {
			ofLogError("GrabScene") << "No parent node set for handle";
			return;
		}
		
		ofNode & node(this->parent->getNode());
		ofVec3f center = node.getPosition();
		ofVec3f direction = (this->getDirection() * node.getOrientationQuat()).normalized();
		
		ofVec3f centerToMouse = cursor.startWorld - center;
		ofVec3f tangentDirection = centerToMouse.crossed(direction);
		
		//find ray for positive rotation angle (starts at cursor, goes at tangent)
		ofVec2f screenRayTangentS = cursor.startScreen;
		ofVec2f screenRayTangentT = camera->worldToScreen(cursor.startWorld + tangentDirection) - screenRayTangentS;
		screenRayTangentT.normalize();
		
		float angle = screenRayTangentT.dot(cursor.getScreenFrameDifference());
		
		if (this->getDirection() != ofVec3f(1,0,0))
			angle *= -1.0f;
		
		//check valid
		if (angle == angle && direction == direction) {
			node.rotate(angle, direction);
			this->parent->updateRotate();
		}
	}
	
	//---------
	void Handles::Rotate::doTransform() const {
		ofTranslate(parent->getNode().getPosition());
		glMultMatrixf(ofMatrix4x4(parent->getNode().getOrientationQuat()).getPtr());
		ofTranslate(parent->getOrigin());
		ofScale(scale, scale, scale);
	}
	
	//---------
	string Handles::Rotate::getReading() const {
		if (this->parent == 0)
			return "";
		
		ofNode & node(this->parent->getNode());
		
		return ofToString(node.getOrientationEuler().dot(this->getDirection()), 2);
	}
}
namespace GrabScene {
	//---------
	ofMesh Handles::Translate::fill = ofMesh();
	
	//---------
	Handles::Translate::Translate(Axis axis) :
	BaseHandle(axis) {
	
	}
	
	//---------
	void Handles::Translate::init() {		
		const float length = GRABSCENE_HANDLES_RADIUS_1;
		const float radius = GRABSCENE_HANDLES_RADIUS_2;
		const float width = GRABSCENE_HANDLES_RADIUS_2 * 2.0f / 3.0f;
		
		fill.addVertex(ofVec3f(-width,-width, radius * 2)); //0
		fill.addVertex(ofVec3f(+width,-width, radius * 2)); //1
		fill.addVertex(ofVec3f(+width,+width, radius * 2)); //2
		fill.addVertex(ofVec3f(-width,+width, radius * 2)); //3
		
		fill.addVertex(ofVec3f(-width,-width, length - radius)); //4
		fill.addVertex(ofVec3f(+width,-width, length - radius)); //5
		fill.addVertex(ofVec3f(+width,+width, length - radius)); //6
		fill.addVertex(ofVec3f(-width,+width, length - radius)); //7
		
		fill.addVertex(ofVec3f(0.0f, 0.0f, length)); //8
		
		//back
		fill.addIndex(0);
		fill.addIndex(2);
		fill.addIndex(1);
		
		fill.addIndex(0);
		fill.addIndex(3);
		fill.addIndex(2);
		
		//left
		fill.addIndex(0);
		fill.addIndex(4);
		fill.addIndex(7);
		
		fill.addIndex(0);
		fill.addIndex(7);
		fill.addIndex(3);
		
		//top
		fill.addIndex(7);
		fill.addIndex(2);
		fill.addIndex(3);
		
		fill.addIndex(7);
		fill.addIndex(6);
		fill.addIndex(2);
		
		//right
		fill.addIndex(1);
		fill.addIndex(6);
		fill.addIndex(5);
		
		fill.addIndex(1);
		fill.addIndex(2);
		fill.addIndex(6);		
		
		//bottom
		fill.addIndex(0);
		fill.addIndex(1);
		fill.addIndex(4);
		
		fill.addIndex(4);
		fill.addIndex(1);
		fill.addIndex(5);		
		
		//tip
		fill.addIndex(8);
		fill.addIndex(6);
		fill.addIndex(7);		
		
		fill.addIndex(4);
		fill.addIndex(8);
		fill.addIndex(7);
		
		fill.addIndex(4);
		fill.addIndex(5);
		fill.addIndex(8);
		
		fill.addIndex(8);
		fill.addIndex(5);
		fill.addIndex(6);
		
		fill.setMode(OF_PRIMITIVE_TRIANGLES);
	}
	
	//---------
	void Handles::Translate::draw() const {
		if (parent == 0 || !this->enabled)
			return;
		
		GLboolean hadLighting;
		glGetBooleanv(GL_LIGHTING, &hadLighting);
		if (hadLighting)
			ofDisableLighting();
		
		ofPushMatrix();
		ofTranslate(parent->getNode().getPosition());
		ofTranslate(parent->getNode().getOrientationQuat() * parent->getOrigin());
		ofScale(scale, scale, scale);
								 
		ofPushStyle();
		if (this->axis == NO_AXIS) {
			this->setStyleFill();
			ofBox(GRABSCENE_HANDLES_RADIUS_2 * 2);
		} else {
			this->rotateAxis();
			this->setStyleFill();
			fill.draw();
		}
		ofPopStyle();
		
		if (this->rollover) {
			ofTranslate(0, 0, GRABSCENE_HANDLES_RADIUS_1 + GRABSCENE_HANDLES_RADIUS_2 * 2);
			ofSetDrawBitmapMode(OF_BITMAPMODE_MODEL_BILLBOARD);
			ofDrawBitmapString(this->getReading(), ofPoint());
		}
		
		ofPopMatrix();
		
		if (hadLighting)
			ofEnableLighting();
	}
	
	//---------
	void Handles::Translate::drawStencil() const {
		if (parent == 0 || !this->enabled)
			return;
		
		ofPushMatrix();
		ofTranslate(parent->getNode().getPosition());
		ofTranslate(parent->getNode().getOrientationQuat() * parent->getOrigin());
		ofScale(scale, scale, scale);
		
		if (this->axis == NO_AXIS) {
			ofBox(GRABSCENE_HANDLES_RADIUS_2 * 2);
		} else {
			this->rotateAxis();
			fill.draw();
			
		}
		
		ofPopMatrix();
	}
	
	//---------
	void Handles::Translate::cursorDragged(const MovingCursor & cursor) {
		if (this->parent == 0) {
			ofLogError("GrabScene") << "No parent node set for handle";
			return;
		}
		if (this->camera == 0) {
			ofLogError("GrabScene") << "No camera set for handle";
			return;
		}
		
		ofVec3f direction = this->getDirection();
		ofVec3f movement;
		if (this->axis == NO_AXIS) {
			movement = cursor.worldViewFrameDifference / 2;
		} else {
			// s = start
			// t = ray vector
			// view = in camera view
			const ofVec3f s = this->parent->getNode().getPosition();
			const ofVec3f t = direction;
			
			ofVec3f sView = this->camera->worldToScreen(s);
			ofVec3f tView = this->camera->worldToScreen(s + t) - sView;
			ofVec3f dXY = cursor.getScreenFrameDifference();
			
			sView.z = 0.0f;
			tView.z = 0.0f;
			
			movement = t * tView.dot(dXY) / (tView.length() * tView.length());
		}
		
		//check valid
		if (movement.lengthSquared() == movement.lengthSquared()) {
			this->parent->getNode().move(movement);
			this->parent->updateTranslate();
		}
	}
	
	//---------
	string Handles::Translate::getReading() const {
		if (this->parent == 0)
			return "";
		
		ofNode & node(this->parent->getNode());
		
		if (this->axis == NO_AXIS) {
			string reading;
			ofVec3f position = node.getPosition();
			reading += ofToString(position.x, 2) + ", ";
			reading += ofToString(position.y, 2) + ", ";
			reading += ofToString(position.z, 2);
			return reading;
		} else {
			return ofToString(node.getPosition().dot(this->getDirection()), 2);
		}
	}
}