This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/wifi/estimate/ray3/Cube.h

117 lines
1.7 KiB
C++

#ifndef QUBE_H
#define QUBE_H
#include "../../../math/Matrix4.h"
#include "Mesh.h"
namespace Ray3D {
class Cube : public Mesh {
public:
/** ctor */
Cube() {
unitCube(true);
}
/** ctor with position, size and rotation */
Cube(const Point3 pos, const Point3 size, const Point3 rot_deg, const bool topAndBottom = true) {
unitCube(topAndBottom);
transform(pos, size, rot_deg);
}
/** get a transformed version */
Cube transformed(const Matrix4& mat) const {
Cube res = *this;
res.transform(mat);
return res;
}
/** get a transformed version */
Cube transformed(const Point3 pos, const Point3 size, const Point3 rot_deg) const {
Cube res = *this;
res.transform(pos, size, rot_deg);
return res;
}
private:
/** build unit-cube faces */
void unitCube(const bool topAndBottom) {
const float s = 1.0f;
// left?
addQuad(
Point3(+s, -s, -s),
Point3(+s, -s, +s),
Point3(-s, -s, +s),
Point3(-s, -s, -s)
);
// right?
addQuad(
Point3(-s, +s, -s),
Point3(-s, +s, +s),
Point3(+s, +s, +s),
Point3(+s, +s, -s)
);
// small side
if (1 == 1) {
// front
addQuad(
Point3(-s, -s, -s),
Point3(-s, -s, +s),
Point3(-s, +s, +s),
Point3(-s, +s, -s)
);
// read
addQuad(
Point3(+s, +s, -s),
Point3(+s, +s, +s),
Point3(+s, -s, +s),
Point3(+s, -s, -s)
);
}
if (topAndBottom) {
// top
addQuad(
Point3(+s, +s, +s),
Point3(-s, +s, +s),
Point3(-s, -s, +s),
Point3(+s, -s, +s)
);
// bottom
addQuad(
Point3(+s, -s, -s),
Point3(-s, -s, -s),
Point3(-s, +s, -s),
Point3(+s, +s, -s)
);
}
}
};
}
#endif // QUBE_H