コード例 #1
0
void AssimpScene::recursive_render(const aiScene * sc, const aiNode * nd, aiMatrix4x4 *matrix_before)
{
	aiMatrix4x4 m = (*matrix_before) * nd->mTransformation;
	//aiTransposeMatrix4(&m);
	//glMultMatrixf((float*)&m);
	//std::cout <<"mNumMeshes " << nd->mNumMeshes <<std::endl;
	for (int n = 0; n < nd->mNumMeshes; ++n) {
		const aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];
		for (int t = 0; t < mesh->mNumFaces; ++t) {
			const struct aiFace* face = &mesh->mFaces[t];
			for (int i = 0; i < face->mNumIndices; i++) {
				int index = face->mIndices[i];
				aiVector3D vert, normal;
				vert = m*mesh->mVertices[index];
				if (mesh->mColors[0] != NULL);// glColor4fv((GLfloat*)&mesh->mColors[0][index]);
				if (mesh->mNormals != NULL) normal = mesh->mNormals[index];

			}
		}

	}

	for (int n = 0; n < nd->mNumChildren; ++n) {
		recursive_render(sc, nd->mChildren[n], &m);
	}
}
コード例 #2
0
void drawAiScene(const aiScene* scene)
{
	logInfo("drawing objects");

	recursive_render(scene, scene->mRootNode, 0.5);

}
コード例 #3
0
ファイル: Scene.cpp プロジェクト: abrajoe/Piano-Scene
void recursive_render (const aiNode* node, aiMatrix4x4 accumulatedTransform)
{
	aiMatrix4x4 transform;
	if (node->mNumMeshes > 0)
	{               
		for (int m=0; m < node->mNumMeshes; m++)
		{
			aiMesh* mesh = scene->mMeshes[m];
			for (int f =0; f< mesh->mNumFaces; f++)
			{
				aiFace * face =  &mesh->mFaces[f];
				glBegin(GL_TRIANGLES);
				::glColor3d(0,1,0);
				for (int v=0; v<3; v++)
				{
						glVertex3f( mesh->mVertices[ face->mIndices[v]].x,mesh->mVertices[ face->mIndices[v]].y,mesh->mVertices[ face->mIndices[v]].z);
				}
				glEnd();
			}
		}
	}
	 else 
     {
		//transform =	node->mTransformation * accumulatedTransform;
		//glLoadIdentity();
		//glMultMatrixf((const GLfloat *) &transform);
     }
	for (int i=0; i<node->mNumChildren; i++)
    {
            recursive_render(node->mChildren[i],transform);
    }
}
コード例 #4
0
ファイル: Model.cpp プロジェクト: ggf31416/CompGraf1
/* ---------------------------------------------------------------------------- */
void Model::draw(GLdouble angulo,GLdouble angulo_centro)
{
	glPushMatrix();
	aiVector3D *min = new aiVector3D(),*max = new aiVector3D();
	get_bounding_box(min,max);
	GLdouble largoMoto = (max->x-min->x);
	GLdouble altoMoto = (max->y-min->y);
	float escala = largoMoto > 1 ? 1/largoMoto : 1;

	//Muevo moto
	glTranslated(posX - largoMoto/2,posY ,0);
	glScalef(escala, escala, escala);
	//Roto moto
	glTranslated(-largoMoto/2+largoMoto*relLargoEjeTrasero,altoMoto*relAltoEjeTrasero,0);
	glRotated(angulo,0,0,1);
	glTranslated(largoMoto/2-largoMoto*relLargoEjeTrasero,-altoMoto*relAltoEjeTrasero,0);
	float centro_rot_x = largoMoto / 2;
	float centro_rot_y = altoMoto / 2;
	glColor3f(1,0,1);
	glTranslated(0,0,0);
	// centro de rotacion
	glBegin(GL_POINTS);
	glVertex3d(0, 0, 0);
	glEnd();
	glRotated(angulo_centro,0,0,1);
	glTranslated(0, 0,0);





	//Dibujo moto
	recursive_render(scene, scene->mRootNode);
	glPopMatrix();
}
コード例 #5
0
ファイル: assimpGUtil.cpp プロジェクト: Fraency189/omplapp
            int assimpRender(const std::vector<const aiScene*> &scenes, const std::vector<aiVector3D> &robotCenter)
            {
                int result = glGenLists(1);

                // create display list for robot; we undo the translation of the robot
                glNewList(result, GL_COMPILE);

                aiMatrix4x4 t;
                for (unsigned int i = 0 ; i < scenes.size() ; ++i)
                {
                    bool tr = robotCenter.size() > i;
                    if (tr)
                    {
                        aiMatrix4x4::Translation(-robotCenter[i], t);
                        aiTransposeMatrix4(&t);
                        glPushMatrix();
                        glMultMatrixf((float*)&t);
                    }

                    recursive_render(scenes[i], scenes[i]->mRootNode);

                    if (tr)
                        glPopMatrix();
                }

                glEndList();

                return result;
            }
