Tyr: Transforming Nodes
Posted in Code on December 11th, 2011 by PyrokaIt’s been a good week, I managed to complete the to-do list from my last post early in the week, node transforming (translate, rotate and scale) went in pretty fast, and it was very nice to be able to drag nodes around the screen. I also buffed up the properties slightly, adding a hash property (created by hashing the name of the property with MurmurHash) and saves that when saving the properties, when loading properties it finds a property that matches that hash, and then checks that the type is what is expected. This should allow me to add, remove and move around properties and it will ‘just work’ (previously it assumed that the order of the properties would be the same loading as it was saving, and that properties were all the correct type, very dangerous assumptions but that was just first-pass temporary code).
Fixing the issue with dragging and dropping items from the scene graph TreeCtrl turned out to be a one-line fix, I forgot that the tree control items own the data you associate with them, and it was being deleted as part of the drag/drop action, and then causing a crash (well, hitting an assert actually) when that item was then selected (as that data was expected to be there).
So with those tasks sorted, I moved on to the next big job: Making it so that you can select multiple nodes and then transform them with the mouse, this was a bit of a pain and is still not entirely complete (currently the properties PropGrid only shows if you have exactly one node selected, in future it will show all common properties shared between all selected nodes, and allow you to change them for all selected nodes at once), but as a task it wasn’t particularly difficult, just a case of going through the code and sorting out each of the places that assumed there was only ever one selected node (not that many, as it turned out).
Then I added a ‘selection marker’, this is a cross that follows the selected node or nodes (assuming the average position in the case of more that one node being selected) and has a (small) hit-area, you click can click and drag that to translate, rotate and scale the selected node(s), thus allowing the click-and-drag transforms to work on nodes that have a size of 0, which previously didn’t work.
Finally I added some extra buttons to the editor to expose some align functions, these allow the user to select a group of nodes and align them to the left, center, right, top, middle or bottom, which uses the nodes personal bounding boxes (as in, the bounding box that encompasses that node only, excluding it’s children) to align the nodes, for example if you select a bunch of nodes and click ‘align-left’ then the nodes will be arranged so that the minimum extent on the x-axis of their personal bounding boxes will all equal that of the left-most node, quite a useful operation.
So then, next week I want to make sure that loading and saving scenes works as intended, and I might move on to attempting to build-up a more complex, realistic scene… I’ve been putting some thought into the game I might make to test features of the engine as I go along, nothing has really solidified yet but I have some interesting (at-least for me) ideas. I also want to make sure it compiles on Linux but progress on that front may be slightly slower (I have to be in a particular mood to comb through GCC compile errors…)