/** * Fetches the world matrix transformation of the given node. * @param node * the node * @return the node's world transformation matrix */ private Matrix4f getWorldMatrix(Node node) { Matrix4f result = new Matrix4f(); result.setTranslation(node.getWorldTranslation()); result.setRotationQuaternion(node.getWorldRotation()); result.setScale(node.getWorldScale()); return result; }
public void buildBindPoseBoneTransform() { if(bone != null) { Matrix4f t = bindTransform; if(t != null) { Matrix4f parentMatrix = parentFbxNode != null ? parentFbxNode.bindTransform : Matrix4f.IDENTITY; if(parentMatrix == null) parentMatrix = node.getLocalToWorldMatrix(null); t = parentMatrix.invert().multLocal(t); bone.setBindTransforms(t.toTranslationVector(), t.toRotationQuat(), t.toScaleVector()); } else { bone.setBindTransforms(node.getLocalTranslation(), node.getLocalRotation(), node.getLocalScale()); } } }
/** * Updates the view projection matrix. */ public void updateViewProjection() { if (overrideProjection) { viewProjectionMatrix.set(projectionMatrixOverride).multLocal(viewMatrix); } else { //viewProjectionMatrix.set(viewMatrix).multLocal(projectionMatrix); viewProjectionMatrix.set(projectionMatrix).multLocal(viewMatrix); } }
@Override protected Matrix4f getTransformMatrix(Geometry g){ // Compute the Local matrix for the geometry cachedLocalMat.loadIdentity(); cachedLocalMat.setRotationQuaternion(g.localTransform.getRotation()); cachedLocalMat.setTranslation(g.localTransform.getTranslation()); TempVars vars = TempVars.get(); Matrix4f scaleMat = vars.tempMat4; scaleMat.loadIdentity(); scaleMat.scale(g.localTransform.getScale()); cachedLocalMat.multLocal(scaleMat); vars.release(); return cachedLocalMat; }
@Override public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) { if (influence == 0 || targetTransform == null) { return;// no need to do anything } Object target = this.getTarget();// Bone or Node Object owner = this.getOwner();// Bone or Node if (!target.getClass().equals(owner.getClass())) { ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); TempVars tempVars = TempVars.get(); Matrix4f m = constraintHelper.toMatrix(targetTransform, tempVars.tempMat4); tempVars.tempMat42.set(BoneContext.BONE_ARMATURE_TRANSFORMATION_MATRIX); if (target instanceof Bone) { tempVars.tempMat42.invertLocal(); } m = m.multLocal(tempVars.tempMat42); tempVars.release(); targetTransform = new Transform(m.toTranslationVector(), m.toRotationQuat(), m.toScaleVector()); } this.applyOwnerTransform(targetTransform, ownerSpace); }
Matrix4f invertedObjectOwnerGlobalMatrix = objectHelper.getMatrix(skeletonOwnerObjectStructure, "obmat", blenderContext.getBlenderKey().isFixUpAxis()).invertLocal(); if (objectHelper.isParent(skeletonOwnerOma, armatureObjectOMA)) { boneMatrixInModelSpace = globalBoneMatrix.mult(invertedObjectOwnerGlobalMatrix); } else { boneMatrixInModelSpace = invertedObjectOwnerGlobalMatrix.mult(globalBoneMatrix); Matrix4f boneLocalMatrix = parent == null ? boneMatrixInModelSpace : parent.boneMatrixInModelSpace.invert().multLocal(boneMatrixInModelSpace); Vector3f poseLocation = parent == null || !this.is(CONNECTED_TO_PARENT) ? boneLocalMatrix.toTranslationVector() : new Vector3f(0, parent.length, 0); Quaternion rotation = boneLocalMatrix.toRotationQuat().normalizeLocal(); Vector3f scale = boneLocalMatrix.toScaleVector();
Matrix4f transformMatrix = new Matrix4f(); transformMatrix.setTranslation(translationLocalRaw.x + rotationOffsetRaw.x + rotationPivotRaw.x, translationLocalRaw.y + rotationOffsetRaw.y + rotationPivotRaw.y, translationLocalRaw.z + rotationOffsetRaw.z + rotationPivotRaw.z); transformMatrix.multLocal(postRotation); } else { transformMatrix.multLocal(rotOrder.rotate(rotationLocalRaw.x, rotationLocalRaw.y, rotationLocalRaw.z)); Matrix4f mat = new Matrix4f(); mat.setTranslation(scaleOffsetRaw.x + scalePivotRaw.x - rotationPivotRaw.x, scaleOffsetRaw.y + scalePivotRaw.y - rotationPivotRaw.y, scaleOffsetRaw.z + scalePivotRaw.z - rotationPivotRaw.z); transformMatrix.multLocal(mat); transformMatrix.scale(scaleLocalRaw); transformMatrix.scale(new Vector3f(scene.unitSize, scene.unitSize, scene.unitSize)); mat.setTranslation(scalePivotRaw.negate()); transformMatrix.multLocal(mat); localTransform = new Transform(transformMatrix.toTranslationVector(), transformMatrix.toRotationQuat(), transformMatrix.toScaleVector());
public void renderQuad(int x, int y, int width, int height, Color color) { //We test for alpha >0 as an optimization to prevent the render of completely transparent quads. //Nifty use layers that are often used for logical positionning and not rendering. //each layer is rendered as a quad, but that can bump up the number of geometry rendered by a lot. //Since we disable depth write, there is absolutely no point in rendering those quads //This optimization can result in a huge increase of perfs on complex Nifty UIs. if(color.getAlpha() >0){ colorMaterial.setColor("Color", convertColor(color, tempColor)); tempMat.loadIdentity(); tempMat.setTranslation(x, getHeight() - y, 0); tempMat.setScale(width, height, 0); rm.setWorldMatrix(tempMat); rm.setForcedRenderState(renderState); colorMaterial.render(quadGeom, rm); } //System.out.format("renderQuad1(%d, %d, %d, %d, %s)\n", x, y, width, height, color.toString()); }
/** * Creates a transform matrix that will convert from this spatials' * local coordinate space to the world coordinate space * based on the world transform. * * @param store Matrix where to store the result, if null, a new one * will be created and returned. * * @return store if not null, otherwise, a new matrix containing the result. * * @see Spatial#getWorldTransform() */ public Matrix4f getLocalToWorldMatrix(Matrix4f store) { if (store == null) { store = new Matrix4f(); } else { store.loadIdentity(); } // multiply with scale first, then rotate, finally translate (cf. // Eberly) store.scale(getWorldScale()); store.multLocal(getWorldRotation()); store.setTranslation(getWorldTranslation()); return store; }
/** * Converts given transformation parameters into the matrix. * * @param position * the position of the feature * @param rotation * the rotation of the feature * @param scale * the scale of the feature * @param store * the matrix where the result will be stored * @return the store matrix */ private Matrix4f toMatrix(Vector3f position, Quaternion rotation, Vector3f scale, Matrix4f store) { store.loadIdentity(); store.setTranslation(position); store.setRotationQuaternion(rotation); store.setScale(scale); return store; }
public void setWorldBindPose(Matrix4f worldBindPose) { if (cachedWorldBindPose != null) { if (!cachedWorldBindPose.equals(worldBindPose)) { throw new UnsupportedOperationException("Bind poses don't match"); } } cachedWorldBindPose = worldBindPose; this.jmeWorldBindPose = new Transform(); this.jmeWorldBindPose.setTranslation(worldBindPose.toTranslationVector()); this.jmeWorldBindPose.setRotation(worldBindPose.toRotationQuat()); this.jmeWorldBindPose.setScale(worldBindPose.toScaleVector()); System.out.println("\tBind Pose for " + getName()); System.out.println(jmeWorldBindPose); float[] angles = new float[3]; jmeWorldBindPose.getRotation().toAngles(angles); System.out.println("Angles: " + angles[0] * FastMath.RAD_TO_DEG + ", " + angles[1] * FastMath.RAD_TO_DEG + ", " + angles[2] * FastMath.RAD_TO_DEG); }
/** * This method transforms the first line of the bevel points positioning it * on the first point of the curve. * * @param startingLinePoints * the vbevel shape points * @param firstCurvePoint * the first curve's point * @param secondCurvePoint * the second curve's point * @return points of transformed bevel */ protected Vector3f[] transformToFirstLineOfBevelPoints(Vector3f[] startingLinePoints, Vector3f firstCurvePoint, Vector3f secondCurvePoint) { Vector3f planeNormal = secondCurvePoint.subtract(firstCurvePoint).normalizeLocal(); float angle = FastMath.acos(planeNormal.dot(Vector3f.UNIT_X)); Vector3f rotationVector = Vector3f.UNIT_X.cross(planeNormal).normalizeLocal(); Matrix4f m = new Matrix4f(); m.setRotationQuaternion(new Quaternion().fromAngleAxis(angle, rotationVector)); m.setTranslation(firstCurvePoint); Vector3f temp = new Vector3f(); Vector3f[] verts = new Vector3f[startingLinePoints.length]; for (int i = 0; i < verts.length; ++i) { verts[i] = m.mult(startingLinePoints[i], temp).clone(); } return verts; } }
@Override public void applyBindPose(Transform localTransform, Matrix4f inverseModelBindMatrix, Joint parent) { modelTransformMatrix.set(inverseModelBindMatrix).invertLocal(); // model transform = model bind if (parent != null) { ((MatrixJointModelTransform) parent.getJointModelTransform()).getModelTransformMatrix().invert().mult(modelTransformMatrix, modelTransformMatrix); } localTransform.fromTransformMatrix(modelTransformMatrix); }
private Transform buildTransform(double[] transform) { float[] m = new float[transform.length]; for(int i = 0; i < transform.length; ++i) m[i] = (float) transform[i]; Matrix4f matrix = new Matrix4f(m); Vector3f pos = matrix.toTranslationVector(); Quaternion rot = matrix.toRotationQuat(); Vector3f scale = matrix.toScaleVector(); return new Transform(pos, rot, scale); }
public Matrix4f toTransformMatrix(Matrix4f store) { if (store == null) { store = new Matrix4f(); } store.setTranslation(translation); rot.toTransformMatrix(store); store.setScale(scale); return store; }
public void fromTransformMatrix(Matrix4f mat) { TempVars vars = TempVars.get(); translation.set(mat.toTranslationVector(vars.vect1)); rot.set(mat.toRotationQuat(vars.quat1)); scale.set(mat.toScaleVector(vars.vect2)); vars.release(); }
hmdRelativeEyePoses[eye] = new Matrix4f(); hmdRelativeEyePositions[eye] = new Vector3f(); hmdRelativeEyePoses[eye].loadIdentity(); hmdRelativeEyePoses[eye].setTranslation(hmdRelativeEyePositions[eye]); hmdRelativeEyePoses[eye].setRotationQuaternion(rotation);
private void createSkinningMatrices() { skinningMatrixes = new Matrix4f[boneList.length]; for (int i = 0; i < skinningMatrixes.length; i++) { skinningMatrixes[i] = new Matrix4f(); } }