Question

Assuming I have a class that contains 3 vectors(one for position, one for scale and one for rotation) I can use them to generate a transform matrix that symbolizes the object's position, rotation and size in 3D space.Then I add parent/child relationships between objects and I multiply the child's local transform matrix by the parent's global one, I get the child's global one and this is the one I use for rendering objects, so when a parent rotates, a child rotates around it like an orbit.Now I need to be able to get a child's local transform(not the entire matrix, just the separate components).I know the child's global transform and I know the parent's global transform.

I can get the child's local transform by multiplying the child's global transform by the parent's transform inversed.However I REALLY need to be able to do this specifically:

1.To be able to get the child's local position, just by knowing it's global position and the parent's global position WITHOUT generating any matrices;

2.To be able to get the child's local rotation, just by knowing it's global rotationand the parent's global rotation WITHOUT generating any matrices;

3.To be able to get the child's local scale, just by knowing it's global scale and the parent's global scale WITHOUT generating any matrices;

Was it helpful?

Solution

If you want those answers separately, then it should be fairly straighforward (i.e. subtract the partent location for the child's to get the child's relative displacement). However I assume you want to reconstruct all of them together. If you start writing down the math you'll figure out a system of equations that gives you those things (the rotations will need to factor into displacement and so on). The thing is that the computation is perfectly equivalent (same number of computations required) to inverting the matrix and doing the multiplication, so you don't get anything by doing it anyway else (likely you'll make a mistake or you make it less cache friendly).

What is usually the design for these things is to use a stack and always keep the changes relative to the parent. Then when you want to do something, you go through the object hierarchy and multiply the matrices as you go along, keeping a stack so that when you move up the parent, you do a pop on the stack instead of inverse multiplication of matrices. This way you get very good performance and also the objects are more stable because you don't make as many computations with them (multiplying a matrix with it's inverse will rarely give a perfect identity matrix).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top