private void updateLocalTransform() { localTransform = parent.transform(); Matrix4f ms = new Matrix4f(); ms.setIdentity(); Vector3f ps = parent.scale(); ms.m00 = ps.x; ms.m11 = ps.y; ms.m22 = ps.z; localTransform.mul(ms); localTransform.invert(); localTransform.mul(transform()); }
public void updateChildTransforms() { Matrix4f pt = transform(); Matrix4f ct = new Matrix4f(); Matrix4f ms = new Matrix4f(); ms.setIdentity(); Vector3f ps = scale(); ms.m00 = ps.x; ms.m11 = ps.y; ms.m22 = ps.z; pt.mul(ms); for (GameObject c : children) { ct.mul(pt, c.localTransform); c.transform(ct, false); } }
public void scale(float x, float y, float z, boolean updateLocal) { activate(); // Set unit scale Matrix4 t = modelInstance.transform; Matrix4 mat_scale = new Matrix4(); Vector3 s = new Vector3(); t.getScale(s); mat_scale.scl(1 / s.x, 1 / s.y, 1 / s.z); t.mul(mat_scale); // Set target scale mat_scale.idt(); mat_scale.scl(x, y, z); t.mul(mat_scale); // Relevant bullet body update CollisionShape cs = body.getCollisionShape(); cs.setLocalScaling(new Vector3f(x, y, z)); if (body.isInWorld() && body.isStaticOrKinematicObject()) scene.world.updateSingleAabb(body); // Child propagation Vector3f ps = scale(); Matrix4f pt = transform(); Matrix4f ct = new Matrix4f(); Matrix4f ms = new Matrix4f(); ms.setIdentity(); ms.m00 = ps.x; ms.m11 = ps.y; ms.m22 = ps.z; pt.mul(ms); for (GameObject c : children) { c.scale(scale().mul(c.localScale), false); ct.mul(pt, c.localTransform); c.transform(ct, false); } if (parent != null && updateLocal) { updateLocalScale(); } }