PGL, a primitive OpenGL 3D primitive library
https://github.com/wcaarls/pgl
Example
The library consists of the following main classes:
- Node, the basic node structure of the scene graph.
- Object, something that can be placed.
- Primitive, something that can be drawn.
- Box, a box.
- WireBox, a wireframe box.
- Sphere, a sphere.
- Cylinder, a generalized cylinder.
- Cone, a cone,
- Arrow, an arrow
- Capsule, a cylinder with rounded encaps.
- Plane, a (possibly textured) plane.
- Model, an STL model.
- Scene, the root node of the scene graph.
- Camera, which defines the viewpoint for drawing a Scene.
- Controller, which adjusts the viewpoint of an associated Camera.
There are also utility Vector3 and matrix functions to specify points and coordinate Transformations such as Rotations and Translations. They mostly behave like you would expect them to.
In general, the classes have public members that can be accessed directly, such as a Primitive::transform or Camera::fovy.
The code to generate the example above is essentially
scene->attach(
new pgl::Box({2, 2, 0.05}, {0, 0, -1}));
scene->attach(
new pgl::Arrow({-1, -1, -1}, { 0, -1, -1}, 0.02))->color = {1, 0, 0};
scene->attach(
new pgl::Arrow({-1, -1, -1}, {-1, 0, -1}, 0.02))->color = {0, 1, 0};
scene->attach(
new pgl::Arrow({-1, -1, -1}, {-1, -1, 0}, 0.02))->color = {0, 0, 1};
object->attach(
new pgl::Capsule({-0.3, 0, 0}, {0.3, 0, 0}, 0.02))->color = {1, 0, 0};
object->attach(
new pgl::Capsule({0, -0.3, 0}, {0, 0.3, 0}, 0.02))->color = {0, 1, 0};
scene->attach(
new pgl::Model(
"teapot.stl", {0, 0, -1}, 0.1))->color = {1, 1, 0};
scene->attach(
new pgl::Plane({-100, 0, 0}, {0, 100, 0}, {0, 0, 10}))->color = {0.5, 0.5, 1};
scene->attach(
new pgl::Plane({1, 0, 0}, {0, 1, 0}, {0, 0, -1},
pgl::Texture(
"ceramic-tiles.ppm"), 9));
scene->attach(
new pgl::Plane({1, 0, 0}, {0, 0, 1}, {0, 1, 0},
pgl::Checkerboard4x4()))->color = {0, 1, 1};
controller->view(0.5, 0.4, 4);
The Camera's draw function would then be called in the window's refresh callback. To enable mouse interaction, the Controller's callback functions must be appropriately hooked into the window system. They are compatible with GLFW constants.
Note that it is not necessary to use the scene graph. You can draw the primitives in your own code by directly calling their draw function.