| 61 | } |
| 62 | |
| 63 | btCollisionShape *Physics::buildFrustumShape() { |
| 64 | float m_ScreenHeight = 768; |
| 65 | float m_ScreenWidth = 1024; |
| 66 | |
| 67 | const btScalar nearPlane = 1.0f; |
| 68 | const btScalar farPlane = 1000.0; |
| 69 | |
| 70 | const btScalar planesFraction = farPlane / nearPlane; |
| 71 | const btScalar centralPlane = (farPlane - nearPlane) * 0.5; // Actually it's the center of the collision shape. |
| 72 | btScalar left, right, bottom, top, farLeft, farRight, farBottom, farTop; |
| 73 | const btScalar aspect = (btScalar) m_ScreenWidth / (btScalar) m_ScreenHeight; |
| 74 | if (m_ScreenWidth > m_ScreenHeight) { |
| 75 | left = -aspect; |
| 76 | right = aspect; |
| 77 | bottom = -1.0; |
| 78 | top = 1.0; |
| 79 | } else { |
| 80 | left = -1.0; |
| 81 | right = 1.0; |
| 82 | bottom = -aspect; |
| 83 | top = aspect; |
| 84 | } |
| 85 | farLeft = left * planesFraction; |
| 86 | farRight = right * planesFraction; |
| 87 | farBottom = bottom * planesFraction; |
| 88 | farTop = top * planesFraction; |
| 89 | |
| 90 | btConvexHullShape *shape = new btConvexHullShape(); |
| 91 | |
| 92 | // Add the frustum points |
| 93 | { |
| 94 | btVector3 points[8] = { |
| 95 | btVector3(left, top, centralPlane), |
| 96 | btVector3(right, top, centralPlane), |
| 97 | btVector3(left, bottom, centralPlane), |
| 98 | btVector3(right, bottom, centralPlane), |
| 99 | |
| 100 | btVector3(farLeft, farTop, -centralPlane), |
| 101 | btVector3(farRight, farTop, -centralPlane), |
| 102 | btVector3(farLeft, farBottom, -centralPlane), |
| 103 | btVector3(farRight, farBottom, -centralPlane), |
| 104 | }; |
| 105 | |
| 106 | for (int t = 0; t < 8; t++) { |
| 107 | shape->addPoint(points[t]); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // Crashes OpenNFS with a frustum thats actually frustum shaped, use a box for now. |
| 112 | /*btCompoundShape *frustumShape = new btCompoundShape(); |
| 113 | const btVector3 v(0., 0., -(nearPlane + centralPlane)); |
| 114 | const btQuaternion q = btQuaternion::getIdentity();// = btQuaternion::getIdentity();//(btVector3(0.,1.,0.),btRadians(180)); |
| 115 | btTransform T(q, v); |
| 116 | frustumShape->addChildShape(T.inverse(), shape); */ |
| 117 | btBoxShape *frustumShape = new btBoxShape(btVector3(2, 2, 2)); |
| 118 | |
| 119 | return frustumShape; |
| 120 | } |
nothing calls this directly
no outgoing calls
no test coverage detected