MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / moveComponentToIndex

Method moveComponentToIndex

src/components/RigidBodyComponents.cpp:256–302  ·  view source on GitHub ↗

Move a component from a source to a destination index in the components array The destination location must contain a constructed object

Source from the content-addressed store, hash-verified

254// Move a component from a source to a destination index in the components array
255// The destination location must contain a constructed object
256void RigidBodyComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex) {
257
258 const Entity entity = mBodiesEntities[srcIndex];
259
260 // Copy the data of the source component to the destination location
261 new (mBodiesEntities + destIndex) Entity(mBodiesEntities[srcIndex]);
262 mRigidBodies[destIndex] = mRigidBodies[srcIndex];
263 mIsAllowedToSleep[destIndex] = mIsAllowedToSleep[srcIndex];
264 mIsSleeping[destIndex] = mIsSleeping[srcIndex];
265 mSleepTimes[destIndex] = mSleepTimes[srcIndex];
266 mBodyTypes[destIndex] = mBodyTypes[srcIndex];
267 new (mLinearVelocities + destIndex) Vector3(mLinearVelocities[srcIndex]);
268 new (mAngularVelocities + destIndex) Vector3(mAngularVelocities[srcIndex]);
269 new (mExternalForces + destIndex) Vector3(mExternalForces[srcIndex]);
270 new (mExternalTorques + destIndex) Vector3(mExternalTorques[srcIndex]);
271 mLinearDampings[destIndex] = mLinearDampings[srcIndex];
272 mAngularDampings[destIndex] = mAngularDampings[srcIndex];
273 mMasses[destIndex] = mMasses[srcIndex];
274 mInverseMasses[destIndex] = mInverseMasses[srcIndex];
275 new (mLocalInertiaTensors + destIndex) Vector3(mLocalInertiaTensors[srcIndex]);
276 new (mInverseInertiaTensorsLocal + destIndex) Vector3(mInverseInertiaTensorsLocal[srcIndex]);
277 new (mInverseInertiaTensorsWorld + destIndex) Matrix3x3(mInverseInertiaTensorsWorld[srcIndex]);
278 new (mConstrainedLinearVelocities + destIndex) Vector3(mConstrainedLinearVelocities[srcIndex]);
279 new (mConstrainedAngularVelocities + destIndex) Vector3(mConstrainedAngularVelocities[srcIndex]);
280 new (mSplitLinearVelocities + destIndex) Vector3(mSplitLinearVelocities[srcIndex]);
281 new (mSplitAngularVelocities + destIndex) Vector3(mSplitAngularVelocities[srcIndex]);
282 new (mConstrainedPositions + destIndex) Vector3(mConstrainedPositions[srcIndex]);
283 new (mConstrainedOrientations + destIndex) Quaternion(mConstrainedOrientations[srcIndex]);
284 new (mCentersOfMassLocal + destIndex) Vector3(mCentersOfMassLocal[srcIndex]);
285 new (mCentersOfMassWorld + destIndex) Vector3(mCentersOfMassWorld[srcIndex]);
286 mIsGravityEnabled[destIndex] = mIsGravityEnabled[srcIndex];
287 mIsAlreadyInIsland[destIndex] = mIsAlreadyInIsland[srcIndex];
288 new (mJoints + destIndex) Array<Entity>(mJoints[srcIndex]);
289 new (mContactPairs + destIndex) Array<uint>(mContactPairs[srcIndex]);
290 new (mLinearLockAxisFactors + destIndex) Vector3(mLinearLockAxisFactors[srcIndex]);
291 new (mAngularLockAxisFactors + destIndex) Vector3(mAngularLockAxisFactors[srcIndex]);
292
293 // Destroy the source component
294 destroyComponent(srcIndex);
295
296 assert(!mMapEntityToComponentIndex.containsKey(entity));
297
298 // Update the entity to component index mapping
299 mMapEntityToComponentIndex.add(Pair<Entity, uint32>(entity, destIndex));
300
301 assert(mMapEntityToComponentIndex[mBodiesEntities[destIndex]] == destIndex);
302}
303
304// Swap two components in the array
305void RigidBodyComponents::swapComponents(uint32 index1, uint32 index2) {

Callers

nothing calls this directly

Calls 2

containsKeyMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected