martedì 3 maggio 2016

Day 118: Parent and children

Today I decided to implement a hierarchy system.

Each trasform can have a parent and a list of children. This means that moving a parent will move the children with it as well. To do so, the model matrix of each object is calculated by combining those of all the parents above it in the hierarchy

The system works, and I also had to change how the light position is passed to the shader to account for the new changes. There are a few big problems though, which i'll probably not fix because are pretty boring things, and I won't use them much, but they should definitely be supported in a decent engine:

1) local and global coordinates: the system now only uses the former. Implementing the latter is not so straightforward, and I'm also thinking of two possible ways to achieve that:
- Only store local coords, and set / retrieve the global ones by calculating them at runtime using the model matrices of the whole hierarcy
- Store them both, and if the last set was a local one, then proceed normaly. Otherwise avoid the whole matrix multiplication and directly send global coord to the shader. Problem is how to separate rotation scale and translation.

2) The second major problem are the rotation of the lights. I actually haven't even checked it, but surely the rotation will remain global. And being it a direction, I cannot use the usual hierarchy matrix, I would need to generate an inverse transpose and so on, maybe I'll fix it one day

For now I'll leave it like that, and I already tested it with a new scene. As you can see in the screenshot, there are 6 point lights (with a gameobject and model of course). They are all children of an invisible gameobject at the center of them. I tried to move it and rotate it, and all the lights follow it nicely.





Nessun commento:

Posta un commento