So, I have an object in my custom engine (C++), with a column-major transform in world space. I'm using a package that takes a look-at direction as an input. What's the most efficient way to get a look-at direction from this transform? Do I extract the rotation matrix? Do I try to extract a quaternion?

  • \$\begingroup\$ Presumably you tried just multiplying your forward direction (eg (0, 0, 1, 0) if your convention is that z+ is the forward axis) by your matrix or quaternion? Do the results you get that way differ from what you need? \$\endgroup\$ – DMGregory Oct 27 '20 at 23:07
  • 1
    \$\begingroup\$ The columns of the matrix are the basis vectors of the transformed space (expressed in untransformed coordinates), so you only need to extract the column that points to the look-at object. A way to do that is to just multiply by a vector from the standard basis, e.g. as DMGregory suggested, (0, 0, 1, 0) picks out just the third column (you can try it on paper to see why). \$\endgroup\$ – Filip Milovanović Oct 27 '20 at 23:32
  • \$\begingroup\$ @DMGregory They do not, I was just wondering if there was a more efficient way. Just pulling out the third column directly might save me some clock cycles! \$\endgroup\$ – Danny Oct 28 '20 at 1:33
  • \$\begingroup\$ If grabbing the third column gets what you need, I'd encourage you or @FilipMilovanović to post that as an Answer below. 🙂 \$\endgroup\$ – DMGregory Oct 28 '20 at 1:43
  • \$\begingroup\$ BTW, by column I mean the column in the convention where you multiply a matrix on the left via a column vector on the right (in the mathematical notation). There's also a convention where a row vector on the left is multiplied by a matrix on the right, in which case (0, 0, 1, 0) gets you the 3rd row in the matrix. This is independent from how you store the matrix (row-major vs column-major), so this complicates things - what you need is in the opposite direction of the way you go when you're calculating a particular component of the result. \$\endgroup\$ – Filip Milovanović Oct 28 '20 at 1:58

Your Answer

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

Browse other questions tagged or ask your own question.