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(); } }
public void render(float delta) { if (cameraCache != viewport.getCamera()) cameraCache = (OrthographicCamera) viewport.getCamera(); viewport.getCamera().position.add(speed.x * delta, speed.y * delta, 0f); for (int i = 0; i < layers.length; i++) { cameraProjectionCache.set(viewport.getCamera().projection); cameraProjectionCache.scl(cameraCache.zoom); batch.setProjectionMatrix(cameraProjectionCache); batch.begin(); float currentX = -viewport.getCamera().position.x * layers[i].parallaxRatio.x % (layers[i].region.getRegionWidth() + layers[i].padding.x); if (speed.x < 0) currentX += -(layers[i].region.getRegionWidth() + layers[i].padding.x); do { /* Y REPEATING DISABLED: float currentY = -viewport.getCamera().position.y * layers[i].parallaxRatio.y % (layers[i].region.getRegionHeight() + layers[i].padding.y); if (speed.y < 0) currentY += -(layers[i].region.getRegionHeight() + layers[i].padding.y); do { batch.draw(layers[i].region, -viewport.getCamera().viewportWidth / 2 + currentX + layers[i].startPosition.x, -viewport.getCamera().viewportHeight / 2 + currentY + layers[i].startPosition.y); currentY += (layers[i].region.getRegionHeight() + layers[i].padding.y); } while (currentY < viewport.getCamera().viewportHeight);*/ batch.draw( layers[i].region, -viewport.getCamera().viewportWidth / 2 + currentX + layers[i].startPosition.x, -viewport.getCamera().viewportHeight / 2 + layers[i].startPosition.y); currentX += (layers[i].region.getRegionWidth() + layers[i].padding.x); } while (currentX < viewport.getCamera().viewportWidth); batch.end(); } }