void MDAL::DriverGdal::createMesh() { Vertices vertices( meshGDALDataset()->mNPoints ); bool is_longitude_shifted = initVertices( vertices ); Faces faces( meshGDALDataset()->mNVolumes ); initFaces( vertices, faces, is_longitude_shifted ); mMesh.reset( new MemoryMesh( name(), vertices.size(), faces.size(), 4, //maximum quads computeExtent( vertices ), mFileName ) ); mMesh->vertices = vertices; mMesh->faces = faces; bool proj_added = addSrcProj(); if ( ( !proj_added ) && is_longitude_shifted ) { std::string wgs84( "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" ); mMesh->setSourceCrs( wgs84 ); } }
bool Decals::init() { if(!initShaders()) return false; if(!initVertices()) return false; return true; }
TexturedQuad::TexturedQuad() { xLength = 1.0f; yLength = 1.0f; filename = 0; initVertices(); initBuffers(); }
TexturedQuad::TexturedQuad(float xLengthIn, float yLengthIn, char* filenameIn, char* filename2In) { xLength = xLengthIn; yLength = yLengthIn; filename = filenameIn; filename2 = filename2In; initVertices(); loadImage(); initBuffers(); }
//---------------------------------------------------------------- // TO DO: Complete this function to create your sphere // The sphere is a unit icosphere centered at the origin (0,0,0). // First add a key press event in KeyCallback that will call this function //---------------------------------------------------------------- void createSphere(void) { globalCount = 0; //for subdivisions // TO DO: Optional remove this as a global var // triangle mesh object std::vector<STTriangleMesh *> gTriangleMeshes_sphere; // vertices std::vector<STVector3> vertices; // Creates the initial verticies initVertices(&vertices); //----------------------------------------------------- // TO DO: create the faces of the intIcosahedron // Place your code in the function initFaces() //----------------------------------------------------- std::vector<TriangleIndices> faces; initFaces(&faces); //--------------------------------------------------------------- // TO DO: Recursively split each triangle into four triangles // See images in docs/icosahedron/ // Determine the levels for the recursion by changing the value in levels //---------------------------------------------------------------- std::vector<TriangleIndices> newfaces; int levels = 1; subDivideTriangles(levels, &faces, &newfaces, &vertices); //----------------------------------------------------------------- // TO DO: Once faces are generated, add each triangle to the // mesh. Place your code in createMySphereMesh() // call createMySphereMesh here //----------------------------------------------------------------- //piyush add code // std::vector<STTriangleMesh*> tmesh; STTriangleMesh *tmesh = new STTriangleMesh(); for(int i =0; i<vertices.size(); i++){ tmesh->AddVertex(vertices.at(i).x, vertices.at(i).y, vertices.at(i).z); } for(int i=0; i< faces.size(); i++){ createMySphereMesh(tmesh, faces[i], &vertices); gTriangleMeshes_sphere.push_back(tmesh); } // save the result sphere for(unsigned int id=0;id<gTriangleMeshes_sphere.size(); id++) gTriangleMeshes_sphere[id]->Write("mysphere.obj"); }
CCubeBox::CCubeBox(FLOAT wx, FLOAT wy, FLOAT wz, FLOAT tilew, FLOAT tileh, bool inner): CObject3D() { m_wx = wx; m_wy = wy; m_wz = wz; m_tileh = tileh; m_tilew = tilew; m_inner = inner; if (tileh <=0 || tilew <=0) m_tiled = false; m_tiled = true; initVertices(); SetPosition(0, 0, 0); SetRotation(0, 0, 0); }
CCubeBox::CCubeBox(FLOAT wx, FLOAT wy, FLOAT wz, bool inner): CObject3D() { m_wx = wx; m_wy = wy; m_wz = wz; m_inner = inner; m_tiled = false; m_vertexCount = 4 * 6; m_indexCount = 6 * 2 * 3; m_vertexSize = sizeof(VERTEX_BOX); m_indexSize = sizeof(WORD); initVertices(); SetPosition(0, 0, 0); SetRotation(0, 0, 0); }
Water::Water(const DTM *dtm): m_dtm(dtm), m_ncols(dtm->ncols()), m_nrows(dtm->nrows()), m_values(new float[m_nrows * m_ncols]) { for(index_t i = 0; i < m_nrows; ++i) for(index_t j = 0; j < m_ncols; ++j) { const index_t k = i * m_ncols + j; m_values[k] = 0; } initVertices(); initIndices(); initVBO(); free(); }
void CircleBuilder::build(shared_ptr<Graph> g) { //Debugging initVertices(g); radialFactor = radius/precision; radius = 0; float longitude = 0; setNextVertex(longitude, 0); int triangles = 6; radius = radialFactor; setNextVertex(longitude, triangles); innerStartIndex = firstUniqueVertex; int longFactor = 60; for (longitude = 60; longitude < 360; longitude += longFactor) { setNextVertex(longitude, triangles); } //Begin Row 3 for (int i = 1; i <= precision; i++) { innerStartIndex = outterStartIndex; outterStartIndex = graph->uniqueVertexPointer; radius = radialFactor * (float) i; if (i >= clip) return setPointers(); triangles += 6; longitude = 0; longFactor = 360/triangles; theta = ( 360 / triangles ) / ( 360 * pi ); longitude = setNextVertex(longitude, triangles); for(int steps = 1; steps < triangles - 1; steps++) longitude = setNextVertex(longitude, triangles); longitude = setNextVertex(longitude, triangles); } return setPointers(); }
void MDAL::LoaderGdal::createMesh() { Vertices vertices( meshGDALDataset()->mNPoints ); bool is_longitude_shifted = initVertices( vertices ); Faces faces( meshGDALDataset()->mNVolumes ); initFaces( vertices, faces, is_longitude_shifted ); mMesh.reset( new Mesh() ); mMesh->vertices = vertices; mMesh->faces = faces; bool proj_added = addSrcProj(); if ( ( !proj_added ) && is_longitude_shifted ) { std::string wgs84( "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" ); mMesh->setSourceCrs( wgs84 ); } }
bool Cube::init() { // first, check for entry errors if (Utils::GLReturnedError("Cube::init - Error on entry")) return false; initVertices(); // get handle for whole bundle glGenVertexArrays(1, &vertexArrayHandle); glBindVertexArray(vertexArrayHandle); // allocate a GPU buffer glGenBuffers(1, &vertexBufferHandle); glBindBuffer(GL_ARRAY_BUFFER, vertexBufferHandle); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(VertexData), &vertices[0], GL_STATIC_DRAW); // setup buffer layout glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (GLvoid*) 0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (GLvoid*) sizeof(vec3)); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (GLvoid*) (2 * sizeof(vec3))); glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (GLvoid*) (3 * sizeof(vec3))); glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (GLvoid*) (4 * sizeof(vec3))); // enable vertex attributes glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); glEnableVertexAttribArray(4); // unbind vertex and buffer handles glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); // check for exit errors if (Utils::GLReturnedError("Cube::init - Error on entry")) return false; return true; }
void CubeGeometry::init(float width, float height, float depth) { std::vector<glm::vec3> positions; std::vector<glm::vec2> texcoords; positions.push_back(glm::vec3(width/2, -height/2, -depth/2)); positions.push_back(glm::vec3(-width/2, -height/2, -depth/2)); positions.push_back(glm::vec3(-width/2, height/2, -depth/2)); positions.push_back(glm::vec3(width/2, height/2, -depth/2)); positions.push_back(glm::vec3(-width/2, -height/2, depth/2)); positions.push_back(glm::vec3(width/2, -height/2, depth/2)); positions.push_back(glm::vec3(width/2, height/2, depth/2)); positions.push_back(glm::vec3(-width/2, height/2, depth/2)); positions.push_back(glm::vec3(-width/2, -height/2, -depth/2)); positions.push_back(glm::vec3(-width/2, -height/2, depth/2)); positions.push_back(glm::vec3(-width/2, height/2, depth/2)); positions.push_back(glm::vec3(-width/2, height/2, -depth/2)); positions.push_back(glm::vec3(width/2, -height/2, depth/2)); positions.push_back(glm::vec3(width/2, -height/2, -depth/2)); positions.push_back(glm::vec3(width/2, height/2, -depth/2)); positions.push_back(glm::vec3(width/2, height/2, depth/2)); positions.push_back(glm::vec3(-width/2, -height/2, -depth/2)); positions.push_back(glm::vec3(width/2, -height/2, -depth/2)); positions.push_back(glm::vec3(width/2, -height/2, depth/2)); positions.push_back(glm::vec3(-width/2, -height/2, depth/2)); positions.push_back(glm::vec3(width/2, height/2, -depth/2)); positions.push_back(glm::vec3(-width/2, height/2, -depth/2)); positions.push_back(glm::vec3(-width/2, height/2, depth/2)); positions.push_back(glm::vec3(width/2, height/2, depth/2)); texcoords.push_back(glm::vec2(0, 0)); texcoords.push_back(glm::vec2(1, 0)); texcoords.push_back(glm::vec2(1, 1)); texcoords.push_back(glm::vec2(0, 1)); texcoords.push_back(glm::vec2(0, 0)); texcoords.push_back(glm::vec2(1, 0)); texcoords.push_back(glm::vec2(1, 1)); texcoords.push_back(glm::vec2(0, 1)); texcoords.push_back(glm::vec2(0, 0)); texcoords.push_back(glm::vec2(1, 0)); texcoords.push_back(glm::vec2(1, 1)); texcoords.push_back(glm::vec2(0, 1)); texcoords.push_back(glm::vec2(0, 0)); texcoords.push_back(glm::vec2(1, 0)); texcoords.push_back(glm::vec2(1, 1)); texcoords.push_back(glm::vec2(0, 1)); texcoords.push_back(glm::vec2(0, 0)); texcoords.push_back(glm::vec2(1, 0)); texcoords.push_back(glm::vec2(1, 1)); texcoords.push_back(glm::vec2(0, 1)); texcoords.push_back(glm::vec2(0, 0)); texcoords.push_back(glm::vec2(1, 0)); texcoords.push_back(glm::vec2(1, 1)); texcoords.push_back(glm::vec2(0, 1)); unsigned int i[] = {0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23}; std::vector<unsigned int> indices(&i[0], &i[0]+36); initVertices(positions, texcoords, indices); }
bool GameSession::init() { Game::shared().getEventManager()->addEventHandler(EVENT_GAME_FULLSTATE, this); input = new GameSessionInput(this); input->init(); if(!initShaders()) return false; if(!initVertices()) return false; Root::shared().addInputListener(input); Root::shared().addFrameListener(input); Root::shared().addFrameListener(this); // init factions localFaction = new Faction; localFaction->setColor(0); factions.push_back(localFaction); Faction* otherFaction = new Faction; otherFaction->setColor(1); factions.push_back(otherFaction); Scene* scene = Root::shared().makeDefaultScene(); if(!scene) return false; Camera* cam = scene->getCamera(); cam->setPosition(vec3(0.0f, 150.0f, 0.0f)); cam->setCameraAngle(0.0f, -60.0f); cam->setZoom(300.0f); Object* obj; // init map vector<Arya::Material*> tileSet; tileSet.push_back(Arya::MaterialManager::shared().getMaterial("grass.tga")); tileSet.push_back(Arya::MaterialManager::shared().getMaterial("rock.tga")); tileSet.push_back(Arya::MaterialManager::shared().getMaterial("snow.tga")); tileSet.push_back(Arya::MaterialManager::shared().getMaterial("dirt.tga")); vector<Arya::Texture*> skyset; skyset.push_back(Arya::TextureManager::shared().getTexture("transparentClouds.png")); skyset.push_back(Arya::TextureManager::shared().getTexture("stars.jpg")); if(!scene->setMap("heightmap.raw", "watermap.raw", tileSet, skyset, Arya::TextureManager::shared().getTexture("splatmap.tga"))) return false; for(int i = 0; i < 30; ++ i) { Unit* unit = new Unit(0); float heightModel = Root::shared().getScene()->getMap()->getTerrain()->heightAtGroundPosition(20.0f * (i / 10), -50.0f+20.0f*(i % 10)); obj = scene->createObject(); obj->setModel(ModelManager::shared().getModel("ogros.aryamodel")); obj->setAnimation("stand"); unit->setObject(obj); unit->setPosition(vec3(20 * (i / 10), heightModel, -50 + 20 * (i % 10))); localFaction->addUnit(unit); } for(int i = 0; i < 30; ++ i) { Unit* unit = new Unit(0); float heightModel = Root::shared().getScene()->getMap()->getTerrain()->heightAtGroundPosition(-100.0f + 20.0f * (i / 10), -100.0f+20.0f*(i % 10)); obj = scene->createObject(); obj->setModel(ModelManager::shared().getModel("ogros.aryamodel")); obj->setAnimation("stand"); unit->setObject(obj); unit->setPosition(vec3(-100.0 + 20 * (i / 10), heightModel, -100.0 + 20 * (i % 10))); otherFaction->addUnit(unit); } for(int i = 0; i < 10; ++ i) { Unit* unit = new Unit(1); float heightModel = Root::shared().getScene()->getMap()->getTerrain()->heightAtGroundPosition(-200.0f + 20.0f * (i / 10), -50.0f+20.0f*(i % 10)); obj = scene->createObject(); obj->setModel(ModelManager::shared().getModel("hep.aryamodel")); obj->setAnimation("stand"); unit->setObject(obj); unit->setPosition(vec3(-200.0f + 20 * (i / 10), heightModel, -50 + 20 * (i % 10))); localFaction->addUnit(unit); } selectionDecalHandle = 0; Texture* selectionTex = TextureManager::shared().getTexture("selection.png"); if(selectionTex) selectionDecalHandle = selectionTex->handle; return true; }
Cylinder(float radius, float height) : m_fRadius(radius), m_fHeight(height), m_vVertices() { initVertices(); }
Triangle::Triangle() { initVertices(); initTexCoords(); }
void reloadVertices() { m_vVertices.clear(); initVertices(); }
/* * March through the grid, creating the tesselation of an isosurface. * The somewhat convoluted logic is necessary to prevent any single cube * edge from being examined more than once. This allows for a compact * mesh representation, with each vertex stored only once and each face * stored simply as three integer indices into the vertex array. */ void MarchCube::march (IsoSurface& surface) { surface.clear(); ImpSurface* function = surface.getFunction(); /* * */ initVertices(0, vtxGrid[0], function); initVertices(1, vtxGrid[1], function); setCubeFlags(); /* * Fill in the back of the grid first (where "forward" is the +z * direction. This is done by checking the left- and bottom-edges * of each square at the very back of the grid, then all the edges * along the top of the back, then all those along the right. */ for (int i = 0; i < resx; ++i) { for (int j = 0; j < resy; ++j) { if (edgeFlags[i][j] & LEFTBACK) edgeGrid[0][i][j][0] = surface.addVertex(vtxGrid[0][i][j].findSurface( vtxGrid[0][i][j + 1], threshold)); if (edgeFlags[i][j] & BOTBACK) edgeGrid[0][i][j][2] = surface.addVertex(vtxGrid[0][i][j].findSurface( vtxGrid[0][i + 1][j], threshold)); } if (edgeFlags[i][resy - 1] & TOPBACK) edgeGrid[0][i][resy][2] = surface.addVertex(vtxGrid[0][i][resy].findSurface( vtxGrid[0][i + 1][resy], threshold)); } for (int i = 0; i < resy; ++i) { if (edgeFlags[resx - 1][i] & RIGHTBACK) edgeGrid[0][resx][i][0] = surface.addVertex(vtxGrid[0][resx][i].findSurface( vtxGrid[0][resx][i + 1], threshold)); } /* * Step forward (in the +z direction) through the grid. We first * consider the bottom-left, front-left, and bottom-front edges from * each cube. The top edges from the top row of cubes are then * examined, followed by those on the right edge of the grid. */ for (int layer = 1; layer <= resz; ++layer) { // cerr << "filling in layer " << layer << endl; if (layer > 1) { initVertices(layer, vtxGrid[1], function); setCubeFlags(); } for (int i = 0; i < resx; ++i) { for (int j = 0; j < resy; ++j) { if (edgeFlags[i][j] & BOTLEFT) edgeGrid[0][i][j][1] = surface.addVertex(vtxGrid[0][i][j].findSurface( vtxGrid[1][i][j], threshold)); if (edgeFlags[i][j] & LEFTFRONT) edgeGrid[1][i][j][0] = surface.addVertex(vtxGrid[1][i][j].findSurface( vtxGrid[1][i][j + 1], threshold)); if (edgeFlags[i][j] & BOTFRONT) edgeGrid[1][i][j][2] = surface.addVertex(vtxGrid[1][i][j].findSurface( vtxGrid[1][i + 1][j], threshold)); } if (edgeFlags[i][resy - 1] & TOPLEFT) edgeGrid[0][i][resy][1] = surface.addVertex(vtxGrid[0][i][resy].findSurface( vtxGrid[1][i][resy], threshold)); if (edgeFlags[i][resy - 1] & TOPFRONT) edgeGrid[1][i][resy][2] = surface.addVertex(vtxGrid[1][i][resy].findSurface( vtxGrid[1][i + 1][resy], threshold)); } for (int i = 0; i < resy; ++i) { if (edgeFlags[resx - 1][i] & RIGHTFRONT) edgeGrid[1][resx][i][0] = surface.addVertex(vtxGrid[1][resx][i].findSurface( vtxGrid[1][resx][i + 1], threshold)); if (edgeFlags[resx - 1][i] & BOTRIGHT) edgeGrid[0][resx][i][1] = surface.addVertex(vtxGrid[0][resx][i].findSurface( vtxGrid[1][resx][i], threshold)); } if (edgeFlags[resx - 1][resy - 1] & TOPRIGHT) edgeGrid[0][resx][resy][1] = surface.addVertex(vtxGrid[0][resx][resy].findSurface( vtxGrid[1][resx][resy], threshold)); /* * Now that we've found all the vertices on the edges of the cubes * in the layer, extract the set of triangles defined. */ int* indices; int e0, e1, e2; int v0, v1, v2; static int badV = 0; for (int i = 0; i < resx; ++i) { for (int j = 0; j < resy; ++j) { indices = triTable[vtxFlags[i][j]]; while(*indices != -1) { e0 = *indices++; e1 = *indices++; e2 = *indices++; v0 = getVertex(i, j, e0); v1 = getVertex(i, j, e1); v2 = getVertex(i, j, e2); surface.addFace(v0, v1, v2); } } } /* * Move the vertex/edge-index grids one step forward */ CubeVtx** vTemp = vtxGrid[0]; vtxGrid[0] = vtxGrid[1]; vtxGrid[1] = vTemp; int*** eTemp = edgeGrid[0]; edgeGrid[0] = edgeGrid[1]; edgeGrid[1] = eTemp; } surface.calcVNorms(); }