Example usage for com.badlogic.gdx.math Matrix4 setTranslation

List of usage examples for com.badlogic.gdx.math Matrix4 setTranslation

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Matrix4 setTranslation.

Prototype

public Matrix4 setTranslation(float x, float y, float z) 

Source Link

Document

Sets the 4th column to the translation vector.

Usage

From source file:MeshBoneUtil.MeshBone.java

License:Open Source License

public void computeRestParentTransforms() {
    Vector3 cur_tangent = new Vector3(local_rest_dir.x, local_rest_dir.y, 0);
    Vector3 cur_binormal = new Vector3(local_binormal_dir.x, local_binormal_dir.y, local_binormal_dir.z);
    Vector3 cur_normal = new Vector3(local_rest_normal_dir.x, local_rest_normal_dir.y, 0);

    Matrix4 cur_translate = new Matrix4();
    cur_translate.setTranslation(local_rest_end_pt.x, local_rest_end_pt.y, 0);

    Matrix4 cur_rotate = new Matrix4();
    /*/*from   www  .  ja va  2  s  .  co  m*/
    cur_rotate.Right = cur_tangent;
    cur_rotate.Up = cur_normal;
    cur_rotate.Backward = cur_binormal;
    */
    cur_rotate.set(cur_tangent, cur_normal, cur_binormal, new Vector3(0, 0, 0));
    cur_rotate.tra();

    //Matrix4 cur_final = cur_translate * cur_rotate;
    Matrix4 cur_final = cur_translate.cpy().mul(cur_rotate);

    //rest_world_mat = rest_parent_mat * cur_final;
    rest_world_mat = rest_parent_mat.cpy().mul(cur_final);

    rest_world_inv_mat = rest_world_mat.cpy();
    rest_world_inv_mat.inv();
    //Matrix4.Invert(ref rest_world_mat, out rest_world_inv_mat);

    Vector3 world_rest_dir = getWorldRestEndPt().cpy().sub(getWorldRestStartPt());
    world_rest_dir.nor();
    world_rest_angle = Utils.angleVec4(world_rest_dir);
    world_rest_pos = getWorldRestStartPt();

    Matrix4 bind_translate = new Matrix4();
    bind_translate.setTranslation(getWorldRestStartPt().x, getWorldRestStartPt().y, 0);

    Matrix4 bind_rotate = Utils.calcRotateMat(getWorldRestEndPt().cpy().sub(getWorldRestStartPt()));
    //Matrix4 cur_bind_final = bind_translate * bind_rotate;
    Matrix4 cur_bind_final = bind_translate.cpy().mul(bind_rotate);

    bind_world_mat = cur_bind_final.cpy();
    bind_world_inv_mat = bind_world_mat.cpy();
    bind_world_inv_mat.inv();
    //Matrix4.Invert(ref bind_world_mat, out bind_world_inv_mat);

    for (int i = 0; i < children.size(); i++) {
        MeshBone cur_bone = children.get(i);
        cur_bone.setRestParentMat(rest_world_mat, rest_world_inv_mat);
        cur_bone.computeRestParentTransforms();
    }
}

From source file:MeshBoneUtil.MeshBone.java

License:Open Source License

public void computeParentTransforms() {
    Matrix4 translate_parent = new Matrix4();
    translate_parent.setTranslation(getWorldEndPt().x, getWorldEndPt().y, 0);

    Matrix4 rotate_parent = Utils.calcRotateMat(getWorldEndPt().cpy().sub(getWorldStartPt()));

    //         Matrix4 final_transform = translate_parent * rotate_parent;
    Matrix4 final_transform = translate_parent.cpy().mul(rotate_parent);

    Matrix4 final_inv_transform = final_transform.cpy();
    final_inv_transform.inv();
    //Matrix4.Invert(ref final_transform, out final_inv_transform);

    for (int i = 0; i < children.size(); i++) {
        MeshBone cur_bone = children.get(i);
        cur_bone.setParentWorldMat(final_transform);
        cur_bone.setParentWorldInvMat(final_inv_transform);
        cur_bone.computeParentTransforms();
    }/*from w w  w. ja v  a2s. c o  m*/
}

From source file:MeshBoneUtil.MeshBone.java

License:Open Source License

public void computeWorldDeltaTransforms() {
    Tuple<Vector3, Vector3> calc = computeDirs(world_start_pt, world_end_pt);
    Vector3 cur_tangent = new Vector3(calc.x.x, calc.x.y, 0);
    Vector3 cur_normal = new Vector3(calc.y.x, calc.y.y, 0);
    Vector3 cur_binormal = new Vector3(local_binormal_dir.x, local_binormal_dir.y, local_binormal_dir.z);

    Matrix4 cur_rotate = new Matrix4();
    /*//from  w  w w. j  ava  2 s. co m
    cur_rotate.Right = cur_tangent;
    cur_rotate.Up = cur_normal;
    cur_rotate.Backward = cur_binormal;
    */
    cur_rotate.set(cur_tangent, cur_normal, cur_binormal, new Vector3(0, 0, 0));
    cur_rotate.tra();

    Matrix4 cur_translate = new Matrix4();
    cur_translate.setTranslation(world_start_pt.x, world_start_pt.y, 0);

    /*
    world_delta_mat = (cur_translate * cur_rotate)
    * bind_world_inv_mat;
    */

    world_delta_mat = (cur_translate.cpy().mul(cur_rotate)).mul(bind_world_inv_mat);
    //world_delta_mat = bind_world_inv_mat.cpy().mul(cur_rotate.cpy().mul(cur_translate));

    //        Quaternion cur_quat = XnaGeometry.Quaternion.CreateFromRotationMatrix(world_delta_mat);
    Quaternion cur_quat = new Quaternion().setFromMatrix(world_delta_mat);
    if (cur_quat.z < 0) {
        //cur_quat = -cur_quat;
    }

    Vector3 tmp_pos = new Vector3();
    world_delta_mat.getTranslation(tmp_pos);
    world_dq = new dualQuat(cur_quat, tmp_pos);

    for (int i = 0; i < children.size(); i++) {
        MeshBone cur_bone = children.get(i);
        cur_bone.computeWorldDeltaTransforms();
    }
}