void ScaleTool::render() { if ( m_active ) { if ( !hasVBO() ) buildVBO(); glPushAttrib( GL_DEPTH_BUFFER_BIT ); glDisable( GL_DEPTH_TEST ); glPushAttrib( GL_LIGHTING_BIT ); glDisable( GL_LIGHTING ); glPushAttrib( GL_COLOR_BUFFER_BIT ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_LINE_SMOOTH ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); for ( unsigned int i = 0; i < 3; ++i ) { glColor3fv( getAxialColor((i==m_axisSelection)?3:i).data ); renderAxis( i ); } glColor3fv( getAxialColor(3).data ); renderCenter(); glPopAttrib(); glPopAttrib(); glPopAttrib(); } }
uint Wick::buildCPointFDF (const FlameConfig& flameConfig, vector< LeadSkeleton * >& leadSkeletons, Field3D* const field ) { CPoint bounds[2], barycentre; /* Création du VBO */ buildVBO(); /* La bounding box est délimitée par les points ptMax[flameConfig.skeletonsNumber] et ptMin[0] */ getBoundingBox (bounds[1], bounds[0]); m_boxesDisplayList=glGenLists(1); glNewList (m_boxesDisplayList, GL_COMPILE); glColor3f(0.0f,1.0f,1.0f); glBegin(GL_LINE_LOOP); glVertex3f(bounds[0].x,bounds[0].y,bounds[0].z); glVertex3f(bounds[0].x,bounds[0].y,bounds[1].z); glVertex3f(bounds[0].x,bounds[1].y,bounds[1].z); glVertex3f(bounds[0].x,bounds[1].y,bounds[0].z); glEnd(); glBegin(GL_LINE_LOOP); glVertex3f(bounds[1].x,bounds[0].y,bounds[0].z); glVertex3f(bounds[1].x,bounds[0].y,bounds[1].z); glVertex3f(bounds[1].x,bounds[1].y,bounds[1].z); glVertex3f(bounds[1].x,bounds[1].y,bounds[0].z); glEnd(); glBegin(GL_LINES); glVertex3f(bounds[0].x,bounds[0].y,bounds[0].z); glVertex3f(bounds[1].x,bounds[0].y,bounds[0].z); glVertex3f(bounds[0].x,bounds[1].y,bounds[0].z); glVertex3f(bounds[1].x,bounds[1].y,bounds[0].z); glVertex3f(bounds[0].x,bounds[0].y,bounds[1].z); glVertex3f(bounds[1].x,bounds[0].y,bounds[1].z); glVertex3f(bounds[0].x,bounds[1].y,bounds[1].z); glVertex3f(bounds[1].x,bounds[1].y,bounds[1].z); glEnd(); glEndList(); CPoint rootMoveFactorL(2.0f,.2f,2.0f); barycentre.resetToNull (); for (vector < Vertex >::iterator vertexIterator = m_vertexArray.begin (); vertexIterator != m_vertexArray.end (); vertexIterator++) { barycentre.x += (*vertexIterator).x; barycentre.y += (*vertexIterator).y; barycentre.z += (*vertexIterator).z; } barycentre = barycentre / (float)m_vertexArray.size(); leadSkeletons.push_back (new LeadSkeleton(field, barycentre, rootMoveFactorL, flameConfig.leadLifeSpan, 1, .5f, 0.0f, .025f)); return 0; }
void Model::render() { if( ! render_inited ) { buildVBO(); bindVBO(); render_inited = true; } glColor3f(0.0, 0.0, 1.0); glDrawElements(GL_TRIANGLES, model->numtriangles * 3, GL_UNSIGNED_INT, NULL); }
// ビルド void Figure::build() { // LOGD("Figure::build"); // ビルド済みの場合は無視 // if (vaoName) { // return; // } // Create a vertex array object (VAO) #ifdef USE_VAO glGenVertexArraysOES(1, &vaoName); glBindVertexArrayOES(vaoName); #else vaoName = 1; #endif // 頂点 vboNames[VBO_VERTEX] = buildVBO(&vertices.front(), vertices.size() * sizeof(float), GL_ARRAY_BUFFER); enableAttribute(ATTRIB_VERTEX); // 法線 if (!normals.empty()) { vboNames[VBO_NORMAL] = buildVBO(&normals.front(), normals.size() * sizeof(float), GL_ARRAY_BUFFER); enableAttribute(ATTRIB_NORMAL); hasNormals = true; } // テクスチャ if (!textureCoords.empty()) { vboNames[VBO_TEXCOORD] = buildVBO(&textureCoords.front(), textureCoords.size() * sizeof(float), GL_ARRAY_BUFFER); enableAttribute(ATTRIB_TEXCOORD); hasTexture = true; } // ジョイント if (!jointData.empty()) { vboNames[VBO_JOINTS] = buildVBO(&jointData.front(), jointData.size() * sizeof(float), GL_ARRAY_BUFFER); enableAttribute(ATTRIB_JOINTS); hasJoint = true; } // 頂点の番号 if (useIndex) { std::vector<short> count; for (int i = 0; i < vertices.size() / 3; i++) { count.push_back(i); } vboNames[VBO_INDEX] = buildVBO(&count.front(), count.size() * sizeof(unsigned short), GL_ARRAY_BUFFER); } // インデックス enableAttribute(ATTRIB_INDEX); vboNames[VBO_ELEMENT] = buildVBO(&vertexIndexes.front(), vertexIndexes.size() * sizeof(unsigned short), GL_ELEMENT_ARRAY_BUFFER); // サイズ計算 int cnt = vertices.size()/3; float maxx = -FLT_MAX, minx = FLT_MAX; float maxy = -FLT_MAX, miny = FLT_MAX; float maxz = -FLT_MAX, minz = FLT_MAX; for (int i = 0; i < cnt; i++) { int idx = i * 3; float x = vertices[idx]; float y = vertices[idx+1]; float z = vertices[idx+2]; if (maxx < x) maxx = x; if (minx > x) minx = x; if (maxy < y) maxy = y; if (miny > y) miny = y; if (maxz < z) maxz = z; if (minz > z) minz = z; } size.x = maxx - minx; size.y = maxy - miny; size.z = maxz - minz; // LOGD("size:%f,%f,%f", size.x, size.y, size.z); // LOGD("Figure::build:end"); }
uint Wick::buildFDF (const FlameConfig& flameConfig, vector< LeadSkeleton * >& leadSkeletons, Field3D* const field ) { CPoint bounds[flameConfig.skeletonsNumber + 1]; CPoint MinBound (FLT_MAX, FLT_MAX, FLT_MAX), MaxBound (-FLT_MAX, -FLT_MAX, -FLT_MAX); CPoint midDist, cellSpan; vector < CPoint * >pointsPartitionsArray[flameConfig.skeletonsNumber]; u_char max; /* 0 -> x, 1 -> y, 2 -> z */ /* Création du VBO */ buildVBO(); /*****************************************************************************/ /* Création des points qui vont servir d'origines pour les squelettes guides */ /*****************************************************************************/ /* Parcours des points */ /* La bounding box est délimitée par les points ptMax[flameConfig.skeletonsNumber] et ptMin[0] */ getBoundingBox (bounds[flameConfig.skeletonsNumber], bounds[0]); /* Découpage de la bounding box en flameConfig.skeletonsNumber partitions */ midDist = (bounds[flameConfig.skeletonsNumber] - bounds[0]) / (flameConfig.skeletonsNumber); cellSpan = bounds[flameConfig.skeletonsNumber] - bounds[0]; if(midDist.x > midDist.y) if(midDist.x > midDist.z) /* Découpage en x */ max=0; else /* Découpage en z */ max=2; else if(midDist.y > midDist.z) /* Découpage en y */ max=1; else /* Découpage en z */ max=2; switch(max){ case 0 : /* Découpage en x */ for (uint i = 1; i < flameConfig.skeletonsNumber; i++){ bounds[i] = bounds[i-1]; bounds[i].x += midDist.x; } cellSpan.x=midDist.x; for (vector < Vertex >::iterator vertexIterator = m_vertexArray.begin (); vertexIterator != m_vertexArray.end (); vertexIterator++) { /* Calcul du max */ if (vertexIterator->x >= MaxBound.x) MaxBound = CPoint(vertexIterator->x, vertexIterator->y, vertexIterator->z); /* Calcul du min */ if (vertexIterator->x <= MinBound.x) MinBound = CPoint(vertexIterator->x, vertexIterator->y, vertexIterator->z); } // cerr << "Découpe en x" << endl; break; case 1 : /* Découpage en y */ for (uint i = 1; i < flameConfig.skeletonsNumber; i++){ bounds[i] = bounds[i-1]; bounds[i].y += midDist.y; } cellSpan.y=midDist.y; for (vector < Vertex >::iterator vertexIterator = m_vertexArray.begin (); vertexIterator != m_vertexArray.end (); vertexIterator++) { /* Calcul du max */ if (vertexIterator->y >= MaxBound.y) MaxBound = CPoint(vertexIterator->x, vertexIterator->y, vertexIterator->z); /* Calcul du min */ if (vertexIterator->y <= MinBound.y) MinBound = CPoint(vertexIterator->x, vertexIterator->y, vertexIterator->z); } // cerr << "Découpe en y" << endl; break; case 2 : /* Découpage en z */ for (uint i = 1; i < flameConfig.skeletonsNumber; i++){ bounds[i] = bounds[i-1]; bounds[i].z += midDist.z; } cellSpan.z=midDist.z; for (vector < Vertex >::iterator vertexIterator = m_vertexArray.begin (); vertexIterator != m_vertexArray.end (); vertexIterator++) { /* Calcul du max */ if (vertexIterator->z >= MaxBound.z) MaxBound = CPoint(vertexIterator->x, vertexIterator->y, vertexIterator->z); /* Calcul du min */ if (vertexIterator->z <= MinBound.z) MinBound = CPoint(vertexIterator->x, vertexIterator->y, vertexIterator->z); } // cerr << "Découpe en z" << endl; break; } // cerr << flameConfig.skeletonsNumber << endl; // for (int i = 0; i <= flameConfig.skeletonsNumber; i++) // cerr << bounds[i] << endl; // cerr << "CellSpan " << cellSpan << endl; m_boxesDisplayList=glGenLists(1); glNewList (m_boxesDisplayList, GL_COMPILE); for (uint i = 0; i < flameConfig.skeletonsNumber; i++){ glColor3f(0.0f,i*1.0f/(float)flameConfig.skeletonsNumber,1.0f); CPoint bounds2 = bounds[i]+cellSpan; glBegin(GL_LINE_LOOP); glVertex3f(bounds[i].x,bounds[i].y,bounds[i].z); glVertex3f(bounds[i].x,bounds[i].y,bounds2.z); glVertex3f(bounds[i].x,bounds2.y,bounds2.z); glVertex3f(bounds[i].x,bounds2.y,bounds[i].z); glEnd(); glBegin(GL_LINE_LOOP); glVertex3f(bounds2.x,bounds[i].y,bounds[i].z); glVertex3f(bounds2.x,bounds[i].y,bounds2.z); glVertex3f(bounds2.x,bounds2.y,bounds2.z); glVertex3f(bounds2.x,bounds2.y,bounds[i].z); glEnd(); glBegin(GL_LINES); glVertex3f(bounds[i].x,bounds[i].y,bounds[i].z); glVertex3f(bounds2.x,bounds[i].y,bounds[i].z); glVertex3f(bounds[i].x,bounds2.y,bounds[i].z); glVertex3f(bounds2.x,bounds2.y,bounds[i].z); glVertex3f(bounds[i].x,bounds[i].y,bounds2.z); glVertex3f(bounds2.x,bounds[i].y,bounds2.z); glVertex3f(bounds[i].x,bounds2.y,bounds2.z); glVertex3f(bounds2.x,bounds2.y,bounds2.z); glEnd(); } glEndList(); /* Tri des points pour les ranger dans les partitions */ /* Il serait possible de faire un tri par dichotomie */ /* pour aller un peu plus vite */ for (vector < Vertex >::iterator vertexIterator = m_vertexArray.begin (); vertexIterator != m_vertexArray.end (); vertexIterator++) for (uint i = 0; i < flameConfig.skeletonsNumber; i++){ CPoint bounds2 = bounds[i]+cellSpan; if (vertexIterator->x > bounds[i].x && vertexIterator->y > bounds[i].y && vertexIterator->z > bounds[i].z && vertexIterator->x < bounds2.x && vertexIterator->y < bounds2.y && vertexIterator->z < bounds2.z) pointsPartitionsArray[i].push_back (new CPoint(vertexIterator->x, vertexIterator->y, vertexIterator->z)); } CPoint rootMoveFactorL(2.0f,.1f,1.0f); float noiseMin=-.1f; float noiseMax=.1f; float noiseInc=.5f; /* Création des leadSkeletons */ /* On prend simplement le barycentre de chaque partition */ leadSkeletons.push_back (new LeadSkeleton(field, MinBound, rootMoveFactorL, flameConfig.leadLifeSpan, -1, noiseInc, noiseMin, noiseMax)); for (uint i = 0; i < flameConfig.skeletonsNumber; i++) { CPoint barycentre; if (!pointsPartitionsArray[i].empty ()) { barycentre.resetToNull (); for (vector < CPoint * >::iterator pointsIterator = pointsPartitionsArray[i].begin (); pointsIterator != pointsPartitionsArray[i].end (); pointsIterator++) { barycentre.x += (*pointsIterator)->x; barycentre.y += (*pointsIterator)->y; barycentre.z += (*pointsIterator)->z; } barycentre = barycentre / (float)pointsPartitionsArray[i].size(); leadSkeletons.push_back (new LeadSkeleton(field, barycentre, rootMoveFactorL, flameConfig.leadLifeSpan, 2*(i+1)/(float)(flameConfig.skeletonsNumber+1)-1, noiseInc, noiseMin, noiseMax)); } else cerr << "Warning ! Wick partition #" << i << " is empty" << endl; } leadSkeletons.push_back (new LeadSkeleton(field, MaxBound, rootMoveFactorL, flameConfig.leadLifeSpan, 1, noiseInc, noiseMin, noiseMax)); /* Suppression des points */ for (uint i = 0; i < flameConfig.skeletonsNumber; i++) { for (vector < CPoint * >::iterator pointsIterator = pointsPartitionsArray[i].begin (); pointsIterator != pointsPartitionsArray[i].end (); pointsIterator++) delete (*pointsIterator); pointsPartitionsArray[i].clear(); } // buildFDF(field); return (max); }
// deletes the current VBOs for the chunk, and rebuilds them bool VBOChunk::reBuildVBO(World &world, std::vector<Vertex> *vb, std::vector<TexVert> *tb, std::vector<ColVert> *cb, std::vector<Vertex> *tvb, std::vector<TexVert> *ttb, std::vector<ColVert> *tcb) { deleteBuffers(); return buildVBO(world, vb, tb, cb, tvb, ttb, tcb); }