-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Primitives SceneGraph Examples #82
base: master
Are you sure you want to change the base?
Conversation
An example showing using primitives and the SceneGraph, as mentioned in: mosra/magnum#102 Implements DrawableObject subclass of Drawable3D, demonstrates parenting objects to the scene and to other objects, and shows local object transformations and camera transformations using left and right click respectively
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Code looks great apart from a bunch of minor whitespace / tabs-vs-spaces issues which I can fix during merge, no problem. (Does your editor support .editorconfig, btw? Maybe there's a plugin at least. Then it would pick up indentation rules automatically.)
Can you show a screenshot so I can see how the example looks like without having to build it locally?
/* Dragging with left mouse button will rotate the objects locally */ | ||
if ((event.buttons() & MouseMoveEvent::Button::Left)) { | ||
for (auto* o : _objects) { | ||
(*o).transformLocal(Matrix4::rotationX(Rad{ delta.y() }) * Matrix4::rotationY(Rad{ delta.x() })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be the same as
(*o).transformLocal(Matrix4::rotationX(Rad{ delta.y() }) * Matrix4::rotationY(Rad{ delta.x() })); | |
(*o).rotateYLocal(Rad{ delta.y() }) | |
.rotateXLocal(Rad{ delta.x() })); |
? It's a bit shorter to write.
explicit DrawableObject(Shaders::Phong& shader, const Color3& color, GL::Mesh& mesh, Object3D& parent, SceneGraph::DrawableGroup3D& drawables) : Object3D{ &parent }, SceneGraph::Drawable3D{ *this, &drawables }, _shader(shader), _color{ color }, _mesh(mesh) {} | ||
|
||
void setColor(Color3 color) { _color = color; } | ||
Color3 getColor() { return _color; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Color3 getColor() { return _color; } | |
Color3 color() const { return _color; } |
Just for consistency -- all getters in Magnum are w/o the get
prefix :)
Original authors — credit is appreciated but not required: | ||
|
||
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 — | ||
Vladimír Vondruš <mosra@centrum.cz> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to list yourself here :)
Thanks for the feedback! I've made almost all the changes you suggested. The only one that needs a bit more review is the rotation. Using rotateLocal() does work fine, but the delta.x() and delta.y() need to be reversed to see the correct rotation. I've included a video showing what I mean: I'm not sure if this is a convention in Magnum or if I'm doing something wrong... 🤷♀️ |
Hah, no, I clearly messed up in that suggestion, sorry. Will fix this during merge. Thank you! |
In case you're wondering why no merge happened yet -- I wanted to take the Viewer tutorial and split the scenegraph-related stuff into a tutorial this example, as it's easier to absorb it in two smaller pieces. So I need to do some writing first :) |
No worries at all! I'm writing examples to help myself learn Magnum in small steps -- being able to contribute them to the project is just a bonus. 👍 |
I've been meaning to get back into learning Magnum, and what better way than to learn than to help make some examples!
I saw that this was a desired sub project from mosra/magnum#102
I added a bit more functionality than the python example had, to control both the drawables and the camera. It's landed somewhere between the primitives example, then python scenegraph, and the picking example.
Let me know if any changes need to be made 👍