Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (collision){
- float xx, yy, zz;
- xx = 2.0 / 5.0 * (fMass * fRadius * fRadius);
- yy = xx;
- zz = xx;// only this way since a sphere is same from all angles
- glm::mat3 ballInertia;
- ballInertia[0][0] = xx;
- ballInertia[1][1] = yy;
- ballInertia[2][2] = zz;
- glm::mat3 I_ballInertia = glm::inverse(ballInertia);
- std::cout << glm::mat4(ballInertia);
- //variables to get J
- //getting rotation matrix
- float e = 1;
- btVector3 contactNormal;
- float vRel;
- glm::vec3 r1, r2;
- contactNormal = vPosition[1] - vPosition[0];
- contactNormal.normalize();
- vRel = contactNormal.dot(vVelocity[0] - vVelocity[1]);
- //just cause im switching from bt math classes to glm
- glm::vec3 n = glm::vec3(contactNormal.getX(), contactNormal.getY(), contactNormal.getZ());
- r1 = n * fRadius;
- r2 = -r1;
- float topPart = -vRel * (e + 1);
- float bottomFirst = 1 / fMass + 1 / fMass;
- float bottomMiddle = glm::dot(n, (glm::cross(I_ballInertia * (glm::cross(r1, n)), r1)));
- float bottomLast = glm::dot(n, (glm::cross(I_ballInertia * (glm::cross(r2, n)), r2)));
- float J = topPart / (bottomFirst + bottomMiddle + bottomLast);
- glm::vec3 tempVel = glm::vec3(vVelocity[0].getX(), vVelocity[0].getY(), vVelocity[0].getZ());
- glm::vec3 temp = tempVel + (J * n) / fMass;
- vVelocity[0] = btVector3(temp.x, temp.y, temp.z);
- tempVel = glm::vec3(vVelocity[1].getX(), vVelocity[1].getY(), vVelocity[1].getZ());
- temp = tempVel + (-J * n) / fMass;
- vVelocity[1] = btVector3(temp.x, temp.y, temp.z);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement