Saturday, May 18, 2024
HomeGame Developmentmathematics - Matrix parent-child transformation for 2D positioning

mathematics – Matrix parent-child transformation for 2D positioning


I am working with matrix math for parent / child transformations. I have to modify existing calculations to keep child scale constant while also keeping child position relative to its parent.

Here’s some info about what I am given:

Input

Appends two matrices. AB = A * B

a – The local (child) matrix.

b – The world (parent) matrix.

Matrix

A matrix has of the following properties:

a – x scale

b – y skew

c – x skew

d – y scale

tx – x translation

ty – y translation

Working Calculations

This is the calculation that scales the child correctly based on parent resize:

a.a = (a.a * b.a) + (a.b * b.c)

This transfroms the child’s x position correctly when the parent’s x position changes:

a.tx = (a.tx * b.a) + b.tx

My goal

I want to keep the child’s size constant, while still keeping it positioned based on the parent. When I try to change the transformation equation (a.tx), I get undesired results. I will post them below.

(To keep the child’s scale the same I just set a.a = a.a)

This is the original parent/child setup. The parent is black, the children are all white

This is what I don’t want. Here we keep the children at a constant scale, but when we shrink the parent, the children are offset from their original values

What is the correct equation to set a.tx to? I have tried a.tx = (a.tx + b.tx), but what didn’t work either.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments