MCPcopy Create free account
hub / github.com/axmolengine/axmol / syncNodeToPhysics

Method syncNodeToPhysics

core/physics3d/Physics3DComponent.cpp:215–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215void Physics3DComponent::syncNodeToPhysics()
216{
217 if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY ||
218 _physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::COLLIDER)
219 {
220 auto mat = _owner->getNodeToWorldTransform();
221 // remove scale, no scale support for physics
222 float oneOverLen = 1.f / sqrtf(mat.m[0] * mat.m[0] + mat.m[1] * mat.m[1] + mat.m[2] * mat.m[2]);
223 mat.m[0] *= oneOverLen;
224 mat.m[1] *= oneOverLen;
225 mat.m[2] *= oneOverLen;
226 oneOverLen = 1.f / sqrtf(mat.m[4] * mat.m[4] + mat.m[5] * mat.m[5] + mat.m[6] * mat.m[6]);
227 mat.m[4] *= oneOverLen;
228 mat.m[5] *= oneOverLen;
229 mat.m[6] *= oneOverLen;
230 oneOverLen = 1.f / sqrtf(mat.m[8] * mat.m[8] + mat.m[9] * mat.m[9] + mat.m[10] * mat.m[10]);
231 mat.m[8] *= oneOverLen;
232 mat.m[9] *= oneOverLen;
233 mat.m[10] *= oneOverLen;
234
235 mat *= _invTransformInPhysics;
236 if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
237 {
238 auto body = static_cast<Physics3DRigidBody*>(_physics3DObj)->getRigidBody();
239 auto motionState = body->getMotionState();
240 motionState->setWorldTransform(convertMat4TobtTransform(mat));
241 body->setMotionState(motionState);
242 }
243 else if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::COLLIDER)
244 {
245 auto object = static_cast<Physics3DCollider*>(_physics3DObj)->getGhostObject();
246 object->setWorldTransform(convertMat4TobtTransform(mat));
247 }
248 }
249}
250
251}
252

Calls 6

convertMat4TobtTransformFunction · 0.85
getRigidBodyMethod · 0.80
getMotionStateMethod · 0.80
setMotionStateMethod · 0.80
getGhostObjectMethod · 0.80

Tested by 2

shootBoxMethod · 0.36
initMethod · 0.36