Swap two components in the array
| 303 | |
| 304 | // Swap two components in the array |
| 305 | void RigidBodyComponents::swapComponents(uint32 index1, uint32 index2) { |
| 306 | |
| 307 | // Copy component 1 data |
| 308 | Entity entity1(mBodiesEntities[index1]); |
| 309 | RigidBody* body1 = mRigidBodies[index1]; |
| 310 | bool isAllowedToSleep1 = mIsAllowedToSleep[index1]; |
| 311 | bool isSleeping1 = mIsSleeping[index1]; |
| 312 | decimal sleepTime1 = mSleepTimes[index1]; |
| 313 | BodyType bodyType1 = mBodyTypes[index1]; |
| 314 | Vector3 linearVelocity1(mLinearVelocities[index1]); |
| 315 | Vector3 angularVelocity1(mAngularVelocities[index1]); |
| 316 | Vector3 externalForce1(mExternalForces[index1]); |
| 317 | Vector3 externalTorque1(mExternalTorques[index1]); |
| 318 | decimal linearDamping1 = mLinearDampings[index1]; |
| 319 | decimal angularDamping1 = mAngularDampings[index1]; |
| 320 | decimal mass1 = mMasses[index1]; |
| 321 | decimal inverseMass1 = mInverseMasses[index1]; |
| 322 | Vector3 inertiaTensorLocal1 = mLocalInertiaTensors[index1]; |
| 323 | Vector3 inertiaTensorLocalInverse1 = mInverseInertiaTensorsLocal[index1]; |
| 324 | Matrix3x3 inertiaTensorWorldInverse1 = mInverseInertiaTensorsWorld[index1]; |
| 325 | Vector3 constrainedLinearVelocity1(mConstrainedLinearVelocities[index1]); |
| 326 | Vector3 constrainedAngularVelocity1(mConstrainedAngularVelocities[index1]); |
| 327 | Vector3 splitLinearVelocity1(mSplitLinearVelocities[index1]); |
| 328 | Vector3 splitAngularVelocity1(mSplitAngularVelocities[index1]); |
| 329 | Vector3 constrainedPosition1 = mConstrainedPositions[index1]; |
| 330 | Quaternion constrainedOrientation1 = mConstrainedOrientations[index1]; |
| 331 | Vector3 centerOfMassLocal1 = mCentersOfMassLocal[index1]; |
| 332 | Vector3 centerOfMassWorld1 = mCentersOfMassWorld[index1]; |
| 333 | bool isGravityEnabled1 = mIsGravityEnabled[index1]; |
| 334 | bool isAlreadyInIsland1 = mIsAlreadyInIsland[index1]; |
| 335 | Array<Entity> joints1 = mJoints[index1]; |
| 336 | Array<uint> contactPairs1 = mContactPairs[index1]; |
| 337 | Vector3 linearLockAxisFactor1(mLinearLockAxisFactors[index1]); |
| 338 | Vector3 angularLockAxisFactor1(mAngularLockAxisFactors[index1]); |
| 339 | |
| 340 | // Destroy component 1 |
| 341 | destroyComponent(index1); |
| 342 | |
| 343 | moveComponentToIndex(index2, index1); |
| 344 | |
| 345 | // Reconstruct component 1 at component 2 location |
| 346 | new (mBodiesEntities + index2) Entity(entity1); |
| 347 | mRigidBodies[index2] = body1; |
| 348 | mIsAllowedToSleep[index2] = isAllowedToSleep1; |
| 349 | mIsSleeping[index2] = isSleeping1; |
| 350 | mSleepTimes[index2] = sleepTime1; |
| 351 | mBodyTypes[index2] = bodyType1; |
| 352 | new (mLinearVelocities + index2) Vector3(linearVelocity1); |
| 353 | new (mAngularVelocities + index2) Vector3(angularVelocity1); |
| 354 | new (mExternalForces + index2) Vector3(externalForce1); |
| 355 | new (mExternalTorques + index2) Vector3(externalTorque1); |
| 356 | mLinearDampings[index2] = linearDamping1; |
| 357 | mAngularDampings[index2] = angularDamping1; |
| 358 | mMasses[index2] = mass1; |
| 359 | mInverseMasses[index2] = inverseMass1; |
| 360 | mLocalInertiaTensors[index2] = inertiaTensorLocal1; |
| 361 | mInverseInertiaTensorsLocal[index2] = inertiaTensorLocalInverse1; |
| 362 | mInverseInertiaTensorsWorld[index2] = inertiaTensorWorldInverse1; |