[ODE] Rotation about Z-axis clockwise ?
Antonio Tejada Lacaci
wildfred at teleline.es
Wed Aug 27 08:55:02 2003
On Wed, 27 Aug 2003 16:05:08 +0200, thomas.miconi@free.fr wrote:
>Quoting Antonio Tejada Lacaci <wildfred@teleline.es>:
>
>> On Tue, 26 Aug 2003 17:31:33 +0200, thomas.miconi@free.fr wrote:
>> >According to the Rule Thumb, this seems to correspond to an indirect
>> rotation
>> >about the z-axis (i.e. clockwise rotation if the z-axis points to you).
>>
>> If you are in a "right-handed coordinate system", i.e. a system which
>> holds the right-hand rule, rotating when the axis points towards you
>> (out of the computer screen) is counterclockwise, not clockwise.
>
> (0.707107, -0.707107, 0.000000) (0.707107, 0.707107, 0.000000) (0.000000,
>0.000000, 1.000000)
>
>I agree wholeheartedly. This is exactly what I wrote (direct -> counterclock,
>indirect -> clock). And it seems to me that ODE does exactly the contrary !
Doh, sorry, I didn't pay enough attention to your original email.
Are you sure you are not experiencing some conceptual row major/column
major order issue?
I haven't looked at your exact numbers (maybe rotating by 90 degrees
would be easier to spot?), but to me it looks like your matrix is
transposed, it could be that you are used to do algebra with row
vectors, while ODE uses column vectors (the position of the new
coordinate system is stored in the last column of the matrix, not in
the last row).
For example, if I rotate around Z 90 degrees,
dMatrix3 m3;
dRSetIdentity(m3);
TRACE("\n (%f, %f, %f)\n (%f, %f, %f)\n (%f, %f, %f) \n",
m3[0], m3[1], m3[2],
m3[4], m3[5], m3[6],
m3[8], m3[9], m3[10]);
dRFromAxisAndAngle(m3, 0, 0, 1, M_PI / 2);
TRACE("\n (%f, %f, %f)\n (%f, %f, %f)\n (%f, %f, %f) \n",
m3[0], m3[1], m3[2],
m3[4], m3[5], m3[6],
m3[8], m3[9], m3[10]);
I get as final matrix:
(0.000000, -1.000000, 0.000000)
(1.000000, 0.000000, 0.000000)
(0.000000, 0.000000, 1.000000)
Which is what I expect, because when doing that rotation, X becomes -Y
and Y becomes X:
| 0, -1, 0 | | X |
| 1, 0, 0 | · | Y | = ( -Y, X, Z )
| 0, 0, 1 | | Z |
I have used dBodySetRotation, dBodyGetRotation, dRFrom2Axes without
problems in my code (I'm used to use column vectors).
In case it's of any use, from ODE documentation:
>------------------
14.1. Matrix storage conventions
Matrix operations like factorization are expensive, so we must store
the data in a way that is most useful to the matrix code. I want to do
4-way SIMD optimizations later, so the format is this: store the
matrix by rows, and each row is rounded up to a multiple of 4
elements. The extra "padding" elements at the end of each row/column
must be set to 0. This is called the "standard format". Hopefully this
decision will remain good in the future, as more and more processors
have 4-way SIMD (especially for fast 3D graphics).
The exception: matrices that have only one column or row (vectors),
are always stored as consecutive elements in standard row format, i.e.
there is no interior padding, only padding at the end.
Thus: all 3x1 floating point vectors are stored as 4x1 vectors:
(x,x,x,0).
>------------------
>Amicalement,
>Thomas
Cheers!
Antonio Tejada Lacaci