コード例 #6
0
void AssimpScene::recursive_render_old(const aiScene * sc, const aiNode * nd)
{
	aiMatrix4x4 m = nd->mTransformation;
	aiTransposeMatrix4(&m);
	glPushMatrix();
	glMultMatrixf((float*)&m);
	//std::cout <<"mNumMeshes " << nd->mNumMeshes <<std::endl;
	for (int n = 0; n < nd->mNumMeshes; ++n) {
		const aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];
		//std::cout << "mNumFaces " << mesh->mNumFaces << std::endl;
		applyMaterial(sc->mMaterials[mesh->mMaterialIndex]);

		if (mesh->mNormals == NULL) {
			//std::cout << "DISABLE LIGHTENING " << std::endl;
			glDisable(GL_LIGHTING);
		}
		else {
			//std::cout << "ENABLE LIGHTENING "  << std::endl;
			glEnable(GL_LIGHTING);
		}
		//apply_material(sc->mMaterials[mesh->mMaterialIndex]);

		//std::cout << "mesh->mNumFaces begin" << std::endl;
		

		for (int t = 0; t < mesh->mNumFaces; ++t) {
			const struct aiFace* face = &mesh->mFaces[t];
			GLenum face_mode;

			switch (face->mNumIndices) {
			case 1: face_mode = GL_POINTS; break;
			case 2: face_mode = GL_LINES; break;
			case 3: face_mode = GL_TRIANGLES; break;
			default: face_mode = GL_POLYGON; break;
			}
			//if (mesh->mNormals == NULL) glDisable(GL_LIGHTING);
			// else glEnable(GL_LIGHTING);
			glBegin(face_mode);

			for (int i = 0; i < face->mNumIndices; i++) {
				int index = face->mIndices[i];
				if (mesh->mColors[0] != NULL)
					glColor4fv((GLfloat*)&mesh->mColors[0][index]);
				if (mesh->mNormals != NULL)
					glNormal3fv(&mesh->mNormals[index].x);
				glVertex3fv(&mesh->mVertices[index].x);
			}

			glEnd();
		}

	}

	for (int n = 0; n < nd->mNumChildren; ++n) {
		aiMatrix4x4 m;
		recursive_render(sc, nd->mChildren[n],&m );
	}
	glPopMatrix();
}
コード例 #7
0
ファイル: Sample_SimpleOpenGL.c プロジェクト: CCJY/assimp
/* ---------------------------------------------------------------------------- */
void recursive_render (const struct aiScene *sc, const struct aiNode* nd)
{
	unsigned int i;
	unsigned int n = 0, t;
	struct aiMatrix4x4 m = nd->mTransformation;

	/* update transform */
	aiTransposeMatrix4(&m);
	glPushMatrix();
	glMultMatrixf((float*)&m);

	/* draw all meshes assigned to this node */
	for (; n < nd->mNumMeshes; ++n) {
		const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];

		apply_material(sc->mMaterials[mesh->mMaterialIndex]);

		if(mesh->mNormals == NULL) {
			glDisable(GL_LIGHTING);
		} else {
			glEnable(GL_LIGHTING);
		}

		for (t = 0; t < mesh->mNumFaces; ++t) {
			const struct aiFace* face = &mesh->mFaces[t];
			GLenum face_mode;

			switch(face->mNumIndices) {
				case 1: face_mode = GL_POINTS; break;
				case 2: face_mode = GL_LINES; break;
				case 3: face_mode = GL_TRIANGLES; break;
				default: face_mode = GL_POLYGON; break;
			}

			glBegin(face_mode);

			for(i = 0; i < face->mNumIndices; i++) {
				int index = face->mIndices[i];
				if(mesh->mColors[0] != NULL)
					glColor4fv((GLfloat*)&mesh->mColors[0][index]);
				if(mesh->mNormals != NULL) 
					glNormal3fv(&mesh->mNormals[index].x);
				glVertex3fv(&mesh->mVertices[index].x);
			}

			glEnd();
		}

	}

	/* draw all children */
	for (n = 0; n < nd->mNumChildren; ++n) {
		recursive_render(sc, nd->mChildren[n]);
	}

	glPopMatrix();
}
コード例 #8
0
void AssimpScene::Render()
{
	bool is_lighting = glIsEnabled(GL_LIGHTING);
	aiMatrix4x4 m;
	recursive_render(this->scene, this->scene->mRootNode, &m);
	if (is_lighting)
		glEnable(GL_LIGHTING);
	else
		glDisable(GL_LIGHTING);
}
コード例 #9
0
ファイル: render_object.cpp プロジェクト: torandi/duststorm
void RenderObject::recursive_render(const aiNode* node,
		const glm::mat4 &parent_matrix) const {


	aiMatrix4x4 m = node->mTransformation;
	m.Transpose();

	glm::mat4 matrix(parent_matrix);

	matrix *= glm::make_mat4((float*)&m);

	Shader::upload_model_matrix(matrix);

	for(unsigned int i=0; i<node->mNumMeshes; ++i) {
		const aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];

		if(mesh->mNumFaces > 0) {
			auto it = mesh_data.find(mesh);
			const mesh_data_t *md;

			if(it != mesh_data.end()) {
				md = &(it->second);
			} else {
				continue;
			}

			if(md->num_indices > 0) {
				glBindBuffer(GL_ARRAY_BUFFER, md->vb);
				glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, md->ib);

				glVertexAttribPointer(Shader::ATTR_POSITION,  3, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, pos));
				glVertexAttribPointer(Shader::ATTR_TEXCOORD,  2, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, uv));
				glVertexAttribPointer(Shader::ATTR_NORMAL,    3, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, normal));
				glVertexAttribPointer(Shader::ATTR_TANGENT,   3, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, tangent));
				glVertexAttribPointer(Shader::ATTR_BITANGENT, 3, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, bitangent));
				glVertexAttribPointer(Shader::ATTR_COLOR,     4, GL_FLOAT, GL_FALSE, sizeof(Shader::vertex_t), (const GLvoid*)offsetof(Shader::vertex_t, color));

				checkForGLErrors("set attrib pointers");

				materials[md->mtl_index].bind();
				checkForGLErrors("Activte material");

				glDrawElements(GL_TRIANGLES, md->num_indices, GL_UNSIGNED_INT,0 );
				checkForGLErrors("Draw material");
			}
		}
	}

	for(unsigned int i=0; i<node->mNumChildren; ++i) {
		recursive_render(node->mChildren[i], matrix);
	}

}
コード例 #10
0
ファイル: Model.cpp プロジェクト: heropunch/cyberdeck
void Model::renderScene(GLuint program, const glm::mat4 &MVP, const glm::mat4 &V, const glm::mat4 &M, bool shadowPass, const glm::mat4 &depthMVP) {
//	glUseProgram(program);
    
    if(shadowPass) {
        glUseProgram(shadowProgram.shader.program);
    } else {
        glUseProgram(modelShaderProgram.shader.program);
        glActiveTexture(GL_TEXTURE0);
        glUniform1i(texUnit,0);
    }
    
//    glActiveTexture(GL_TEXTURE0);
//    glUniform1i(ModelUniformLocations[3], 0);
    
	recursive_render(scene, scene->mRootNode, MVP, V, M, shadowPass, depthMVP);
}
コード例 #11
0
void Model3D::draw(int selection) {
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glLoadMatrixd(modelview_matrix);

    glTranslatef(x, y, z);
    glRotatef(rotationx, rotationy, rotationz, 0);
    glScalef(scalex, scaley, scalez);

    glPushMatrix();

    glColor4f(1, 1, 1, 1);

    recursive_render(scene, scene->mRootNode);
    glPopMatrix();
}
コード例 #12
0
ファイル: main.cpp プロジェクト: licnep/RangoShooter
void drawBullet()
{
    int i;
    float posX = 0.0f;
    
    for (i = 0; i < gun0.bullet_number; i++) {
        glPushMatrix();
        glScalef(0.05,0.05,0.05); //rimpiccioliamo i proiettili
        glTranslatef(5.f+posX, -6.5f, -23.0f);
        recursive_render(gun0.proiettile.scene,gun0.proiettile.scene->mRootNode, 1.0);
        posX += 1.0f;
        glPopMatrix();
        
    }
    
    return;
}
コード例 #13
0
void renderScene(void) {

	static float step = 0.0f;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// set camera matrix
	setCamera(camX,camY,camZ,0,0,0);

	// set the model matrix to the identity Matrix
	setIdentityMatrix(modelMatrix,4);

	// sets the model matrix to a scale matrix so that the model fits in the window
	scale(scaleFactor, scaleFactor, scaleFactor);

	// keep rotating the model
	rotate(step, 0.0f, 1.0f, 0.0f);
	
	// use our shader
	glUseProgram(program);

	// we are only going to use texture unit 0
	// unfortunately samplers can't reside in uniform blocks
	// so we have set this uniform separately
	glUniform1i(texUnit,0);

	recursive_render(scene, scene->mRootNode);

	// FPS computation and display
	frame++;
	time=glutGet(GLUT_ELAPSED_TIME);
	if (time - timebase > 1000) {
		sprintf(s,"FPS:%4.2f",
			frame*1000.0/(time-timebase));
		timebase = time;
		frame = 0;
		glutSetWindowTitle(s);
	}

	// swap buffers
	glutSwapBuffers();

	// increase the rotation angle
	//step++;
}
コード例 #14
0
ファイル: Scene.cpp プロジェクト: abrajoe/Piano-Scene
void display()
{
  glLoadIdentity();  
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
  
  glTranslatef(0,0, dist);
  glRotatef(rotation, 0, 1, 0);
  ::aiMatrix4x4 mat;
  recursive_render(scene->mRootNode, mat);
 
  
 // for (int numMesh = 0; numMesh < scene ->mNumMeshes; numMesh++)
 // {
	//  //glBegin(returnprimitvetype(scene->mMeshes[numMesh]->mPrimitiveTypes));
	//  
	//  glColor3d(0,1,0);
	//  scene->mRootNode-

	//  for(int vcount = 0; vcount < scene->mMeshes[numMesh]->mNumVertices; vcount++)
	//  {

	//	 std::cout<<scene->mMeshes[numMesh]->mNumVertices<<std::endl;
	//	  glVertex3f(scene->mMeshes[numMesh]->mVertices[vcount].x,scene->mMeshes[numMesh]->mVertices[vcount].y, scene->mMeshes[numMesh]->mVertices[vcount].z);
	//  }
	//glEnd();
 // }

  glutSwapBuffers();
  // Now we can access the file's contents. 
  //DoTheSceneProcessing( scene);

	//for(int x = 0; x < 1; x++)
	//{
	//	for(int y = 0; y <1; y++)
	//	{
	//		for(int z = -1; z < 0; z++)
	//		{
	//			glVertex3f(x,y,z);
	//		}
	//	}
	//}

}
コード例 #15
0
ファイル: Sample_SimpleOpenGL.c プロジェクト: CCJY/assimp
/* ---------------------------------------------------------------------------- */
void display(void)
{
	float tmp;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0.f,0.f,3.f,0.f,0.f,-5.f,0.f,1.f,0.f);

	/* rotate it around the y axis */
	glRotatef(angle,0.f,1.f,0.f);

	/* scale the whole asset to fit into our view frustum */
	tmp = scene_max.x-scene_min.x;
	tmp = aisgl_max(scene_max.y - scene_min.y,tmp);
	tmp = aisgl_max(scene_max.z - scene_min.z,tmp);
	tmp = 1.f / tmp;
	glScalef(tmp, tmp, tmp);

        /* center the model */
	glTranslatef( -scene_center.x, -scene_center.y, -scene_center.z );

        /* if the display list has not been made yet, create a new one and
           fill it with scene contents */
	if(scene_list == 0) {
	    scene_list = glGenLists(1);
	    glNewList(scene_list, GL_COMPILE);
            /* now begin at the root node of the imported data and traverse
               the scenegraph by multiplying subsequent local transforms
               together on GL's matrix stack. */
	    recursive_render(scene, scene->mRootNode);
	    glEndList();
	}

	glCallList(scene_list);

	glutSwapBuffers();

	do_motion();
}
コード例 #16
0
ファイル: main.cpp プロジェクト: licnep/RangoShooter
void drawGun ()
{
	aiVector2D xy;
	float x,y;
	xy=cursor_position();

	//coordinate in pixel con origine nel centro della finestra
	x=xy.x-100.0;
	y=xy.y-100.0;
	glPushMatrix();
	glScalef(0.05,0.05,0.05); //la rimpiccioliamo perche' e' enorme
	glTranslatef(0.f, -7.f, -17.2);
	pistola.applyGlMatrixTransformations(); //applico l'animazione
	glRotatef(-y*0.2, 1.0f, 0.0f, 0.f);
	glRotatef(-x*0.4, 0.0f, 1.0f, 0.f);
	glTranslatef(0.f, 0.f, -6.0f);
	glRotatef(90.0,0.0,1.0,0.0);
	recursive_render(gun0.pistola.scene,gun0.pistola.scene->mRootNode, 1.0);

	glPopMatrix();

}
コード例 #17
0
ファイル: Model.cpp プロジェクト: heropunch/cyberdeck
void Model::recursive_render(const aiScene *sc, const aiNode* nd,  const glm::mat4 &MVP, const glm::mat4 &V, const glm::mat4 &M, bool shadowPass, const glm::mat4 &depthMVP)
{
    aiMatrix4x4 m = nd->mTransformation;
    m.Transpose(); // OpenGL matrices are column major
    
    glm::mat4 transformation(m.a1, m.a2, m.a3, m.a4,
                             m.b1, m.b2, m.b3, m.b4,
                             m.c1, m.c2, m.c3, m.c4,
                             m.d1, m.d2, m.d3, m.d4);
    glm::mat4 MVP2 = MVP*transformation;
    glm::mat4 M2 = M*transformation;
    
    if(shadowPass) {
        glUniformMatrix4fv(ShadowUniformLocations[0], 1, GL_FALSE, &MVP2[0][0]);
    } else {
        glUniformMatrix4fv(ModelUniformLocations[0], 1, GL_FALSE, &MVP2[0][0]);
        glUniformMatrix4fv(ModelUniformLocations[1], 1, GL_FALSE, &V[0][0]);
        glUniformMatrix4fv(ModelUniformLocations[2], 1, GL_FALSE, &M2[0][0]);
        glUniformMatrix4fv(ModelUniformLocations[4], 1, GL_FALSE, &(V*M2)[0][0]);
        if(ModelUniformLocations[5] > -1) glUniform3f(ModelUniformLocations[5], lightInvDir.x, lightInvDir.y, lightInvDir.z);
    }
    
    // draw node
    for (unsigned int n=0; n < nd->mNumMeshes; ++n){
        glBindBufferRange(GL_UNIFORM_BUFFER, materialUniLoc, myMeshes[nd->mMeshes[n]].uniformBlockIndex, 0, sizeof(struct MyMaterial));
        
        if(!shadowPass) {
            glBindTexture(GL_TEXTURE_2D, myMeshes[nd->mMeshes[n]].texIndex);
        }
        glBindVertexArray(myMeshes[nd->mMeshes[n]].vao);
        glDrawElements(GL_TRIANGLES,myMeshes[nd->mMeshes[n]].numFaces*3,GL_UNSIGNED_INT,0);
        
    }
    
    // draw children
    for (unsigned int n=0; n < nd->mNumChildren; ++n){
        recursive_render(sc, nd->mChildren[n], MVP2, V, M2, shadowPass, depthMVP);
    }
}
コード例 #18
0
ファイル: Render.cpp プロジェクト: aarich/3DLocalization
    void recursive_render(const aiNode* nd)
    {

        // Get node transformation matrix
        aiMatrix4x4 m = nd->mTransformation;
        // OpenGL matrices are column major
        m.Transpose();

        // save model matrix and apply node transformation
        pushMatrix();

        float aux[16];
        memcpy(aux,&m,sizeof(float) * 16);
        MathHelp::multMatrix(modelMatrix, aux);
        setModelMatrix();


        // draw all meshes assigned to this node
        for (unsigned int n=0; n < nd->mNumMeshes; ++n)
        {
            // bind material uniform
            glBindBufferRange(GL_UNIFORM_BUFFER, materialUniLoc, myMeshes[nd->mMeshes[n]].uniformBlockIndex, 0, sizeof(struct Helper::MyMaterial)); 
            // bind texture
            glBindTexture(GL_TEXTURE_2D, myMeshes[nd->mMeshes[n]].texIndex);
            // bind VAO
            glBindVertexArray(myMeshes[nd->mMeshes[n]].vao);
            // draw
            glDrawElements(GL_TRIANGLES,myMeshes[nd->mMeshes[n]].numFaces*3,GL_UNSIGNED_INT,0);
        }

        // draw all children
        for (unsigned int n=0; n < nd->mNumChildren; ++n)
        {
            recursive_render(nd->mChildren[n]);
        }
        popMatrix();
    }
コード例 #19
0
ファイル: render.c プロジェクト: ShapeNet/LightweightRenderer
void drawAiScene(const aiScene* scene)
{
    recursive_render(scene, scene->mRootNode, 1);
}
コード例 #20
0
void Model3D::recursive_render(const struct aiScene *sc, const struct aiNode* nd) {
    int i;
    unsigned int n = 0, t;
    struct aiMatrix4x4 m = nd->mTransformation;

    // update transform
    aiTransposeMatrix4(&m);
    glPushMatrix();
    glMultMatrixf((float*) &m);

    // draw all meshes assigned to this node
    for (; n < nd->mNumMeshes; ++n) {
        const struct aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];

        if (n < texturesAndPaths.size())
            glBindTexture(GL_TEXTURE_2D, texturesAndPaths[n].hTexture);

        apply_material(sc->mMaterials[mesh->mMaterialIndex]);

        if (mesh->mNormals == NULL
           )
            glDisable(GL_LIGHTING);
        else
            glEnable(GL_LIGHTING);

        if (mesh->mColors[0] != NULL
           )
            glEnable(GL_COLOR_MATERIAL);
        else
            glDisable(GL_COLOR_MATERIAL);

        for (t = 0; t < mesh->mNumFaces; ++t) {
            const struct aiFace* face = &mesh->mFaces[t];
            GLenum face_mode;

            switch (face->mNumIndices) {
            case 1:
                face_mode = GL_POINTS;
                break;
            case 2:
                face_mode = GL_LINES;
                break;
            case 3:
                face_mode = GL_TRIANGLES;
                break;
            default:
                face_mode = GL_POLYGON;
                break;
            }

            glBegin(face_mode);

            for (i = 0; i < face->mNumIndices; i++) {
                int index = face->mIndices[i];
                if (mesh->mColors[0] != NULL
                   )
                    Color4f(&mesh->mColors[0][index]);
                if (mesh->mNormals != NULL
                   )
                    glNormal3fv(&mesh->mNormals[index].x);
                if (mesh->HasTextureCoords(0))
                    glTexCoord2f(mesh->mTextureCoords[0][index].x, mesh->mTextureCoords[0][index].y);
                glVertex3fv(&mesh->mVertices[index].x);
            }

            glEnd();
        }
    }

    // draw all children
    for (n = 0; n < nd->mNumChildren; ++n)
        recursive_render(sc, nd->mChildren[n]);

    glPopMatrix();
}
コード例 #21
0
void recursive_render (const struct aiScene *sc, const struct aiNode* nd, float scale)
{
	unsigned int i;
	unsigned int n=0, t;
	aiMatrix4x4 m = nd->mTransformation;

	m.Scaling(aiVector3D(scale, scale, scale), m);

	// update transform
	m.Transpose();
	glPushMatrix();
	glMultMatrixf((float*)&m);

	// draw all meshes assigned to this node
	for (; n < nd->mNumMeshes; ++n)
	{
		const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];

		apply_material(sc->mMaterials[mesh->mMaterialIndex]);


		if(mesh->mNormals == NULL)
		{
			glDisable(GL_LIGHTING);
		}
		else
		{
			glEnable(GL_LIGHTING);
		}

		if(mesh->mColors[0] != NULL)
		{
			glEnable(GL_COLOR_MATERIAL);
		}
		else
		{
			glDisable(GL_COLOR_MATERIAL);
		}



		for (t = 0; t < mesh->mNumFaces; ++t) {
			const struct aiFace* face = &mesh->mFaces[t];
			GLenum face_mode;

			switch(face->mNumIndices)
			{
				case 1: face_mode = GL_POINTS; break;
				case 2: face_mode = GL_LINES; break;
				case 3: face_mode = GL_TRIANGLES; break;
				default: face_mode = GL_POLYGON; break;
			}

			glBegin(face_mode);

			for(i = 0; i < face->mNumIndices; i++)		// go through all vertices in face
			{
				int vertexIndex = face->mIndices[i];	// get group index for current index
				if(mesh->mColors[0] != NULL)
					Color4f(&mesh->mColors[0][vertexIndex]);
				if(mesh->mNormals != NULL)

					if(mesh->HasTextureCoords(0))		//HasTextureCoords(texture_coordinates_set)
					{
						glTexCoord2f(mesh->mTextureCoords[0][vertexIndex].x, 1 - mesh->mTextureCoords[0][vertexIndex].y); //mTextureCoords[channel][vertex]
					}

					glNormal3fv(&mesh->mNormals[vertexIndex].x);
					glVertex3fv(&mesh->mVertices[vertexIndex].x);
			}

			glEnd();

		}

	}


	// draw all children
	for (n = 0; n < nd->mNumChildren; ++n)
	{
		recursive_render(sc, nd->mChildren[n], scale);
	}

	glPopMatrix();
}
コード例 #22
0
ファイル: render_object.cpp プロジェクト: torandi/duststorm
void RenderObject::render(const glm::mat4& m) const {
	if ( !scene ) return;
	recursive_render(scene->mRootNode, m * matrix());
}
コード例 #23
0
void AssimpSimpleModelLoader::recursive_render (const aiScene *sc, const aiNode* nd)
{
	unsigned int i;
	unsigned int n = 0, t;
	aiMatrix4x4 m = nd->mTransformation;

	// Debug
	// printf("Node name: %s\n",nd->mName.data);	

	// update transform
	aiTransposeMatrix4(&m);
	glPushMatrix();
	glMultMatrixf((float*)&m);
	
			
	// draw all meshes assigned to this node
	for (; n < nd->mNumMeshes; ++n) {
		const aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];
		// Debug
		// printf("--------------->Drawing MESH with this name: %s\n",mesh->mName.data);
		apply_material(sc->mMaterials[mesh->mMaterialIndex]);

		if(mesh->mNormals == NULL) {
			glDisable(GL_LIGHTING);
		} else {
			glEnable(GL_LIGHTING);
		}

		// Texture UV
		if(mesh->HasTextureCoords(0))
			glEnable(GL_TEXTURE_2D);
		else
			glDisable(GL_TEXTURE_2D);

		if(mesh->mColors[0] != NULL)
		{
			glEnable(GL_COLOR_MATERIAL);
		}
		else
		{
			glDisable(GL_COLOR_MATERIAL);
		}


		for (t = 0; t < mesh->mNumFaces; ++t) {
			const aiFace* face = &mesh->mFaces[t];
			GLenum face_mode;

			switch(face->mNumIndices) {
				case 1: face_mode = GL_POINTS; break;
				case 2: face_mode = GL_LINES; break;
				case 3: face_mode = GL_TRIANGLES; break;
				default: face_mode = GL_POLYGON; break;
			}
			
			glBegin(face_mode);

			for(i = 0; i < face->mNumIndices; i++) {
				int index = face->mIndices[i];
				if(mesh->mColors[0] != NULL)
					glColor4fv((GLfloat*)&mesh->mColors[0][index]);
				if(mesh->mNormals != NULL) {
					glNormal3fv(&mesh->mNormals[index].x);
					if(mesh->HasTextureCoords(0))		//HasTextureCoords(texture_coordinates_set)
					{
						glTexCoord2f(mesh->mTextureCoords[0][index].x, 1 - mesh->mTextureCoords[0][index].y); //mTextureCoords[channel][vertex]
					}
				}
				glVertex3fv(&mesh->mVertices[index].x);
			}

			glEnd();
		}

	}

	// draw all children
	for (n = 0; n < nd->mNumChildren; ++n) {
		recursive_render(sc, nd->mChildren[n]);
	}

	glPopMatrix();
}
コード例 #24
0
ファイル: Render.cpp プロジェクト: aarich/3DLocalization
    void renderScene(void)
    {
        //std::cout << "render" << std::endl;
        static float step = 0.0f;

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


        View::setCamera(camera[0], camera[1], camera[2],translation[0], translation[1], translation[2]);

        // set the model matrix to the identity Matrix
        MathHelp::setIdentityMatrix(modelMatrix,4);

        // sets the model matrix to a scale matrix so that the model fits in the window
        scale(scaleFactor, scaleFactor, scaleFactor);

        // keep rotating the model
        //rotate(step, 0.0f, 1.0f, 0.0f);
        
        // use our shader
        glUseProgram(program);

        // we are only going to use texture unit 0
        // unfortunately samplers can't reside in uniform blocks
        // so we have set this uniform separately
        glUniform1i(texUnit,0);

        recursive_render(scene->mRootNode);

        // FPS computation and display
        frame++;
        time1=glutGet(GLUT_ELAPSED_TIME);
        if (time1 - timebase > 1000) 
        {
            sprintf(s,"FPS:%4.2f", frame*1000.0/(time1-timebase));
            timebase = time1;
            frame = 0;
            glutSetWindowTitle(s);
        }

        // swap buffers
        glutSwapBuffers();


        if(start)
        {
            unsigned char * pixels = new unsigned char[width * height * 3 ];
            glReadPixels( 0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, pixels );
            cv::Mat image(height, width, CV_8UC3);
            int index = 0;
            for(int i = 0; i < height; i++)
            {
                for(int j = 0; j < width; j++)
                {
                    cv::Point3_<uchar> * p = image.ptr<cv::Point3_<uchar> >(height-i-1, j);
                    p->x = pixels[index++];
                    p->y = pixels[index++];
                    p->z = pixels[index++];
                }
            }

            std::stringstream ss;
            ss << generatedImagesDirectory << modelDirectoryName << "_" << camera[0] << "_" << camera[1] << "_" << camera[2] << "_" << 
            translation[0] << "_" <<  translation[1] << "_" <<  translation[2] << "_" << fileExt;
            std::string z = ss.str();
            std::cout << "\n" << z << std::endl;
            cv::imwrite(z, image);
            imageNum++;
            delete [] pixels;


            IO::nextLocation(-1);


            if(imageNum == perspectiveCount)
            {
                imageNum = 0;
                start = false;
            }
        }

    }
