Refine search
@Override public void update (boolean updateFrustum) { projection.setToOrtho(zoom * -viewportWidth / 2, zoom * (viewportWidth / 2), zoom * -(viewportHeight / 2), zoom * viewportHeight / 2, near, far); view.setToLookAt(position, tmp.set(position).add(direction), up); combined.set(projection); Matrix4.mul(combined.val, view.val); if (updateFrustum) { invProjectionView.set(combined); Matrix4.inv(invProjectionView.val); frustum.update(invProjectionView); } }
private void init () { // create the isometric transform isoTransform = new Matrix4(); isoTransform.idt(); // isoTransform.translate(0, 32, 0); isoTransform.scale((float)(Math.sqrt(2.0) / 2.0), (float)(Math.sqrt(2.0) / 4.0), 1.0f); isoTransform.rotate(0.0f, 0.0f, 1.0f, -45); // ... and the inverse matrix invIsotransform = new Matrix4(isoTransform); invIsotransform.inv(); }
@Override public void render () { angle = angle + Gdx.graphics.getDeltaTime() * 360f / 5f; kinematicBox3.transform.idt().rotate(Vector3.Y, 360f - 2f * angle).translate(position3); if (angle >= 360f) { angle = 0; kinematicBox = (kinematicBox == kinematicBox1) ? kinematicBox2 : kinematicBox1; position = (position == position1) ? position2 : position1; } kinematicBox.transform.idt().rotate(Vector3.Y, angle).translate(position); // This makes bullet call btMotionState#getWorldTransform once: kinematicBox.body.setActivationState(Collision.ACTIVE_TAG); super.render(); }
/** Calculates the world transform; the product of local transform and the parent's world transform. * @return the world transform */ public Matrix4 calculateWorldTransform () { if (inheritTransform && parent != null) globalTransform.set(parent.globalTransform).mul(localTransform); else globalTransform.set(localTransform); return globalTransform; }
/** Averages the given transforms and stores the result in this matrix. Translations and scales are lerped while rotations are * slerped. Does not destroy the data contained in t. * @param t List of transforms * @return This matrix for chaining */ public Matrix4 avg (Matrix4[] t) { final float w = 1.0f / t.length; tmpVec.set(t[0].getScale(tmpUp).scl(w)); quat.set(t[0].getRotation(quat2).exp(w)); tmpForward.set(t[0].getTranslation(tmpUp).scl(w)); for (int i = 1; i < t.length; i++) { tmpVec.add(t[i].getScale(tmpUp).scl(w)); quat.mul(t[i].getRotation(quat2).exp(w)); tmpForward.add(t[i].getTranslation(tmpUp).scl(w)); } quat.nor(); setToScaling(tmpVec); rotate(quat); setTranslation(tmpForward); return this; }
/** Sets this matrix to a look at matrix with the given position, target and up vector. * * @param position the position * @param target the target * @param up the up vector * @return This matrix */ public Matrix4 setToLookAt (Vector3 position, Vector3 target, Vector3 up) { tmpVec.set(target).sub(position); setToLookAt(tmpVec, up); this.mul(tmpMat.setToTranslation(-position.x, -position.y, -position.z)); return this; }
@Override public void update (boolean updateFrustum) { float aspect = viewportWidth / viewportHeight; projection.setToProjection(Math.abs(near), Math.abs(far), fieldOfView, aspect); view.setToLookAt(position, tmp.set(position).add(direction), up); combined.set(projection); Matrix4.mul(combined.val, view.val); if (updateFrustum) { invProjectionView.set(combined); Matrix4.inv(invProjectionView.val); frustum.update(invProjectionView); } } }
jsonNode.translation = translation == null ? null : new Vector3(translation.getFloat(0), translation.getFloat(1), translation.getFloat(2)); jsonNode.rotation = rotation == null ? null : new Quaternion(rotation.getFloat(0), rotation.getFloat(1), rotation.getFloat(2), rotation.getFloat(3)); jsonNode.scale = scale == null ? null : new Vector3(scale.getFloat(0), scale.getFloat(1), scale.getFloat(2)); if (nodeId == null) throw new GdxRuntimeException("Bone node ID missing"); Matrix4 transform = new Matrix4(); if (val != null && val.size >= 3) transform.translate(val.getFloat(0), val.getFloat(1), val.getFloat(2)); transform.rotate(tempQ.set(val.getFloat(0), val.getFloat(1), val.getFloat(2), val.getFloat(3))); if (val != null && val.size >= 3) transform.scale(val.getFloat(0), val.getFloat(1), val.getFloat(2));
public Matrix4 calculateParallaxMatrix (float parallaxX, float parallaxY) { update(); tmp.set(position); tmp.x *= parallaxX; tmp.y *= parallaxY; parallaxView.setToLookAt(tmp, tmp2.set(tmp).add(direction), up); parallaxCombined.set(projection); Matrix4.mul(parallaxCombined.val, parallaxView.val); return parallaxCombined; } }
/** Averages the given transform with this one and stores the result in this matrix. Translations and scales are lerped while * rotations are slerped. * @param other The other transform * @param w Weight of this transform; weight of the other transform is (1 - w) * @return This matrix for chaining */ public Matrix4 avg (Matrix4 other, float w) { getScale(tmpVec); other.getScale(tmpForward); getRotation(quat); other.getRotation(quat2); getTranslation(tmpUp); other.getTranslation(right); setToScaling(tmpVec.scl(w).add(tmpForward.scl(1 - w))); rotate(quat.slerp(quat2, 1 - w)); setTranslation(tmpUp.scl(w).add(right.scl(1 - w))); return this; }
private Vector3 getTranslation (Matrix4 worldTransform, Vector3 center, Vector3 output) { if (center.isZero()) worldTransform.getTranslation(output); else if (!worldTransform.hasRotationOrScaling()) worldTransform.getTranslation(output).add(center); else output.set(center).mul(worldTransform); return output; }
Vector3 position1 = new Vector3(), position2 = new Vector3(), direction = new Vector3(); instance2.transform.translate(0.5f, 0, 0.5f).rotate(0, 1, 0, 45*Gdx.graphics.getDeltaTime()).translate(0, 0, 0); instance1.transform.getTranslation(position1); instance2.transform.getTranslation(position2); direction = (position2).sub(position1).nor(); direction.set(-direction.x, -direction.y, -direction.z); Quaternion quaternion = new Quaternion(); Matrix4 instanceRotation = instance1.transform.cpy().mul(instance1transform); instanceRotation.setToLookAt(direction, new Vector3(0,-1,0)); instanceRotation.rotate(0, 0, 1, 180); instanceRotation.getRotation(quaternion); instance1.transform.set(position1, quaternion);
/** @param model The source {@link Model} * @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix. * @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain * @param recursive True to recursively search the Model's node tree, false to only search for a root node * @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true). * @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */ public ModelInstance (final Model model, final Matrix4 transform, final String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform, boolean shareKeyframes) { this.model = model; this.transform = transform == null ? new Matrix4() : transform; Node copy, node = model.getNode(nodeId, recursive); this.nodes.add(copy = node.copy()); if (mergeTransform) { this.transform.mul(parentTransform ? node.globalTransform : node.localTransform); copy.translation.set(0, 0, 0); copy.rotation.idt(); copy.scale.set(1, 1, 1); } else if (parentTransform && copy.hasParent()) this.transform.mul(node.getParent().globalTransform); invalidate(); copyAnimations(model.animations, shareKeyframes); calculateTransforms(); }
/** Creates a nested copy of this Node, any child nodes are copied using the {@link #copy()} method. This will detach this node * from its parent, but does not attach it to the parent of node being copied. The {@link #parts} are copied using the * {@link NodePart#copy()} method. Note that that method copies the material and nodes (bones) by reference. If you intend to * use this node in a different node tree (e.g. a different Model or ModelInstance) then you will need to update these * references afterwards. * * Override this method in your custom Node class to copy any additional fields you've added. * @return This Node for chaining */ protected Node set (Node other) { detach(); id = other.id; isAnimated = other.isAnimated; inheritTransform = other.inheritTransform; translation.set(other.translation); rotation.set(other.rotation); scale.set(other.scale); localTransform.set(other.localTransform); globalTransform.set(other.globalTransform); parts.clear(); for (NodePart nodePart : other.parts) { parts.add(nodePart.copy()); } children.clear(); for (Node child : other.getChildren()) { addChild(child.copy()); } return this; }
mpb = modelBuilder.part("cone", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material); mpb.setVertexTransform(new Matrix4().rotate(Vector3.X, -45f)); mpb.cone(2f, 3f, 1f, 8); | Usage.ColorPacked, solidMaterial); mpb.setUVRange(1f, 1f, 0f, 0f); mpb.sphere(new Matrix4().translate(5, 0, 10).rotate(Vector3.Z, 45).scale(1, 2, 1), 1f, 1f, 1f, 12, 16); Matrix4 transform = new Matrix4(); mpb.setVertexTransform(transform.setToTranslation(0, 2, 0)); mpb.addMesh(mesh); mpb.setColor(Color.BLUE); mpb.setVertexTransform(transform.setToTranslation(1, 1, 0)); mpb.addMesh(mesh); mpb.setColor(null); mpb.setVertexTransform(transform.setToTranslation(-1, 1, 0).rotate(Vector3.X, 45)); mpb.addMesh(mesh); mpb.setVertexTransform(transform.setToTranslation(0, 1, 1)); mpb.setUVRange(0.75f, 0.75f, 0.25f, 0.25f); mpb.addMesh(mesh); instances.add(new ModelInstance(model, new Matrix4().trn(0f, 0f, 0f), "mesh", true)); instances.add(new ModelInstance(model, new Matrix4().trn(-5f, 0f, -5f), "box", true)); instances.add(new ModelInstance(model, new Matrix4().trn(5f, 0f, -5f), "sphere", true)); instances.add(new ModelInstance(model, new Matrix4().trn(-5f, 0f, 5f), "cone", true)); instances.add(new ModelInstance(model, new Matrix4().trn(5f, 0f, 5f), "cylinder", true)); instances.add(new ModelInstance(model, new Matrix4().trn(0f, 0f, 5f), "capsule", true)); instances.add(new ModelInstance(model, new Matrix4().trn(0f, 0f, 10f), "capsuleNoTexture", true));
protected void updateLocalTransform() { // Local transform try { localTransform.idt().setToLookAt(posf, directionf.add(posf), upf).inv(); float sizeFac = (float) (sizeFactor * size); localTransform.scale(sizeFac, sizeFac, sizeFac); // Rotation for attitude indicator rotationMatrix.idt().setToLookAt(directionf, upf); rotationMatrix.getRotation(qf); } catch (Exception e) { } }