Advertisement
BDawgz

Untitled

Oct 22nd, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. if (collision){
  2.  
  3. float xx, yy, zz;
  4. xx = 2.0 / 5.0 * (fMass * fRadius * fRadius);
  5. yy = xx;
  6. zz = xx;// only this way since a sphere is same from all angles
  7.  
  8. glm::mat3 ballInertia;
  9.  
  10. ballInertia[0][0] = xx;
  11. ballInertia[1][1] = yy;
  12. ballInertia[2][2] = zz;
  13.  
  14. glm::mat3 I_ballInertia = glm::inverse(ballInertia);
  15.  
  16. std::cout << glm::mat4(ballInertia);
  17. //variables to get J
  18.  
  19.  
  20. //getting rotation matrix
  21.  
  22. float e = 1;
  23. btVector3 contactNormal;
  24. float vRel;
  25. glm::vec3 r1, r2;
  26.  
  27. contactNormal = vPosition[1] - vPosition[0];
  28. contactNormal.normalize();
  29.  
  30. vRel = contactNormal.dot(vVelocity[0] - vVelocity[1]);
  31.  
  32. //just cause im switching from bt math classes to glm
  33. glm::vec3 n = glm::vec3(contactNormal.getX(), contactNormal.getY(), contactNormal.getZ());
  34.  
  35. r1 = n * fRadius;
  36. r2 = -r1;
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. float topPart = -vRel * (e + 1);
  44.  
  45. float bottomFirst = 1 / fMass + 1 / fMass;
  46.  
  47. float bottomMiddle = glm::dot(n, (glm::cross(I_ballInertia * (glm::cross(r1, n)), r1)));
  48. float bottomLast = glm::dot(n, (glm::cross(I_ballInertia * (glm::cross(r2, n)), r2)));
  49.  
  50.  
  51. float J = topPart / (bottomFirst + bottomMiddle + bottomLast);
  52.  
  53. glm::vec3 tempVel = glm::vec3(vVelocity[0].getX(), vVelocity[0].getY(), vVelocity[0].getZ());
  54.  
  55. glm::vec3 temp = tempVel + (J * n) / fMass;
  56.  
  57. vVelocity[0] = btVector3(temp.x, temp.y, temp.z);
  58.  
  59.  
  60. tempVel = glm::vec3(vVelocity[1].getX(), vVelocity[1].getY(), vVelocity[1].getZ());
  61.  
  62. temp = tempVel + (-J * n) / fMass;
  63.  
  64. vVelocity[1] = btVector3(temp.x, temp.y, temp.z);
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement