Ejemplo n.º 1
0
void get_bounding_box_for_node (const struct aiScene *sc,
                                const struct aiNode* nd,
                                struct aiVector3D* min,
                                struct aiVector3D* max,
                                struct aiMatrix4x4* trafo)
{
	struct aiMatrix4x4 prev;
	unsigned int n = 0, t;
    
	prev = *trafo;
	aiMultiplyMatrix4(trafo,&nd->mTransformation);
    
	for (; n < nd->mNumMeshes; ++n) {
		const struct aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];
		for (t = 0; t < mesh->mNumVertices; ++t) {
            
			struct aiVector3D tmp = mesh->mVertices[t];
			aiTransformVecByMatrix4(&tmp,trafo);
            
			min->x = aisgl_min(min->x,tmp.x);
			min->y = aisgl_min(min->y,tmp.y);
			min->z = aisgl_min(min->z,tmp.z);
            
			max->x = aisgl_max(max->x,tmp.x);
			max->y = aisgl_max(max->y,tmp.y);
			max->z = aisgl_max(max->z,tmp.z);
		}
	}
    
	for (n = 0; n < nd->mNumChildren; ++n) {
		get_bounding_box_for_node(sc, nd->mChildren[n],min,max,trafo);
	}
	*trafo = prev;
}
//-------------------------------------------
void ofxAssimpModelLoader::getBoundingBoxForNode(const struct aiNode* nd,  struct aiVector3D* min, struct aiVector3D* max, struct aiMatrix4x4* trafo)
{
	struct aiMatrix4x4 prev;
	unsigned int n = 0, t;
    
	prev = *trafo;
	aiMultiplyMatrix4(trafo,&nd->mTransformation);
    
	for (; n < nd->mNumMeshes; ++n){
		const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
		for (t = 0; t < mesh->mNumVertices; ++t){
        	struct aiVector3D tmp = mesh->mVertices[t];
			aiTransformVecByMatrix4(&tmp,trafo);
        
            
			min->x = aisgl_min(min->x,tmp.x);
			min->y = aisgl_min(min->y,tmp.y);
			min->z = aisgl_min(min->z,tmp.z);
            
			max->x = aisgl_max(max->x,tmp.x);
			max->y = aisgl_max(max->y,tmp.y);
			max->z = aisgl_max(max->z,tmp.z);
		}
	}
    
	for (n = 0; n < nd->mNumChildren; ++n){
		this->getBoundingBoxForNode(nd->mChildren[n], min, max, trafo);
	}
    
	*trafo = prev;
}
Ejemplo n.º 3
0
void Model3D::get_bounding_box_for_node(const struct aiNode* nd, struct aiVector3D* min, struct aiVector3D* max, struct aiMatrix4x4* trafo) {
    struct aiMatrix4x4 prev; // Use struct keyword to show you want struct version of this, not normal typedef?
    unsigned int n = 0, t;

    prev = *trafo;
    aiMultiplyMatrix4(trafo, &nd->mTransformation);

    for (; n < nd->mNumMeshes; ++n) {
        const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
        for (t = 0; t < mesh->mNumVertices; ++t) {
            struct aiVector3D tmp = mesh->mVertices[t];
            aiTransformVecByMatrix4(&tmp, trafo);

            min->x = aisgl_min(min->x,tmp.x);
            min->y = aisgl_min(min->y,tmp.y);
            min->z = aisgl_min(min->z,tmp.z);

            max->x = aisgl_max(max->x,tmp.x);
            max->y = aisgl_max(max->y,tmp.y);
            max->z = aisgl_max(max->z,tmp.z);
        }
    }

    for (n = 0; n < nd->mNumChildren; ++n)
        get_bounding_box_for_node(nd->mChildren[n], min, max, trafo);

    *trafo = prev;
}
Ejemplo n.º 4
0
void get_bounding_box_for_node (const aiNode* nd, 
	aiVector3D* min, 
	aiVector3D* max)
	
{
	aiMatrix4x4 prev;
	unsigned int n = 0, t;

	for (; n < nd->mNumMeshes; ++n) {
		const aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
		for (t = 0; t < mesh->mNumVertices; ++t) {

			aiVector3D tmp = mesh->mVertices[t];

			min->x = aisgl_min(min->x,tmp.x);
			min->y = aisgl_min(min->y,tmp.y);
			min->z = aisgl_min(min->z,tmp.z);

			max->x = aisgl_max(max->x,tmp.x);
			max->y = aisgl_max(max->y,tmp.y);
			max->z = aisgl_max(max->z,tmp.z);
		}
	}

	for (n = 0; n < nd->mNumChildren; ++n) {
		get_bounding_box_for_node(nd->mChildren[n],min,max);
	}
}
Ejemplo n.º 5
0
void
VSResModelLib::get_bounding_box_for_node (const struct aiNode* nd,
        struct aiVector3D* min,
        struct aiVector3D* max)

{
    unsigned int n = 0;

    mVSML->pushMatrix(VSMathLib::AUX0);

    if (nd->mNumMeshes) {

        // Get node transformation matrix
        struct aiMatrix4x4 m = nd->mTransformation;

        // OpenGL matrices are column major
        m.Transpose();

        // apply node transformation
        float aux[16];
        memcpy(aux,&m,sizeof(float) * 16);
        mVSML->multMatrix(VSMathLib::AUX0, aux);


        for (; n < nd->mNumMeshes; ++n) {
            const struct aiMesh* mesh =
                    pScene->mMeshes[nd->mMeshes[n]];
            for (unsigned int t = 0; t < mesh->mNumVertices; ++t) {

                struct aiVector3D tmp = mesh->mVertices[t];
                float a[4], res[4];

                a[0] = tmp.x;
                a[1] = tmp.y;
                a[2] = tmp.z;
                a[3] = 1.0f;

                mVSML->multMatrixPoint(VSMathLib::AUX0, a, res);

                min->x = aisgl_min(min->x,res[0]);
                min->y = aisgl_min(min->y,res[1]);
                min->z = aisgl_min(min->z,res[2]);

                max->x = aisgl_max(max->x,res[0]);
                max->y = aisgl_max(max->y,res[1]);
                max->z = aisgl_max(max->z,res[2]);
            }
        }
    }

    for (n = 0; n < nd->mNumChildren; ++n) {
        get_bounding_box_for_node(nd->mChildren[n],min,max);
    }

    mVSML->popMatrix(VSMathLib::AUX0);
}