Author Topic: How do I rotate an axis-angle around a normal vector?  (Read 1252 times)

Tried it right after I posted but no dice unfortunately. Are we sure axis-angles and quaternions are the same thing lol? I always thought axis-angles were the relatively simple concept that you explained but quats were terrifying theoretical 4d math cones or something
my understanding is that quats were axis angles but with then angle in radians, but given irrel's last post thats clearly not the case.

Forgot to respond: Unfortunately the updated function didn't work either.

can you provide some details as to what's going wrong? or let me join your server? i'm likely misinterpreting something, and oversimplifying

It's pretty difficult to explain, I tried doing it on a bunch of different surfaces but I couldn't find any patterns.

Essentially the static shape is created via a function that is fed a position and a brick normal
Code: [Select]
%rotation = normal2Rotation(%normal);

%explosive = new StaticShape()
datablock = C4PlacedStaticShape;
position = %position;
rotation = %rotation;
normal = %normal;
sourceObject = %source;
client = %source.client;

The initial axis-angle rotation of the shape is supplied by the first line there. Note that if you were to call %explosive.setTransform(%explosive.getPosition() SPC %rotation), I'm pretty sure the result would be inaccurate, because I believe one is supposed to be in radians while the other is in degrees?

Anyways at this point I'd get the transform and attempt to rotate it again like this:

Code: [Select]
%rotation = getWords(%explosive.getTransform(), 3, 6);
%rot1 = %rotation;
%rot2 = %normal SPC mDegToRad(90);
%rotation = combineAxisAngleRotations(%rot1, %rot2);
%explosive.setTransform(%explosive.getPosition() SPC %rotation);

I tried calling it with arguments in both orders to no avail, and I also tried adjusting the rotation before the shape is instantiated, as well as with and without mDegToRad(). The second rotation is created using the normal of the brick the shape is sitting on, and then just an arbitrary rotation of 90 degrees for testing purposes.

I keep reading lots of different things about quaternions and axis-angle representations, and they are definitely different. There appears to be multiple ways to convert between the two, so I'll keep reading and try to find the best one.
Do the rotations result in the shape still being normal to the face, or no?

EDIT: I feel a little stupid now. Just realized I should be doing vector addition. Replace
Code: [Select]
%quatCombined = %quatAngle1 * %quatAngle2 - vectorDot(%quatVector1, %quatVector2) SPC vectorScale(%quatVector2, %quatAngle1) + vectorScale(%quatVector1, %quatAngle2) + vectorCross(%quatVector1, %quatVector2);with
Code: [Select]
%quatCombined = %quatAngle1 * %quatAngle2 - vectorDot(%quatVector1, %quatVector2) SPC vectorAdd(vectorAdd(vectorScale(%quatVector2, %quatAngle1), vectorScale(%quatVector1, %quatAngle2)), vectorCross(%quatVector1, %quatVector2));
« Last Edit: May 17, 2018, 08:10:47 PM by irrel »

You should just be able to use MatrixMultiply("0 0 0 a1 a2 a3 a4", "0 0 0 b1 b2 b3 b4") to get a transform (translation, rotation axis, rotation angle) that applies both a and b

Glad I was able to help even with my odd solution!