Hi!
I hope you can answer a question for me that has been bugging me for close to a week now. I cant seem to get the matrix operations correct. I am using android.graphics.Matrix.
I am trying to rotate the player char but it doesnt seem to work right. This is what i am doing at the moment.
matrix.preTranslate(lCenterX, lCenterY);
matrix.postRotate(entity.rotation);
matrix.postTranslate(entity.x-lCenterX,entity.y-lCenterY);
I am trying rotate the player vertices (a rectangle so it has 4 of them) by a differing amount of degrees (like 20d, 45d, 90d) but the player ends up displaced very far away. The higher amount of degrees the more the player is displaced. It gets really wierd.
public static Vector2D[] transform(Vector2D[] src, Vector2D[] dst, Matrix matrix){
for (int i = 0; i < src.length; i++){
transformBuffer[0] = src[i].x;
transformBuffer[1] = src[i].y;
matrix.mapPoints(transformBuffer);
dst[i].x = transformBuffer[0];
dst[i].y = transformBuffer[1];
}
return dst;
}
I am using matrix.mapPoints to move the vertices. Also worth knowing is that i have an array of vertices that represent the untransformed vertices (in model space) which i am transforming into a set of transformed vertices into world space.