Design: Object transformation

Started by
18 comments, last by L. Spiro 11 years, 12 months ago

I personally maintain a CVector3 position, CVector3 scale, and CVector3[3] rotation.

How do you compose two such objects? Or do you only allow composition if the second transformation doesn't change the scale?
Advertisement
Define what you mean by “compose”. I am assuming it means basing one object’s transformation off another, like in a parent-child situation, but it is almost midnight here and I am not so clear-minded right now.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

A transformation is a mapping from 3-dimensional affine space into itself. The composition of two mappings f ang g is defined as

(f*g)(x) = f(g(x))

So if you take a point x, you first apply g to it and then f, you should get the same result as if you had done it in one step (f*g).

And yes, you can use composition to describe articulated models where the transformation of the child needs to be considered on top of the transformation of the parent.

The composition of two rotation-and-translation transformations is another rotation-and-translation transformation, but the composition of two scaling-and-rotation-and-translation transformations is not necessarily a scaling-and-rotation-and-translation transformation. So my question is: How do you handle that? Or do you somehow restrict yourself when you compose transformations so the second one cannot have scaling in it?
Still late for me but if I guess correctly from the reading resources you provided and typed (and mind you I am self-taught, which is why certain terms can escape me even if the concept does not (and I am also a musician which is why this term specifically is hard for me to remember in the technical sense)) then it is really no big problem.

Currently I am imagining (and feel free to correct me if I am wrong given my sleepiness) that under normal circumstances you would have an arm holding a gun and that arm could swell by a disease, but without special care the gun could swell as well.

As far as I am concerned, by default all transformations that affect a parent should affect children, which includes scaling, so the simple act of cascading down parent world transforms effectively handles this.
However I employ one of the settings in Maya called, “Inherits Transform”, which is a boolean switch that does what it suggests. If not enabled, its coordinates are not local to its parent. Its implementation is simple because I use 2 matrices for all objects.

I keep a COrientation object as mentioned which handles the creation of a matrix from the given position, scale, and rotation members it manages.
It generates for me a matrix that represents the data it holds.

By assuming that data is always local transform, things work intuitively. Basically anything I get from that object is local, and if there is a parent I need to multiply with that parent’s world matrix to get my own final world matrix. Dirty flags cascade up and down here but in practice it really is efficient.

If an object is not set to inherit the parent’s transform, it simply does not ask for parent transform information when a world transform is requested. It just copies the local transform over and returns that.

You are specifically asking about scaling.
With my system as it is, you would need a special flag to indicate that rotation and position are inherited, but scaling is not. And that would be as simple as normalizing the rotation rows or columns of the parent world matrix, multiplied by the scale of the local “scale” member (which will probably be 1 so can be omitted).

This would be trivial to implement and fairly low overhead because only a few objects in any scene would ever use it. The only case I could imagine would be a swelling hand holding onto a gun that needs to point the same way as the hand and be at the same position, bot not swell (scale up). I wouldn’t worry about the extra steps to handle this since they would be very rare in practice.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Actually, even scaling is not a problem, as long as it is uniform in all directions (like in your swelling example). The problem arises with transformations that scale different axes differently. When you combine them with rotations, you can produce shear mappings, which cannot be expressed with a single scaling-rotation-translation transformation.

By the way, I tend to link to Wikipedia when I introduce terms that people here might not be familiar with. I don't know if it comes out as me giving homework or anything, but I am just trying to be more clear.
Non-uniform scaling is also no problem, but shearing is. I don’t support shearing.
Combining non-uniform scales with rotation doesn’t cause shearing though. It just causes the body to get fat one way, and then it is rotated about and then translated. The results then carry down to children normally, causing them to also get fat in the rotated direction of the parent’s fatness.

It doesn’t come off as giving homework, at least to me.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

The problems happen if you mix scalings with rotations like this:

scaling_A:
1/cos(pi/8) 0
0 sqrt(2)/cos(pi/8)

rotation_B (rotate 45 degrees clockwise):
sqrt(1/2) sqrt(1/2)
-sqrt(1/2) sqrt(1.2)

scaling_C:
(1+sqrt(2))/2 0
0 1/2

rotation_D (rotate 22.5 degrees counterclockwise):
cos(pi/8) -sin(pi/8)
sin(pi/8) cos(pi/8)

Now the product rotation_D * scaling_C * rotation_B * scaling_A is the matrix
1 1
0 1
So clearly, you can achieve shearing.

If you restrict the non-uniform scaling to only happen at the beginning, you are in good shape. That's why I asked if you restrict composition to transformations in which the second transformation doesn't have a non-uniform scaling.
Sorry, I meant that shearing is not possible within only one matrix transform, which is basically what you had stated earlier.
You presented a case in which shearing can occur in children, but it is the natural result of that kind of matrix propagation, so my philosophy is that that is what the user gets for doing that. Detecting non-uniform scales and then counting how far they propagate would be too slow, especially given that it is very rare.
So I just combine and if this happens, the user him- or her- self has the choice of how to handle it (or to not).


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


Sorry, I meant that shearing is not possible within only one matrix transform, which is basically what you had stated earlier.

I didn't say that.
I am referring to this:

which cannot be expressed with a single scaling-rotation-translation transformation.

Your wording was more accurate, but this is what I meant.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement