This tutorial shows how to create a geometry model with different parts and effects.
This tutorial creates two triangle parts and two polyline parts. All parts has color effects. The second triangle and the second polyline will have the halo effect applied.
- Note
- This tutorial expect the application to have a correctly configured cee::vis::View in place. See demo applications on how to set up a cee::vis::View in your application.
- Create model
Create the model and add it to the view.
- Set vertices and indices
Create data arrays of vertices and indices for the triangle parts and polyline parts. The second triangle will use the same vertices and indices as the first, but apply a transformation. The two polyline parts will have separate vertices, but share the same array of indices. (They have the same connectivities, but different coordinates.)
std::vector<cee::Vec3d> triangleVertices;
triangleVertices.push_back(
cee::Vec3d(0.0, 0.0, 2.0));
triangleVertices.push_back(
cee::Vec3d(2.0, 0.0, 2.0));
triangleVertices.push_back(
cee::Vec3d(1.0, 0.0, 3.0));
std::vector<unsigned int> triangleIndices = { 0, 1, 2 };
std::vector<cee::Vec3d> firstPolylinesVertices;
firstPolylinesVertices.push_back(
cee::Vec3d(0.0, 0.0, 0.0));
firstPolylinesVertices.push_back(
cee::Vec3d(1.0, 0.0, 0.0));
firstPolylinesVertices.push_back(
cee::Vec3d(1.5, 0.0, 1.0));
firstPolylinesVertices.push_back(
cee::Vec3d(0.0, 0.0, -1.0));
firstPolylinesVertices.push_back(
cee::Vec3d(1.0, 0.0, -1.0));
firstPolylinesVertices.push_back(
cee::Vec3d(1.5, 0.0, 0.0));
std::vector<cee::Vec3d> secondPolylinesVertices;
secondPolylinesVertices.push_back(
cee::Vec3d(2.0, 0.0, 0.0));
secondPolylinesVertices.push_back(
cee::Vec3d(3.0, 0.0, 0.0));
secondPolylinesVertices.push_back(
cee::Vec3d(3.5, 0.0, 1.0));
secondPolylinesVertices.push_back(
cee::Vec3d(2.0, 0.0, -1.0));
secondPolylinesVertices.push_back(
cee::Vec3d(3.0, 0.0, -1.0));
secondPolylinesVertices.push_back(
cee::Vec3d(3.5, 0.0, 0.0));
std::vector<unsigned int> firstLineIndices = { 0, 1, 2 };
std::vector<unsigned int> secondLineIndices = { 3, 4, 5 };
std::vector<std::vector<unsigned int> > polylinesIndices;
polylinesIndices.push_back(firstLineIndices);
polylinesIndices.push_back(secondLineIndices);
- Create part data and build parts
Create a Data for each of the triangles and polylines. The part data binds vertices and indices and can be used in one or more parts. We only create one part data for triangles, as this will be used for both triangle parts below.
The triangles will be DataIndexedTriangles objects, while the polylines will be DataIndexedPolylines objects.
firstLinePartData->
setVertices(firstPolylinesVertices);
secondLinePartData->
setVertices(secondPolylinesVertices);
Build the parts using the corresponding data parts. Notice that both the triangles uses the same data part, but the second triangle has a transformation to move it to a separate position.
transformedTrianglePart->
setData(triangleDataPart.
get());
secondLinePart->
setData(secondLinePartData.
get());
- Add effects
In this tutorial we will draw the triangles with the color red. The lines will be colored blue. The second triangle and the second polyline will get a halo effect. The halo effect draws a part with silhouetted edges.
Create the effects:
Add the effects to the parts:
We're done. Add all the parts to the model:
gcgeoModel->
addPart(transformedTrianglePart.
get());
- See the complete source code here:
Geometry: Create a geometry model