1

I am trying to rotate a vector based on another orientation vector. Elsewhere in the code, this works fine. But here, it fails and Boost complains about an operator error.

  // (Assume these vectors are filled with useful values)
  boost::qvm::vec<double, 3> aspectVec;
  boost::qvm::vec<double, 3> orientation;

  // Rotate aspect into world coords
  // Note, orientation already in radians
  auto rot = boost::qvm::rot_mat_zyx<3>( orientation.a[2],
                                         orientation.a[1],
                                         orientation.a[0]);

  boost::qvm::vec<double, 3> aspectRotated;
  aspectRotated = boost::qvm::normalized(rot * aspectVec);

The specific error I get is:

myfile.cpp:391: error: no match for ‘operator*’ (operand types are ‘boost::qvm::qvm_detail::rot_mat_<3, double>’ and ‘boost::qvm::vec<double, 3>’)
  391 |   aspectRotated = boost::qvm::normalized(rot * aspectVec);
      |                                          ~~~ ^ ~~~~~~~~~
      |                                          |     |
      |                                          |     boost::qvm::vec<double, 3>
      |                                          boost::qvm::qvm_detail::rot_mat_<3, double>

But I don't understand why. In another file, I have an identical line and it works flawlessly. I'm wondering if it's somehow a missing include? I have both ones I thought were relevant:

#include <boost/qvm/mat_operations.hpp>
#include <boost/qvm/vec_operations.hpp>

1 Answer 1

2

The issue was the includes. I noticed they were the only difference in the code between the two files. I swapped out:

#include <boost/qvm/mat_operations.hpp>
#include <boost/qvm/vec_operations.hpp>

For:

#include <boost/qvm/all.hpp>

And the problem went away. I'm not really sure why, but it did. I don't like including more than necessary, so if anyone knows a sub-set of this that is more appropriate, please let me know.

1
  • including unnecessary template definitions don't affect the compiled executable at all. You have to remember that templates require instantiation and until they are instantiated they aren't part of the executable generated by the compiler. Compile times? Yea, they might make it take a little longer to compile the code, but in my experience, it's only noticeable on large code bases.
    – Jonathan
    Jun 27, 2022 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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