Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How is slaked lime powder prepared ?

Answered: 1 week ago

Question

Why does electric current flow through acid?

Answered: 1 week ago

Question

What is Taxonomy ?

Answered: 1 week ago

Question

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago