1.addMark()是用来添加新Mark的,并为其设置一个索引(Index);
如:
static unsigned char arrowBits[] = {
0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff,
0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01,
0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00,
0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff,
0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00,
0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff,
0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01,
0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00,
0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff,
0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01,
0xfe, 0xff, 0xff, 0xff, 0x00, 0xf8, 0xff, 0xff, 0x3f, 0x00, 0xe0, 0xff,
0xff, 0x0f, 0x00, 0xc0, 0xff, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0x01,
0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x00,
0xe0, 0x07, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00
};
SoMarkerSet::addMarker(90, SbVec2s(17, 17), targetBits);
2.设置坐标
SbVec3f markersCoords[NUM_MARKERS] = {
SbVec3f(0.5f, 0.5f, 0.0f), SbVec3f(1.5f, 3.8f, 0.0f),
SbVec3f(1.8f, 1.2f, 0.0f), SbVec3f(2.4f, 1.9f, 0.0f),
SbVec3f(3.2f, 6.3f, 0.0f), SbVec3f(4.5f, 7.2f, 0.0f),
SbVec3f(6.3f, 9.3f, 0.0f), SbVec3f(6.9f, 7.2f, 0.0f),
SbVec3f(8.0f, 6.0f, 0.0f), SbVec3f(8.5f, 6.3f, 0.0f)
};
// Sets the coordinates of the markers.
SoCoordinate3 *coords = new SoCoordinate3;
coords->point.setValues(0, NUM_MARKERS, markersCoords);
其中markersCoords坐标数组。
3.设置显示何种marker
int32_t markersIndexes[NUM_MARKERS] = {
90, 91, 92, SoMarkerSet::CIRCLE_FILLED_9_9, SoMarkerSet::SQUARE_FILLED_9_9,
SoMarkerSet::DIAMOND_FILLED_9_9, SoMarkerSet::TRIANGLE_FILLED_9_9,
SoMarkerSet::RHOMBUS_FILLED_9_9, SoMarkerSet::HOURGLASS_FILLED_9_9
};
// Sets the indices of the markers.
SoMarkerSet *markerSet = new SoMarkerSet;
markerSet->markerIndex.setValues(0, NUM_MARKERS, markersIndexes);
其中markersIndexes为marker的Index数组。
若只想用一种形状,则可以这样:
markerSet->markerIndex.setValue(SoMarkerSet::DIAMOND_FILLED_9_9);
4.设置材质绑定方式
SoMaterialBinding *matBind = new SoMaterialBinding;
matBind->value = SoMaterialBinding::PER_VERTEX;//表明One material for each vertex of object
5.设置每一个marker的颜色
// Sets the color of the markers.
SoMaterial *mat = new SoMaterial;
mat->diffuseColor.setValues(0, NUM_MARKERS, markersColors);
6.节点的添加顺序
root->addChild(coords);
root->addChild(matBind);
root->addChild(mat);
root->addChild(markerSet);
效果图