# Keeping the meshes “thickness” the same when scaling an object

I've been bashing my head for the past couple of weeks trying to find a way to help me accomplish, on first look very easy task. So, I got this one object currently made out of 5 cuboids (2 sides, 1 top, 1 bottom, 1 back), this is just for an example, later on there will be whole range of different set ups. Now, the thing is when the user chooses to scale the whole object this is what should happen:

X scale: top and bottom cuboids should get scaled by a scale factor, sides should get moved so they are positioned just like they were before(in this case at both ends of top and bottom cuboids), back should get scaled so it fits like before(if I simply scale it by a scale factor it will leave gaps on each side).

Y scale: sides should get scaled by a scale factor, top and bottom cuboid should get moved, and back should also get scaled.

Z scale: sides, top and bottom cuboids should get scaled, back should get moved.

Hope you can help,

EDIT I am asking you, if any of you have any idea on how to accomplish this scaling.

I have tried whole bunch of things, from scaling all of the object by the same scale factor, to subtracting and adding sizes to get the right size. But nothing I tried worked, if one mesh got scaled correctly then others didn't.

• Are you wanting the thickness of the "walls" to remain the same? – MichaelHouse Dec 15 '12 at 16:21
• Yes thats right, I forgot to mention that. – user1806687 Dec 15 '12 at 16:43
• Your update is pushing your question into the "too localized" realm. It sounds like you're no longer looking for algorithms, but you want code. That's something you'll be unlikely to get. – MichaelHouse Dec 16 '12 at 16:13
• I am just looking for a way to achieve this. – user1806687 Dec 16 '12 at 18:13
• I'm sure you are. I've presented that below. It doesn't mean someone is going to write code for you. If you're still unclear about something in my answer, ask about it. – MichaelHouse Dec 16 '12 at 18:15

You have a few options.

• Apply a scale matrix to all the vertices that make up all the objects used to create your form. This is a common procedure, I'm sure XNA has something built in for this. This should be your preferred approach. It's the most common and it will produce the results you want. Additionally, it will work for any combination of shapes you make.

• Scale an invisible box and resize/move your objects to fit around it. Just have six positions that represent each face of a invisible cube. Move those along the axis they represent (top/bottom = y axis, left/right = x axis, front/back = z axis), and have your cuboids make their size and positions match up to the positions. This method would be useful if you wanted to maintain the thickness of your "walls" even after scaling.

• For example, the top cuboid would use the top position as it's position. It would then use each of the side positions to set its width and height.

EDIT to clarify the second option.

You have 6 positions:

Those positions define the positions and size of the shapes you have attached.

For example, the top cuboid would defined as such:

position = YP
width = XP-XM
height = wallThickness
depth = ZP-ZM


Or the back cuboid would be defined as:

position = ZP
width = XP-XM
height = YP-YM
depth = wallThickness

• I am sorry, I am not really sure what you meant? – user1806687 Dec 15 '12 at 16:45
• I could explain the whole thing again, or you can tell me what you're unsure about. – MichaelHouse Dec 15 '12 at 17:06
• How you meant the second thing, with the invisible box thingie – user1806687 Dec 15 '12 at 17:16
• First imagine that the right cuboid position is XP, left position = XM, top = YP and so on. You can imagine that re-sizing this box will move the cuboids around, but they'll have gaps. The next step is to just re-size the cuboids to fill the gaps. – MichaelHouse Dec 16 '12 at 19:10
• OK, you can modify the above algorithm to allow for that. You need to implement something like a scene graph. Where there are parent objects and child objects. The child positions are defined in relation to the parent size/position. For example, you could place the two back cuboids at 25% and 75% of their parent's width. That would adjust them to remain in their relative positions when the parent is re-sized. This is similar to the way 2D GUIs are defined. Where moving the parent around and re-sizing it keeps the elements (buttons, menus, etc.) in their correct positions. – MichaelHouse Dec 17 '12 at 19:28