133 lines
2.7 KiB
C++
133 lines
2.7 KiB
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#ifndef FLOORPLAN_3D_TUBE_H
|
||
#define FLOORPLAN_3D_TUBE_H
|
||
|
||
|
||
#include "../../../math/Matrix4.h"
|
||
#include "Mesh.h"
|
||
|
||
namespace Floorplan3D {
|
||
|
||
/** walled cylinder */
|
||
class Tube : public Mesh {
|
||
|
||
public:
|
||
|
||
/** ctor */
|
||
Tube() {
|
||
;
|
||
}
|
||
|
||
|
||
/** get a transformed version */
|
||
Tube transformed(const Matrix4& mat) const {
|
||
Tube res = *this;
|
||
res.transform(mat);
|
||
return res;
|
||
}
|
||
|
||
/** build */
|
||
void addSegment(const float from_deg, const float to_deg, const float rInner, const float rOuter, const float h, bool closeSides, bool topAndBottom) {
|
||
|
||
const int tiles = 32;
|
||
const float deg_per_tile = 360.0f / tiles;
|
||
const float rad_per_tile = deg_per_tile / 180.0f * M_PI;
|
||
const int startTile = std::round(from_deg / deg_per_tile);
|
||
const int endTile = std::round(to_deg / deg_per_tile);
|
||
|
||
for (int i = startTile; i < endTile; ++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 xi0 = std::cos(startRad) * rInner;
|
||
const float yi0 = std::sin(startRad) * rInner;
|
||
const float xi1 = std::cos(endRad) * rInner;
|
||
const float yi1 = std::sin(endRad) * rInner;
|
||
|
||
if (closeSides) {
|
||
|
||
// close start of segment
|
||
if (i == startTile) {
|
||
addQuad(
|
||
Point3(xi0, yi0, -h),
|
||
Point3(xo0, yo0, -h),
|
||
Point3(xo0, yo0, +h),
|
||
Point3(xi0, yi0, +h)
|
||
);
|
||
}
|
||
|
||
// close end of segment
|
||
if (i == endTile-1) {
|
||
addQuad(
|
||
Point3(xi1, yi1, +h),
|
||
Point3(xo1, yo1, +h),
|
||
Point3(xo1, yo1, -h),
|
||
Point3(xi1, yi1, -h)
|
||
);
|
||
}
|
||
|
||
}
|
||
|
||
// outer
|
||
addQuad(
|
||
Point3(xo0, yo0, -h),
|
||
Point3(xo1, yo1, -h),
|
||
Point3(xo1, yo1, +h),
|
||
Point3(xo0, yo0, +h)
|
||
);
|
||
|
||
// innser
|
||
addQuad(
|
||
Point3(xi0, yi0, +h),
|
||
Point3(xi1, yi1, +h),
|
||
Point3(xi1, yi1, -h),
|
||
Point3(xi0, yi0, -h)
|
||
);
|
||
|
||
if (topAndBottom) {
|
||
|
||
// top
|
||
addQuad(
|
||
Point3(xi0, yi0, h),
|
||
Point3(xo0, yo0, h),
|
||
Point3(xo1, yo1, h),
|
||
Point3(xi1, yi1, h)
|
||
);
|
||
|
||
// bottom
|
||
addQuad(
|
||
Point3(xi1, yi1, -h),
|
||
Point3(xo1, yo1, -h),
|
||
Point3(xo0, yo0, -h),
|
||
Point3(xi0, yi0, -h)
|
||
);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
};
|
||
|
||
}
|
||
|
||
#endif // FLOORPLAN_3D_TUBE_H
|