//Funcion para renderizar la esfera void render_esfera(float m_Radius, int sl, int st , int id_textura) { struct vertice m_Vertex[sl*st*2]; float x0, y0, z0; float x1, y1, z1; float sinxy; int i, j, v= 0; unsigned int numVertex = 2*sl*st; float xzAngle = 2.0f*3.1415/(float)sl; float xyAngle = 2.0f*3.1415/(float)st; glEnable(GL_TEXTURE_2D); // Con esta función indicamos que vamos a utilizar la textura glBindTexture(GL_TEXTURE_2D, textura[id_textura]); glColor3d(1,1,1); //El color que le asignamos en 3D if ( numVertex <= MAX_TAM_ESFERA ) { for (i=0; i < sl; i++){// Meridianos for (j=0; j < st; j++){// Paralelos sinxy= sin(j*xyAngle); // Para no calcularlo 4 veces x0= sinxy * cos(i*xzAngle); y0= cos(j*xyAngle); z0= sinxy * sin(i*xzAngle); // Vertice m_Vertex[v].x = m_Radius*x0; m_Vertex[v].y = m_Radius*y0; m_Vertex[v].z = m_Radius*z0; // Normal m_Vertex[v].nx= x0; m_Vertex[v].ny= y0; m_Vertex[v].nz= z0; //m_Vertex[v].su= 1.0f-i/(float)slices; // SU= 1-i*xzAngle/2PI m_Vertex[v].su= i/(float)sl; // SU= i*xzAngle/2PI m_Vertex[v].tv= ((float)st-2.0f*j)/(float)st; // TV= 1-j*xyAngle/PI v++; x1= sinxy * cos((i+1)*xzAngle); y1= y0; z1= sinxy * sin((i+1)*xzAngle); m_Vertex[v].x = m_Radius*x1; m_Vertex[v].y = m_Radius*y1; m_Vertex[v].z = m_Radius*z1; m_Vertex[v].nx= x1; m_Vertex[v].ny= y1; m_Vertex[v].nz= z1; // m_Vertex[v].su= 1.0f-(i+1)/(float)slices; m_Vertex[v].su= (i+1)/(float)sl; m_Vertex[v].tv= m_Vertex[v-1].tv; // Igual que el anterior. v++; } } RenderVertices( 4, (char *)m_Vertex, sizeof(vertice), 0, numVertex);//, eFVF_XYZ|eFVF_NORMAL|eFVF_TEX1 ); } glDisable(GL_TEXTURE_2D); }
/** @brief @date 2014-04-17 */ void cParticle::Render(HDC hdc) { RenderVertices(hdc, m_vertices, m_localTm*m_tm); }