コード例 #25
0
ファイル: example.cpp プロジェクト: animehunter/clanlib-2.3
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;
    CL_GL1WindowDescription desc;

	desc.set_title("ClanLib Object 3D Example");
	desc.set_size(CL_Size(640, 480), true);
	desc.set_multisampling(4);
	desc.set_depth_size(16);

	CL_DisplayWindow window(desc);

#ifdef _DEBUG
	//struct aiLogStream stream;
	//stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
	//aiAttachLogStream(&stream);
	//stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
	//aiAttachLogStream(&stream);
#endif

	// Connect the Window close event
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

	// Connect a keyboard handler to on_key_up()
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	// Get the graphic context
	CL_GraphicContext gc = window.get_gc();

#ifdef USE_OPENGL_1
    CL_GraphicContext_GL1 gc_gl1 = gc;
#endif

	// Prepare the display
	gc.set_map_mode(cl_user_projection);

	CL_PolygonRasterizer polygon_rasterizer;
	polygon_rasterizer.set_culled(true);
	polygon_rasterizer.set_face_cull_mode(cl_cull_back);
	polygon_rasterizer.set_front_face(cl_face_side_clockwise);
	gc.set_polygon_rasterizer(polygon_rasterizer);

	CL_BufferControl buffer_control;
	buffer_control.enable_depth_test(true);
	buffer_control.set_depth_compare_function(cl_comparefunc_lequal);
	buffer_control.enable_depth_write(true);
	gc.set_buffer_control(buffer_control);

