void MarchingCubes::drawTriangleWithNormals(const Vec3f &n1, const Vec3f &p1, const Vec3f &n2, const Vec3f &p2, const Vec3f &n3, const Vec3f &p3) { int num_marching_cubes_tris = marching_cubes_tri_indices.size(); marching_cubes_verts.push_back(VBOPosNormal(p1,n1)); marching_cubes_verts.push_back(VBOPosNormal(p2,n2)); marching_cubes_verts.push_back(VBOPosNormal(p3,n3)); marching_cubes_tri_indices.push_back(VBOIndexedTri(num_marching_cubes_tris*3+0, num_marching_cubes_tris*3+1, num_marching_cubes_tris*3+2)); }
void Mesh::SetupFloor() { Vec3f diff = bbox.getMax()-bbox.getMin(); // create vertices just a bit bigger than the bounding box Vec3f a = bbox.getMin() + Vec3f(-0.75*diff.x(),0,-0.75*diff.z()); Vec3f b = bbox.getMin() + Vec3f( 1.75*diff.x(),0,-0.75*diff.z()); Vec3f c = bbox.getMin() + Vec3f(-0.75*diff.x(),0, 1.75*diff.z()); Vec3f d = bbox.getMin() + Vec3f( 1.75*diff.x(),0, 1.75*diff.z()); Vec3f normal = ComputeNormal(a,c,d); floor_quad_verts.push_back(VBOPosNormal(a,normal)); floor_quad_verts.push_back(VBOPosNormal(c,normal)); floor_quad_verts.push_back(VBOPosNormal(d,normal)); floor_quad_verts.push_back(VBOPosNormal(b,normal)); glBindBuffer(GL_ARRAY_BUFFER,floor_quad_verts_VBO); glBufferData(GL_ARRAY_BUFFER,sizeof(VBOPosNormal)*4,&floor_quad_verts[0],GL_STATIC_DRAW); }
void Mesh::SetupMesh(triangleshashtype &triSet, GLuint VBO, std::vector<VBOPosNormal> &VBO_verts_vector) { for (auto iter = triSet.begin(); iter != triSet.end(); iter++) { Triangle *t = iter->second; Vec3f a = (*t)[0]->getPos(); Vec3f b = (*t)[1]->getPos(); Vec3f c = (*t)[2]->getPos(); Vec3f na = ComputeNormal(a,b,c); Vec3f nb = na; Vec3f nc = na; if (args->gouraud_normals) { na = (*t)[0]->getGouraudNormal(); nb = (*t)[1]->getGouraudNormal(); nc = (*t)[2]->getGouraudNormal(); } VBO_verts_vector.push_back(VBOPosNormal(a,na)); VBO_verts_vector.push_back(VBOPosNormal(b,nb)); VBO_verts_vector.push_back(VBOPosNormal(c,nc)); } glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(VBOPosNormal) * numTriangles(triSet) * 3, &VBO_verts_vector[0], GL_STATIC_DRAW); }