void SplineTransferFunction::insertPointAt(int i, QPointF sp) { if (Global::use1D()) return; if (i == 0) { m_points.insert(i, sp); float rot = m_normalRotations[i]; m_normalRotations.insert(i, rot); QPointF nw = m_normalWidths[i]; m_normalWidths.insert(i, nw); } else { m_points.insert(i, sp); float rot = (m_normalRotations[i]+m_normalRotations[i-1])/2; m_normalRotations.insert(i, rot); QPointF nw = (m_normalWidths[i]+m_normalWidths[i-1])/2; m_normalWidths.insert(i, nw); } updateNormals(); updateColorMapImage(); }
SplineTransferFunction::SplineTransferFunction() : QObject() { m_name = "TF"; m_on.clear(); m_points.clear(); m_points << QPointF(0.5, 1.0) << QPointF(0.5, 0.0); m_normals.clear(); m_rightNormals.clear(); m_leftNormals.clear(); m_normalWidths.clear(); m_normalWidths << QPointF(0.4, 0.4) << QPointF(0.4, 0.4); m_normalRotations.clear(); m_normalRotations << 0.0 << 0.0; m_gradientStops.clear(); m_gradientStops << QGradientStop(0.0, QColor(0,0,0,128)) << QGradientStop(1.0, QColor(255,255,255,128)); m_colorMapImage = QImage(256, 256, QImage::Format_ARGB32); m_colorMapImage.fill(0); switch1D(); updateNormals(); updateColorMapImage(); }
//-***************************************************************************** void MeshDrwHelper::update( P3fArraySamplePtr iP, V3fArraySamplePtr iN, Abc::Box3d iBounds ) { // Check validity. if ( !m_valid || !iP || !m_meshP || ( iP->size() != m_meshP->size() ) ) { makeInvalid(); return; } // Set meshP m_meshP = iP; if ( iBounds.isEmpty() ) { computeBounds(); } else { m_bounds = iBounds; } updateNormals( iN ); }
void SplineTransferFunction::switch1D() { if (Global::use1D() == false) return; QPointF pt = m_points[0]; m_points.clear(); pt.setY(1.0); m_points << pt; pt.setY(0.0); m_points << pt; pt = m_normalWidths[0]; m_normalWidths.clear(); m_normalWidths << pt; m_normalWidths << pt; m_normalRotations.clear(); m_normalRotations << 0.0 << 0.0; updateNormals(); updateColorMapImage(); }
inline void vertex_buffer_object<Ta, Te>::update() { updateVertices(); updateNormals(); updateColors(); updateTexCoords(); updateElements(); }
void SplineTransferFunction::moveAllPoints(const QPointF diff) { for (int i=0; i<m_points.size(); i++) m_points[i] += diff; updateNormals(); updateColorMapImage(); }
// ---------------------------------------------------------------------- void ObjMesh::transform(const NxMat34 &a) { for (int i = 0; i < (int)mVertices.size(); i++) { NxVec3 &v = mVertices[i]; v = a * v; } updateBounds(); updateNormals(); }
void REdit::undo() { //replace edited elements with their "before" value for(int i = 0; i < _vertex.size(); i++) Model::vertex()[_vertex[i].index] = _vertex[i].before; for(int i = 0; i < _triangle.size(); i++) *_triangle[i].iterator = _triangle[i].before; updateNormals(); }
void SplineTransferFunction::removePointAt(int index) { if (Global::use1D()) return; m_points.remove(index); m_normalRotations.remove(index); m_normalWidths.remove(index); updateNormals(); updateColorMapImage(); }
void SplineTransferFunction::setSpline(SplineInformation splineInfo) { m_name = splineInfo.name(); m_on = splineInfo.on(); m_points = splineInfo.points(); m_normalWidths = splineInfo.normalWidths(); m_normalRotations = splineInfo.normalRotations(); m_gradientStops = splineInfo.gradientStops(); updateNormals(); updateColorMapImage(); }
void SplineTransferFunction::moveNormalAt(int idxCenter, int idxNormal, QPointF point, bool shiftModifier) { if (idxNormal == RightNormal) // move rigntNormal { QLineF l0 = QLineF(m_points[idxCenter], point); float dotp = (m_normals[idxCenter].x()*l0.dx() + m_normals[idxCenter].y()*l0.dy()); if (dotp >= 0) m_normalWidths[idxCenter].setX(dotp); else m_normalWidths[idxCenter].setX(0); if (shiftModifier) { float w = m_normalWidths[idxCenter].x(); m_normalWidths[idxCenter].setY(w); } } else if (idxNormal == LeftNormal) // move rigntNormal { QLineF l0 = QLineF(point, m_points[idxCenter]); float dotp = (m_normals[idxCenter].x()*l0.dx() + m_normals[idxCenter].y()*l0.dy()); if (dotp >= 0) m_normalWidths[idxCenter].setY(dotp); else m_normalWidths[idxCenter].setY(0); if (shiftModifier) { float w = m_normalWidths[idxCenter].y(); m_normalWidths[idxCenter].setX(w); } } if (Global::use1D()) { if (idxCenter == 0) m_normalWidths[1] = m_normalWidths[0]; else m_normalWidths[0] = m_normalWidths[1]; } updateNormals(); updateColorMapImage(); }
void SplineTransferFunction::movePointAt(int index, QPointF point) { if (Global::use1D()) { m_points[0].setX(point.x()); m_points[1].setX(point.x()); } else m_points[index] = point; updateNormals(); updateColorMapImage(); }
void Mesh::triangulateFirstLayer() { bottom_cover.need_triangulate = true; auto layer = layers_[outLayers().first]; bottom_cover.vertex = layerCenter(layer); // точка схода вершин первого слоя bottom_cover.triangles.clear(); // третий индекс - фиктивный, вместо него будет top_cover.first bottom_cover.triangles.push_back(Trid(layer.second - 1, layer.first, BOTTOM_VERT_INDEX)); for (int i = layer.first; i < layer.second - 1; ++i) { bottom_cover.triangles.push_back(Trid(i, i + 1, BOTTOM_VERT_INDEX)); } updateNormals(); }
//-***************************************************************************** void MeshDrwHelper::update( V3fArraySamplePtr iP, V3fArraySamplePtr iN ) { // Check validity. if ( !m_valid || !iP || !m_meshP || ( iP->size() != m_meshP->size() ) ) { makeInvalid(); return; } // Set meshP m_meshP = iP; computeBounds(); updateNormals( iN ); }
void SplineTransferFunction::rotateNormalAt(int idxCenter, int idxNormal, QPointF point) { if (Global::use1D()) return; QLineF dir, normVec, ln; if (idxCenter == 0) dir = QLineF(m_points[idxCenter], m_points[idxCenter+1]); else if (idxCenter == m_points.size()-1) dir = QLineF(m_points[idxCenter-1], m_points[idxCenter]); else dir = QLineF(m_points[idxCenter-1], m_points[idxCenter+1]); if (dir.length() > 0) dir = dir.unitVector(); else dir = QLineF(dir.p1(), dir.p1()+QPointF(1,0)); normVec = dir.normalVector(); ln = QLineF(m_points[idxCenter], point); ln.translate(-ln.p1()); float angle = 0;; if (idxNormal == RightNormal) { float angle1, angle2; angle1 = atan2(-ln.dy(), ln.dx()); angle2 = atan2(-normVec.dy(), normVec.dx()); angle = angle1-angle2; } else // LeftNormal { float angle1, angle2; angle1 = atan2(-ln.dy(), ln.dx()); angle2 = atan2(normVec.dy(), -normVec.dx()); angle = angle1-angle2; } m_normalRotations[idxCenter] = angle; updateNormals(); updateColorMapImage(); }
void SplineTransferFunction::appendPoint(QPointF sp) { if (Global::use1D()) return; m_points.push_back(sp); float rot = m_normalRotations[m_normalRotations.size()-1]; m_normalRotations.push_back(rot); QPointF nw = m_normalWidths[m_normalWidths.size()-1]; m_normalWidths.push_back(nw); updateNormals(); updateColorMapImage(); }
Mesh& Mesh::mirror(int anchor) { if (!anchor) { anchor = center().x; } bottom_cover.vertex.x = anchor - (bottom_cover.vertex.x - anchor); top_cover.vertex.x = anchor - (top_cover.vertex.x - anchor); for (auto& e : vertices) { e.x = anchor - (e.x - anchor); } for (auto &layer : anchor_points) { for (auto &e : layer) { e.x = anchor - (e.x - anchor); } } updateNormals(); return *this; }
// ---------------------------------------------------------------------- bool ObjMesh::updateTetraLinks(const NxMeshData &tetraMeshData) { if (mTetraLinks.size() != mVertices.size()) return false; NxU32 numVertices = *tetraMeshData.numVerticesPtr; NxU32 numTetrahedra = *tetraMeshData.numIndicesPtr / 4; const NxVec3 *vertices = (NxVec3*)tetraMeshData.verticesPosBegin; NxU32* indices = (NxU32*)tetraMeshData.indicesBegin; for (int i = 0; i < (int)mVertices.size(); i++) { ObjMeshTetraLink &link = mTetraLinks[i]; if (!mDrainedTriVertices[i]) { // only done if tetra was not drained before const NxU32 *ix = &indices[4*link.tetraNr]; if (*ix == *(ix + 1)) { // this tetra was drained removeTrisRelatedToVertex(i); mDrainedTriVertices[i] = true; continue; } const NxVec3 &p0 = vertices[*ix++]; const NxVec3 &p1 = vertices[*ix++]; const NxVec3 &p2 = vertices[*ix++]; const NxVec3 &p3 = vertices[*ix++]; NxVec3 &b = link.barycentricCoords; mVertices[i] = p0 * b.x + p1 * b.y + p2 * b.z + p3 * (1.0f - b.x - b.y - b.z); } } updateNormals(); return true; }
/*! * \brief Initializes the triangle object * * This method is invoked by different constructors to do the same generic * initializing of the triangle object. This includes setting the internal * vertices variable mVertices and the internal normals variable mNormals. * * When one or more of the given normal vectors \p n1, \p n2 or \p n3 equals * null it is replaced by a internally calculated value, see * Triangle::updateNormals() for more details). * * Throws an MeshTopologyException when one of the given vertices is null. */ void Triangle::init(Vertex* v1, Vector3* n1, Vertex* v2, Vector3* n2, Vertex* v3, Vector3* n3) { if (!v1 || !v2 || !v3) { throw MeshTopologyException( "The triangle hasn't enough vertices!" ); } mVertices[0] = v1; mVertices[1] = v2; mVertices[2] = v3; if (!n1 || !n2 || !n3) { updateNormals(); mNormals[0] = (!n1) ? mNormals[0] : n1; mNormals[1] = (!n2) ? mNormals[1] : n2; mNormals[2] = (!n3) ? mNormals[2] : n3; } else { mNormals = std::vector<Vector3*>(3); mNormals[0] = n1; mNormals[1] = n2; mNormals[2] = n3; } mNormalsInitialized = true; mNormalConeInitialized = false; mNormalVectorInitialized = false; mWorldCoordinatesNormalVectorInitialized = false; }
// ---------------------------------------------------------------------- bool ObjMesh::loadFromObjFile(char *filename) { FILE *f = fopen(filename, "r"); if (!f) return false; clear(); ObjMeshString s, subs[maxVerticesPerFace]; ObjMeshString mtllib, matName; mHasTextureCoords = false; mHasNormals = false; strcpy(mtllib, ""); int materialNr = -1; int i,j; NxVec3 v; ObjMeshTriangle t; TexCoord tc; std::vector<NxVec3> centermVertices; std::vector<TexCoord> centermTexCoords; std::vector<NxVec3> centerNormals; extractPath(filename); while (!feof(f)) { if (fgets(s, OBJ_MESH_STRING_LEN, f) == NULL) break; if (strncmp(s, "mtllib", 6) == 0) { // material library sscanf(&s[7], "%s", mtllib); importMtlFile(mtllib); } else if (strncmp(s, "usemtl", 6) == 0) { // use material sscanf(&s[7], "%s", matName); materialNr = 0; int numMaterials = (int)mMaterials.size(); while (materialNr < numMaterials && strcasecmp(mMaterials[materialNr].name, matName) != 0) materialNr++; if (materialNr >= numMaterials) materialNr = -1; } else if (strncmp(s, "v ", 2) == 0) { // vertex sscanf(s, "v %f %f %f", &v.x, &v.y, &v.z); mVertices.push_back(v); } else if (strncmp(s, "vn ", 3) == 0) { // normal sscanf(s, "vn %f %f %f", &v.x, &v.y, &v.z); mNormals.push_back(v); } else if (strncmp(s, "vt ", 3) == 0) { // texture coords sscanf(s, "vt %f %f", &tc.u, &tc.v); mTexCoords.push_back(tc); } else if (strncmp(s, "f ", 2) == 0) { // face int nr; nr = sscanf(s, "f %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", subs[0], subs[1], subs[2], subs[3], subs[4], subs[5], subs[6], subs[7], subs[8], subs[9], subs[10], subs[11], subs[12],subs[13], subs[14]); int vertNr[maxVerticesPerFace], texNr[maxVerticesPerFace]; int normalNr[maxVerticesPerFace]; for (i = 0; i < nr; i++) { int refs[3]; parseRef(subs[i], refs); vertNr[i] = refs[0]-1; texNr[i] = refs[1]-1; normalNr[i] = refs[2]-1; } if (nr <= 4) { // simple non-singular triangle or quad if (vertNr[0] != vertNr[1] && vertNr[1] != vertNr[2] && vertNr[2] != vertNr[0]) { t.init(); t.vertexNr[0] = vertNr[0]; t.vertexNr[1] = vertNr[1]; t.vertexNr[2] = vertNr[2]; t.normalNr[0] = normalNr[0]; t.normalNr[1] = normalNr[1]; t.normalNr[2] = normalNr[2]; t.texCoordNr[0] = texNr[0]; t.texCoordNr[1] = texNr[1]; t.texCoordNr[2] = texNr[2]; t.materialNr = materialNr; mTriangles.push_back(t); } if (nr == 4) { // non-singular quad -> generate a second triangle if (vertNr[2] != vertNr[3] && vertNr[3] != vertNr[0] && vertNr[0] != vertNr[2]) { t.init(); t.vertexNr[0] = vertNr[2]; t.vertexNr[1] = vertNr[3]; t.vertexNr[2] = vertNr[0]; t.normalNr[0] = normalNr[2]; t.normalNr[1] = normalNr[3]; t.normalNr[2] = normalNr[0]; t.texCoordNr[0] = texNr[0]; t.texCoordNr[1] = texNr[1]; t.texCoordNr[2] = texNr[2]; t.materialNr = materialNr; mTriangles.push_back(t); } } } else { // polygonal face // compute center properties NxVec3 centerPos(0.0f, 0.0f, 0.0f); TexCoord centerTex; centerTex.zero(); for (i = 0; i < nr; i++) { centerPos += mVertices[vertNr[i]]; if (texNr[i] >= 0) centerTex += mTexCoords[texNr[i]]; } centerPos /= (float)nr; centerTex /= (float)nr; NxVec3 d1 = centerPos - mVertices[vertNr[0]]; NxVec3 d2 = centerPos - mVertices[vertNr[1]]; NxVec3 centerNormal = d1.cross(d2); centerNormal.normalize(); // add center vertex centermVertices.push_back(centerPos); centermTexCoords.push_back(centerTex); centerNormals.push_back(centerNormal); // add surrounding elements for (i = 0; i < nr; i++) { j = i+1; if (j >= nr) j = 0; t.init(); t.vertexNr[0] = mVertices.size() + centermVertices.size()-1; t.vertexNr[1] = vertNr[i]; t.vertexNr[2] = vertNr[j]; t.normalNr[0] = mNormals.size() + centerNormals.size()-1; t.normalNr[1] = normalNr[i]; t.normalNr[2] = normalNr[j]; t.texCoordNr[0] = mTexCoords.size() + centermTexCoords.size()-1; t.texCoordNr[1] = texNr[i]; t.texCoordNr[2] = texNr[j]; t.materialNr = materialNr; mTriangles.push_back(t); } } } } fclose(f); // new center mVertices are inserted here. // If they were inserted when generated, the vertex numbering would be corrupted for (i = 0; i < (int)centermVertices.size(); i++) mVertices.push_back(centermVertices[i]); for (i = 0; i < (int)centerNormals.size(); i++) mNormals.push_back(centerNormals[i]); for (i = 0; i < (int)centermTexCoords.size(); i++) mTexCoords.push_back(centermTexCoords[i]); if (mTexCoords.size() > 0) mHasTextureCoords = true; if (mNormals.size() > 0) mHasNormals = true; else updateNormals(); updateBounds(); return true; }
//-***************************************************************************** void MeshDrwHelper::update( P3fArraySamplePtr iP, V3fArraySamplePtr iN, Int32ArraySamplePtr iIndices, Int32ArraySamplePtr iCounts, Abc::Box3d iBounds ) { // Before doing a ton, just have a quick look. if ( m_meshP && iP && ( m_meshP->size() == iP->size() ) && m_meshIndices && ( m_meshIndices == iIndices ) && m_meshCounts && ( m_meshCounts == iCounts ) ) { if ( m_meshP == iP ) { updateNormals( iN ); } else { update( iP, iN ); } return; } // Okay, if we're here, the indices are not equal or the counts // are not equal or the P-array size changed. // So we can clobber those three, but leave N alone for now. m_meshP = iP; m_meshIndices = iIndices; m_meshCounts = iCounts; m_triangles.clear (); // Check stuff. if ( !m_meshP || !m_meshIndices || !m_meshCounts ) { std::cerr << "Mesh update quitting because no input data" << std::endl; makeInvalid(); return; } // Get the number of each thing. size_t numFaces = m_meshCounts->size(); size_t numIndices = m_meshIndices->size(); size_t numPoints = m_meshP->size(); if ( numFaces < 1 || numIndices < 1 || numPoints < 1 ) { // Invalid. std::cerr << "Mesh update quitting because bad arrays" << ", numFaces = " << numFaces << ", numIndices = " << numIndices << ", numPoints = " << numPoints << std::endl; makeInvalid(); return; } // Make triangles. size_t faceIndexBegin = 0; size_t faceIndexEnd = 0; for ( size_t face = 0; face < numFaces; ++face ) { faceIndexBegin = faceIndexEnd; size_t count = (*m_meshCounts)[face]; faceIndexEnd = faceIndexBegin + count; // Check this face is valid if ( faceIndexEnd > numIndices || faceIndexEnd < faceIndexBegin ) { std::cerr << "Mesh update quitting on face: " << face << " because of wonky numbers" << ", faceIndexBegin = " << faceIndexBegin << ", faceIndexEnd = " << faceIndexEnd << ", numIndices = " << numIndices << ", count = " << count << std::endl; // Just get out, make no more triangles. break; } // Checking indices are valid. bool goodFace = true; for ( size_t fidx = faceIndexBegin; fidx < faceIndexEnd; ++fidx ) { if ( ( size_t ) ( (*m_meshIndices)[fidx] ) >= numPoints ) { std::cout << "Mesh update quitting on face: " << face << " because of bad indices" << ", indexIndex = " << fidx << ", vertexIndex = " << (*m_meshIndices)[fidx] << ", numPoints = " << numPoints << std::endl; goodFace = false; break; } } // Make triangles to fill this face. if ( goodFace && count > 2 ) { m_triangles.push_back( Tri( ( unsigned int )(*m_meshIndices)[faceIndexBegin+0], ( unsigned int )(*m_meshIndices)[faceIndexBegin+1], ( unsigned int )(*m_meshIndices)[faceIndexBegin+2] ) ); for ( size_t c = 3; c < count; ++c ) { m_triangles.push_back( Tri( ( unsigned int )(*m_meshIndices)[faceIndexBegin+0], ( unsigned int )(*m_meshIndices)[faceIndexBegin+c-1], ( unsigned int )(*m_meshIndices)[faceIndexBegin+c] ) ); } } } // Cool, we made triangles. // Pretend the mesh is made... m_valid = true; // And now update just the P and N, which will update bounds // and calculate new normals if necessary. if ( iBounds.isEmpty() ) { computeBounds(); } else { m_bounds = iBounds; } updateNormals( iN ); // And that's it. }
void ofApp::update(){ // lights spotLight.setPosition( 60, 60, 200); spotLight.lookAt(ofVec3f(30, 0, -50)); // from GUI ofSetGlobalAmbientColor( globalAmbient.get() ); //spotLight.setGlobalPosition( lightPosition.get() ); spotLight.setAmbientColor( lightAmbient.get() ); spotLight.setDiffuseColor( lightDiffuse.get() ); spotLight.setSpecularColor( lightSpecular.get() ); // Material from GUI //material.setColors(matDiffuse.get(), matAmbient.get(), matEmissive.get(), matSpecular.get()); material.setShininess(matShiny.get()); // mesh auto mesh = sphereBase.getMeshPtr(); auto MeshOut = sphere.getMeshPtr(); updateMesh(mesh, MeshOut); if (isIcoSphere) { mesh = icoSphereBase.getMeshPtr(); MeshOut = icoSphere.getMeshPtr(); updateMesh(mesh, MeshOut); } if (!ofGetKeyPressed('r')) { if (isIcoSphere) setNormals(*MeshOut); else updateNormals(MeshOut); } // depth of field depthOfField.setBlurAmount(blurAmount); depthOfField.setFocalDistance(focalDistance); depthOfField.setFocalRange(focalRange); // FFT fftLive.update(); int n = levels.size(); float * audioData = new float[n]; fftLive.getFftPeakData(audioData, n); for(int i=0; i<levels.size(); i++) { float audioValue = audioData[i]; levels[i] = audioValue; } delete[] audioData; // animate noise if (isNoiseAnimated) { float time = ofGetElapsedTimef(); ofVec3f noiseAnim( (ofNoise(time/2)-0.5) * 80, (ofNoise(time/3)-0.5) * 80, (ofNoise(time/4)-0.5) * 80); noiseIn.set(noiseAnim); //if (levels.size() > 0) noiseIn.set(ofVec3f(levels[0] * 20, levels[1] * 20, levels[2] * 20)); //spotLight.setDiffuseColor( ofColor(ofNoise(ofGetElapsedTimef()/2)*255, ofNoise(ofGetElapsedTimef()/3)*255, ofNoise(ofGetElapsedTimef()/4)*255) ); } }
void m_Polygon::updateAll() { updateNormals(); updateClockwise(); updateEdges(); }
int contextDraw(context_t *ctx) { const char me[]="contextDraw"; unsigned int gi; GLfloat modelMat[16]; /* if (ctx->buttonDown) { // When the mouse is down, use a velocity of zero thetaPerSecU = 0; thetaPerSecV = 0; thetaPerSecN = 0; } else { // Otherwise, use the previous velocity thetaPerSecU = ctx->thetaPerSecU; thetaPerSecV = ctx->thetaPerSecV; thetaPerSecN = ctx->thetaPerSecN; } gctx->angleU = (thetaPerSecU * dt) * 0.1; gctx->angleV = (thetaPerSecV * dt) * 0.1; gctx->angleN = (thetaPerSecN * dt) * 0.1; rotate_model_UV(gctx->angleU, -gctx->angleV); rotate_model_N(-gctx->angleN); */ /* re-assert which program is being used (AntTweakBar uses its own) */ glUseProgram(ctx->program); /* background color; setting alpha=0 means that we'll see the background color in the render window, but upon doing "spotImageScreenshot(img, SPOT_TRUE)" (SPOT_TRUE for "withAlpha") we'll get a meaningful alpha channel, so that the image can recomposited with a different background, or used in programs (including web browsers) that respect the alpha channel */ glClearColor(ctx->bgColor[0], ctx->bgColor[1], ctx->bgColor[2], 0.0f); /* Clear the window and the depth buffer */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* The following will be useful when you want to use textures, especially two textures at once, here sampled in the fragment shader with "samplerA" and "samplerB". There are some non-intuitive calls required to specify which texture data will be sampled by which sampler. See OpenGL SuperBible (5th edition) pg 279. Also, http://tinyurl.com/7bvnej3 is amusing and informative */ // Sun glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, ctx->image[0]->textureId); glUniform1i(ctx->uniloc.sampler0, 0); // Mercury glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, ctx->image[1]->textureId); glUniform1i(ctx->uniloc.sampler1, 1); // Venus glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, ctx->image[2]->textureId); glUniform1i(ctx->uniloc.sampler2, 2); // Earth glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, ctx->image[3]->textureId); glUniform1i(ctx->uniloc.sampler3, 3); // Mars glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, ctx->image[4]->textureId); glUniform1i(ctx->uniloc.sampler4, 4); // Jupiter glActiveTexture(GL_TEXTURE5); glBindTexture(GL_TEXTURE_2D, ctx->image[5]->textureId); glUniform1i(ctx->uniloc.sampler5, 5); // Saturn glActiveTexture(GL_TEXTURE6); glBindTexture(GL_TEXTURE_2D, ctx->image[6]->textureId); glUniform1i(ctx->uniloc.sampler6, 6); // Uranus glActiveTexture(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D, ctx->image[7]->textureId); glUniform1i(ctx->uniloc.sampler7, 7); // Neptune glActiveTexture(GL_TEXTURE8); glBindTexture(GL_TEXTURE_2D, ctx->image[8]->textureId); glUniform1i(ctx->uniloc.sampler8, 8); // Pluto glActiveTexture(GL_TEXTURE9); glBindTexture(GL_TEXTURE_2D, ctx->image[9]->textureId); glUniform1i(ctx->uniloc.sampler9, 9); // set time double toc = spotTime(); if (ctx->ticDraw == -1) ctx->ticDraw = toc; double dt = toc - ctx->ticDraw; ctx->ticDraw = toc; if (!gctx->paused) { updateScene(gctx->time, dt); } // NOTE: we must normalize our UVN matrix norm_M4(gctx->camera.uvn); inverseUVN(gctx->camera.inverse_uvn, gctx->camera.uvn); // NOTE: update our unilocs glUniformMatrix4fv(ctx->uniloc.viewMatrix, 1, GL_FALSE, gctx->camera.uvn); glUniformMatrix4fv(ctx->uniloc.inverseViewMatrix, 1, GL_FALSE, gctx->camera.inverse_uvn); glUniformMatrix4fv(ctx->uniloc.projMatrix, 1, GL_FALSE, gctx->camera.proj); glUniform3fv(ctx->uniloc.lightDir, 1, ctx->lightDir); glUniform3fv(ctx->uniloc.lightColor, 1, ctx->lightColor); glUniform1i(ctx->uniloc.seamFix, ctx->seamFix); for (gi=0; gi<ctx->geomNum; gi++) { set_model_transform(modelMat, ctx->geom[gi]); glUniformMatrix4fv(ctx->uniloc.modelMatrix, 1, GL_FALSE, modelMat); updateNormals(ctx->geom[gi]->normalMatrix, modelMat); glUniformMatrix3fv(ctx->uniloc.normalMatrix, 1, GL_FALSE, ctx->geom[gi]->normalMatrix); glUniform3fv(ctx->uniloc.objColor, 1, ctx->geom[gi]->objColor); glUniform1f(ctx->uniloc.Ka, ctx->geom[gi]->Ka); glUniform1f(ctx->uniloc.Kd, ctx->geom[gi]->Kd); glUniform1i(ctx->uniloc.gi, gi); spotGeomDraw(ctx->geom[gi]); } /* // NOTE: update our geom-specific unilocs for (gi=sceneGeomOffset; gi<ctx->geomNum; gi++) { set_model_transform(modelMat, ctx->geom[gi]); // NOTE: we normalize the model matrix; while we may not need to, it is cheap to do so norm_M4(modelMat); glUniformMatrix4fv(ctx->uniloc.modelMatrix, 1, GL_FALSE, modelMat); // NOTE: we update normals in our `matrixFunctions.c' functions on a case-by-case basis updateNormals(gctx->geom[gi]->normalMatrix, modelMat); glUniformMatrix3fv(ctx->uniloc.normalMatrix, 1, GL_FALSE, ctx->geom[gi]->normalMatrix); // glUniform3fv(ctx->uniloc.objColor, 1, ctx->geom[gi]->objColor); glUniform1f(ctx->uniloc.Ka, ctx->geom[gi]->Ka); glUniform1f(ctx->uniloc.Kd, ctx->geom[gi]->Kd); glUniform1f(ctx->uniloc.Ks, ctx->geom[gi]->Ks); glUniform1i(ctx->uniloc.gi, gi); glUniform1f(ctx->uniloc.shexp, ctx->geom[gi]->shexp); spotGeomDraw(ctx->geom[gi]); } */ /* These lines are also related to using textures. We finish by leaving GL_TEXTURE0 as the active unit since AntTweakBar uses that, but doesn't seem to explicitly select it */ glActiveTexture(GL_TEXTURE9); glBindTexture(GL_TEXTURE_2D, 9); glActiveTexture(GL_TEXTURE8); glBindTexture(GL_TEXTURE_2D, 8); glActiveTexture(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D, 7); glActiveTexture(GL_TEXTURE6); glBindTexture(GL_TEXTURE_2D, 6); glActiveTexture(GL_TEXTURE5); glBindTexture(GL_TEXTURE_2D, 5); glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, 4); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, 3); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, 2); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, 1); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); /* You are welcome to do error-checking with higher granularity than just once per render, in which case this error checking loop should be repackaged into its own function. */ GLenum glerr = glGetError(); if (glerr) { while (glerr) { spotErrorAdd("%s: OpenGL error %d (%s)", me, glerr, spotGLErrorString(glerr)); glerr = glGetError(); } return 1; } return 0; }
void InterpolationData::update(float t, bool cycle){ updateVertices(t, cycle); updateNormals(t, cycle); }
void SplineTransferFunction::fromDomElement(QDomElement de) { m_on.clear(); m_name.clear(); m_points.clear(); m_normals.clear(); m_rightNormals.clear(); m_leftNormals.clear(); m_normalWidths.clear(); m_normalRotations.clear(); m_gradientStops.clear(); QDomNodeList dlist = de.childNodes(); for(int i=0; i<dlist.count(); i++) { QDomElement dnode = dlist.at(i).toElement(); if (dnode.tagName() == "name") { m_name = dnode.toElement().text(); } else if (dnode.tagName() == "points") { QString str = dnode.toElement().text(); QStringList strlist = str.split(" ", QString::SkipEmptyParts); for(int j=0; j<strlist.count()/2; j++) { float x,y; x = strlist[2*j].toFloat(); y = strlist[2*j+1].toFloat(); m_points << QPointF(x,y); } } else if (dnode.tagName() == "normalwidths") { QString str = dnode.toElement().text(); QStringList strlist = str.split(" ", QString::SkipEmptyParts); for(int j=0; j<strlist.count()/2; j++) { float x,y; x = strlist[2*j].toFloat(); y = strlist[2*j+1].toFloat(); m_normalWidths << QPointF(x,y); } } else if (dnode.tagName() == "normalrotations") { QString str = dnode.toElement().text(); QStringList strlist = str.split(" ", QString::SkipEmptyParts); for(int j=0; j<strlist.count(); j++) m_normalRotations << strlist[j].toFloat(); } else if (dnode.tagName() == "gradientstops") { QString str = dnode.toElement().text(); QStringList strlist = str.split(" ", QString::SkipEmptyParts); for(int j=0; j<strlist.count()/5; j++) { float pos, r,g,b,a; pos = strlist[5*j].toFloat(); r = strlist[5*j+1].toInt(); g = strlist[5*j+2].toInt(); b = strlist[5*j+3].toInt(); a = strlist[5*j+4].toInt(); m_gradientStops << QGradientStop(pos, QColor(r,g,b,a)); } } else if (dnode.tagName() == "sets") { QString str = dnode.toElement().text(); QStringList strlist = str.split(" ", QString::SkipEmptyParts); for(int j=0; j<strlist.count(); j++) m_on.append(strlist[j].toInt() > 0); } } updateNormals(); updateColorMapImage(); }