Is this how to set the local rotation axis system the same as the world axis system ?
3dcheapskate
Posts: 2,719
I want to set the 'orientation' parameter of a node (prop) to align with the world axes. From the DAZ Script 2 reference this seems to be the method I need:
void DzNode::setOrientation ( DzQuat orientation, Boolean makeDefault = false )
Sets the orientation for the node
- orientation: The orientation for the node. This defines the space in which node rotations occur.
- makeDefault: Whether or not to set the default value as well as the current value.
I don't comprehend quaternions (yet), but I obviously need to set up one of these:
DzQuat::DzQuat ( Number q0, Number q1, Number q2, Number q3 )
So I'm guessing that this will do what I want
var qZero = new DzQuat(0,0,0,0);
oProp.setOrientation(qZero);
It would be nice if somebody who knows can confirm/refute...
Post edited by 3dcheapskate on
Comments
use
or
because orientation quaternions should be normalized. A complete zero quaternion is like a rotation around a zero vector (i.e. not defined).
Even with my minimal understanding of quaternions (i.e. that w represents the angle of rotation, and x/y/z define the axis of rotation) I was wondering whether x/y/z should be non-zero... "rotation around a zero vector" sums up the thought that was slowly forming in the fog !
When you say 'normalized' (by which I assume you mean setting the x/y/z values so that the quaternion is 'equal to one'...I don't know the quaternion terms but I think you can see what I'm thinking!) do you specifically mean DzQuat(0,0,0,1), or would DzQuat(0,0,1,0) or DzQuat(0,1,0,0) work ? How about DzQuat(0,0,0.707,0.707) ? (I realize that 0.707 is probably not the right value, but once again I think you can see what I'm thinking)
I meant specifically DzQuat (0, 0, 0, 1).
Generally you use a quaternion with unit length for setting the orientation. DzQuat (0, 1, 0, 0), DzQuat (0.707, 0.707, 0, 0) all have unit lengths, and so they can be used for the orientation. But only one of all those unit-length quaternions (in fact, two, but i do not go into that here) represents the world axis system (like in your original question). As you already know, the w contains the angle of the rotation. To be exact, it contains the cosinus of half the angle. For the world axis system the angle is zero, and the cosinus of zero is one, so the w has to be 1. if It is anything else the rotation would be non-zero. For example if w is zero, like in DzQuat (1, 0, 0, 0), it would be rotated 180 degrees, because the cosinus of 90 (= 180/2) is 0. Rotated around the x-axis in this case.
I meant specifically DzQuat (0, 0, 0, 1).
Generally you use a quaternion with unit length for setting the orientation. DzQuat (0, 1, 0, 0), DzQuat (0.707, 0.707, 0, 0) all have unit lengths, and so they can be used for the orientation. But only one of all those unit-length quaternions (in fact, two, but i do not go into that here) represents the world axis system (like in your original question). As you already know, the w contains the angle of the rotation. To be exact, it contains the cosinus of half the angle. For the world axis system the angle is zero, and the cosinus of zero is one, so the w has to be 1. if It is anything else the rotation would be non-zero. For example if w is zero, like in DzQuat (1, 0, 0, 0), it would be rotated 180 degrees, because the cosinus of 90 (= 180/2) is 0. Rotated around the x-axis in this case.
I think your reply has confused me and enlightened me equally ! :)
Just to be sure - the parameters for DzQuat() are in the order w, x, y, z, yes?
So DzQuat ( w, x, y, z ), correct?
I've also read in allstereo's brief Poser guide to quaternions (Renderosity Freestuff) that w is the cosine of half the rotation angle, so that bit makes sense.
But the following comments puzzle me:
- "I meant specifically DzQuat (0, 0, 0, 1)." ...but since w=0 in this example the rotation angle here is surely 90°?
- "DzQuat (0, 1, 0, 0), DzQuat (0.707, 0.707, 0, 0) all have unit lengths,..." ... the second example has w=0.707, and I would think does not have a unit length?
- "For example if w is zero, like in DzQuat (1, 0, 0, 0),..." ... but w=1 in the example you give here?
Just found a useful bit here http://www.ogre3d.org/tikiwiki/Quaternion+and+Rotation+Primer about a third of the way down, section titled "Some useful (normalized) quaternions"
w x y z Description
1 0 0 0 Identity quaternion, no rotation
0 1 0 0 180° turn around X axis
0 0 1 0 180° turn around Y axis
0 0 0 1 180° turn around Z axis
So I'm guessing the q = DzQuat ( 1, 0, 0, 0 ) is what I need to use in my oProp.setOrientation(q) to ensure the prop axes are aligned with the world axes ?
Strange...
(1,0,0,0) rotated it 180° about the X-axis
(0,1,0,0) rotated it 180° about the Y-axis
(0,0,1,0) rotated it 180° about the Z-axis
(0,0,0,1) left it as it was, aligned with the world axes
It looks as as if it's DzQuat( x, y, z, w ) then ? And that makes all millighost's examples make sense...
Hmmm... looking at the DAZ Script reference I see this
Properties
Number w
Number x
Number y
Number z
Constructors
DzQuat (Number q0, Number q1, Number q2, Number q3)
So I'd clearly just (wrongly) assumed the order was w,x,y,z,....
The mists are beginning to lift... :D