Sphere::Sphere() { setNormalsTrue(); setIndexTrue(); setUVTrue(); create(1.0f,20); }
Terrain::Terrain(std::string filename, float resolution, float interval) { // set member values m_interval = interval; m_resolution = resolution; // initialize the height field loadHeightmap(filename); for (int z = 1; z < m_resolutionY - 1; z++){ for (int x = 1; x < m_resolutionX - 1; x++){ m_normals.push_back(calculateNormal(x, z)); m_vertices.push_back(glm::vec4(x, getHeight(glm::vec2(x, z)), z, 1.0)); //m_uvs.push_back(glm::vec2(x / (float)m_resolutionX, z / (float)m_resolutionY)); m_uvs.push_back(glm::vec2((float)x / 5, (float)z / 5)); } } int offset = 0; for (int z = 0; z < m_resolutionY - 3; z++){ for (int x = 0; x < m_resolutionX - 3; x++){ // 1. Triangle m_index.push_back(offset + x); m_index.push_back(offset + x + 1); m_index.push_back(offset + x + (m_resolutionY - 2)); // 2. Triangle m_index.push_back(offset + x + (m_resolutionY - 2)); m_index.push_back(offset + x + 1); m_index.push_back(offset + x + (m_resolutionY - 2) + 1); } offset += (m_resolutionY - 2); } m_indices = m_index.size(); m_points = m_vertices.size(); setNormalsTrue(); setIndexTrue(); setUVTrue(); }
Cube::Cube() { m_points = 36; m_indices = 36; setIndexFalse(); setNormalsTrue(); setUVTrue(); GLfloat vertices[] = { // Front face -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, // Right face 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, // Back face -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, // Left face -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, // Bottom face -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, // Top Face -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0 }; GLfloat normals[] = { // Front face 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, // Right face 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, // Back face 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, // Left face -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, // Bottom face 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, // Top face 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0 }; GLfloat texCoords[] = { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 }; for (int i = 0; i<m_points; i++) { m_vertices.push_back(glm::vec4(vertices[i * 3]*0.5, vertices[i * 3 + 1]*0.5, vertices[i * 3 + 2]*0.5, 1.0f)); m_normals.push_back(glm::vec3(normals[i * 3], normals[i * 3 + 1], normals[i * 3 + 2])); m_uvs.push_back(glm::vec2(texCoords[i * 2], texCoords[i * 2 + 1])); } for (int i = 0; i < m_indices; i++) { m_index.push_back(i); } }