Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. float dotProduct(const vec4& v, const vec4& k){
  2. return v.v[0]*k.v[0] + v.v[1]*k.v[1] + v.v[2] * k.v[2];
  3. }
  4.  
  5. vec4 crossProduct(const vec4& v, const vec4& k){
  6. vec4 result(0,0,0,1);
  7. result.v[0] = (v.v[1]*k.v[2])-(v.v[2]*k.v[1]);
  8. result.v[1] = -((v.v[0]*k.v[2]) - (v.v[2]*k.v[0]));
  9. result.v[2] = (v.v[0]*k.v[1]) - (v.v[1]*k.v[0]);
  10.  
  11. return result;
  12. }
  13.  
  14. vec4 floatMultiply(const vec4& v, float f){
  15. vec4 return_v = v;
  16. return_v.v[0] *= f;
  17. return_v.v[1] *= f;
  18. return_v.v[2] *= f;
  19.  
  20. return return_v;
  21. }
  22.  
  23. vec4 RodriguesRot(const vec4& r, float theta){
  24.  
  25. //w a forgatasi tengely
  26. vec4 w(1,0,0,1);
  27.  
  28. float dotResult = dotProduct(w,r);
  29.  
  30. vec4 rotated_r = r;
  31. rotated_r = rotated_r.v[0] * cosf(theta) + rotated_r.v[1] * cosf(theta);
  32.  
  33. vec4 temp1 = floatMultiply(floatMultiply(w,dotResult),1-cosf(theta));
  34. vec4 temp2 = floatMultiply(crossProduct(w,r),sinf(theta));
  35.  
  36. rotated_r.v[0] = rotated_r.v[0] + temp1.v[0] + temp2.v[0];
  37. rotated_r.v[1] = rotated_r.v[1] + temp1.v[1] + temp2.v[1];
  38. rotated_r.v[2] = rotated_r.v[2] + temp1.v[2] + temp2.v[2];
  39.  
  40. return rotated_r;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement