| 135 | } |
| 136 | |
| 137 | Joint* Joint::spring( |
| 138 | bool collideConnected, |
| 139 | Body* bodyA, |
| 140 | Body* bodyB, |
| 141 | Vec2 linearOffset, |
| 142 | float angularOffset, |
| 143 | float maxForce, |
| 144 | float maxTorque, |
| 145 | float correctionFactor) { |
| 146 | if (bodyA->getPhysicsWorld() != bodyB->getPhysicsWorld()) { |
| 147 | return nullptr; |
| 148 | } |
| 149 | pr::BodyID bA = bodyA->getPrBody(); |
| 150 | pr::BodyID bB = bodyB->getPrBody(); |
| 151 | auto world = bodyA->getPhysicsWorld(); |
| 152 | if (!world || !world->getPrWorld()) { |
| 153 | return nullptr; |
| 154 | } |
| 155 | auto& prWorld = *world->getPrWorld(); |
| 156 | Joint* joint = Joint::create(); |
| 157 | maxForce = std::max(maxForce, 0.0f); |
| 158 | maxTorque = std::max(maxTorque, 0.0f); |
| 159 | correctionFactor = std::clamp(correctionFactor, 0.0f, 1.0f); |
| 160 | joint->_world = world; |
| 161 | joint->_joint = pd::CreateJoint(prWorld, |
| 162 | pd::MotorJointConf{bA, bB} |
| 163 | .UseLinearOffset(PhysicsWorld::prVal(linearOffset)) |
| 164 | .UseAngularOffset(-bx::toRad(angularOffset)) |
| 165 | .UseMaxForce(maxForce) |
| 166 | .UseMaxTorque(maxTorque) |
| 167 | .UseCorrectionFactor(correctionFactor) |
| 168 | .UseCollideConnected(collideConnected)); |
| 169 | world->setJointData(joint->_joint, joint); |
| 170 | return joint; |
| 171 | } |
| 172 | |
| 173 | MoveJoint* Joint::move( |
| 174 | bool collideConnected, |
nothing calls this directly
no test coverage detected