| 246 | } |
| 247 | |
| 248 | void Physics::registerVehicle(std::shared_ptr<Car> &car) { |
| 249 | cars.emplace_back(car); |
| 250 | |
| 251 | btVector3 wheelDirectionCS0(0, -1, 0); |
| 252 | btVector3 wheelAxleCS(-1, 0, 0); |
| 253 | float wheelRadius = car->getWheelRadius(); |
| 254 | float wheelWidth = car->getWheelWidth(); |
| 255 | btScalar sRestLength = car->getSuspensionRestLength(); |
| 256 | |
| 257 | dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(car->getVehicleRigidBody()->getBroadphaseHandle(), dynamicsWorld->getDispatcher()); |
| 258 | |
| 259 | dynamicsWorld->addRigidBody(car->getVehicleRigidBody(), COL_CAR, COL_TRACK| COL_RAY); |
| 260 | car->m_vehicleRayCaster = new btDefaultVehicleRaycaster(dynamicsWorld); |
| 261 | car->m_vehicle = new btRaycastVehicle(car->m_tuning, car->getVehicleRigidBody(), car->getRaycaster()); |
| 262 | car->getVehicleRigidBody()->setActivationState(DISABLE_DEACTIVATION); |
| 263 | dynamicsWorld->addVehicle(car->m_vehicle); |
| 264 | car->getRaycast()->setCoordinateSystem(0, 1, 2); |
| 265 | |
| 266 | // Wire up the wheels |
| 267 | // Fronties |
| 268 | btVector3 connectionPointCS0(Utils::glmToBullet(car->left_front_wheel_model.position)); |
| 269 | car->getRaycast()->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, sRestLength, wheelRadius, car->m_tuning, true); |
| 270 | connectionPointCS0 = btVector3(Utils::glmToBullet(car->right_front_wheel_model.position)); |
| 271 | car->getRaycast()->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, sRestLength, wheelRadius, car->m_tuning, true); |
| 272 | // Rearies |
| 273 | connectionPointCS0 = btVector3(Utils::glmToBullet(car->left_rear_wheel_model.position)); |
| 274 | car->getRaycast()->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, sRestLength, wheelRadius, car->m_tuning, false); |
| 275 | connectionPointCS0 = btVector3(Utils::glmToBullet(car->right_rear_wheel_model.position)); |
| 276 | car->getRaycast()->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, sRestLength, wheelRadius, car->m_tuning, false); |
| 277 | |
| 278 | for (int i = 0; i < car->getRaycast()->getNumWheels(); i++) { |
| 279 | btWheelInfo &wheel = car->getRaycast()->getWheelInfo(i); |
| 280 | wheel.m_suspensionStiffness = car->getSuspensionStiffness(); |
| 281 | wheel.m_wheelsDampingRelaxation = car->getSuspensionDamping(); |
| 282 | wheel.m_wheelsDampingCompression = car->getSuspensionCompression(); |
| 283 | wheel.m_frictionSlip = car->getWheelFriction(); |
| 284 | wheel.m_rollInfluence = car->getRollInfluence(); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | Physics::Physics() { |
| 289 | initSimulation(); |
no test coverage detected