Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mg/cylinder #38

Merged
merged 4 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 102 additions & 77 deletions generator/src/shapes/cylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,94 +15,119 @@ calculateCylinder(const float radius, const float height, const int slices) {
std::vector<Point> normals;
std::vector<Point2D> textures;

float alpha = 2 * M_PI / slices;
float half = height / 2;

float r = 0;

for (int i = 0; i < slices; i++) {
// base
float px = radius * sin(r);
float pz = radius * cos(r);
points.push_back(Point(px, -half, pz));
points.push_back(Point(0, -half, 0));
r += alpha;
px = radius * sin(r);
pz = radius * cos(r);
points.push_back(Point(px, -half, pz));

Point n1(0.0f, -1.0f, 0.0f);
for (int j = 0; j < 3; j++) {
normals.push_back(n1); // Push normals to normals vector
}
Point v;
Point n;
Point2D t;

textures.push_back(Point2D(0.5f, 0.5f));
textures.push_back(Point2D(0.5f, 0.5f));
textures.push_back(Point2D(0.5f, 0.5f));

// face
points.push_back(Point(px, -half, pz));
points.push_back(Point(px, half, pz));
float delta = 2.0f * M_PI / slices;

Point n2(px, 0.0f, pz);
for (int j = 0; j < 2; j++) {
normals.push_back(n2); // Push normals to normals vector
}
for (int i = 0; i < slices; ++i) {
// topo
// ponto central
n = {0.0f, 1.0f, 0.0f};
v = {0.0f, height / 2.0f, 0.0f};
t = {0.4375f, 0.1875f};

r -= alpha;
px = radius * sin(r);
pz = radius * cos(r);
points.push_back(Point(px, half, pz));
points.push_back(v);
normals.push_back(n);
textures.push_back(t);

n2 = Point(px, 0.0f, pz);
normals.push_back(n2); // Push normals to normals vector
v = {radius * sin(i * delta), height / 2.0f, radius * cos(i * delta)};
t = {0.4375f + 0.1875 * sin(i * delta), 0.1875f + 0.1875 * cos(i * delta)};

textures.push_back(Point2D(0.5f, 0.5f));
textures.push_back(Point2D(0.5f, 0.5f));
textures.push_back(Point2D(0.5f, 0.5f));
points.push_back(v);
normals.push_back(n);
textures.push_back(t);

points.push_back(Point(px, half, pz));
points.push_back(Point(px, -half, pz));
v = {radius * sin((i + 1) * delta), height / 2.0f, radius * cos((i + 1) * delta)};
t = {0.4375f + 0.1875 * sin((i + 1) * delta), 0.1875f + 0.1875 * cos((i + 1) * delta)};

Point n3 = Point(px, 0.0f, pz);
points.push_back(v);
normals.push_back(n);
textures.push_back(t);

for (int j = 0; j < 2; j++) {
normals.push_back(n3); // Push normals to normals vector
}

r += alpha;
px = radius * sin(r);
pz = radius * cos(r);
points.push_back(Point(px, -half, pz));

n3 = Point(px, 0.0f, pz);

normals.push_back(n3); // Push normals to normals vector

textures.push_back(Point2D(0.5f, 0.5f));
textures.push_back(Point2D(0.5f, 0.5f));
textures.push_back(Point2D(0.5f, 0.5f));

// top
r += alpha;
px = radius * sin(r);
pz = radius * cos(r);
points.push_back(Point(px, half, pz));
points.push_back(Point(0, half, 0));
r -= alpha;
px = radius * sin(r);
pz = radius * cos(r);
points.push_back(Point(px, half, pz));

Point n4(0.0f, 1.0f, 0.0f);
for (int j = 0; j < 3; j++) {
normals.push_back(n4); // Push normals to normals vector
}
// corpo

n = {sin(i + 1 * delta), 0.0f, cos(i + 1 * delta)};
v = {radius * sin((i + 1) * delta), height / 2.0f, radius * cos((i + 1) * delta)};
t = {(i + 1) / static_cast<float>(slices), 1.0f};

textures.push_back(Point2D(0.5f, 0.5f));
textures.push_back(Point2D(0.5f, 0.5f));
textures.push_back(Point2D(0.5f, 0.5f));
}
points.push_back(v);
normals.push_back(n);
textures.push_back(t);

n = {sin(i * delta), 0.0f, cos(i * delta)};
v = {radius * sin(i * delta), height / 2.0f, radius * cos(i * delta)};
t = {i / static_cast<float>(slices), 1.0f};

points.push_back(v);
normals.push_back(n);
textures.push_back(t);

n = {sin(i * delta), 0.0f, cos(i * delta)};
v = {radius * sin(i * delta), -height / 2.0f, radius * cos(i * delta)};
t = {i / static_cast<float>(slices), 0.375f};

points.push_back(v);
normals.push_back(n);
textures.push_back(t);

n = {sin(i + 1 * delta), 0.0f, cos(i + 1 * delta)};
v = {radius * sin((i + 1) * delta), -height / 2.0f, radius * cos((i + 1) * delta)};
t = {(i + 1) / static_cast<float>(slices), 0.375f};

points.push_back(v);
normals.push_back(n);
textures.push_back(t);

n = {sin(i + 1 * delta), 0.0f, cos(i + 1 * delta)};
v = {radius * sin((i + 1) * delta), height / 2.0f, radius * cos((i + 1) * delta)};
t = {(i + 1) / static_cast<float>(slices), 1.0f};

points.push_back(v);
normals.push_back(n);
textures.push_back(t);

n = {sin(i * delta), 0.0f, cos(i * delta)};
v = {radius * sin(i * delta), -height / 2.0f, radius * cos(i * delta)};
t = {i / static_cast<float>(slices), 0.375f};

points.push_back(v);
normals.push_back(n);
textures.push_back(t);


// base

n = {0.0f, -1.0f, 0.0f};
v = {0.0f, -height / 2.0f, 0.0f};
t = {0.8125f, 0.1875f};

points.push_back(v);
normals.push_back(n);
textures.push_back(t);

n = {0.0f, -1.0f, 0.0f};
v = {radius * sin((i + 1) * delta), -height / 2.0f, radius * cos((i + 1) * delta)};
t = {0.8125f + 0.1875 * sin((i + 1) * delta), 0.1875f + 0.1875 * cos((i + 1) * delta)};

points.push_back(v);
normals.push_back(n);
textures.push_back(t);

n = {0.0f, -1.0f, 0.0f};
v = {radius * sin(i * delta), -height / 2.0f, radius * cos(i * delta)};
t = {0.8125f + 0.1875 * sin(i * delta), 0.1875f + 0.1875 * cos(i * delta)};

points.push_back(v);
normals.push_back(n);
textures.push_back(t);



}

return std::make_pair(std::make_pair(points, normals), textures);
}
Expand Down
1 change: 1 addition & 0 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Collapsed=0

