The code below is for a rag-doll using Verlet method, I have the correct points (or joints) positions, I just need the correct Quaternions, otherwise the resulting model looks like in the picture, I'm constraining the body to the bind pose on purpose for testing purposes.

Based on the two points, their position and quaternion, what will the new Quaternion be for each translated point?

struct Point
    XMVECTOR position = { 0,0,0 };
    XMVECTOR quaternion = { 0,0,0,-1 };

Point p1;
Point p2;

p1.position += { 0.0f,0.3f, 0.1f };
p2.position += { -1.0,0.3f,0.1f };

Vertices are all messed up, Im constraining the body to the bind pose on purpose

  • \$\begingroup\$ I think in order to answer this, we'd need to know the expected orientations of each bone (eg. "the thigh bone's z+ axis points toward the knee and its y+ axis points forward"). For some situations you might need more than two points to decide the orientation of the bone — for instance, to pick the forward direction of the thigh we might want to know which way the shin is pointing — otherwise we might introduce an unnatural twist at the knee. \$\endgroup\$ – DMGregory Sep 15 '17 at 11:19
  • \$\begingroup\$ Most of the joints in the bindpose have a quaternion of ( 0,0,0,-1), I construct the matrix and send it to the shaders for skinned animations, the model animates perfectly. But when I try to apply ragdoll the joint positions are ok, its the quaternions that are not ok , I do not know how to fix the quaternions after translating two points at a time. \$\endgroup\$ – Surface Sep 15 '17 at 18:33
  • \$\begingroup\$ Quaternions don't do translation - they're for rotation only. \$\endgroup\$ – Maximus Minimus Apr 15 '19 at 13:18

I think you're confusing Quaternions with Euler angles. Euler angles are 3 variables that give you pitch (x), yaw (y), and roll (z) ... and are probably easiest for the brain to comprehend intuitively as each variable has a very specific function. There are downsides to it, so most games use Quaternions to overcome this. Quaternions have 4 variables, and while each variable is a bit more complex than this explanation, 3 of the variables will give you a vector, otherwise seen as the pitch and roll of your orientation, and the last rotates around that vector to give you a roll.

So I'm not entirely sure what you're trying to do from the image, mathematically at least. However, thebennybox has a great video on understanding Quaternions here, and you can see him coding all the math for calculating Quaternions here.

However, if you simply want to move something along an orientation:

void movePosxAxis(const glm::vec3 &n_pos) { placement.m_pos += n_pos * placement.m_orient; }

That's just C++, but basically broken down: Act like your object is axis aligned, and add to it the value of the movement along xyz that you want multiplied to the object's orientation (quaternion) -- any good math library that handles quaternions should handle vec3 * quat equations.

  • \$\begingroup\$ The description of what the components of the quaternion represent is not correct. The three imaginary components represent the axis of rotation, scaled by the sine of half the angle of rotation. The real component is the cosine of half the angle of rotation. So quaternions representing 180 degrees of pitch, yaw, and roll would be (1,0,0,0), (0,1,0,0), and (0,0,1,0) respectively, and "no rotation" would be (0,0,0,1). A 180 degree rotation about a diagonal axis running 45 degrees between the x and y axes would be (1/sqrt(2),1/sqrt(2),0,0) \$\endgroup\$ – DMGregory Sep 15 '17 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.