#ifdef USE_OPENGL_1
	// Set the lights
	CL_LightModel_GL1 light_model;
	light_model.enable_lighting(true);
	light_model.set_flat_shading(false);
	light_model.set_scene_ambient_light(CL_Colorf(0.2f, 0.2f, 0.2f, 1.0f));
	gc_gl1.set_light_model(light_model);

	CL_LightSource_GL1 light_distant;
	light_distant.set_spot_cutoff(180.0f);
	light_distant.set_diffuse_intensity(CL_Colorf(1.0f, 1.0f, 1.0f, 1.0f));
	light_distant.set_position(CL_Vec4f(0.0f, -2.0f, 30.0f, 0.0f).normalize3());
	gc_gl1.set_light(0, light_distant);

	cl1Enable(GL_NORMALIZE);
#endif

#ifdef USE_OPENGL_2
    Shader shader(gc);
#endif

	// Create the objects

	aiSetImportPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,89.53f);

	const struct aiScene* scene_teapot = aiImportFile("../Clan3D/Resources/teapot.dae",aiProcessPreset_TargetRealtime_MaxQuality);
	if (!scene_teapot)
		throw CL_Exception("Cannot load the teapot model");

	const struct aiScene* scene_clanlib = aiImportFile("../Clan3D/Resources/clanlib.dae",aiProcessPreset_TargetRealtime_MaxQuality);
	if (!scene_clanlib)
		throw CL_Exception("Cannot load the clanlib model");

	const struct aiScene* scene_tuxball = aiImportFile("../Clan3D/Resources/tux_ball.dae",aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_FlipUVs);
	if (!scene_tuxball)
		throw CL_Exception("Cannot load the tux ball model");

	// Load the texture
	CL_Texture tux(gc, "../Clan3D/Resources/tux.png");

	float angle = 0.0f;
	// Run until someone presses escape
	while (!quit)
	{

		CL_Mat4f perp = CL_Mat4f::perspective(45.0f, ((float) gc.get_width()) / ((float) gc.get_height()), 0.1f, 1000.0f);
		gc.set_projection(perp);

		gc.clear(CL_Colorf::black);
		gc.clear_depth(1.0f);

		angle += 1.0f;
		if (angle >= 360.0f)
			angle -= 360.0f;


#ifdef USE_OPENGL_2
        shader.Set(gc);
        shader.Use(gc);
#else
        gc.set_program_object(cl_program_color_only);
#endif

		CL_PrimitivesArray prim_array(gc);

		gc.set_modelview(CL_Mat4f::identity());
		gc.mult_scale(1.0f,1.0f, -1.0f);	// So +'ve Z goes into the screen
		gc.mult_translate(0.0f, 0.0f, 2.0f);
		gc.mult_rotate(CL_Angle(angle, cl_degrees), 0.0f, 1.0f, 0.0f, false);

		gc.push_modelview();
		recursive_render(gc, scene_teapot, scene_teapot->mRootNode, false);
		gc.pop_modelview();

		gc.push_modelview();
		gc.mult_scale(0.5f, 0.5f, 0.5f);
		gc.mult_translate(0.0f, -0.5f, 0.0f);
		recursive_render(gc, scene_clanlib, scene_clanlib->mRootNode, false);
		gc.pop_modelview();

#ifdef USE_OPENGL_2
        shader.Set(gc, 0);
        shader.Use(gc);
#else
        gc.set_program_object(cl_program_single_texture);
#endif

		gc.set_texture(0, tux);
 		gc.set_modelview(CL_Mat4f::identity());
		gc.mult_scale(1.0f,1.0f, -1.0f);	// So +'ve Z goes into the screen
		gc.mult_translate(0.7f, 0.5f, 2.0f);
		gc.mult_scale(0.05f, 0.05f, 0.05f);
		gc.mult_rotate(CL_Angle(angle * 4.0f, cl_degrees), 0.0f, 1.0f, 0.0f, false);
		recursive_render(gc, scene_tuxball, scene_tuxball->mRootNode, true);
		gc.reset_texture(0);

		gc.reset_program_object();
		
		// Flip the display, showing on the screen what we have drawed
		// since last call to flip()
		window.flip(1);

		// This call processes user input and other events
		CL_KeepAlive::process();
	}

	aiReleaseImport(scene_tuxball);
	aiReleaseImport(scene_clanlib);
	aiReleaseImport(scene_teapot);
	aiDetachAllLogStreams();

	return 0;
}
コード例 #26
0
ファイル: example.cpp プロジェクト: animehunter/clanlib-2.3
void App::recursive_render(CL_GraphicContext &gc, const struct aiScene *sc, const struct aiNode* nd, bool use_texture_coords)
{
	int i;
	unsigned int n = 0, t;
	struct aiMatrix4x4 m = nd->mTransformation;

	// update transform
	aiTransposeMatrix4(&m);
	gc.push_modelview();
	gc.mult_modelview((float*)&m);

	// draw all meshes assigned to this node
	for (; n < nd->mNumMeshes; ++n)
	{
		const struct aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];

		if (mesh->mNormals == NULL)
			throw CL_Exception("This example expects normals to be set");

		std::vector<CL_Vec3f> normals;
		std::vector<CL_Vec3f> vertices;
		std::vector<CL_Vec3f> tex_coords;

		normals.reserve(mesh->mNumFaces * 3);
		vertices.reserve(mesh->mNumFaces * 3);

		if (use_texture_coords)
		{
			if (mesh->mTextureCoords == NULL || mesh->mTextureCoords[0] == NULL)
				throw CL_Exception("This example expects texcoords to be set for this object");
			tex_coords.reserve(mesh->mNumFaces * 3);
		}

		for (t = 0; t < mesh->mNumFaces; ++t)
		{
			const struct aiFace* face = &mesh->mFaces[t];

			if (face->mNumIndices != 3)
					throw CL_Exception("This example only supports triangles");

			for(i = 0; i < face->mNumIndices; i++)
			{
				int index = face->mIndices[i];
				normals.push_back(&mesh->mNormals[index].x);
				vertices.push_back( &mesh->mVertices[index].x);
				if (use_texture_coords)
					tex_coords.push_back( &mesh->mTextureCoords[0][index].x);
			}
		}

		if (!vertices.empty())
		{
			CL_PrimitivesArray prim_array(gc);
			prim_array.set_attributes(cl_attrib_position, &vertices[0]);
			prim_array.set_attribute(cl_attrib_color, CL_Colorf::white);
			prim_array.set_attributes(cl_attrib_normal, &normals[0]);
			if (use_texture_coords)
				prim_array.set_attributes(cl_attrib_texture_position, &tex_coords[0]);
			gc.draw_primitives(cl_triangles, vertices.size(), prim_array);
		}
	}

	// draw all children
	for (n = 0; n < nd->mNumChildren; ++n)
	{
		recursive_render(gc, sc, nd->mChildren[n], use_texture_coords);
	}

	gc.pop_modelview();
}
コード例 #27
0
/* ---------------------------------------------------------------------------- */
void display(void)
{
    float Ambient[]   = {0,0,0,1};
    float Diffuse[]   = {1,1,1,1};
    float Specular[]  = {1.0,1.0,1.0,1};
    float white[]     = {1,1,1,1};
    float tmp;
    glPushMatrix();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.f,0.f,3.f,0.f,0.f,-5.f,0.f,1.f,0.f);
    /* rotate it around the y axis */
    //glRotatef(angle,0.f,1.f,0.f);
    glRotatef(180,0.f,1.f,0.f);
    glEnable(GL_LIGHTING);
    /* scale the whole asset to fit into our view frustum */
    tmp = scene_max.x-scene_min.x;
    tmp = aisgl_max(scene_max.y - scene_min.y,tmp);
    tmp = aisgl_max(scene_max.z - scene_min.z,tmp);
    double len = tmp;
    tmp = 1.f / tmp;
    float Position[] = {len*3.5,len/2,0,1};
    glScalef(tmp, tmp, tmp);
    /* center the model */
    glTranslatef( -scene_center.x, -scene_center.y, -scene_center.z );
    /* if the display list has not been made yet, create a new one and
       fill it with scene contents */
    // Place this in the mode switching function
    if(scene_list == 0) {
        scene_list = glGenLists(1);
        glNewList(scene_list, GL_COMPILE);
        /* now begin at the root node of the imported data and traverse
           the scenegraph by multiplying subsequent local transforms
           together on GL's matrix stack. */
        recursive_render(scene, scene->mRootNode);
        glEndList();
    }
    // move ship to mouse cursor
    glTranslatef(mouseWorldCoord[0],mouseWorldCoord[1],0);
    // add some slight sway to make ship seem more 'alive'
    glTranslatef(infinitySymbol[0],infinitySymbol[1],0);

    glCallList(scene_list);
    glPopMatrix();
    ball(Position[0],Position[1],Position[2],10);
    glPushMatrix();
    glRotatef(angle,0.0,1.0,0.0);
    Sky(len*3.5);
    glPopMatrix();
    glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
    glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
    glLightfv(GL_LIGHT0,GL_SPECULAR,Specular);
    glLightfv(GL_LIGHT0,GL_POSITION,Position);
    glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,32.0f);
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);

    // Draw axes - no lighting from here on
    if(axes){
        glDisable(GL_LIGHTING);
        glColor3f(1, 1, 1);
        glBegin(GL_LINES);
        glVertex3d(0.0, 0.0, 0.0);
        glVertex3d(len, 0.0, 0.0);
        glVertex3d(0.0, 0.0, 0.0);
        glVertex3d(0.0, len, 0.0);
        glVertex3d(0.0, 0.0, 0.0);
        glVertex3d(0.0, 0.0, len);
        glEnd();
    }
    glutSwapBuffers();

    do_motion();
}