Thanks for informations! I can now understand your way in collision editor.
At first, I tried to do the same way of Collision Editor. But because I didn't make sense of it, I decided to use "Selection Mode".
I managed to make selection system 10 days ago, but I have a trouble with "drag-and-drop" function.
Because each bones have different rotation and coordinates, I can't find a good way to rotate bones.
Would you do me a favor and tell me some hints to do that?
Tips:
- Remember that a bone segment consists of a line then a point.
- Transformations occur in this order: translate, rotate, scale.
- When you rotate a bone, you are making changes to the child bones. Even though the node rotates, translation has already been applied and doesn't affect the node's location.
- To get the world position of a bone, use its bind/frame matrix. The values in the 4th column are the XYZ coordinates.
After hit-detection, highlight the bone node and render a sphere around it. You can use the bone's Frame Matrix to achieve a local coordinate system (just multiply this to the modelview matrix). Once in a local coordinate system, you can simply render the sphere. You don't need to apply any other changes to it, the matrix does all the work for you!
Once you have a bone chosen and a sphere to render, use the same two-pass depth buffer trick. This time, you're going to hit-detect
the sphere first. To make tings easier, you may consider setting the depth buffer exclusively for the sphere. Any depth value < 1 means the user did not click the sphere, and you can cancel the selection.
Once you have the world-coordinates of the user-selected point, transform this to the bone's local coordinates using its
Inverse Frame Matrix (just multiply the point by the matrix). Now that we have a local point, the rest is fairly easy. When the user FIRST clicks the sphere, do two things:
- Calculate the XYZ angles of the clicked point using trigonometry. (these will be your origin angles)
- Use these angles to determine axis-snapping. (If the x-axis is the only one with an angle, we can safely snap to it)
As the user moves the mouse around, repeat the point+depth -> local point process. Calculate the XYZ angles each time, and subtract the origin angles. This will give you an 'angle offset', for which you can apply to the FrameState or AnimationFrame (just add them together).