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

Method syncPhysicsToNode

core/physics3d/Physics3DComponent.cpp:181–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179}
180
181void Physics3DComponent::syncPhysicsToNode()
182{
183 if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY ||
184 _physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::COLLIDER)
185 {
186 Mat4 parentMat;
187 if (_owner->getParent())
188 parentMat = _owner->getParent()->getNodeToWorldTransform();
189
190 auto mat = parentMat.getInversed() * _physics3DObj->getWorldTransform();
191 // remove scale, no scale support for physics
192 float oneOverLen = 1.f / sqrtf(mat.m[0] * mat.m[0] + mat.m[1] * mat.m[1] + mat.m[2] * mat.m[2]);
193 mat.m[0] *= oneOverLen;
194 mat.m[1] *= oneOverLen;
195 mat.m[2] *= oneOverLen;
196 oneOverLen = 1.f / sqrtf(mat.m[4] * mat.m[4] + mat.m[5] * mat.m[5] + mat.m[6] * mat.m[6]);
197 mat.m[4] *= oneOverLen;
198 mat.m[5] *= oneOverLen;
199 mat.m[6] *= oneOverLen;
200 oneOverLen = 1.f / sqrtf(mat.m[8] * mat.m[8] + mat.m[9] * mat.m[9] + mat.m[10] * mat.m[10]);
201 mat.m[8] *= oneOverLen;
202 mat.m[9] *= oneOverLen;
203 mat.m[10] *= oneOverLen;
204
205 mat *= _transformInPhysics;
206 static Vec3 scale, translation;
207 static Quaternion quat;
208 mat.decompose(&scale, &quat, &translation);
209 _owner->setPosition3D(translation);
210 quat.normalize();
211 _owner->setRotationQuat(quat);
212 }
213}
214
215void Physics3DComponent::syncNodeToPhysics()
216{

Calls 8

getWorldTransformMethod · 0.80
getParentMethod · 0.45
getInversedMethod · 0.45
decomposeMethod · 0.45
setPosition3DMethod · 0.45
normalizeMethod · 0.45
setRotationQuatMethod · 0.45

Tested by

no test coverage detected