MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / spring

Method spring

Source/Physics/Joint.cpp:137–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135}
136
137Joint* 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
173MoveJoint* Joint::move(
174 bool collideConnected,

Callers

nothing calls this directly

Calls 10

toRadFunction · 0.85
getPrBodyMethod · 0.80
getPrWorldMethod · 0.80
UseCollideConnectedMethod · 0.80
setJointDataMethod · 0.80
createFunction · 0.50
maxFunction · 0.50
clampFunction · 0.50
CreateJointFunction · 0.50
getPhysicsWorldMethod · 0.45

Tested by

no test coverage detected