83 lines
1.4 KiB
C++
83 lines
1.4 KiB
C++
#ifndef FLOORPLAN_3D_CYLINDER_H
|
|
#define FLOORPLAN_3D_CYLINDER_H
|
|
|
|
|
|
#include "../../../math/Matrix4.h"
|
|
#include "Mesh.h"
|
|
|
|
namespace Floorplan3D {
|
|
|
|
/** walled cylinder */
|
|
class Cylinder : public Mesh {
|
|
|
|
public:
|
|
|
|
/** ctor */
|
|
Cylinder() {
|
|
;
|
|
}
|
|
|
|
/** get a transformed version */
|
|
Cylinder transformed(const Matrix4& mat) const {
|
|
Cylinder res = *this;
|
|
res.transform(mat);
|
|
return res;
|
|
}
|
|
|
|
/** build */
|
|
void add(const float rOuter, const float h, bool topAndBottom) {
|
|
|
|
const int tiles = 8;
|
|
const float deg_per_tile = 360.0f / tiles;
|
|
const float rad_per_tile = deg_per_tile / 180.0f * M_PI;
|
|
|
|
for (int i = 0; i < tiles; ++i) {
|
|
|
|
const float startRad = (i+0) * rad_per_tile;
|
|
const float endRad = (i+1) * rad_per_tile;
|
|
|
|
const float xo0 = std::cos(startRad) * rOuter;
|
|
const float yo0 = std::sin(startRad) * rOuter;
|
|
const float xo1 = std::cos(endRad) * rOuter;
|
|
const float yo1 = std::sin(endRad) * rOuter;
|
|
const float cx = 0;
|
|
const float cy = 0;
|
|
|
|
// outer
|
|
addQuad(
|
|
Point3(xo0, yo0, -h),
|
|
Point3(xo1, yo1, -h),
|
|
Point3(xo1, yo1, +h),
|
|
Point3(xo0, yo0, +h)
|
|
);
|
|
|
|
if (topAndBottom) {
|
|
|
|
// top
|
|
addTriangle(
|
|
Point3(cx, cy, h),
|
|
Point3(xo0, yo0, h),
|
|
Point3(xo1, yo1, h)
|
|
);
|
|
|
|
// bottom
|
|
addTriangle(
|
|
Point3(cx, cy, -h),
|
|
Point3(xo1, yo1, -h),
|
|
Point3(xo0, yo0, -h)
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // FLOORPLAN_3D_CYLINDER_H
|