CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Basic Orientation Matrix Question

1. Junior Member
Join Date
Mar 2010
Posts
2

## Basic Orientation Matrix Question

Hi all,

I am the author of bvhacker, a free animation application (see here: www.bvhacker.com)

I'm currently working on a new release, and am trying to change the orientation of bones in a bvh animation file. My problem is this:

I have a bvh file that has it's arms aligned down the y-axis. I need to convert it so that it's arms are aligned along the x-axis.

Or, put another way, when all joint's rotations are set to zero, the figure's arms are by it's sides. I need the figure's arms to be outstreched horizontally when zeroed out.

When I first encountered the problem I tried the naive solutions - e.g. just rotating the arms through 90 degrees. Of course, this didn't work well!

I've researched this as far as I can on the web. The solution *appears* to be in changing the arm bones initial translations from 0,L,0 to L,0,0 (where L represents the length of the arm) and then multiplying all my XYZ rotation data values in turn, each rotation value represented by a 4-element vector (where w=1), by a 4x4 'orientation matrix'. I'm fairly comfortable implementing this in code, but I have no idea of the values that should go into the orientation matrix, other than as follows ('u' is for unknown value)

u u u 0
u u u 0
u u u 0
0 0 0 1

I did study matrix transformations at uni, but it was a long time ago now, and I didn't get a really good grasp on the subject at the time! Can anyone help?

Cheers,

:-Davedub

2. ## Re: Basic Orientation Matrix Question

http://en.wikipedia.org/wiki/Rotatio...asic_rotations
and
http://mathworld.wolfram.com/RotationMatrix.html.

(These are 3x3, but just "plug" them in your u-fields...)

Also, be careful: row-major or column-major matrix? And remember that matrix multiplication is not commutative.

3. Junior Member
Join Date
Mar 2010
Posts
2

## Re: Basic Orientation Matrix Question

Thanks for the reply. I have now (mostly) solved the problem. Wikipedia was a great source of info for this.

I actually found that the shoulder and arms joints could simply be re-aligned by swapping the x and y offsets to align the arms along the x-axis, changing the joint rotation order from ZXY to ZYX and inverting the new X rotations.

However, the resultant ZYX rotation order is next to useless, as many 3D environments cannot use it. Reading up on Wikipedia, I found that there are two ways to change the rotation order, one using matrices and one using quaternions.

I opted for a quaternion based solution in the end, to avoid the problem of gimble lock. I implemented Noel Hughes algorithm (see http://noelhughes.net/uploads/quat_2...per_ver2-2.pdf)

The algorithm works great, except it only works within the limits of +/- 90 degrees (i.e. a hemisphere). I've now run out of time to go any further with this (for now) but plan to extend the solution by using Noel Hughes algorithm over two 'back-to-back' hemispheres when I can find some time.

The latest version of bvhacker is now in test and will (hopefully!) be available for download sometime over the next few days at www.bvhacker.com

cheers!

:-Davedub

4. Junior Member
Join Date
Mar 2010
Posts
2

## Re: Basic Orientation Matrix Question

footnote:

I noticed a very small error in Noel Hughes paper. I notified Noel, and he has updated the paper. The new version is here:

The link in my earlier post no longer works...

:-Davedub

5. Junior Member
Join Date
Oct 2011
Posts
1

## Re: Basic Orientation Matrix Question

Hi Dave
I'm using BVH hacker for some time and it help me alot. I'm trying to build loader for BVH in AS3.
I've some success but also problems.
Main problem is swing that I get with very big values for example
in frame 315 I can read in the hacker
Z=-174.49
Y=173.50
and visually such big rotation aren't happen and lead to nasty swing of legs in AS3
I imported .bvh in Daz3D(where is all correct) and in same frame I'm reading
Z=-11.63;
Y=-10.45;
what should I do with Z,X,Y Euler angles so swing not happen.
Body in AS3 (Flash) is along Y+(up) hands along X(+-) and looking towards screen Z+
Also I'm bit confused with offsets. Just x,y,z pos of the root is animated. Did offset mean joint offset from parent joint which is actually x,y,z of the joint???
If you could share your experiences would be great
Regards
Alex

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•