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

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

Introduction

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

Prototype

public Matrix4 tra() 

Source Link

Document

Transposes the matrix.

Usage

From source file:MeshBoneUtil.MeshBone.java

License:Open Source License

public Vector3 getWorldRestStartPt() {
    //Vector3 ret_vec = Vector3.Transform(local_rest_start_pt, rest_parent_mat);
    Matrix4 tmp_mat = rest_parent_mat.cpy();
    tmp_mat.tra();
    Vector3 ret_vec = local_rest_start_pt.cpy().traMul(tmp_mat);

    return ret_vec;
}

From source file:MeshBoneUtil.MeshBone.java

License:Open Source License

public Vector3 getWorldRestEndPt() {
    //        Vector3 ret_vec = Vector3.Transform(local_rest_end_pt, rest_parent_mat);
    Matrix4 tmp_mat = rest_parent_mat.cpy();
    tmp_mat.tra();
    Vector3 ret_vec = local_rest_end_pt.cpy().traMul(tmp_mat);

    return ret_vec;
}

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  w ww  .j a v  a  2 s . c o 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 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();
    /*//  ww 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();
    }
}

From source file:MeshBoneUtil.Utils.java

License:Open Source License

public static Matrix4 calcRotateMat(Vector3 vec_in) {
    Vector3 dir = vec_in.cpy();/*from  www.  j  a v  a 2 s .  c o m*/
    dir.nor();

    Vector3 pep_dir = rotateVec4_90(dir);

    Vector3 cur_tangent = new Vector3(dir.x, dir.y, 0);
    Vector3 cur_normal = new Vector3(pep_dir.x, pep_dir.y, 0);
    Vector3 cur_binormal = new Vector3(0, 0, 1);

    //XnaGeometry.Matrix cur_rotate(cur_tangent, cur_normal, cur_binormal, glm::vec4(0,0,0,1));
    Matrix4 cur_rotate = new Matrix4();
    //cur_rotate = Matrix.Identity; // Already identity by default

    /*
    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();

    return cur_rotate;
}