Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. int main()
  2. {
  3. //I want to rotate this vector about the x axis by PI/2 radians:
  4. Quaternion v(0, 1, 0, 0);
  5. v.normalize();
  6.  
  7.  
  8. float angle = PI / 2.0f;
  9. float cos = math::cos(angle / 2.0f);
  10. float sin = math::sin(angle / 2.0f);
  11.  
  12. Quaternion q(1.0f*sin, 0.0f*sin, 0.0f*sin, cos);
  13.  
  14. std::cout << "q not normalized = " <<"t"<< q.x << " " << q.y << " " << q.z << " " << q.w << std::endl;
  15.  
  16. q.normalize();
  17.  
  18. std::cout << "q normalized = " <<"tt"<< q.x << " " << q.y << " " << q.z << " " << q.w << std::endl;
  19. std::cout << std::endl;
  20.  
  21. Quaternion r;
  22.  
  23.  
  24. //I multiply the vector v by the quaternion v, then I multiply by the conjugate.
  25. r = q * v;
  26. //do I need to normalize here?
  27. r = r * q.conjugate();
  28. //and here?
  29.  
  30.  
  31. //shouldn't the resulting vector be 0,0,1?
  32.  
  33. std::cout << "r not normalized = " << "t" << r.x << " " << r.y << " " << r.z << " " << r.w << std::endl;
  34. r.normalize();
  35.  
  36. std::cout << "r normalized = " << "tt" << r.x << " " << r.y << " " << r.z << " " << r.w << std::endl;
  37. std::cout << std::endl;
  38.  
  39. system("pause");
  40. return 0;
  41. }
  42.  
  43. float cos = math::cos(angle / 2.0f);
  44. float sin = math::sin(angle / 2.0f);
  45.  
  46. float cos = math::cos(angle);
  47. float sin = math::sin(angle);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement