Affine transform and setNodeToParentTransform

Affine transform and setNodeToParentTransform


How can I calculate affine transform between three pairs of the corresponding points?

I have 3 pairs of the corresponding points:

cocos2d::Vec2 ps1[3];
cocos2d::Vec2 ps2[3];

I need function

cocos2d::Mat4 getAffineTransform(const cocos2d::Vec2 ps1[3], const cocos2d::Vec2 ps2[3])
//compute mat4 for transformation
return cocos2d::Mat4{};

and result pass to:

void Node::setNodeToParentTransform(const Mat4& transform)

To transform my cocos2d::Sprite


Check OpenCV’s impl. .


@stevetranby Thank you for answer.
Do you know how to exactly convert cv::Mat matrix 2x3 to cocos2d::Mat4 matrix 4x4?


Here’s the usage code and info: .

I don’t know for sure, but my guess is the 2x3 matrix it returns would be the upper left sub-matrix of the desired 4x4 transform matrix? It can’t give you rotation unless you had a 3rd input point that you used as the origin for rotation.

// getAffineTransformation's Matrix (2x3)
[[scale_x, shear_x, translate_x]
[shear_y, scale_y, translate_y]]

// if scale negative then it's also reflected 

That’s about as much as I know without research/experimenting myself.