Question: Build me a UBuildSphere function for OpenGL in c + + thats takes a mesh in as arguments? Here's my cylinder and cone functions: /

Build me a UBuildSphere function for OpenGL in c++ thats takes a mesh in as arguments? Here's my cylinder and cone functions:
// Function to build cylinders (so far used to make the cameras on the phone)
void Shapes::UBuildCylinder(GLMesh& mesh)
{
vector c ={ mesh.p[0], mesh.p[1], mesh.p[2], mesh.p[3]};
float r = mesh.radius;
float l = mesh.width;
float s = mesh.numOfSides;
float h = mesh.height;
constexpr float PI =3.14f;
const float sectorStep =2.0f * PI / s;
vector v;
for (auto i =1; i < s +1; i++)
{
v.insert(v.end(),{0.5f,0.5f,0.0f, c[0], c[1], c[2], c[3],0.5f,0.5f });
v.insert(v.end(),{0.5f + r * cos(i * sectorStep),
0.5f + r * sin(i * sectorStep),
0.0f ,
c[0], c[1], c[2], c[3],
0.5f +(r * cos((i)*sectorStep)),
0.5f +(r * sin((i)*sectorStep))});
v.insert(v.end(),{0.5f + r * cos((i +1)* sectorStep),
0.5f + r * sin((i +1)* sectorStep),
0.0f ,
c[0], c[1], c[2], c[3],
0.5f +(r * cos((i +1)* sectorStep)),
0.5f +(r * sin((i +1)* sectorStep))});
}
for (auto i =1; i < s +1; i++)
{
v.insert(v.end(),{0.5f,0.5f, l, c[0], c[1], c[2], c[3],0.5f,0.5f });
v.insert(v.end(),{0.5f + r * cos(i * sectorStep),
0.5f + r * sin(i * sectorStep),
l ,
c[0], c[1], c[2], c[3],
0.5f +(r * cos((i)*sectorStep)),
0.5f +(r * sin((i)*sectorStep))});
v.insert(v.end(),{0.5f + r * cos((i +1)* sectorStep),
0.5f + r * sin((i +1)* sectorStep),
l ,
c[0], c[1], c[2], c[3],
0.5f +(r * cos((i +1)* sectorStep)),
0.5f +(r * sin((i +1)* sectorStep))});
}
constexpr float x =3.0f;
float j =1.0f /(s / x);
float k =0.0f;
for (auto i =1; i < s +1; i++)
{
v.insert(v.end(),{0.5f + r * cos(i * sectorStep),
0.5f + r * sin(i * sectorStep),
0.0f ,
c[0], c[1], c[2], c[3],
k ,
0});
v.insert(v.end(),{0.5f + r * cos(i * sectorStep),
0.5f + r * sin(i * sectorStep),
l ,
c[0], c[1], c[2], c[3],
k ,
1.0f });
v.insert(v.end(),{0.5f + r * cos((i +1)* sectorStep),
0.5f + r * sin((i +1)* sectorStep),
l ,
c[0], c[1], c[2], c[3],
k + j ,
1.0f });
v.insert(v.end(),{0.5f + r * cos((i +1)* sectorStep),
0.5f + r * sin((i +1)* sectorStep),
l ,
c[0], c[1], c[2], c[3],
k + j ,
1.0f });
v.insert(v.end(),{0.5f + r * cos((i +1)* sectorStep),
0.5f + r * sin((i +1)* sectorStep),
0.0f ,
c[0], c[1], c[2], c[3],
k + j ,
0.0f });
v.insert(v.end(),{0.5f + r * cos(i * sectorStep),
0.5f + r * sin(i * sectorStep),
0.0f ,
c[0], c[1], c[2], c[3],
k,
0.0f });
k += j;
}
mesh.v = v;
v.clear();
UTranslator(mesh);
}
void Shapes::UBuildCone(GLMesh& mesh)
{
vector c ={ mesh.p[0], mesh.p[1], mesh.p[2], mesh.p[3]};
float r = mesh.radius;
float l = mesh.height;
float s = mesh.numOfSides;
constexpr float PI =3.14f;
const float sectorStep =2.0f * PI / s;
const float textStep =1.0f / s;
float textureXLoc =0.0f;
vector v;
for (auto i =1; i < s +1; i++){
float one =0.5f + r * cos(i * sectorStep);
float two =0.5f + r * sin(i * sectorStep);
one -=0.5f;
one *=2.0f;
two -=0.5f;
two *=2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!