示例#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;
}
示例#2
0
//--------------------------------------------------------------
ofMatrix4x4 Path3D::zForward(ofMatrix4x4 originalMat){
    
    ofVec3f pos  = originalMat.getTranslation();
    ofVec3f y = originalMat.getRowAsVec3f(1);   // local y-axis
    
    originalMat.setTranslation(0,0,0);
    originalMat.rotate(90, y.x, y.y, y.z);     // rotate about the y
    originalMat.setTranslation(pos);
    
    return originalMat;
}
示例#3
0
//--------------------------------------------------------------
ofMatrix4x4 Path3D::zOut(ofMatrix4x4 originalMat){
    
    ofVec3f pos  = originalMat.getTranslation();
    ofVec3f x = originalMat.getRowAsVec3f(0);   // local x-axis
    
    originalMat.setTranslation(0,0,0);
    originalMat.rotate(-90, x.x, x.y, x.z);      // rotate about the y
    originalMat.setTranslation(pos);
    
    return originalMat;
}
示例#4
0
//--------------------------------------------------------------
ofMatrix4x4 Path3D::flip(ofMatrix4x4 originalMat){
    
    ofVec3f pos  = originalMat.getTranslation();
    ofVec3f z = originalMat.getRowAsVec3f(2);   // local y-axis
    
    originalMat.setTranslation(0,0,0);
    originalMat.rotate(180, z.x, z.y, z.z);     // rotate about the y
    originalMat.setTranslation(pos);
    
    return originalMat;
}
void Model::draw(ofMatrix4x4 camMvpMatrix)
{
    diffuseTex.bind();
    shader.begin();
    ofPushStyle();
    
    GLuint matLoc = glGetUniformLocation(shader.getProgram(), "camMvpMatrix");
    if (matLoc != -1)
    {
        glUniformMatrix4fv(matLoc, 1, GL_FALSE, camMvpMatrix.getPtr());
    }

    shader.setUniformTexture("modelTransTexture", modelTransTexture, 1);
    
    for (auto p : pieces)
    {
        shader.setUniformTexture("animationTexture", p.instancedAnimTextre, 2);
        shader.setUniformTexture("diffuseTex", diffuseTex, 3);
        
        p.material.begin();
        
        ofEnableBlendMode(p.blendmode);
        
        p.vbo.drawElements(GL_TRIANGLES, p.vbo.getNumIndices());
        
        p.material.end();
    }
    
    ofPopStyle();
    shader.end();
    diffuseTex.unbind();
}
void collisionTester::setTransformFromOF(ofMatrix4x4& mat, ofVec3f& s, btCollisionObject& obj){
    
    btTransform trans;
    trans.setFromOpenGLMatrix(mat.getPtr());
    obj.setWorldTransform(trans);
    obj.getCollisionShape()->setLocalScaling(btVector3(s.x, s.y, s.z));
}
示例#7
0
ramPyramidPrimitive::ramPyramidPrimitive(const ofMatrix4x4& mat, float size)
{
	size *= 0.5;

	mesh.addVertex(ofVec3f(1, 1, 1) * size);
	mesh.addVertex(ofVec3f(-1, 1, -1) * size);
	mesh.addVertex(ofVec3f(-1, -1, 1) * size);
	mesh.addVertex(ofVec3f(1, -1, -1) * size);

	mesh.addTriangle(0, 1, 2);
	mesh.addTriangle(0, 2, 3);
	mesh.addTriangle(0, 3, 1);
	mesh.addTriangle(3, 2, 1);

	body = getWorld().addMesh(mesh, mat.getTranslation(), mat.getRotate().getEuler());
}
示例#8
0
static inline aiMatrix4x4 ofMatrix4x4ToAiMatrix44(const ofMatrix4x4 &m)
{
	const float *d = m.getPtr();
	return aiMatrix4x4(d[0], d[4], d[8], d[12],
					d[1], d[5], d[9], d[13],
					d[2], d[6], d[10], d[14],
					d[3], d[7], d[11], d[15]);
}
示例#9
0
ofVec3f ofkUnProjectionHelper::getProjectionPoint(float ofScreenPosX, float ofScreenPosY, ofMatrix4x4 modelView, ofMatrix4x4 projection, float viewWidth, float viewHeight )
{
    GLdouble modelMAT[16];
    GLdouble projectionMAT[16];
    GLint view[4];
    
    for(int i = 0 ; i < 16 ; i++)
    {
        modelMAT[i] = modelView.getPtr()[i];
        projectionMAT[i] = projection.getPtr()[i];
    }
    
    view[0] = 0;
    view[1] = 0;
    view[2] = viewWidth;
    view[3] = viewHeight;
    
    return getProjectionPoint(ofScreenPosX,  ofScreenPosY, modelMAT, projectionMAT, view);
}
示例#10
0
ofVec3f ofkMatrixHelper::getProjectionPoint(ofVec3f pos, const ofMatrix4x4 modelView, ofMatrix4x4 projection, const int *_view)
{
	GLdouble modelMAT[16];
    GLdouble projectionMAT[16];
    GLint view[4];
    
    for(int i = 0 ; i < 16 ; i++)
    {
        modelMAT[i] = modelView.getPtr()[i];
        projectionMAT[i] = projection.getPtr()[i];
    }
    
    view[0] = _view[0];
    view[1] = _view[1];
    view[2] = _view[2];
    view[3] = _view[3];

	return getProjectionPoint(pos,modelMAT, projectionMAT,view);
}
示例#11
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;
}
示例#12
0
void ofxARToolkitPlus::getTranslationAndOrientation(int markerIndex, ofVec3f &translation, ofMatrix4x4 &orientation) {
	
	ARToolKitPlus::ARMarkerInfo marker = tracker->getDetectedMarker(markerIndex);

	getTransMat( &marker, c, m34 );
	
	// Translation
	translation.set(m34[0][3], m34[1][3], m34[2][3]);
	
	// Orientation
	orientation.set(m34[0][0], m34[0][1], m34[0][2], 0,
					m34[1][0], m34[1][1], m34[1][2], 0,
					m34[2][0], m34[2][1], m34[2][2], 0,
					0, 0, 0, 1);
}
示例#13
0
ofMatrix4x4 headTracking::getLastHeadView(ofMatrix4x4 headView)
{
    if (!mTracker.isReady()) {
        return headView;
    }

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

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

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

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

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


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

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

    return headView;
}
示例#14
0
//----------------------------------------------------------
void ofGLRenderer::loadViewMatrix(const ofMatrix4x4 & m){
	int matrixMode;
	glGetIntegerv(GL_MATRIX_MODE,&matrixMode);
	matrixStack.loadViewMatrix(m);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(m.getPtr());
	glMatrixMode(matrixMode);

	if(lightingEnabled){
		for(size_t i=0;i<ofLightsData().size();i++){
			shared_ptr<ofLight::Data> lightData = ofLightsData()[i].lock();
			if(lightData && lightData->isEnabled){
				glLightfv(GL_LIGHT0 + lightData->glIndex, GL_POSITION, &lightData->position.x);
			}
		}
	}
}
示例#15
0
文件: ofxICP.cpp 项目: matusv/ofxICP
void ofxIcp::compute(const vector<ofPoint> & initial, const vector<ofPoint> & target, vector<ofPoint> & output, ofMatrix4x4 & transformation, double & error, int & iterations){
    
    vector<cv::Point3d> initial_cv;
    vector<cv::Point3d> target_cv;
    
    toCV(initial, initial_cv);
    toCV(target, target_cv);
    
    cv::Mat transformation_matrix;
    
    vector<cv::Point3d> output_cv;
    compute(initial_cv, target_cv, output_cv, transformation_matrix, error, iterations);
    
    toOF(output_cv, output);
    
    transformation.set(transformation_matrix.ptr<double>());
}
示例#16
0
bool ofxSymbolInstance::getChildMat(ofxSymbolInstance *child,ofMatrix4x4 &mat) {
    if (this==child) {
        mat = this->mat;
        return true;
    }
    
    for (vector<layer>::iterator liter=layers.begin();liter!=layers.end();liter++) {
        frame &f = liter->frames[liter->currentFrame];
        for (vector<ofxSymbolInstance>::iterator iter=f.instances.begin(); iter!=f.instances.end(); iter++) {
            if (iter->getChildMat(child, mat)) {
                mat.postMult(this->mat);
                return  true;
            }
        }
    }
    
    return false;
}
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);
	}
}
示例#18
0
void ofxARToolkitPlus::getMultiMarkerTranslationAndOrientation(ofVec3f &translation, ofMatrix4x4 &orientation) {

	const ARToolKitPlus::ARMultiMarkerInfoT *multiMarkerConst = tracker->getMultiMarkerConfig();
	if(multiMarkerConst != NULL) {
		// Create a copy of the ARMultiMarkerInfoT struct
		ARToolKitPlus::ARMultiMarkerInfoT mm;
		size_t mmSize = sizeof(ARToolKitPlus::ARMultiMarkerInfoT);
		memcpy(&mm, multiMarkerConst, mmSize);
		
		// Copy and pass in the markers
		int numberOfMarkers = tracker->getNumDetectedMarkers();
#ifdef TARGET_WIN32
		ARToolKitPlus::ARMarkerInfo *marker = new ARToolKitPlus::ARMarkerInfo[numberOfMarkers];
#else
		ARToolKitPlus::ARMarkerInfo marker[numberOfMarkers];
#endif
		for (int i=0; i<numberOfMarkers; i++) {
			marker[i] = tracker->getDetectedMarker(i);
		}
		float result = tracker->rppMultiGetTransMat(marker, numberOfMarkers, &mm);
		
		// Check for error - yes this does occur
		if(result < 0 || result >= INT_MAX) {
			tracker->arMultiGetTransMat(marker, numberOfMarkers, &mm);
			ofLog(OF_LOG_VERBOSE, "RPP failed on multimarker");	
		} 
		
		// Translation
		translation.set(mm.trans[0][3], mm.trans[1][3], mm.trans[2][3]);		
		// Orientation
		orientation.set(mm.trans[0][0], mm.trans[0][1], mm.trans[0][2], 0,
						mm.trans[1][0], mm.trans[1][1], mm.trans[1][2], 0,
						mm.trans[2][0], mm.trans[2][1], mm.trans[2][2], 0,
						0, 0, 0, 1);
#ifdef TARGET_WIN32
		free(marker);
#endif
	} else {
		ofLog(OF_LOG_VERBOSE, "MultiMarkerConfig file NULL");
	}

}
示例#19
0
//----------------------------------------
void ofNode::setTransformMatrix(const ofMatrix4x4 &m44) {
	setTransformMatrix(m44.getPtr());
}
示例#20
0
void Shader::setUniform( const char* name, ofMatrix4x4& _value, bool transpose ){
    if(uniforms.count( name )){
        begin();
        glUniformMatrix4fv(uniforms[name].loc,1, transpose, _value.getPtr() );
    }
}
示例#21
0
void ofxMesh::transform(const ofMatrix4x4 trans) {
    for (int i=0; i<getNumVertices(); i++) {
		getVertices()[i] = trans.preMult(getVertices()[i]);
    }
}
示例#22
0
void ofQuaternion::get(ofMatrix4x4& matrix) const {
	matrix.makeRotationMatrix(*this);
}
示例#23
0
void ofQuaternion::set(const ofMatrix4x4& matrix) {
	*this = matrix.getRotate();
}
示例#24
0
//--------------------------------------------------------------
void ofShader::setUniformMatrix4f(const char* name, const ofMatrix4x4 & m) {
	if(bLoaded)
		glUniformMatrix4fv(getUniformLocation(name), 1, GL_FALSE, m.getPtr());
}
示例#25
0
void applyMatrix(const ofMatrix4x4& matrix) {
	glMultMatrixf((GLfloat*) matrix.getPtr());
}
示例#26
0
//----------------------------------------------------------
void ofGLRenderer::loadMatrix (const ofMatrix4x4 & m){
	loadMatrix( m.getPtr() );
}
示例#27
0
//--------------------------------------------------------------
void ofShader::setUniformMatrix4f(const string & name, const ofMatrix4x4 & m, int count)  const{
	if(bLoaded) {
		int loc = getUniformLocation(name);
		if (loc != -1) glUniformMatrix4fv(loc, count, GL_FALSE, m.getPtr());
	}
}
示例#28
0
void VDB::transform(ofMatrix4x4 & mat) {
	tempTransform.postMult(mat);
	math::Mat4d vMat(mat.getPtr());
	grid->transform().postMult(vMat);
}
示例#29
0
//----------------------------------------------------------
void ofGLRenderer::multMatrix (const ofMatrix4x4 & m){
	multMatrix( m.getPtr() );
}
示例#30
0
void ofxOpenVR::setCurrentHMDMatrix(ofMatrix4x4 & mat) {

	_mat4HMDPose.set(mat.getPtr());
}