74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
#include "cube.h"
|
|
|
|
void cube(
|
|
Eigen::MatrixXd & V,
|
|
Eigen::MatrixXi & F,
|
|
Eigen::MatrixXd & UV,
|
|
Eigen::MatrixXi & UF,
|
|
Eigen::MatrixXd & NV,
|
|
Eigen::MatrixXi & NF)
|
|
{
|
|
// Construct default Blender cube.
|
|
|
|
V.resize(8,3);
|
|
F.resize(6,4);
|
|
// for (int i = 0; i < 8; i++) {
|
|
// V(i,0) = 1 - (i&4) / 2;
|
|
// V(i,1) = 1 - 2 * (i&1);
|
|
// V(i,2) = -1 + 1 * (i&2);
|
|
|
|
// V.row(i) = Eigen::RowVector3d(1 - (i&4) / 2, 1 - 2 * (i&1), -1 + 1 * (i&2));
|
|
|
|
/* Add Vertex to the faces it belongs to */
|
|
// F(0 + (i&4) / 2, i % 4) = i;
|
|
// F(1 + 2 * (i&1), i / 2) = i;
|
|
// F(5 - (i&2) / 2, (i % 4) % 2 + (i / 4) * 2) = i;
|
|
// }
|
|
|
|
V.row(0) = Eigen::RowVector3d( 1, 1, -1);
|
|
V.row(1) = Eigen::RowVector3d( 1, -1, -1);
|
|
V.row(2) = Eigen::RowVector3d( 1, 1, 1);
|
|
V.row(3) = Eigen::RowVector3d( 1, -1, 1);
|
|
V.row(4) = Eigen::RowVector3d(-1, 1, -1);
|
|
V.row(5) = Eigen::RowVector3d(-1, -1, -1);
|
|
V.row(6) = Eigen::RowVector3d(-1, 1, 1);
|
|
V.row(7) = Eigen::RowVector3d(-1, -1, 1);
|
|
|
|
F.row(0) = Eigen::RowVector4i(1, 2, 4, 3);
|
|
F.row(1) = Eigen::RowVector4i(5, 1, 3, 7);
|
|
F.row(2) = Eigen::RowVector4i(6, 5, 7, 8);
|
|
F.row(3) = Eigen::RowVector4i(2, 6, 8, 4);
|
|
F.row(4) = Eigen::RowVector4i(3, 4, 8, 7);
|
|
F.row(5) = Eigen::RowVector4i(5, 6, 2, 1);
|
|
|
|
NV.resize(6,3);
|
|
NV.row(0) = Eigen::RowVector3d(1, 0, 0);
|
|
NV.row(1) = Eigen::RowVector3d(0, 1, 0);
|
|
NV.row(2) = Eigen::RowVector3d(-1, 0, 0);
|
|
NV.row(3) = Eigen::RowVector3d(0, -1, 0);
|
|
NV.row(4) = Eigen::RowVector3d(0, 0, 1);
|
|
NV.row(5) = Eigen::RowVector3d(0, 0, -1);
|
|
|
|
NF.resize(6,4);
|
|
for (int i = 1; i <= 6; i++) {
|
|
NF.row(i - 1) = Eigen::RowVector4i(i, i, i, i);
|
|
}
|
|
|
|
UV.resize(14,2);
|
|
UV.row(0) = Eigen::RowVector2d(0.25, 0);
|
|
UV.row(1) = Eigen::RowVector2d(0.5, 0);
|
|
for (int i = 0; i < 5; i++) {
|
|
UV.row(2 + i) = Eigen::RowVector2d(0.25 * i, 0.25);
|
|
UV.row(7 + i) = Eigen::RowVector2d(0.25 * i, 0.5);
|
|
}
|
|
UV.row(12) = Eigen::RowVector2d(0.25, 0.75);
|
|
UV.row(13) = Eigen::RowVector2d(0.5, 0.75);
|
|
|
|
UF.resize(6,4);
|
|
UF.row(0) = Eigen::RowVector4i(4, 5, 10, 9);
|
|
UF.row(1) = Eigen::RowVector4i(5, 6, 11, 10);
|
|
UF.row(2) = Eigen::RowVector4i(6, 7, 12, 11);
|
|
UF.row(3) = Eigen::RowVector4i(3, 4, 9, 8);
|
|
UF.row(4) = Eigen::RowVector4i(9, 10, 14, 13);
|
|
UF.row(5) = Eigen::RowVector4i(1, 2, 5, 4);
|
|
}
|