Hello
I'm using spine-c along with sdl-gpu for my game engine. Everything has gone fine so far but I've ran into problems when I want to use a slot's rendering information to render text instead. This is definitely me at fault as I'm not great at matrices etc.
I have it set up so I have a slot that I track, then when I go to render this slot I instead replace it with some text. I get the slot's bone and use the worldPositionX/Y, colour etc and even this works great. It falls over when I want to shear the text though. sdl-gpu using a similar matrix system to opengl and they're an array of 16 floats like matrix[16].
I've tried a couple of things...
1) Use the matrix values directly.
a) Create an sdl-gpu identity matrix
b) Translate it by the bone's worldX/Y
c) Get the bone's 2x2 matrix (a,b,c,d).
d) Set bone's matrix on the sdl matrix.
matrix[0] = bone->a;
matrix[1] = bone->b;
matrix[4] = -bone->c;
matrix[5] = -bone->d;
(c and d are inverted so we rotate the correct way).
e) render the text at 0,0
This works when shear isn't involved, but as soon as it does it doesn't look correct. On further investigation it looks like the shearing is back to front. ie, if I set shearX to 45 and shearY to 0 in Spine, the result I get in game is what it would look like if I set shearX to 0 and shearY to 45 in Spine. And vice-versa.
2) Trying to use a shear matrix
a) Create an sdl-gpu identity matrix
b) Translate it by the bone's worldX/Y
c) Create an sdl-gpu identity matrix for the xShear
d) Set the xShear value onto the matrix
xshear[1] = (bone->shearX);
e) Create an sdl-gpu identity matrix for the yShear
f) Set the yShear value onto the matrix
yshear[1] = (bone->shearY);
g) Multiply the 3 matrices together
h) Rotate the matrix by worldRotationX
i) Render the text 0,0
Just wrong in different ways when it starts to shear.
3) Without using shear I would...
a) Translate the current matrix by worldX/Y
b) Scake the current matrix by scaleX/Y
c) Rotate the current matrix by worldRotationX
d) Render the text at 0,0
This worked but obviously doessn't take into account the shearing.
Can anyone advise on the best way forward for this? I can live without shearing but I just thought it would be nice to have while I'm working on it.
Basically I need to know how to convert a bone's a,b,c,d,worldX,worldY to something like an opengl matrix. It would let me parent other game objects to bones and have the artist control the animations.
Failing that, how do I use the worldRotationX and worldRotationY values?
Thanks!
Scott