Hi Nate, I'm getting closer to a solution, I found a really cool class in Github that does all kind of calculations with matrices in Lua, I did a quick test and it works great to calculate the determinant and inverse the matrix. You can find it here https://github.com/davidm/lua-matrix
I studied the matrices in your code and I see that m20, m21 and m22 are constant values (0 and 1), and m02 and m12 are the worldX and worldY of the bone which I can get from the Corona's bone class. Based on this structure for the matrix and the Matrix Lua Class, I was able to inverse the matrix (the determinant always gives me one, not sure if that is correct).
Loading Image
So with the matrix inversed all I have to do now is to multiply the vector to get the local x and y positions. This is the piece of your code that I need to translate into Lua
public Vector2 mul (Matrix3 mat) {
float x = this.x * mat.val[0] + this.y * mat.val[3] + mat.val[6];
float y = this.x * mat.val[1] + this.y * mat.val[4] + mat.val[7];
this.x = x;
this.y = y;
return this;
}
Couple of questions:
1) Which varaibles from the matrix correspond to the mat.val values in your Java function. I'm pretty sure mat.val[0] corresponds to m00, but not sure about the rest
2) Should I be using the bone I'm trying to move or its parent's m* variables and worldX/Y?
3) I imagine that "this.x" in my case would be the worldX and worldY values of the bone I'm trying to move, as I'm trying to get local x and y values, am I right?
@mixedup Nate is correct in what I'm trying to make. If I'm successful, I will not only be able to position the bone based on gravity but also implement dragging like in a ragdoll. Reason I'm doing this via bounding boxes > polygons > physical bodies is because I'm using a Texture Packer SpriteSheet and not individial images, and I think with SpriteSheets and Corona is not so easy to apply phisics to Spritesheet indexes, at least that's been my personal experience.
Regards
Hector