Example usage for com.badlogic.gdx.math Vector3 cpy

List of usage examples for com.badlogic.gdx.math Vector3 cpy

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector3 cpy.

Prototype

@Override
    public Vector3 cpy() 

Source Link

Usage

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.model.GameObject.java

License:Apache License

public void lookAt(Vector3 point) {
    Vector3 from = transform.getTranslation(new Vector3()).cpy();
    Vector3 to = point.cpy();
    Vector3 direction = to.sub(from).nor();
    direction.set(-direction.x, -direction.y, -direction.z);

    Quaternion quaternion = new Quaternion();
    Matrix4 instanceRotation = transform.cpy().mul(transform);

    instanceRotation.setToLookAt(direction, new Vector3(0, -1, 0));
    instanceRotation.rotate(0, 0, 1, 180);
    instanceRotation.getRotation(quaternion);

    transform.set(from, quaternion);//from  ww  w  .j  av  a 2  s.c o m
}

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.model.Word.java

License:Apache License

private void init() {
    float centerX = 0f;
    float centerY = ((((float) words.length) * FONT_HEIGHT) - FONT_HEIGHT) / 2f;

    nodes.clear();//from  w w  w. j av  a  2s  .  c  o m
    nodesPosition = new Array<Vector3>();
    if (words != null && words.length > 0) {
        for (int y = 0; y < words.length; y++) {
            String[] word = translateSpecialCharacters(words[y]);
            centerX = (((float) word.length) * FONT_WIDTH) / 2f;
            for (int x = 0; x < word.length; x++) {
                String letter = String.valueOf(word[x]);

                Node node = model.getNode(letter);
                if (node != null) {
                    Vector3 position = new Vector3((FONT_WIDTH * x) - centerX, (-FONT_HEIGHT * y) + centerY, 0);
                    node = node.copy();
                    node.globalTransform.setTranslation(position);
                    nodes.add(node);
                    nodesPosition.add(position.cpy());
                }
            }
        }
    }
}

From source file:com.lyeeedar.Roguelike3D.Graphics.Lights.LightManager.java

License:Open Source License

private Color calculateLight(Vector3 l_vector, Color l_colour, float l_attenuation, float l_power,
        Vector3 n_dir) {/* w  w  w  .  j a va 2s .  co  m*/
    float distance = l_vector.len();
    Vector3 l_dir = l_vector.cpy().div(distance);

    float NdotL = n_dir.dot(l_dir);
    float intensity = MathUtils.clamp(NdotL, 0.0f, 1.0f);

    float attenuation = 1.0f;
    if (l_attenuation != 0)
        attenuation /= (l_attenuation * distance + l_attenuation / 10 * distance * distance);

    return l_colour.mul(intensity).mul(l_power).mul(attenuation);
}

From source file:com.lyeeedar.Roguelike3D.Graphics.Models.Shapes.java

License:Open Source License

public static Mesh insertTangents(Mesh mesh) {
    VertexAttributes attributes = mesh.getVertexAttributes();
    final int vertCount = mesh.getNumVertices();
    final int vertexSize = attributes.vertexSize / 4;

    VertexAttribute[] newAttributes = new VertexAttribute[attributes.size() + 1];
    for (int i = 0; i < attributes.size(); i++) {
        newAttributes[i] = attributes.get(i);
    }//  ww w.  j ava2 s. c o  m
    newAttributes[attributes.size()] = new VertexAttribute(Usage.Generic, 4, "a_tangent");

    final int newVertexSize = vertexSize + 4;

    float[] verts = new float[vertexSize * vertCount];
    mesh.getVertices(verts);
    short[] indices = new short[mesh.getNumIndices()];
    mesh.getIndices(indices);
    float[] newVerts = new float[newVertexSize * vertCount];

    int positionOffset = attributes.getOffset(Usage.Position);
    int normalOffset = attributes.getOffset(Usage.Normal);
    int textureOffset = attributes.getOffset(Usage.TextureCoordinates);

    int tangentOffset = 0;
    for (int i = 0; i < vertCount; i += 3) {
        int j = 0;
        for (; j < vertexSize; j++) {
            newVerts[(i * newVertexSize) + j] = verts[(i * vertexSize) + j];
            newVerts[((i + 1) * newVertexSize) + j] = verts[((i + 1) * vertexSize) + j];
            newVerts[((i + 2) * newVertexSize) + j] = verts[((i + 2) * vertexSize) + j];
        }
        tangentOffset = j;
    }
    for (int i = 0; i < mesh.getNumIndices(); i += 3) {
        int i1 = indices[i];
        int i2 = indices[i + 1];
        int i3 = indices[i + 2];

        Vector3 v1 = new Vector3(verts[(i1 * vertexSize) + positionOffset],
                verts[(i1 * vertexSize) + positionOffset] + 1, verts[(i1 * vertexSize) + positionOffset] + 2);
        Vector3 v2 = new Vector3(verts[(i2 * vertexSize) + positionOffset],
                verts[(i2 * vertexSize) + positionOffset] + 1, verts[(i2 * vertexSize) + positionOffset] + 2);
        Vector3 v3 = new Vector3(verts[(i3 * vertexSize) + positionOffset],
                verts[(i3 * vertexSize) + positionOffset] + 1, verts[(i3 * vertexSize) + positionOffset] + 2);

        float[] w1 = { verts[(i1 * vertexSize) + textureOffset], verts[(i1 * vertexSize) + textureOffset] + 1 };
        float[] w2 = { verts[(i2 * vertexSize) + textureOffset], verts[(i2 * vertexSize) + textureOffset] + 1 };
        float[] w3 = { verts[(i3 * vertexSize) + textureOffset], verts[(i3 * vertexSize) + textureOffset] + 1 };

        float x1 = v2.x - v1.x;
        float x2 = v3.x - v1.x;
        float y1 = v2.y - v1.y;
        float y2 = v3.y - v1.y;
        float z1 = v2.z - v1.z;
        float z2 = v3.z - v1.z;

        float s1 = w2[0] - w1[0];
        float s2 = w3[0] - w1[0];
        float t1 = w2[1] - w1[1];
        float t2 = w3[1] - w1[1];

        float div = s1 * t2 - s2 * t1;
        float r = div == 0.0f ? 0.0f : 1.0f / div;

        Vector3 t = new Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
        Vector3 n = new Vector3(verts[(i1 * vertexSize) + normalOffset],
                verts[(i1 * vertexSize) + normalOffset] + 1, verts[(i1 * vertexSize) + normalOffset] + 2);

        //Vector3 tangent = t.cpy().sub(n).mul(n.tmp().dot(t)).nor();
        Vector3 tangent = orthoNormalize(n, t);

        System.out.println(t2);

        Vector3 tan2 = new Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
        float handedness = (n.tmp().crs(t).dot(tan2) < 0.0f) ? -1.0f : 1.0f;

        Vector3 c1 = n.cpy().crs(0.0f, 0.0f, 1.0f);
        Vector3 c2 = n.cpy().crs(0.0f, 1.0f, 0.0f);

        if (c1.len2() > c2.len2()) {
            tangent = c1;
        } else {
            tangent = c2;
        }

        newVerts[(i1 * newVertexSize) + tangentOffset] = tangent.x;
        newVerts[(i1 * newVertexSize) + tangentOffset + 1] = tangent.y;
        newVerts[(i1 * newVertexSize) + tangentOffset + 2] = tangent.z;
        newVerts[(i1 * newVertexSize) + tangentOffset + 3] = handedness;

        newVerts[(i2 * newVertexSize) + tangentOffset] = tangent.x;
        newVerts[(i2 * newVertexSize) + tangentOffset + 1] = tangent.y;
        newVerts[(i2 * newVertexSize) + tangentOffset + 2] = tangent.z;
        newVerts[(i2 * newVertexSize) + tangentOffset + 3] = handedness;

        newVerts[(i3 * newVertexSize) + tangentOffset] = tangent.x;
        newVerts[(i3 * newVertexSize) + tangentOffset + 1] = tangent.y;
        newVerts[(i3 * newVertexSize) + tangentOffset + 2] = tangent.z;
        newVerts[(i3 * newVertexSize) + tangentOffset + 3] = handedness;
    }

    Mesh newMesh = new Mesh(true, mesh.getNumVertices(), mesh.getNumIndices(), newAttributes);
    newMesh.setVertices(newVerts);
    newMesh.setIndices(indices);

    return newMesh;
}

From source file:com.ruin.castile.displayable.DecalDisplayable.java

License:Open Source License

