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

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

Introduction

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

Prototype

public Matrix4 set(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis, Vector3 pos) 

Source Link

Document

Sets the four columns of the matrix which correspond to the x-, y- and z-axis of the vector space this matrix creates as well as the 4th column representing the translation of any point that is multiplied by this matrix.

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();
    /*/*w w  w  .  j  a va 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();
    /*/*from ww w  .  j av 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_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  w  w  w.j ava2 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;
}