//---------------------------------------------------------------------------------------------------------------------- BBox::BBox( Real _minX, Real _maxX, Real _minY, Real _maxY, Real _minZ, Real _maxZ ) noexcept { m_minX=_minX; m_maxX=_maxX; m_minY=_minY; m_maxY=_maxY; m_minZ=_minZ; m_maxZ=_maxZ; m_center.set(0,0,0); m_vert[0].m_x=_minX; m_vert[0].m_y=_maxY; m_vert[0].m_z=_minZ; m_vert[1].m_x=_maxX; m_vert[1].m_y=_maxY; m_vert[1].m_z=_minZ; m_vert[2].m_x=_maxX; m_vert[2].m_y=_maxY; m_vert[2].m_z=_maxZ; m_vert[3].m_x=_minX; m_vert[3].m_y=_maxY; m_vert[3].m_z=_maxZ; m_vert[4].m_x=_minX; m_vert[4].m_y=_minY; m_vert[4].m_z=_minZ; m_vert[5].m_x=_maxX; m_vert[5].m_y=_minY; m_vert[5].m_z=_minZ; m_vert[6].m_x=_maxX; m_vert[6].m_y=_minY; m_vert[6].m_z=_maxZ; m_vert[7].m_x=_minX; m_vert[7].m_y=_minY; m_vert[7].m_z=_maxZ; #ifdef USINGIOS_ m_drawMode=GL_LINE_LOOP; #else m_drawMode=GL_LINE; #endif m_width=m_maxX-m_minX; m_height=m_maxY-m_minY; m_depth=m_maxZ-m_minZ; m_vao=0; setVAO(); }
//---------------------------------------------------------------------------------------------------------------------- BBox::BBox( Real _minX, Real _maxX, Real _minY, Real _maxY, Real _minZ, Real _maxZ ) { m_minX=_minX; m_maxX=_maxX; m_minY=_minY; m_maxY=_maxY; m_minZ=_minZ; m_maxZ=_maxZ; m_center.set(0,0,0); m_vert[0].m_x=_minX; m_vert[0].m_y=_maxY; m_vert[0].m_z=_minZ; m_vert[1].m_x=_maxX; m_vert[1].m_y=_maxY; m_vert[1].m_z=_minZ; m_vert[2].m_x=_maxX; m_vert[2].m_y=_maxY; m_vert[2].m_z=_maxZ; m_vert[3].m_x=_minX; m_vert[3].m_y=_maxY; m_vert[3].m_z=_maxZ; m_vert[4].m_x=_minX; m_vert[4].m_y=_minY; m_vert[4].m_z=_minZ; m_vert[5].m_x=_maxX; m_vert[5].m_y=_minY; m_vert[5].m_z=_minZ; m_vert[6].m_x=_maxX; m_vert[6].m_y=_minY; m_vert[6].m_z=_maxZ; m_vert[7].m_x=_minX; m_vert[7].m_y=_minY; m_vert[7].m_z=_maxZ; m_drawMode=GL_LINE; m_width=m_maxX-m_minX; m_height=m_maxY-m_minY; m_depth=m_maxZ-m_minZ; m_vao=0; setVAO(); }
//---------------------------------------------------------------------------------------------------------------------- BBox::BBox() { //default constructor creates a unit BBox m_center.m_x=m_center.m_y=m_center.m_z=0.0f; m_drawMode=GL_LINE; m_width=2.0; m_height=2.0; m_depth=2.0; m_vao=0; setVAO(); }
void PointArray::initializeGL() { Geometry::initializeGL(); GLuint vao; glGenVertexArrays(1, &vao); setVAO("points", vao); GLuint vbo; glGenBuffers(1, &vbo); setVBO("point_buffer", vbo); }
Menu2D::Menu2D(const std::string pathTextureMenu): nbButtonInMenu(0){ vertices[0] = glimac::Vertex2DUV(glm::vec2(-1.f, -1.f), glm::vec2(0,1)); vertices[1] = glimac::Vertex2DUV(glm::vec2(1.f, -1.f), glm::vec2(1,1)); vertices[2] = glimac::Vertex2DUV(glm::vec2(1.f, 1.f), glm::vec2(1,0)); vertices[3] = glimac::Vertex2DUV(glm::vec2(-1.f, 1.f), glm::vec2(0,0)); glimac::Texture* background = new glimac::Texture(GL_TEXTURE_2D); background->loadTexture2D(pathTextureMenu); tabTexture.push_back(background); activTexture = tabTexture[0]; setVBO(); setVAO(); }
//---------------------------------------------------------------------------------------------------------------------- BBox::BBox() noexcept { //default constructor creates a unit BBox m_center.m_x=m_center.m_y=m_center.m_z=0.0f; #ifdef USINGIOS_ m_drawMode=GL_LINE_LOOP; #else m_drawMode=GL_LINE; #endif m_width=2.0; m_height=2.0; m_depth=2.0; m_vao=nullptr; setVAO(); }
void BBox::recalculate() noexcept { // Calculate the Vertices based on the w,h,d params passed in the box is asumed // to be centered on the _center with equal w / h / d // -x +y -z m_vert[0].m_x=m_center.m_x-(m_width/2.0f); m_vert[0].m_y=m_center.m_y+(m_height/2.0f); m_vert[0].m_z=m_center.m_z-(m_depth/2.0f); // + x -y -z m_vert[1].m_x=m_center.m_x+(m_width/2.0f); m_vert[1].m_y=m_center.m_y+(m_height/2.0f); m_vert[1].m_z=m_center.m_z-(m_depth/2.0f); m_vert[2].m_x=m_center.m_x+(m_width/2.0f); m_vert[2].m_y=m_center.m_y+(m_height/2.0f); m_vert[2].m_z=m_center.m_z+(m_depth/2.0f); m_vert[3].m_x=m_center.m_x-(m_width/2.0f); m_vert[3].m_y=m_center.m_y+(m_height/2.0f); m_vert[3].m_z=m_center.m_z+(m_depth/2.0f); m_vert[4].m_x=m_center.m_x-(m_width/2.0f); m_vert[4].m_y=m_center.m_y-(m_height/2.0f); m_vert[4].m_z=m_center.m_z-(m_depth/2.0f); m_vert[5].m_x=m_center.m_x+(m_width/2.0f); m_vert[5].m_y=m_center.m_y-(m_height/2.0f); m_vert[5].m_z=m_center.m_z-(m_depth/2.0f); m_vert[6].m_x=m_center.m_x+(m_width/2.0f); m_vert[6].m_y=m_center.m_y-(m_height/2.0f); m_vert[6].m_z=m_center.m_z+(m_depth/2.0f); m_vert[7].m_x=m_center.m_x-(m_width/2.0f); m_vert[7].m_y=m_center.m_y-(m_height/2.0f); m_vert[7].m_z=m_center.m_z+(m_depth/2.0f); setVAO(); }
Block::Block(int column, int row, int colorValue) { this->colorValue = colorValue; this->column = column; this->row = row; setVertices(); indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 1; indices[4] = 2; indices[5] = 3; glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); glGenBuffers(1, &EBO); setVAO(); }
//---------------------------------------------------------------------------------------------------------------------- BBox::BBox( const Vec3& _center, Real _width, Real _height, Real _depth ) noexcept { // Calculate the Vertices based on the w,h,d params passed in the box is asumed // to be centered on the _center with equal w / h / d // -x +y -z m_vert[0].m_x=_center.m_x-(_width/2.0f); m_vert[0].m_y=_center.m_y+(_height/2.0f); m_vert[0].m_z=_center.m_z-(_depth/2.0f); // + x -y -z m_vert[1].m_x=_center.m_x+(_width/2.0f); m_vert[1].m_y=_center.m_y+(_height/2.0f); m_vert[1].m_z=_center.m_z-(_depth/2.0f); m_vert[2].m_x=_center.m_x+(_width/2.0f); m_vert[2].m_y=_center.m_y+(_height/2.0f); m_vert[2].m_z=_center.m_z+(_depth/2.0f); m_vert[3].m_x=_center.m_x-(_width/2.0f); m_vert[3].m_y=_center.m_y+(_height/2.0f); m_vert[3].m_z=_center.m_z+(_depth/2.0f); m_vert[4].m_x=_center.m_x-(_width/2.0f); m_vert[4].m_y=_center.m_y-(_height/2.0f); m_vert[4].m_z=_center.m_z-(_depth/2.0f); m_vert[5].m_x=_center.m_x+(_width/2.0f); m_vert[5].m_y=_center.m_y-(_height/2.0f); m_vert[5].m_z=_center.m_z-(_depth/2.0f); m_vert[6].m_x=_center.m_x+(_width/2.0f); m_vert[6].m_y=_center.m_y-(_height/2.0f); m_vert[6].m_z=_center.m_z+(_depth/2.0f); m_vert[7].m_x=_center.m_x-(_width/2.0f); m_vert[7].m_y=_center.m_y-(_height/2.0f); m_vert[7].m_z=_center.m_z+(_depth/2.0f); //Store the _center m_center=_center; // Setup the Plane Normals for Collision Detection m_norm[0].set(0.0f,1.0f,0.0f); m_norm[1].set(0.0f,-1.0f,0.0f); m_norm[2].set(1.0f,0.0f,0.0f); m_norm[3].set(-1.0f,0.0f,0.0f); m_norm[4].set(0.0f,0.0f,1.0f); m_norm[5].set(0.0f,0.0f,-1.0f); // store width height and depth m_width=_width; m_height=_height; m_depth=_depth; #ifdef USINGIOS_ m_drawMode=GL_LINE_LOOP; #else m_drawMode=GL_LINE; #endif m_vao=0; setVAO(); }
//---------------------------------------------------------------------------------------------------------------------- BBox::BBox( const Vec3& _center, Real _width, Real _height, Real _depth ) { // Calculate the Vertices based on the w,h,d params passed in the box is asumed // to be centered on the _center with equal w / h / d // -x +y -z m_vert[0].m_x=_center.m_x-(_width/2.0f); m_vert[0].m_y=_center.m_y+(_height/2.0f); m_vert[0].m_z=_center.m_z-(_depth/2.0f); // + x -y -z m_vert[1].m_x=_center.m_x+(_width/2.0f); m_vert[1].m_y=_center.m_y+(_height/2.0f); m_vert[1].m_z=_center.m_z-(_depth/2.0f); m_vert[2].m_x=_center.m_x+(_width/2.0f); m_vert[2].m_y=_center.m_y+(_height/2.0f); m_vert[2].m_z=_center.m_z+(_depth/2.0f); m_vert[3].m_x=_center.m_x-(_width/2.0f); m_vert[3].m_y=_center.m_y+(_height/2.0f); m_vert[3].m_z=_center.m_z+(_depth/2.0f); m_vert[4].m_x=_center.m_x-(_width/2.0f); m_vert[4].m_y=_center.m_y-(_height/2.0f); m_vert[4].m_z=_center.m_z-(_depth/2.0f); m_vert[5].m_x=_center.m_x+(_width/2.0f); m_vert[5].m_y=_center.m_y-(_height/2.0f); m_vert[5].m_z=_center.m_z-(_depth/2.0f); m_vert[6].m_x=_center.m_x+(_width/2.0f); m_vert[6].m_y=_center.m_y-(_height/2.0f); m_vert[6].m_z=_center.m_z+(_depth/2.0f); m_vert[7].m_x=_center.m_x-(_width/2.0f); m_vert[7].m_y=_center.m_y-(_height/2.0f); m_vert[7].m_z=_center.m_z+(_depth/2.0f); //Store the _center m_center=_center; // Setup the Plane Normals for Collision Detection m_norm[0].set(0.0f,1.0f,0.0f); m_norm[1].set(0.0f,-1.0f,0.0f); m_norm[2].set(1.0f,0.0f,0.0f); m_norm[3].set(-1.0f,0.0f,0.0f); m_norm[4].set(0.0f,0.0f,1.0f); m_norm[5].set(0.0f,0.0f,-1.0f); // store width height and depth m_width=_width; m_height=_height; m_depth=_depth; m_drawMode=GL_LINE; m_vao=0; setVAO(); for(int i=0; i<8; ++i) { std::cout<<&m_vert[i]<<"\n"; } }
void Cell::Initialize() { setVAO(); }
void TriMesh::initializeVertexGL(const char * vertArrayName, const std::vector<unsigned int>& elementInds, const char * positionAttrName, const char * normAttrName, const char * colorAttrName, const char* texCoordAttrName) { unsigned int vertexShaderId = shaderId(vertArrayName); if (!vertexShaderId) { return; } // create VBA VBO for rendering ... GLuint vertexArray; glGenVertexArrays(1, &vertexArray); glBindVertexArray(vertexArray); // store this vertex array id setVAO(vertArrayName, vertexArray); // Buffer for element indices GlBuffer elementBuffer; elementBuffer.bind(GL_ELEMENT_ARRAY_BUFFER); glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementInds.size()*sizeof(unsigned int), &elementInds[0], GL_STATIC_DRAW); // Position attribute GlBuffer positionBuffer; positionBuffer.bind(GL_ARRAY_BUFFER); glBufferData(GL_ARRAY_BUFFER, m_verts.size() * sizeof(float), &m_verts[0], GL_STATIC_DRAW); GLuint positionAttribute = glGetAttribLocation(vertexShaderId, positionAttrName); glVertexAttribPointer(positionAttribute, 3, GL_FLOAT, GL_FALSE, sizeof(float) * (3), (const GLvoid *) 0); glEnableVertexAttribArray(positionAttribute); // Normal attribute GlBuffer normalBuffer; normalBuffer.bind(GL_ARRAY_BUFFER); glBufferData(GL_ARRAY_BUFFER, m_normals.size() * sizeof(float), &m_normals[0], GL_STATIC_DRAW); GLuint normalAttribute = glGetAttribLocation(vertexShaderId, normAttrName); glVertexAttribPointer(normalAttribute, 3, GL_FLOAT, GL_FALSE, sizeof(float) * (3), (const GLvoid *) 0); glEnableVertexAttribArray(normalAttribute); // Color attribute GlBuffer colorBuffer; colorBuffer.bind(GL_ARRAY_BUFFER); if (!m_colors.empty()) { glBufferData(GL_ARRAY_BUFFER, m_colors.size() * sizeof(float), &m_colors[0], GL_STATIC_DRAW); } else { std::vector<float> tmp_colors(m_verts.size(), 1.0f); glBufferData(GL_ARRAY_BUFFER, tmp_colors.size() * sizeof(float), &tmp_colors[0], GL_STATIC_DRAW); } GLuint colorAttribute = glGetAttribLocation(vertexShaderId, colorAttrName); glVertexAttribPointer(colorAttribute, 3, GL_FLOAT, GL_FALSE, sizeof(float) * (3), (const GLvoid *) 0); glEnableVertexAttribArray(colorAttribute); // Texture coordinate GLint texcoordsLocation = glGetAttribLocation(vertexShaderId, texCoordAttrName); GlBuffer texcoordBuffer; if (texcoordsLocation != -1) { if (m_texcoords.empty()) { glDisableVertexAttribArray(texcoordsLocation); glVertexAttrib2f(texcoordsLocation, 0, 0); } else { texcoordBuffer.bind(GL_ARRAY_BUFFER); glBufferData(GL_ARRAY_BUFFER, m_texcoords.size() * sizeof(float), &m_texcoords[0], GL_STATIC_DRAW); glVertexAttribPointer(texcoordsLocation, 2, GL_FLOAT, GL_FALSE, sizeof(float) * (2), (const GLvoid *) 0); glEnableVertexAttribArray(texcoordsLocation); } } glBindVertexArray(0); }
//---------------------------------------------------------------------------------------------------------------------- void BBox::setDrawMode( GLenum _mode) noexcept { m_drawMode=_mode; setVAO(); }