@@ -40,8 +40,10 @@ pub fn is_transform_ui(id: u32) bool {
4040}
4141
4242pub fn tranform_points (ui_component_id : u32 , points : * [4 ]PointUV , raw_x : f32 , raw_y : f32 ) void {
43- const asset_angle = points [0 ].angle_to (points [1 ]);
44- const transform_matrix = Matrix3x3 .rotation (asset_angle );
43+ const asset_angle_y = points [0 ].angle_to (points [3 ]) + std .math .pi / 2.0 ;
44+ // it's important we dont meausre horizontal one, because reflecting by X axis makes no change in horizontal angle
45+ // but should be 180 degree opposite
46+ const transform_matrix = Matrix3x3 .rotation (asset_angle_y );
4547 const inverted_transform_matrix = transform_matrix .inverse ().? ;
4648 const pointer = inverted_transform_matrix .transform_point (Point {
4749 .x = raw_x ,
@@ -110,12 +112,14 @@ pub fn tranform_points(ui_component_id: u32, points: *[4]PointUV, raw_x: f32, ra
110112 9 = > {
111113 // rotation
112114 const asset_center = points [0 ].mid (points [2 ]);
113- const asset_pointer_angle = std .math .atan2 (raw_y - asset_center .y , raw_x - asset_center .x );
114- const asset_new_angle = asset_pointer_angle + std .math .pi / 2.0 ;
115+ const asset_new_angle = std .math .atan2 (
116+ asset_center .y - raw_y ,
117+ asset_center .x - raw_x ,
118+ ) - std .math .pi / 2.0 ;
115119
116120 for (points ) | * point | {
117121 const current_angle = std .math .atan2 (point .y - asset_center .y , point .x - asset_center .x );
118- const default_angle = current_angle - asset_angle ; // angle without any user rotation introduced
122+ const default_angle = current_angle - asset_angle_y ; // angle without any user rotation introduced
119123 const length = std .math .hypot (point .x - asset_center .x , point .y - asset_center .y );
120124 const new_angle = default_angle + asset_new_angle ;
121125
0 commit comments