简体   繁体   中英

Modifying 3D coordinates in C++

I'm attempting to animate a skeleton in C++. I currently have the coordinates of all the joints and which joints connect to which.

Does anyone know how I would go about, say, raising the arm up by 90 degrees and then calculate the new coordinates for all the joints further down the arm?

I'm guessing I'd have to get the vectors for each bone and rotate those and take it from there, but I'm not sure how to go about doing that.

(I'm using openGL to display them)

Calculate the point and axis you wish to rotate around. The axis is perpendicular to the rotation plane. The point is the shoulder in your case. You would rotate all points in the arm hierarchy the same amount. There are many examples on the web for rotation about an arbitrary axis. Here's one: http://paulbourke.net/geometry/rotate/

Another way to go about it is to reinterpret your skeleton using local transformations: ie each new bone has a transformation from its parent bone's world space. This is useful for forward kinematics (FK) where you simply pose a skeleton based on local rotations. Most motion capture data is stored in this way. To calculate the world co-ordinates of each joint, you must multiply all local matrices up the hierarchy.

If you currently only have skeleton joint positions in world space it is a pain to generate the local transformation matrices, because you don't necessarily know the local matrix of each joint. This is a bigger topic. I did it years ago when I worked on the motion capture retargetting module in a 3dsmax plugin called CAT.

I worked with two popular formats: BVH and HTR. From memory, BVH uses global positions (and is a pain), whereas HTR uses local joint matrices and is much easier to import.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM