How to convert between local and parent?
There's been multiple times where I've needed to convert coordinates and axis from a Game-Object's Local-Space to their parent Game-Object's Local-Space. At the moment, I do this by first converting said data to World-Space, which feels wasteful.
Shouldn't there be a way to convert something from Local-Space to Parent-Space? When you stop to think about it, the conversion of Local-Space to World-Space has to go through Parent-Space first. Why can't we stop it right there? Can we stop it right there? It feels like I'm taking two steps forward and one step back just to get to where I want to go.
I suspect that I could do something with the conversion matrices of the two objects to create a single matrix that can be applied to multiple points, but even then, I'm first going though World-Space. Also, we're dealing with floats here, so precision goes down the drain really fast once you start doing compound multiplications.
Answer by elenzil · Jul 31, 2018 at 06:36 PM
As you suggested, you could compose the two matrices of child.localToWorldMatrix and parent.worldToLocalMatrix into a single matrix and then multiply that matrix times all your points. I wouldn't worry about loss of precision with just two matrices involved. You've got to have a lot of floating point operations before that becomes an issue, and they have to be cumulative. ie, where the output of one is the input to the next, in a chain several hundred or thousand operations long.
Yeah, I was worried that might be the case. Although, the change in space isn't the only calculation I'm running, it's just one of the first calculations done for the sake of getting everything within the same coordinate system, and I'm not doing the math in World-Space because the scale, rotation, and location of the root object is important.
While the error from this one step is of no consequence on it's own, it does add to the overall error. I have managed to cut down number of calculations done along the chain of calculations over the months, and the current error only becomes visible when dealing with very large distances. And the error is so small that it shouldn't be visible in the final result when viewed on a monitor. But, it just feels like this is one step that shouldn't be needed.
This is only an assumption, but my assumption is that in order to get a matrix to go from local space to world space, you need to apply parent, grand-parent, etc. matrices to create it. It just feels wasteful when all we really need is the first of those mentioned matrices. If feels even worse when the parent coordinate system has multiple children.
There are still other items of higher importance that need work on the framework I'm working on, but this is one of those things in the back of my had that just bothers me.
Your answer
Follow this Question
Related Questions
Making joint aim in the same direction as the main camera, regardless of joint axis 0 Answers
How could I find out if an objects vector3 hits between 2 points without raycasting in a 3D game? 1 Answer
Modifying number based on % change 0 Answers