torun

  • 3 juin 2024
  • Inscrit 8 mars 2023
    • Modifié

    You can fix it this way:
    以下のように修正できます:

    var rotation = Math.atan2(y, x) * 180 / Math.PI + 180;
    var length = Math.sqrt(x * x + y * y);
    json += ', "length": ' + length + ', "rotation": ' + rotation + ' }';

    This points the child bones to the parent though.
    これによって、子ボーンが親を指すようになります。
     Loading Image
    A bone can have multiple children, so pointing at the children would have to decide which, like the first. You can sort of do that this way:
    一つのボーンには複数の子がいる可能性があるため、子を指す場合にはどの子を指すかを決める必要があります。例えば、最初の子を指すことができます。その場合、以下のようにしてそれを行うことができます:

    		for (var boneName in bones) {
    			if (!bones.hasOwnProperty(boneName)) continue;
    			var child = bones[boneName];
    			if (child.parent == bone) {
    				var cx = child.x - bone.x, cy = child.y - bone.y;
    				var rotation = Math.atan2(cy, cx) * 180 / Math.PI + 180;
    				var length = Math.sqrt(cx * cx + cy * cy);
    				json += ', "length": ' + length + ', "rotation": ' + rotation;
    				break;
    			}
    		}
    		json += ' }';

    However, it doesn't give you what you want because when you rotate the parent to point at the child, all the children are rotated:
    ただし、親を子に指すように回転させると、すべての子も回転してしまうので、望む結果は得られません:
     Loading Image
    If you could rotate all the children the opposite amount you'd see it work (done by hand):
    もし子たちを逆方向に同じ量だけ回転させることができれば、正しく動作すると思います(手動で行った場合):
     Loading Image
    The code to rotate all the children is a little tricky. I think it would be easier to create the bones by hand than to write that code!
    すべての子を回転させるためのコードは少々複雑になります。そのコードを書くよりは、手動でボーンを作成した方が簡単だと思います!