Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to convert a library called DragonBones to C++ Opengl which allows you to use Flash based skeletal animation. I'm almost done but I am running into a problem. I am trying to transform the parent bone with the child bone when I load in the data. The as3 code(Im using hardcoded numbers to factor out any other problems) is

var matrix:Matrix = new Matrix();  

    matrix.a =  1 * Math.cos(120);
matrix.b =  1 * Math.sin(120);
matrix.c = -1 * Math.sin(120);
matrix.d =  1 * Math.cos(120);
//Parent Point
matrix.tx = 10;
matrix.ty = 10;

var _helpPoint:Point = new Point();

//Child Point
_helpPoint.x = 40;
_helpPoint.y = 50;


var newPoint:Point = new Point();

newPoint = matrix.transformPoint(_helpPoint);


It comes out with x being 47.64987648428943 and y being 15.148903294693044

Now for GLM here is the code:

float a =   1 * cos(120);
float b =   1 * sin(120);
float c =  -1 * sin(120);
float d =   1 * cos(120);
float tx =  10;
float ty =  10;

glm::mat3 parentMatrix = glm::mat3(a,b,0,c,d,0,tx,ty,1);
glm::vec3 childPoint = glm::vec3(40,50,0);
parentMatrix = glm::inverse(parentMatrix);
glm::vec3 finalpoint = parentMatrix * childPoint;
printf("Final Point is %f, %f \n", finalpoint.x, finalpoint.y );

Which comes out to be X:61.597794 Y:17.484602

I think there is something wrong when I am multiplying the parentMatrix and childPoint because if you set the tx and ty to 0 in the as3 code it comes out with the same output as anything you put in tx and ty for glm. So for some reason the tx and ty in glm is not factoring into the equation. Does anyone know what I am doing wrong? Thanks in advance

I think this is more fit for stackoverflow? Have you checked whether the matrix is originally transposed or not? BTW why are you multiplying by 1? –  Sidar Jul 20 '13 at 1:29
just transpose your result before mutiplying –  Quonux Jul 20 '13 at 1:39
The 1 is just a representation of scale. This is a hard coded example to see if I could get it to work so I just replaced bone->scaleX and bone->scaleY with 1. EDIT: Sorry if this was meant more for stackflow. This is my first time using either because I can usually find my answers with google or figure them out myself. –  KingNormac Jul 20 '13 at 2:15

1 Answer 1

up vote 0 down vote accepted

3 by 3 Matrix can't handle translations.

You need to use a 4 by 4 matrix

float a =   1 * cos(120); 
float b =   1 * sin(120); 
float c =  -1 * sin(120); 
float d =   1 * cos(120); 
float tx =  10; 
float ty =  10; 

glm::mat4 parentMatrix = glm::mat4(a,b,0,0,c,d,0,0,0,0,1,0,tx,ty,0,1); 
glm::vec4 childPoint = glm::vec4(40,50,0,1); 
parentMatrix = glm::inverse(parentMatrix); 
glm::vec4 finalpoint = parentMatrix * childPoint; 
printf("Final Point is %f, %f \n", finalpoint.x, finalpoint.y ); 

This code should return the expected results ;)

Edit: I tested to verify my hypothesis just in case... and it returns

Final Point is 47.649876, 15.148905

So it should solve your problem.

A 3x3 matrix can represent a translation for 2D homogeneous coordinates, with the third component (Z) acting like the homogeneous component (W) of 3D homogeneous coordinates. You may have to apply manual division by W for points if the library doesn't expect you to use it in that way, however. –  Lars Viklund Jul 20 '13 at 2:01
I may be wrong, but I answered with the supposition that this code should handle 3D coordinates. But now that you make me think about this, when reading again, some hints let me suppose it's 2D only. You are probably right. –  Valkea Jul 20 '13 at 2:05
Thanks! It is 2D and I mainly work with mat4 but the as3 code was in a matrix 3x3 and glm::translate and glm::rotate wasnt producing the correct results so I switched over to mat3. –  KingNormac Jul 20 '13 at 2:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.