[Window][Infos]
Pos=15,18

Size=325,139
Collapsed=0

Expand Down
182 changes: 121 additions & 61 deletions models/advanced/cylinder.3d
Original file line number Diff line number Diff line change
@@ -1,61 +1,121 @@
# 60
p 0 -2.5 5 0 -1 0 0.5 0.5
p 0 -2.5 0 0 -1 0 0.5 0.5
p 4.75528 -2.5 1.54508 0 -1 0 0.5 0.5
p 4.75528 -2.5 1.54508 4.75528 0 1.54508 0.5 0.5
p 4.75528 2.5 1.54508 4.75528 0 1.54508 0.5 0.5
p 0 2.5 5 0 0 5 0.5 0.5
p 0 2.5 5 0 0 5 0.5 0.5
p 0 -2.5 5 0 0 5 0.5 0.5
p 4.75528 -2.5 1.54508 4.75528 0 1.54508 0.5 0.5
p 2.93893 2.5 -4.04508 0 1 0 0.5 0.5
p 0 2.5 0 0 1 0 0.5 0.5
p 4.75528 2.5 1.54508 0 1 0 0.5 0.5
p 4.75528 -2.5 1.54508 0 -1 0 0.5 0.5
p 0 -2.5 0 0 -1 0 0.5 0.5
p 2.93893 -2.5 -4.04508 0 -1 0 0.5 0.5
p 2.93893 -2.5 -4.04508 2.93893 0 -4.04508 0.5 0.5
p 2.93893 2.5 -4.04508 2.93893 0 -4.04508 0.5 0.5
p 4.75528 2.5 1.54508 4.75528 0 1.54508 0.5 0.5
p 4.75528 2.5 1.54508 4.75528 0 1.54508 0.5 0.5
p 4.75528 -2.5 1.54508 4.75528 0 1.54508 0.5 0.5
p 2.93893 -2.5 -4.04508 2.93893 0 -4.04508 0.5 0.5
p -2.93893 2.5 -4.04508 0 1 0 0.5 0.5
p 0 2.5 0 0 1 0 0.5 0.5
p 2.93893 2.5 -4.04508 0 1 0 0.5 0.5
p 2.93893 -2.5 -4.04508 0 -1 0 0.5 0.5
p 0 -2.5 0 0 -1 0 0.5 0.5
p -2.93893 -2.5 -4.04508 0 -1 0 0.5 0.5
p -2.93893 -2.5 -4.04508 -2.93893 0 -4.04508 0.5 0.5
p -2.93893 2.5 -4.04508 -2.93893 0 -4.04508 0.5 0.5
p 2.93893 2.5 -4.04508 2.93893 0 -4.04508 0.5 0.5
p 2.93893 2.5 -4.04508 2.93893 0 -4.04508 0.5 0.5
p 2.93893 -2.5 -4.04508 2.93893 0 -4.04508 0.5 0.5
p -2.93893 -2.5 -4.04508 -2.93893 0 -4.04508 0.5 0.5
p -4.75528 2.5 1.54509 0 1 0 0.5 0.5
p 0 2.5 0 0 1 0 0.5 0.5
p -2.93893 2.5 -4.04508 0 1 0 0.5 0.5
p -2.93893 -2.5 -4.04508 0 -1 0 0.5 0.5
p 0 -2.5 0 0 -1 0 0.5 0.5
p -4.75528 -2.5 1.54509 0 -1 0 0.5 0.5
p -4.75528 -2.5 1.54509 -4.75528 0 1.54509 0.5 0.5
p -4.75528 2.5 1.54509 -4.75528 0 1.54509 0.5 0.5
p -2.93893 2.5 -4.04508 -2.93893 0 -4.04508 0.5 0.5
p -2.93893 2.5 -4.04508 -2.93893 0 -4.04508 0.5 0.5
p -2.93893 -2.5 -4.04508 -2.93893 0 -4.04508 0.5 0.5
p -4.75528 -2.5 1.54509 -4.75528 0 1.54509 0.5 0.5
p 8.74228e-07 2.5 5 0 1 0 0.5 0.5
p 0 2.5 0 0 1 0 0.5 0.5
p -4.75528 2.5 1.54509 0 1 0 0.5 0.5
p -4.75528 -2.5 1.54509 0 -1 0 0.5 0.5
p 0 -2.5 0 0 -1 0 0.5 0.5
p 8.74228e-07 -2.5 5 0 -1 0 0.5 0.5
p 8.74228e-07 -2.5 5 8.74228e-07 0 5 0.5 0.5
p 8.74228e-07 2.5 5 8.74228e-07 0 5 0.5 0.5
p -4.75528 2.5 1.54509 -4.75528 0 1.54509 0.5 0.5
p -4.75528 2.5 1.54509 -4.75528 0 1.54509 0.5 0.5
p -4.75528 -2.5 1.54509 -4.75528 0 1.54509 0.5 0.5
p 8.74228e-07 -2.5 5 8.74228e-07 0 5 0.5 0.5
p 4.75528 2.5 1.54508 0 1 0 0.5 0.5
p 0 2.5 0 0 1 0 0.5 0.5
p 8.74228e-07 2.5 5 0 1 0 0.5 0.5
# 120
p 0 2.5 0 0 1 0 0.4375 0.1875
p 0 2.5 3 0 1 0 0.4375 0.375
p 1.76336 2.5 2.42705 0 1 0 0.54771 0.339191
p 1.76336 2.5 2.42705 0.587785 0 0.809017 0.1 1
p 0 2.5 3 0 0 1 0 1
p 0 -2.5 3 0 0 1 0 0.375
p 1.76336 -2.5 2.42705 0.587785 0 0.809017 0.1 0.375
p 1.76336 2.5 2.42705 0.587785 0 0.809017 0.1 1
p 0 -2.5 3 0 0 1 0 0.375
p 0 -2.5 0 0 -1 0 0.8125 0.1875
p 1.76336 -2.5 2.42705 0 -1 0 0.92271 0.339191
p 0 -2.5 3 0 -1 0 0.8125 0.375
p 0 2.5 0 0 1 0 0.4375 0.1875
p 1.76336 2.5 2.42705 0 1 0 0.54771 0.339191
p 2.85317 2.5 0.927051 0 1 0 0.615823 0.245441
p 2.85317 2.5 0.927051 0.998346 0 -0.0574905 0.2 1
p 1.76336 2.5 2.42705 0.587785 0 0.809017 0.1 1
p 1.76336 -2.5 2.42705 0.587785 0 0.809017 0.1 0.375
p 2.85317 -2.5 0.927051 0.998346 0 -0.0574905 0.2 0.375
p 2.85317 2.5 0.927051 0.998346 0 -0.0574905 0.2 1
p 1.76336 -2.5 2.42705 0.587785 0 0.809017 0.1 0.375
p 0 -2.5 0 0 -1 0 0.8125 0.1875
p 2.85317 -2.5 0.927051 0 -1 0 0.990823 0.245441
p 1.76336 -2.5 2.42705 0 -1 0 0.92271 0.339191
p 0 2.5 0 0 1 0 0.4375 0.1875
p 2.85317 2.5 0.927051 0 1 0 0.615823 0.245441
p 2.85317 2.5 -0.927051 0 1 0 0.615823 0.129559
p 2.85317 2.5 -0.927051 0.491032 0 -0.871141 0.3 1
p 2.85317 2.5 0.927051 0.951057 0 0.309017 0.2 1
p 2.85317 -2.5 0.927051 0.951057 0 0.309017 0.2 0.375
p 2.85317 -2.5 -0.927051 0.491032 0 -0.871141 0.3 0.375
p 2.85317 2.5 -0.927051 0.491032 0 -0.871141 0.3 1
p 2.85317 -2.5 0.927051 0.951057 0 0.309017 0.2 0.375
p 0 -2.5 0 0 -1 0 0.8125 0.1875
p 2.85317 -2.5 -0.927051 0 -1 0 0.990823 0.129559
p 2.85317 -2.5 0.927051 0 -1 0 0.990823 0.245441
p 0 2.5 0 0 1 0 0.4375 0.1875
p 2.85317 2.5 -0.927051 0 1 0 0.615823 0.129559
p 1.76336 2.5 -2.42705 0 1 0 0.54771 0.0358093
p 1.76336 2.5 -2.42705 -0.467735 0 -0.883869 0.4 1
p 2.85317 2.5 -0.927051 0.951056 0 -0.309017 0.3 1
p 2.85317 -2.5 -0.927051 0.951056 0 -0.309017 0.3 0.375
p 1.76336 -2.5 -2.42705 -0.467735 0 -0.883869 0.4 0.375
p 1.76336 2.5 -2.42705 -0.467735 0 -0.883869 0.4 1
p 2.85317 -2.5 -0.927051 0.951056 0 -0.309017 0.3 0.375
p 0 -2.5 0 0 -1 0 0.8125 0.1875
p 1.76336 -2.5 -2.42705 0 -1 0 0.92271 0.0358093
p 2.85317 -2.5 -0.927051 0 -1 0 0.990823 0.129559
p 0 2.5 0 0 1 0 0.4375 0.1875
p 1.76336 2.5 -2.42705 0 1 0 0.54771 0.0358093
p -2.62268e-07 2.5 -3 0 1 0 0.4375 7.21645e-16
p -2.62268e-07 2.5 -3 -0.996468 0 -0.0839712 0.5 1
p 1.76336 2.5 -2.42705 0.587785 0 -0.809017 0.4 1
p 1.76336 -2.5 -2.42705 0.587785 0 -0.809017 0.4 0.375
p -2.62268e-07 -2.5 -3 -0.996468 0 -0.0839712 0.5 0.375
p -2.62268e-07 2.5 -3 -0.996468 0 -0.0839712 0.5 1
p 1.76336 -2.5 -2.42705 0.587785 0 -0.809017 0.4 0.375
p 0 -2.5 0 0 -1 0 0.8125 0.1875
p -2.62268e-07 -2.5 -3 0 -1 0 0.8125 7.21645e-16
p 1.76336 -2.5 -2.42705 0 -1 0 0.92271 0.0358093
p 0 2.5 0 0 1 0 0.4375 0.1875
p -2.62268e-07 2.5 -3 0 1 0 0.4375 7.21645e-16
p -1.76336 2.5 -2.42705 0 1 0 0.32729 0.0358093
p -1.76336 2.5 -2.42705 -0.609053 0 0.793129 0.6 1
p -2.62268e-07 2.5 -3 -8.74228e-08 0 -1 0.5 1
p -2.62268e-07 -2.5 -3 -8.74228e-08 0 -1 0.5 0.375
p -1.76336 -2.5 -2.42705 -0.609053 0 0.793129 0.6 0.375
p -1.76336 2.5 -2.42705 -0.609053 0 0.793129 0.6 1
p -2.62268e-07 -2.5 -3 -8.74228e-08 0 -1 0.5 0.375
p 0 -2.5 0 0 -1 0 0.8125 0.1875
p -1.76336 -2.5 -2.42705 0 -1 0 0.70229 0.0358093
p -2.62268e-07 -2.5 -3 0 -1 0 0.8125 7.21645e-16
p 0 2.5 0 0 1 0 0.4375 0.1875
p -1.76336 2.5 -2.42705 0 1 0 0.32729 0.0358093
p -2.85317 2.5 -0.927051 0 1 0 0.259177 0.129559
p -2.85317 2.5 -0.927051 0.338322 0 0.94103 0.7 1
p -1.76336 2.5 -2.42705 -0.587785 0 -0.809017 0.6 1
p -1.76336 -2.5 -2.42705 -0.587785 0 -0.809017 0.6 0.375
p -2.85317 -2.5 -0.927051 0.338322 0 0.94103 0.7 0.375
p -2.85317 2.5 -0.927051 0.338322 0 0.94103 0.7 1
p -1.76336 -2.5 -2.42705 -0.587785 0 -0.809017 0.6 0.375
p 0 -2.5 0 0 -1 0 0.8125 0.1875
p -2.85317 -2.5 -0.927051 0 -1 0 0.634177 0.129559
p -1.76336 -2.5 -2.42705 0 -1 0 0.70229 0.0358093
p 0 2.5 0 0 1 0 0.4375 0.1875
p -2.85317 2.5 -0.927051 0 1 0 0.259177 0.129559
p -2.85317 2.5 0.927051 0 1 0 0.259177 0.245441
p -2.85317 2.5 0.927051 0.974646 0 0.223752 0.8 1
p -2.85317 2.5 -0.927051 -0.951056 0 -0.309017 0.7 1
p -2.85317 -2.5 -0.927051 -0.951056 0 -0.309017 0.7 0.375
p -2.85317 -2.5 0.927051 0.974646 0 0.223752 0.8 0.375
p -2.85317 2.5 0.927051 0.974646 0 0.223752 0.8 1
p -2.85317 -2.5 -0.927051 -0.951056 0 -0.309017 0.7 0.375
p 0 -2.5 0 0 -1 0 0.8125 0.1875
p -2.85317 -2.5 0.927051 0 -1 0 0.634177 0.245441
p -2.85317 -2.5 -0.927051 0 -1 0 0.634177 0.129559
p 0 2.5 0 0 1 0 0.4375 0.1875
p -2.85317 2.5 0.927051 0 1 0 0.259177 0.245441
p -1.76335 2.5 2.42705 0 1 0 0.32729 0.339191
p -1.76335 2.5 2.42705 0.714885 0 -0.699242 0.9 1
p -2.85317 2.5 0.927051 -0.951056 0 0.309017 0.8 1
p -2.85317 -2.5 0.927051 -0.951056 0 0.309017 0.8 0.375
p -1.76335 -2.5 2.42705 0.714885 0 -0.699242 0.9 0.375
p -1.76335 2.5 2.42705 0.714885 0 -0.699242 0.9 1
p -2.85317 -2.5 0.927051 -0.951056 0 0.309017 0.8 0.375
p 0 -2.5 0 0 -1 0 0.8125 0.1875
p -1.76335 -2.5 2.42705 0 -1 0 0.70229 0.339191
p -2.85317 -2.5 0.927051 0 -1 0 0.634177 0.245441
p 0 2.5 0 0 1 0 0.4375 0.1875
p -1.76335 2.5 2.42705 0 1 0 0.32729 0.339191
p 5.24537e-07 2.5 3 0 1 0 0.4375 0.375
p 5.24537e-07 2.5 3 -0.202138 0 -0.979357 1 1
p -1.76335 2.5 2.42705 -0.587785 0 0.809017 0.9 1
p -1.76335 -2.5 2.42705 -0.587785 0 0.809017 0.9 0.375
p 5.24537e-07 -2.5 3 -0.202138 0 -0.979357 1 0.375
p 5.24537e-07 2.5 3 -0.202138 0 -0.979357 1 1
p -1.76335 -2.5 2.42705 -0.587785 0 0.809017 0.9 0.375
p 0 -2.5 0 0 -1 0 0.8125 0.1875
p 5.24537e-07 -2.5 3 0 -1 0 0.8125 0.375
p -1.76335 -2.5 2.42705 0 -1 0 0.70229 0.339191
Loading
Loading