public void moveTo(Vector3 position) {
    Vector3 translation = position.cpy().sub(this.position);

    move(translation);
}

From source file:edu.lehigh.cse.lol.Control.java

License:Open Source License

/**
 * Add a control with callbacks for down, up, and pan
 *
 * @param x/*from   www. j av  a2  s  .  com*/
 *            The X coordinate of the bottom left corner (in pixels)
 * @param y
 *            The Y coordinate of the bottom left corner (in pixels)
 * @param width
 *            The width of the image
 * @param height
 *            The height of the image
 * @param imgName
 *            The name of the image to display. Use "" for an invisible
 *            button
 * @param upCB
 *            The callback to run when the Control is released
 * @param dnCB
 *            The callback to run when the Control is pressed
 * @param mvCB
 *            The callback to run when there is a finger move (pan) on the
 *            Control
 */
public static Control addPanCallbackControl(int x, int y, int width, int height, String imgName,
        final LolCallback upCB, final LolCallback dnCB, final LolCallback mvCB) {
    final Control c = new Control(imgName, x, y, width, height);
    // Pan only consists of pan-stop and pan events. That means we can't
    // capture a down-press or up-press that isn't also involved in a move.
    // To overcome this limitation, we'll make this BOTH a pan control and a
    // toggle control
    c.mGestureAction = new GestureAction() {
        /**
         * Toggle action: either call the "up" callback or the "down" callback
         */
        @Override
        public boolean toggle(boolean isUp, Vector3 touchVec) {
            // up event
            if (isUp) {
                upCB.mUpLocation = touchVec.cpy();
                upCB.onEvent();
                mHolding = false;
            }
            // down event
            else {
                mHolding = true;
                dnCB.mDownLocation = touchVec.cpy();
                dnCB.onEvent();
            }
            // toggle state
            mHolding = !isUp;
            return true;
        }

        /**
         * Finger move action: call the "pan" callback
         */
        @Override
        public boolean onPan(Vector3 touchVec, float deltaX, float deltaY) {
            // force a down event, if we didn't get one
            if (!mHolding) {
                toggle(false, touchVec);
                return true;
            }
            // pan event
            mvCB.mMoveLocation = touchVec.cpy();
            mvCB.onEvent();
            return true;
        }

        /**
         * Pan stop doesn't always trigger an up, so force one if necessary
         */
        @Override
        public boolean onPanStop(Vector3 touchVec) {
            // force an up event?
            if (mHolding) {
                toggle(true, touchVec);
                return true;
            }
            return false;
        }
    };
    Lol.sGame.mCurrentLevel.mControls.add(c);
    Lol.sGame.mCurrentLevel.mPanControls.add(c);
    Lol.sGame.mCurrentLevel.mToggleControls.add(c);
    return c;
}

From source file:MeshBoneUtil.MeshBone.java

License:Open Source License

public void setLocalRestStartPt(Vector3 world_pt_in) {
    //local_rest_start_pt = Vector3.Transform(world_pt_in, rest_parent_inv_mat);
    local_rest_start_pt = world_pt_in.cpy().traMul(rest_parent_inv_mat);
    calcRestData();//www .j  a  v  a  2  s. c  o m
}

From source file:MeshBoneUtil.MeshBone.java

License:Open Source License

public void setLocalRestEndPt(Vector3 world_pt_in) {
    //local_rest_end_pt = Vector3.Transform(world_pt_in, rest_parent_inv_mat);
    local_rest_end_pt = world_pt_in.cpy().traMul(rest_parent_inv_mat);
    calcRestData();//w  w  w .j a  v a  2 s.  co m
}

From source file:MeshBoneUtil.MeshBone.java

License:Open Source License

public Tuple<Vector3, Vector3> computeDirs(Vector3 start_pt, Vector3 end_pt) {
    Vector3 tangent = end_pt.cpy().sub(start_pt);
    tangent.nor();//  w  w  w  .  j  ava 2s  .c o m

    Vector3 normal = Utils.rotateVec4_90(tangent);

    return new Tuple<Vector3, Vector3>(tangent, normal);
}

From source file:MeshBoneUtil.Utils.java

License:Open Source License

public static Matrix4 calcRotateMat(Vector3 vec_in) {
    Vector3 dir = vec_in.cpy();
    dir.nor();// ww w  . jav  a 2s.co m

    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;
}