Exemplo n.º 1
0
ofRectangle ofxSymbolInstance::getBoundingBox(ofMatrix4x4 mat) {
//    cout << "bounding box" << endl;
    ofRectangle rect(0,0,0,0);
    mat.preMult(this->mat);
    
    switch (type) {
        case BITMAP_INSTANCE: {
            ofVec2f p0 = mat.preMult(ofVec3f(0,0,0));
            ofVec2f p1 = mat.preMult(ofVec3f(bitmapItem->getWidth(),bitmapItem->getHeight()));
            rect = ofRectangle(p0.x,p0.y,p1.x-p0.x,p1.y-p0.y);
        } break;
            
        case SYMBOL_INSTANCE: {
            
            for (vector<layer>::iterator liter=layers.begin();liter!=layers.end();liter++) {
                frame &f = liter->frames[liter->currentFrame];
                
                vector<ofxSymbolInstance>::iterator iter=f.instances.begin();
                while (iter!=f.instances.end()) {
                    rect = iter->getBoundingBox(mat);
                    iter++;
                    if (rect.width!=0 || rect.height!=0) {
                        break;
                    }
                }
                
                while (iter!=f.instances.end()) {
                    
                    ofRectangle iterect = iter->getBoundingBox();
                    if (iterect.width!=0 || iterect.height!=0) {
                    
                        ofVec2f p0(rect.x,rect.y);
                        ofVec2f p1(p0.x+rect.width,p0.y+rect.height);
                        
                        ofVec2f q0(iterect.x,iterect.y);
                        ofVec2f q1(q0.x+iterect.width,q0.y+iterect.height);
                        
                        ofVec2f pos(MIN(p0.x,q0.x),MIN(p0.y,q0.y));
                        rect = ofRectangle(pos.x,pos.y,MAX(p1.x,q1.x)-pos.x,MAX(p1.y,q1.y)-pos.y);
                            
                       
                            //                    cout << rect.x << "\t" << rect.y << "\t" << rect.width << "\t" << rect.height << endl;
                            
                    }
                    iter++;
                   
                }
            }
        } break;
            
        default:
            break;
    } 
    
        
    return rect;
}
Exemplo n.º 2
0
ofRectangle ofRectangleTransform(const ofRectangle & rect, const ofMatrix4x4 & mat) {
    ofVec3f tl = rect.getTopLeft();
    ofVec3f br = rect.getBottomRight();
    
    tl = mat.preMult(tl);
    br = mat.preMult(br);
    
    ofRectangle r;
    r.setPosition(tl);
    r.growToInclude(br);
    
    return r;
}
Exemplo n.º 3
0
void ofxPolyline2Mesh::pushSegment(const ofColor& c2, const ofColor& c1,
				 const ofMatrix4x4 &m)
{
	for (int i = 0; i < shape.size(); i++)
	{
		const ofVec3f &p = m.preMult(shape[i]);
		current_segments[i] = p;
	}

	for (int i = 0; i < shape.size() - 1; i++)
	{
		const ofVec3f &p1 = last_segments[i];
		const ofVec3f &p2 = current_segments[i];

		const ofVec3f &n1 = last_segments[i + 1];
		const ofVec3f &n2 = current_segments[i + 1];

		const ofVec3f norm = (p2 - p1).crossed((n1 - p1)).normalized();

		mesh.addNormal(norm);
		mesh.addColor(c1);
		mesh.addVertex(p1);

		mesh.addNormal(norm);
		mesh.addColor(c2);
		mesh.addVertex(p2);

		mesh.addNormal(norm);
		mesh.addColor(c1);
		mesh.addVertex(n1);

		mesh.addNormal(norm);
		mesh.addColor(c1);
		mesh.addVertex(n1);

		mesh.addNormal(norm);
		mesh.addColor(c2);
		mesh.addVertex(p2);

		mesh.addNormal(norm);
		mesh.addColor(c2);
		mesh.addVertex(n2);
	}
}
Exemplo n.º 4
0
void ofxMesh::transform(const ofMatrix4x4 trans) {
    for (int i=0; i<getNumVertices(); i++) {
		getVertices()[i] = trans.preMult(getVertices()[i]);
    }
}