mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-19 04:52:12 +01:00
LP-32 add Rhombicuboctahedron shape
This commit is contained in:
parent
104f98315f
commit
70975f0d3f
@ -68,6 +68,9 @@ public:
|
||||
case ShapeType::Axis:
|
||||
node = ShapeUtils::create3DAxis();
|
||||
break;
|
||||
case ShapeType::Rhombicuboctahedron:
|
||||
node = ShapeUtils::createRhombicuboctahedron();
|
||||
break;
|
||||
}
|
||||
self->setNode(node);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ namespace osgQtQuick {
|
||||
class ShapeType : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Enum { Cube, Sphere, Torus, Axis };
|
||||
enum Enum { Cube, Sphere, Torus, Axis, Rhombicuboctahedron };
|
||||
Q_ENUMS(Enum) // TODO switch to Q_ENUM once on Qt 5.5
|
||||
};
|
||||
|
||||
|
@ -50,7 +50,6 @@ osg::Geode *createCube()
|
||||
// Declare a instance of the geode class:
|
||||
osg::Geode *geode = new osg::Geode();
|
||||
|
||||
|
||||
// Add the unit cube drawable to the geode:
|
||||
geode->addDrawable(unitCubeDrawable);
|
||||
|
||||
@ -239,6 +238,7 @@ osg::Geode *createTorus(float innerRadius, float outerRadius, float sweepCuts, f
|
||||
|
||||
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
|
||||
geometry->setStateSet(stateset);
|
||||
|
||||
geometry->setVertexArray(vertices);
|
||||
|
||||
osg::Vec4Array *colors = new osg::Vec4Array;
|
||||
@ -258,4 +258,190 @@ osg::Geode *createTorus(float innerRadius, float outerRadius, float sweepCuts, f
|
||||
|
||||
return geode.release();
|
||||
}
|
||||
|
||||
osg::Geode *createRhombicuboctahedron()
|
||||
{
|
||||
// Top *
|
||||
// Bottom o
|
||||
// Front ^
|
||||
// Stern v
|
||||
// Left <
|
||||
// Right >
|
||||
const double alpha = 1; // 0.65;
|
||||
const osg::Vec4 colors[] = {
|
||||
osg::Vec4(0.7, 0.5, 0.7, alpha), // TFR
|
||||
osg::Vec4(0.9, 0.9, 0.9, alpha), // T
|
||||
osg::Vec4(0.5, 0.7, 0.7, alpha), // TFL
|
||||
osg::Vec4(1.0, 0.7, 0.7, alpha), // TS
|
||||
osg::Vec4(0.7, 0.7, 1.0, alpha), // TF
|
||||
osg::Vec4(0.5, 0.0, 0.7, alpha), // BFR
|
||||
osg::Vec4(0.5, 0.5, 1.0, alpha), // F
|
||||
osg::Vec4(0.1, 0.5, 0.7, alpha), // BFL
|
||||
osg::Vec4(0.9, 0.5, 0.9, alpha), // TR
|
||||
osg::Vec4(0.5, 0.0, 0.5, alpha), // R
|
||||
osg::Vec4(1.0, 0.5, 0.7, alpha), // TSR
|
||||
osg::Vec4(0.2, 0.0, 0.2, alpha), // BR
|
||||
osg::Vec4(0.2, 0.2, 1.0, alpha), // BF
|
||||
osg::Vec4(0.7, 0.0, 0.2, alpha), // BSR
|
||||
osg::Vec4(0.1, 0.1, 0.1, alpha), // B
|
||||
osg::Vec4(0.5, 0.5, 0.2, alpha), // BSL
|
||||
osg::Vec4(0.9, 0.0, 0.4, alpha), // SR
|
||||
osg::Vec4(1.0, 0.2, 0.2, alpha), // BS
|
||||
osg::Vec4(1.0, 0.5, 0.5, alpha), // S
|
||||
osg::Vec4(0.7, 0.7, 0.5, alpha), // SL
|
||||
osg::Vec4(0.5, 0.9, 0.5, alpha), // TL
|
||||
osg::Vec4(0.5, 0.7, 0.5, alpha), // L
|
||||
osg::Vec4(1.0, 1.0, 0.7, alpha), // TSL
|
||||
osg::Vec4(0.2, 0.5, 0.2, alpha), // BL
|
||||
osg::Vec4(0.5, 0.0, 0.8, alpha), // FR
|
||||
osg::Vec4(0.5, 0.7, 1.0, alpha) // FL
|
||||
};
|
||||
|
||||
const double no = -1.0;
|
||||
const double po = 1.0f;
|
||||
const double ps = 1.0 + sqrt(1.0);
|
||||
const double ns = -ps;
|
||||
const osg::Vec3 vertices[] = {
|
||||
osg::Vec3(po, po, ps),
|
||||
osg::Vec3(po, no, ps),
|
||||
osg::Vec3(no, po, ps),
|
||||
osg::Vec3(no, no, ps),
|
||||
|
||||
osg::Vec3(po, ps, po),
|
||||
osg::Vec3(po, ps, no),
|
||||
osg::Vec3(no, ps, po),
|
||||
osg::Vec3(no, ps, no),
|
||||
|
||||
osg::Vec3(ps, po, po),
|
||||
osg::Vec3(ps, po, no),
|
||||
osg::Vec3(ps, no, po),
|
||||
osg::Vec3(ps, no, no),
|
||||
|
||||
osg::Vec3(po, po, ns),
|
||||
osg::Vec3(po, no, ns),
|
||||
osg::Vec3(no, po, ns),
|
||||
osg::Vec3(no, no, ns),
|
||||
|
||||
osg::Vec3(po, ns, po),
|
||||
osg::Vec3(po, ns, no),
|
||||
osg::Vec3(no, ns, po),
|
||||
osg::Vec3(no, ns, no),
|
||||
|
||||
osg::Vec3(ns, po, po),
|
||||
osg::Vec3(ns, po, no),
|
||||
osg::Vec3(ns, no, po),
|
||||
osg::Vec3(ns, no, no),
|
||||
|
||||
// bonus vertices to map unique colors
|
||||
// we have only 24 regular vertices, but 26 faces
|
||||
osg::Vec3(ps, po, no), // copy from vertex 9
|
||||
osg::Vec3(no, ps, no) // copy from vertex 7
|
||||
};
|
||||
|
||||
const unsigned int indices[] = {
|
||||
// PITCH ROLL YAW
|
||||
8, 4, 0, // TFR 45 -45
|
||||
|
||||
0, 2, 1, // T1 0 0
|
||||
3, 2, 1, // T2
|
||||
|
||||
6, 20, 2, // TFL 45 45
|
||||
|
||||
1, 16, 3, // TS1 -45 0
|
||||
18, 16, 3, // TS2
|
||||
|
||||
0, 2, 4, // TF1 45 0
|
||||
6, 2, 4, // TF2
|
||||
|
||||
12, 9, 5, // BFR 45 -135
|
||||
|
||||
4, 5, 6, // F1 90 X
|
||||
7, 5, 6, // F2
|
||||
|
||||
14, 21, 7, // BFL 45 135
|
||||
|
||||
0, 1, 8, // TR1 0 -45
|
||||
10, 1, 8, // TR2
|
||||
|
||||
8, 10, 9, // R1 0 -90
|
||||
11, 10, 9, // R2
|
||||
|
||||
1, 16, 10, // TSR -45 -45
|
||||
// PITCH ROLL YAW
|
||||
13, 12, 11, // BR1 0 -135
|
||||
9, 12, 11, // BR2
|
||||
|
||||
5, 7, 12, // BF1 45 +-180
|
||||
14, 7, 12, // BF2
|
||||
|
||||
11, 17, 13, // BSR -45 -135
|
||||
|
||||
12, 13, 14, // B1 0 +-180
|
||||
15, 13, 14, // B2
|
||||
|
||||
19, 23, 15, // BSL -45 135
|
||||
|
||||
11, 17, 16, // SR1 -45 -90
|
||||
11, 10, 16, // SR2
|
||||
|
||||
13, 15, 17, // BS1 -45 +-180
|
||||
19, 15, 17, // BS2
|
||||
|
||||
16, 17, 18, // S1 -90 X
|
||||
19, 17, 18, // S2
|
||||
|
||||
18, 22, 19, // SL -45 90
|
||||
22, 23, 19, // SL
|
||||
// PITCH ROLL YAW
|
||||
2, 3, 20, // TL1 0 45
|
||||
22, 3, 20, // TL2
|
||||
|
||||
20, 22, 21, // L1 0 90
|
||||
23, 22, 21, // L2
|
||||
|
||||
3, 18, 22, // TSL -45 45
|
||||
|
||||
14, 15, 23, // BL1 0 135
|
||||
14, 21, 23, // BL2
|
||||
|
||||
// last vertex is equal to vertex 9 to map a unique color
|
||||
4, 5, 24, // FR 45 -90
|
||||
4, 8, 24, // FR
|
||||
|
||||
// last vertex is equal to vertex 7 to map a unique color
|
||||
6, 20, 25, // FL 45 90
|
||||
21, 20, 25 // FL
|
||||
};
|
||||
|
||||
osg::ShadeModel *shademodel = new osg::ShadeModel;
|
||||
|
||||
shademodel->setMode(osg::ShadeModel::FLAT);
|
||||
|
||||
osg::StateSet *stateset = new osg::StateSet;
|
||||
stateset->setAttribute(shademodel);
|
||||
|
||||
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
|
||||
|
||||
geom->setStateSet(stateset);
|
||||
|
||||
unsigned int vertexCount = sizeof(vertices) / sizeof(vertices[0]);
|
||||
osg::Vec3Array *vertexArray = new osg::Vec3Array(vertexCount, const_cast<osg::Vec3 *>(&vertices[0]));
|
||||
geom->setVertexArray(vertexArray);
|
||||
|
||||
unsigned int indexCount = sizeof(indices) / sizeof(indices[0]);
|
||||
geom->addPrimitiveSet(new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, indexCount, indices));
|
||||
|
||||
unsigned int colorCount = sizeof(colors) / sizeof(colors[0]);
|
||||
osg::Vec4Array *colorArray = new osg::Vec4Array(colorCount, const_cast<osg::Vec4 *>(&colors[0]));
|
||||
geom->setColorArray(colorArray);
|
||||
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
|
||||
// geometry->setNormalArray(normals);
|
||||
// geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
|
||||
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
|
||||
geode->addDrawable(geom.get());
|
||||
|
||||
return geode.release();
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ osg::PositionAttitudeTransform *createArrow(const osg::Vec4 &color);
|
||||
osg::Node *create3DAxis();
|
||||
osg::Node *createOrientatedTorus(float innerRadius, float outerRadius);
|
||||
osg::Geode *createTorus(float innerRadius, float outerRadius, float sweepCuts, float sphereCuts);
|
||||
osg::Geode *createRhombicuboctahedron();
|
||||
}
|
||||
|
||||
#endif /* SHAPE_UTILS_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user