void Mesh::initTriangles(GLuint shader, std::vector<Tri> tris, const glm::vec3 *verts) { m_mappingSize = tris.size() * 3; GLuint memsize = m_mappingSize * 8 * sizeof(float); createBuffers(shader, memsize); setTriangles(tris, verts); }
MS3DGroup::MS3DGroup(byte fl, char* nm, word ct, word* ind, char mi){ flags = fl; strcpy(name, nm); triangleIndices = NULL; setTriangles(ind, ct); materialIndex = mi; }
MS3DGroup& MS3DGroup::operator=(MS3DGroup& g){ flags = g.flags; strcpy(name, g.name); triangleIndices = NULL; setTriangles(g.triangleIndices, g.numTriangles); materialIndex = g.materialIndex; return *this; }
void GeoParticle::update(float timeScale) { //if exploding, update that sturr if (m_isExploding) { if (m_explodeTime >= s_explosionTimeout) { m_isDead = true; return; } float explodeSpeed = m_explodeTime / s_explosionTimeout; explodeSpeed = (1.f - explodeSpeed * explodeSpeed * explodeSpeed) * 0.05f; for (int i = 0; i < m_numTriangles; ++i) { float angle = atan2f(m_triangles[i].center.y, m_triangles[i].center.x); m_triangles[i].offset += ofVec2f(cos(angle) * explodeSpeed * timeScale, sin(angle) * explodeSpeed * timeScale); m_triangles[i].angle += ofNoise(i) * 0.05f; } m_explodeTime += timeScale * 16.f; if (m_explodeTime >= s_explosionTimeout) m_explodeTime = s_explosionTimeout; } // update noise counters for (int i = 0; i < m_numVerts; ++i) { m_noiseOffsets[i] += 0.01f * timeScale; } setTriangles(); //build main vbo for (int i = 0; i < m_numTriangles; ++i) { for (int j = 0; j < 3; ++j) { m_currentVerts[i * 3 + j] = m_triangles[i].verts[j] + m_triangles[i].offset; } } m_vbo.setVertexData(&m_currentVerts[0], m_numTriangles*3, GL_DYNAMIC_DRAW); if(m_isExploding == true){ alphaTime = alphaTime + timeScale*16.f; if (alphaTime > s_explosionTimeout * 0.2){ alphaExplode = 200; } if (alphaTime > s_explosionTimeout *0.4){ alphaExplode = 150; } if (alphaTime > s_explosionTimeout*0.6){ alphaExplode = 50; } if (alphaTime > s_explosionTimeout*0.8){ alphaExplode = 0; } } }
void DrawableStatsAttachment::operator -=(DrawableStatsAttachment *arg) { setVertices (getVertices() - arg->getVertices()); setPoints (getPoints() - arg->getPoints()); setLines (getLines() - arg->getLines()); setTriangles (getTriangles() - arg->getTriangles()); setPatches (getPatches () - arg->getPatches ()); setProcessedAttributeBytes(getProcessedAttributeBytes() - arg->getProcessedAttributeBytes()); setStoredAttributeBytes (getStoredAttributeBytes() - arg->getStoredAttributeBytes()); setValid(true); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int TriangleGeom::readGeometryFromHDF5(hid_t parentId, bool preflight) { herr_t err = 0; SharedVertexList::Pointer vertices = GeometryHelpers::GeomIO::ReadListFromHDF5<SharedVertexList>(DREAM3D::Geometry::SharedVertexList, parentId, preflight, err); SharedTriList::Pointer tris = GeometryHelpers::GeomIO::ReadListFromHDF5<SharedQuadList>(DREAM3D::Geometry::SharedTriList, parentId, preflight, err); if (tris.get() == NULL || vertices.get() == NULL) { return -1; } size_t numTris = tris->getNumberOfTuples(); size_t numVerts = vertices->getNumberOfTuples(); SharedEdgeList::Pointer edges = GeometryHelpers::GeomIO::ReadListFromHDF5<SharedEdgeList>(DREAM3D::Geometry::SharedEdgeList, parentId, preflight, err); if (err < 0 && err != -2) { return -1; } SharedEdgeList::Pointer bEdges = GeometryHelpers::GeomIO::ReadListFromHDF5<SharedEdgeList>(DREAM3D::Geometry::UnsharedEdgeList, parentId, preflight, err); if (err < 0 && err != -2) { return -1; } FloatArrayType::Pointer triCentroids = GeometryHelpers::GeomIO::ReadListFromHDF5<FloatArrayType>(DREAM3D::StringConstants::TriangleCentroids, parentId, preflight, err); if (err < 0 && err != -2) { return -1; } ElementDynamicList::Pointer triNeighbors = GeometryHelpers::GeomIO::ReadDynamicListFromHDF5<uint16_t, int64_t>(DREAM3D::StringConstants::TriangleNeighbors, parentId, numTris, preflight, err); if (err < 0 && err != -2) { return -1; } ElementDynamicList::Pointer trisContainingVert = GeometryHelpers::GeomIO::ReadDynamicListFromHDF5<uint16_t, int64_t>(DREAM3D::StringConstants::TrianglesContainingVert, parentId, numVerts, preflight, err); if (err < 0 && err != -2) { return -1; } setVertices(vertices); setEdges(edges); setUnsharedEdges(bEdges); setTriangles(tris); setElementCentroids(triCentroids); setElementNeighbors(triNeighbors); setElementsContainingVert(trisContainingVert); return 1; }
void DrawableStatsAttachment::reset(void) { // Don't change it unless it's valid. // Needed to protect intermediate results if(!getValid()) return; setVertices (0); setPoints (0); setLines (0); setTriangles (0); setPatches (0); setProcessedAttributeBytes(0); setStoredAttributeBytes (0); setValid(false); }
void ParallelogramLight::set(const QVector3D &origin, const QVector3D &u, const QVector3D &v) { QVector3D p0 = origin, p1 = origin + u, p2 = origin + v, p3 = origin + u + v, n = QVector3D::crossProduct(u, v).normalized(); Vertex* v0 = new Vertex(p0, n); Vertex* v1 = new Vertex(p1, n); Vertex* v2 = new Vertex(p2, n); Vertex* v3 = new Vertex(p3, n); Triangle* t0 = new Triangle(v0, v1, v3); Triangle* t1 = new Triangle(v0, v3, v2); QVector<Triangle*> triangles(2); triangles[0] = t0; triangles[1] = t1; setTriangles(triangles); }
/** * Constructs a new BoxGeom and hands the DoubleValues for updating the * geometry to the new object. */ BoxGeom::BoxGeom(SimObject *sim, double width, double height, double depth) : TriangleGeom(sim) { mSimObject = sim; QVector<Triangle> triangles; triangles.push_back(Triangle(0, 2, 1)); triangles.push_back(Triangle(0, 3, 2)); triangles.push_back(Triangle(0, 1, 4)); triangles.push_back(Triangle(0, 4, 5)); triangles.push_back(Triangle(0, 5, 6)); triangles.push_back(Triangle(0, 6, 3)); triangles.push_back(Triangle(1, 7, 4)); triangles.push_back(Triangle(1, 2, 7)); triangles.push_back(Triangle(2, 3, 6)); triangles.push_back(Triangle(2, 6, 7)); triangles.push_back(Triangle(4, 6, 5)); triangles.push_back(Triangle(4, 7, 6)); setTriangles(triangles); setSize(width, height, depth); }
GeoParticle::GeoParticle(ofVec3f _pos) : Particle(_pos) { startTime = 0; alphaTime = 0; m_explodeTime = 0; m_isExploding = false; m_isDead = false; alphaExplode = 250; m_vbo.disableVAOs(); //get a random radius GeoSize = ofRandom(ofGetWidth() * 0.05, ofGetWidth() * 0.1); //choose random gradient m_gradNum = floor(ofRandom(0, 6)); //get a random number of triangles m_numTriangles = (int)ofRandom(3, 7); m_triangles = new GeoTriangle[m_numTriangles]; m_numVerts = m_numTriangles + 1; m_originalVerts = new ofVec2f[m_numVerts]; m_noiseOffsets = new float[m_numVerts]; m_currentVerts = new ofVec2f[m_numTriangles * 3];; m_currentTexCoords = new ofVec2f[m_numTriangles * 3];; float angle = PI*2.f / m_numTriangles; m_originalVerts[0] = ofVec2f(0.f, 0.f); for (int i = 1; i < m_numVerts; ++i) { m_originalVerts[i] = ofVec2f(cos(angle*i), sin(angle*i)); m_noiseOffsets[i] = ofRandom(0, 10000); } setTriangles(); //calculate triangle centers for (int i = 0; i < m_numTriangles; ++i) { m_triangles[i].center = ofVec2f(0.f, 0.f); m_triangles[i].center += m_originalVerts[0] + ofNoise(m_noiseOffsets[0]) * 0.2f; m_triangles[i].center += m_originalVerts[i + 1] + ofNoise(m_noiseOffsets[i + 1]) * 0.2f; if (i == m_numTriangles - 1) m_triangles[i].center += m_originalVerts[1] + ofNoise(m_noiseOffsets[1]) * 0.2f; else m_triangles[i].center += m_originalVerts[i + 2] + ofNoise(m_noiseOffsets[i + 2]) * 0.2f; m_triangles[i].center /= 3; m_triangles[i].angle = 0; } //texture data for(int i = 0; i < m_numTriangles; ++i) { getRandomTexCoord(m_triangles[i].texCoords); } //set to vbo for (int i = 0; i < m_numTriangles; ++i) { for (int j = 0; j < 3; ++j) { m_currentTexCoords[i * 3 + j] = m_triangles[i].texCoords[j]; } } m_vbo.setTexCoordData(&m_currentTexCoords[0], m_numTriangles * 3, GL_STATIC_DRAW); }