#169995 - vuurrobin - Fri Aug 21, 2009 1:58 am
hello everybody,
because the ds hardware needs an inverse affine matrix instead of a normal affine matrix, I wanted to make an function that would inverse the matrix before storing it and some functions to get the normal matrix elements back. I used the inverse matrix formule on toncs affine matrix page.
it seems to work, but there seems to be some inaccuracy with the inverted matrix, and when inverting it back, the numbers are some points off. the axes also seems wrong. the y ax points down (which it should, according to tonc) but the x ax points to the left instead of the right.
here is the code to invert the matrix:
where FIX_VALUE_1 and FIX_SCALE is (1<<8) and FIX_SHIFT is 8.
and this is the code to invert one of the values back to its original:
does anybody sees a mistake that could explain the wrong ax, or a way to increase the accuracy so the points are more acurate? (maybe using more bits for the fixed point)
I've also created a program to test this, if anybody is interesting:
http://vuurrobin.100webcustomers.com/stuff/changingAffineMatrix.zip
(copy-paste to the adress balk if clicking it doesn't work)
the first 4 values are the normal affine matrix, which you can change with the ABXY and directional keys.
the second 4 is the inverse matrix, which the hardware uses.
the last value is one of the matrix values inverted back. this should be equal to the first value, but sometimes it is off.
because the ds hardware needs an inverse affine matrix instead of a normal affine matrix, I wanted to make an function that would inverse the matrix before storing it and some functions to get the normal matrix elements back. I used the inverse matrix formule on toncs affine matrix page.
it seems to work, but there seems to be some inaccuracy with the inverted matrix, and when inverting it back, the numbers are some points off. the axes also seems wrong. the y ax points down (which it should, according to tonc) but the x ax points to the left instead of the right.
here is the code to invert the matrix:
Code: |
/**
@brief Allows you to directly sets the affine transformation matrix. with this, you have more freedom to set the matrix, but it might be more difficult to use if you're not used to affine transformation matrix. this function will invert the matrix so it will work correctly with the hardware. * @param hdx the 1st matrix value, in .8 fixed point format. * @param vdx the 2nd matrix value, in .8 fixed point format. * @param hdy the 3th matrix value, in .8 fixed point format. * @param vdy the 4th matrix value, in .8 fixed point format. @return a reference to the object, so you can chain multiple commands. */ inline AffineMatrix& setAffineTransformation(const int hdx, const int vdx, const int hdy, const int vdy) { register int temp = (((hdx*vdy) >> FIX_SHIFT) - ((vdx*hdy) >> FIX_SHIFT)); temp = ((FIX_VALUE_1 * FIX_SCALE) / temp); this->hdx = (temp * vdy) >> FIX_SHIFT; this->hdy = (temp * -vdx) >> FIX_SHIFT; this->vdx = (temp * -hdy) >> FIX_SHIFT; this->vdy = (temp * hdx) >> FIX_SHIFT; return *this; } |
where FIX_VALUE_1 and FIX_SCALE is (1<<8) and FIX_SHIFT is 8.
and this is the code to invert one of the values back to its original:
Code: |
/**
@brief returns the 1st value of the affine matrix. @return the 1st value of the affine matrix, in .8 fixed point format. */ inline const int gettesthdx() const { register int temp = (((hdx*vdy) >> FIX_SHIFT) - ((vdx*hdy) >> FIX_SHIFT)); temp = ((FIX_VALUE_1 * FIX_SCALE) / temp); return (temp * vdy) >> FIX_SHIFT; } |
does anybody sees a mistake that could explain the wrong ax, or a way to increase the accuracy so the points are more acurate? (maybe using more bits for the fixed point)
I've also created a program to test this, if anybody is interesting:
http://vuurrobin.100webcustomers.com/stuff/changingAffineMatrix.zip
(copy-paste to the adress balk if clicking it doesn't work)
the first 4 values are the normal affine matrix, which you can change with the ABXY and directional keys.
the second 4 is the inverse matrix, which the hardware uses.
the last value is one of the matrix values inverted back. this should be equal to the first value, but sometimes it is off.