moved from ray3 to floorplan/3D
worked on new wall models refactoring
This commit is contained in:
166
floorplan/3D/primitives/Cube.h
Normal file
166
floorplan/3D/primitives/Cube.h
Normal file
@@ -0,0 +1,166 @@
|
||||
#ifndef FLOORPLAN_3D_CUBE_H
|
||||
#define FLOORPLAN_3D_CUBE_H
|
||||
|
||||
|
||||
#include "../../../math/Matrix4.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
namespace Floorplan3D {
|
||||
|
||||
class Cube : public Mesh {
|
||||
|
||||
private:
|
||||
|
||||
/** ctor */
|
||||
Cube() {
|
||||
//unitCube(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
|
||||
enum Part {
|
||||
CUBE_TOP = 1,
|
||||
CUBE_BOTTOM = 2,
|
||||
CUBE_LEFT = 4,
|
||||
CUBE_RIGHT = 8,
|
||||
CUBE_FRONT = 16,
|
||||
CUBE_BACK = 32,
|
||||
};
|
||||
|
||||
// Cube (const Point3 p1, const Point3 p2, const Point3 p3, const Point3 p4, const float h) {
|
||||
//// const Point3 ph(0,0,h);
|
||||
//// addQuad(p1+ph, p2+ph, p3+ph, p4+ph); // top
|
||||
//// addQuad(p4, p3, p2, p1); // bottom
|
||||
//// addQuad(p3+ph, p2+ph, p2, p3); // right
|
||||
//// addQuad(p1+ph, p4+ph, p4, p1); // left
|
||||
//// addQuad(p2+ph, p1+ph, p1, p2); // front
|
||||
//// addQuad(p4+ph, p3+ph, p3, p4); // back
|
||||
// addQuad();
|
||||
// }
|
||||
|
||||
/** ctor with position, size and rotation */
|
||||
Cube(const Point3 pos, const Point3 size, const Point3 rot_deg, const Part parts = (Part)63) {
|
||||
unitCube(parts);
|
||||
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;
|
||||
}
|
||||
|
||||
static Cube unit(const Part parts = (Part) 63) {
|
||||
Cube cube;
|
||||
cube.unitCube(parts);
|
||||
return cube;
|
||||
}
|
||||
|
||||
/** cube from 8 vertices (upper 4, lower 4) */
|
||||
static Cube fromVertices(const Point3 pt1, const Point3 pt2, const Point3 pt3, const Point3 pt4, const Point3 pb1, const Point3 pb2, const Point3 pb3, const Point3 pb4) {
|
||||
Cube cube;
|
||||
cube.addQuad(pt1, pt2, pt3, pt4); // top
|
||||
cube.addQuad(pb4, pb3, pb2, pb1); // bottom
|
||||
cube.addQuad(pt3, pt2, pb2, pb3); // right
|
||||
cube.addQuad(pt1, pt4, pb4, pb1); // left
|
||||
cube.addQuad(pt2, pt1, pb1, pb2); // front
|
||||
cube.addQuad(pt4, pt3, pb3, pb4); // back
|
||||
return cube;
|
||||
}
|
||||
|
||||
/** cube from 8 vertices (upper 4, lower 4) */
|
||||
static Cube fromBottomAndHeight(const Point3 pb1, const Point3 pb2, const Point3 pb3, const Point3 pb4, const float h) {
|
||||
const Point3 ph(0,0,h);
|
||||
return Cube::fromVertices(pb1+ph, pb2+ph, pb3+ph, pb4+ph, pb1, pb2, pb3, pb4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** build unit-cube faces */
|
||||
void unitCube(const Part parts) {
|
||||
|
||||
const float s = 1.0f;
|
||||
|
||||
|
||||
|
||||
// left?
|
||||
if (parts & CUBE_LEFT) {
|
||||
addQuad(
|
||||
Point3(+s, -s, -s),
|
||||
Point3(+s, -s, +s),
|
||||
Point3(-s, -s, +s),
|
||||
Point3(-s, -s, -s)
|
||||
);
|
||||
}
|
||||
|
||||
// right?
|
||||
if (parts & CUBE_RIGHT) {
|
||||
addQuad(
|
||||
Point3(-s, +s, -s),
|
||||
Point3(-s, +s, +s),
|
||||
Point3(+s, +s, +s),
|
||||
Point3(+s, +s, -s)
|
||||
);
|
||||
}
|
||||
|
||||
// front
|
||||
if (parts & CUBE_FRONT) {
|
||||
addQuad(
|
||||
Point3(-s, -s, -s),
|
||||
Point3(-s, -s, +s),
|
||||
Point3(-s, +s, +s),
|
||||
Point3(-s, +s, -s)
|
||||
);
|
||||
}
|
||||
|
||||
// back
|
||||
if (parts & CUBE_BACK) {
|
||||
addQuad(
|
||||
Point3(+s, +s, -s),
|
||||
Point3(+s, +s, +s),
|
||||
Point3(+s, -s, +s),
|
||||
Point3(+s, -s, -s)
|
||||
);
|
||||
}
|
||||
|
||||
// top
|
||||
if (parts & CUBE_TOP) {
|
||||
addQuad(
|
||||
Point3(+s, +s, +s),
|
||||
Point3(-s, +s, +s),
|
||||
Point3(-s, -s, +s),
|
||||
Point3(+s, -s, +s)
|
||||
);
|
||||
}
|
||||
|
||||
// bottom
|
||||
if (parts & CUBE_BOTTOM) {
|
||||
addQuad(
|
||||
Point3(+s, -s, -s),
|
||||
Point3(-s, -s, -s),
|
||||
Point3(-s, +s, -s),
|
||||
Point3(+s, +s, -s)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FLOORPLAN_3D_CUBE_H
|
||||
Reference in New Issue
Block a user