Example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D getZ

List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D getZ

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.threed Vector3D getZ.

Prototype

public double getZ() 

Source Link

Document

Get the height of the vector.

Usage

From source file:org.gearvrf.keyboard.util.Util.java

public static float getYRotationAngle(Vector3D rotatingVector, Vector3D targetObject) {
    return (float) Math.toDegrees(Math.atan2(targetObject.getX() - rotatingVector.getX(),
            targetObject.getZ() - rotatingVector.getZ()));
}

From source file:org.gearvrf.keyboard.util.Util.java

public static float[] calculatePointBetweenTwoObjects(GVRSceneObject object, Vector3D vector,
        float desiredDistance) {
    float[] point = new float[3];
    float ratio = desiredDistance / (float) distance(vector, object);
    point[0] = (1 - ratio) * object.getTransform().getPositionX() + (ratio) * (float) vector.getX();
    point[1] = (1 - ratio) * object.getTransform().getPositionY() + (ratio) * (float) vector.getY();
    point[2] = (1 - ratio) * object.getTransform().getPositionZ() + (ratio) * (float) vector.getZ();

    return point;
}

From source file:org.gearvrf.keyboard.util.Util.java

public static float[] calculatePointBetweenTwoObjects(GVRTransform object, Vector3D vector,
        float desiredDistance) {
    float[] point = new float[3];
    float ratio = desiredDistance / (float) distance(vector, object);
    point[0] = (1 - ratio) * object.getPositionX() + (ratio) * (float) vector.getX();
    point[1] = (1 - ratio) * object.getPositionY() + (ratio) * (float) vector.getY();
    point[2] = (1 - ratio) * object.getPositionZ() + (ratio) * (float) vector.getZ();

    return point;
}

From source file:org.gearvrf.keyboard.util.Util.java

public static double distance(Vector3D vector, GVRSceneObject object) {
    return Math.sqrt(Math.pow(vector.getX() - object.getTransform().getPositionX(), 2)
            + Math.pow(vector.getY() - object.getTransform().getPositionY(), 2)
            + Math.pow(vector.getZ() - object.getTransform().getPositionZ(), 2));

}

From source file:org.gearvrf.keyboard.util.Util.java

public static double distance(Vector3D vector, GVRTransform object) {
    return Math.sqrt(Math.pow(vector.getX() - object.getPositionX(), 2)
            + Math.pow(vector.getY() - object.getPositionY(), 2)
            + Math.pow(vector.getZ() - object.getPositionZ(), 2));

}

From source file:org.gearvrf.keyboard.util.Util.java

public static void rotateWithOpenGLLookAt(Vector3D cameraVector, Vector3D parentVector, GVRSceneObject object) {
    Vector3D globalUpVector = new Vector3D(0, 1, 0);
    Vector3D lookVector = parentVector.normalize();
    Vector3D rightVector = lookVector.crossProduct(globalUpVector);
    Vector3D upVector = rightVector.crossProduct(lookVector);
    Vector3D zAxis = cameraVector.subtract(parentVector).normalize();
    // Vector3D xAxis = upVector.crossProduct(zAxis).normalize();
    Vector3D xAxis = zAxis.crossProduct(upVector).normalize();
    Vector3D yAxis = xAxis.crossProduct(zAxis).normalize();
    // Vector3D yAxis = xAxis.crossProduct(zAxis).normalize();
    zAxis = zAxis.scalarMultiply(-1.f);//from   w w w.j a  v  a2s.c  om

    float angle = (float) Vector3D.angle(parentVector, cameraVector);
    angle = (float) Math.toDegrees(angle);

    object.getTransform().rotateByAxis(angle, (float) xAxis.getX(), (float) xAxis.getY(), (float) xAxis.getZ());
    object.getTransform().rotateByAxis(angle, (float) yAxis.getX(), (float) yAxis.getY(), (float) yAxis.getZ());
    object.getTransform().rotateByAxis(angle, (float) zAxis.getX(), (float) zAxis.getY(), (float) zAxis.getZ());
}

From source file:org.gearvrf.scene_objects.GVRCylinderSceneObject.java

private void createBody(float bottomRadius, float topRadius, float height, int stackNumber, int sliceNumber) {
    float difference = bottomRadius - topRadius;
    float halfHeight = height / 2.0f;

    for (int stack = 0; stack < stackNumber; stack++) {

        int initVertexCount = vertexCount;

        float stackPercentage0 = ((float) (stack) / stackNumber);
        float stackPercentage1 = ((float) (stack + 1) / stackNumber);

        float t0 = 1.0f - stackPercentage0;
        float t1 = 1.0f - stackPercentage1;
        float y0 = -halfHeight + (stackPercentage0 * height);
        float y1 = -halfHeight + (stackPercentage1 * height);

        float nx, ny, nz;
        for (int slice = 0; slice < sliceNumber; slice++) {
            float slicePercentage0 = ((float) (slice) / sliceNumber);
            float slicePercentage1 = ((float) (slice + 1) / sliceNumber);
            double theta0 = slicePercentage0 * 2.0 * Math.PI;
            double theta1 = slicePercentage1 * 2.0 * Math.PI;
            double cosTheta0 = Math.cos(theta0);
            double sinTheta0 = Math.sin(theta0);
            double cosTheta1 = Math.cos(theta1);
            double sinTheta1 = Math.sin(theta1);

            float radius = (bottomRadius - (difference * stackPercentage0));
            float x0 = (float) (radius * cosTheta0);
            float z0 = (float) (-radius * sinTheta0);
            float x1 = (float) (radius * cosTheta1);
            float z1 = (float) (-radius * sinTheta1);

            radius = (bottomRadius - (difference * stackPercentage1));
            float x2 = (float) (radius * cosTheta0);
            float z2 = (float) (-radius * sinTheta0);
            float x3 = (float) (radius * cosTheta1);
            float z3 = (float) (-radius * sinTheta1);

            float s0 = slicePercentage0;
            float s1 = slicePercentage1;

            vertices[vertexCount + 0] = x0;
            vertices[vertexCount + 1] = y0;
            vertices[vertexCount + 2] = z0;

            vertices[vertexCount + 3] = x1;
            vertices[vertexCount + 4] = y0;
            vertices[vertexCount + 5] = z1;

            vertices[vertexCount + 6] = x2;
            vertices[vertexCount + 7] = y1;
            vertices[vertexCount + 8] = z2;

            vertices[vertexCount + 9] = x3;
            vertices[vertexCount + 10] = y1;
            vertices[vertexCount + 11] = z3;

            // calculate normal
            Vector3D v1 = new Vector3D(x1 - x0, 0, z1 - z0);
            Vector3D v2 = new Vector3D(x2 - x0, y1 - y0, z2 - z0);
            Vector3D v3 = v1.crossProduct(v2).normalize();

            nx = (float) v3.getX();
            ny = (float) v3.getY();
            nz = (float) v3.getZ();
            normals[vertexCount + 0] = nx;
            normals[vertexCount + 1] = ny;
            normals[vertexCount + 2] = nz;
            normals[vertexCount + 3] = nx;
            normals[vertexCount + 4] = ny;
            normals[vertexCount + 5] = nz;
            normals[vertexCount + 6] = nx;
            normals[vertexCount + 7] = ny;
            normals[vertexCount + 8] = nz;
            normals[vertexCount + 9] = nx;
            normals[vertexCount + 10] = ny;
            normals[vertexCount + 11] = nz;

            texCoords[texCoordCount + 0] = s0;
            texCoords[texCoordCount + 1] = t0;

            texCoords[texCoordCount + 2] = s1;
            texCoords[texCoordCount + 3] = t0;

            texCoords[texCoordCount + 4] = s0;
            texCoords[texCoordCount + 5] = t1;

            texCoords[texCoordCount + 6] = s1;
            texCoords[texCoordCount + 7] = t1;

            indices[indexCount + 0] = (char) (triangleCount + 0); // 0
            indices[indexCount + 1] = (char) (triangleCount + 1); // 1
            indices[indexCount + 2] = (char) (triangleCount + 2); // 2

            indices[indexCount + 3] = (char) (triangleCount + 2); // 2
            indices[indexCount + 4] = (char) (triangleCount + 1); // 1
            indices[indexCount + 5] = (char) (triangleCount + 3); // 3

            vertexCount += 12;//from   w  w w. j ava  2 s .co m
            texCoordCount += 8;
            indexCount += 6;
            triangleCount += 4;
        }

        for (int i = initVertexCount; i < vertexCount - 12; i += 12) {
            Vector3D v1 = new Vector3D(normals[i + 3], normals[i + 4], normals[i + 5]);
            Vector3D v2 = new Vector3D(normals[i + 12], normals[i + 13], normals[i + 14]);
            Vector3D v3 = v1.add(v2).normalize();
            nx = (float) v3.getX();
            ny = (float) v3.getY();
            nz = (float) v3.getZ();
            normals[i + 3] = nx;
            normals[i + 4] = ny;
            normals[i + 5] = nz;
            normals[i + 12] = nx;
            normals[i + 13] = ny;
            normals[i + 14] = nz;

            v1 = new Vector3D(normals[i + 9], normals[i + 10], normals[i + 11]);
            v2 = new Vector3D(normals[i + 18], normals[i + 19], normals[i + 20]);
            v3 = v1.add(v2).normalize();
            nx = (float) v3.getX();
            ny = (float) v3.getY();
            nz = (float) v3.getZ();
            normals[i + 9] = nx;
            normals[i + 10] = ny;
            normals[i + 11] = nz;
            normals[i + 18] = nx;
            normals[i + 19] = ny;
            normals[i + 20] = nz;
        }
        int i1 = vertexCount - 12;
        Vector3D v1 = new Vector3D(normals[i1 + 3], normals[i1 + 4], normals[i1 + 5]);
        int i2 = initVertexCount;
        Vector3D v2 = new Vector3D(normals[i2 + 0], normals[i2 + 1], normals[i2 + 2]);
        Vector3D v3 = v1.add(v2).normalize();
        nx = (float) v3.getX();
        ny = (float) v3.getY();
        nz = (float) v3.getZ();
        normals[i1 + 3] = nx;
        normals[i1 + 4] = ny;
        normals[i1 + 5] = nz;
        normals[i2 + 0] = nx;
        normals[i2 + 1] = ny;
        normals[i2 + 2] = nz;

        v1 = new Vector3D(normals[i1 + 9], normals[i1 + 10], normals[i1 + 11]);
        v2 = new Vector3D(normals[i2 + 6], normals[i2 + 7], normals[i2 + 8]);
        v3 = v1.add(v2).normalize();
        nx = (float) v3.getX();
        ny = (float) v3.getY();
        nz = (float) v3.getZ();
        normals[i1 + 9] = nx;
        normals[i1 + 10] = ny;
        normals[i1 + 11] = nz;
        normals[i2 + 6] = nx;
        normals[i2 + 7] = ny;
        normals[i2 + 8] = nz;
    }
}

From source file:org.hakkit.hakkitmc.entity.HakkitEntity.java

@Override
public void setVelocity(Vector3D velocity) {
    //We may want to fire an event here.

    handle.motionX = velocity.getX();/*from ww w .  j  a  v a 2 s. c o  m*/
    handle.motionY = velocity.getY();
    handle.motionZ = velocity.getZ();
}

From source file:org.jtrfp.trcl.beh.AutoFiring.java

/**
 * Adapted from <a href='http://jaran.de/goodbits/2011/07/17/calculating-an-intercept-course-to-a-target-with-constant-direction-and-velocity-in-a-2-dimensional-plane/'>this article.</a>
 * @param targetPos// w w w  . j  a v  a  2s. co  m
 * @param targetVel
 * @param attackPos
 * @param attackSpeed
 * @return
 * @since Feb 13, 2014
 */
private static Vector3D interceptOf(final Vector3D targetPos, final Vector3D targetVel,
        final Vector3D attackPos, final double attackSpeed) {
    final double dX = targetPos.getX() - attackPos.getX();
    final double dY = targetPos.getY() - attackPos.getY();
    final double dZ = targetPos.getZ() - attackPos.getZ();

    final double h1 = targetVel.getX() * targetVel.getX() + targetVel.getY() * targetVel.getY()
            + targetVel.getZ() * targetVel.getZ() - attackSpeed * attackSpeed;
    final double h2 = dX * targetVel.getX() + dY * targetVel.getY() + dZ * targetVel.getZ();
    double t;
    if (h1 == 0)
        t = -(dX * dX + dY * dY + dZ * dZ) / 2 * h2;
    else {
        final double minusPHalf = -h2 / h1;
        final double disc = minusPHalf * minusPHalf - (dX * dX + dY * dY + dZ * dZ) / h1;
        if (disc < 0)
            return null;

        final double root = Math.sqrt(disc);
        final double t1 = minusPHalf + root;
        final double t2 = minusPHalf - root;
        final double tMin = Math.min(t1, t2);
        final double tMax = Math.max(t1, t2);
        t = tMin > 0 ? tMin : tMax;

        if (t < 0)
            return null;
    } //end else(calculate full)
    return new Vector3D(targetPos.getX() + t * targetVel.getX(), targetPos.getY() + t * targetVel.getY(),
            targetPos.getZ() + t * targetVel.getZ());
}

From source file:org.jtrfp.trcl.beh.AutoLeveling.java

@Override
public void _tick(long timeInMillis) {
    final WorldObject parent = getParent();
    final Vector3D oldHeading = parent.getHeading();
    final Vector3D oldTop = parent.getTop();
    final Vector3D oldCross = oldHeading.crossProduct(oldTop);

    final Vector3D newHeading = levelingAxis == LevelingAxis.HEADING
            ? new Vector3D(
                    oldHeading.getX() * retainmentCoeff[0] + levelingVector.getX() * inverseRetainmentCoeff[0],
                    oldHeading.getY() * retainmentCoeff[1] + levelingVector.getY() * inverseRetainmentCoeff[1],
                    oldHeading.getZ() * retainmentCoeff[2] + levelingVector.getZ() * inverseRetainmentCoeff[2])
                            .normalize()
            : oldHeading.normalize();// w  ww  . j av  a 2s  .  co m

    final Vector3D newTop = levelingAxis == LevelingAxis.TOP ? new Vector3D(
            oldTop.getX() * retainmentCoeff[0] + levelingVector.getX() * inverseRetainmentCoeff[0],
            oldTop.getY() * retainmentCoeff[1] + levelingVector.getY() * inverseRetainmentCoeff[1],
            oldTop.getZ() * retainmentCoeff[2] + levelingVector.getZ() * inverseRetainmentCoeff[2]).normalize()
            : oldTop.normalize();
    final Vector3D newCross = levelingAxis == LevelingAxis.CROSS ? new Vector3D(
            oldCross.getX() * retainmentCoeff[0] + levelingVector.getX() * inverseRetainmentCoeff[0],
            oldCross.getY() * retainmentCoeff[1] + levelingVector.getY() * inverseRetainmentCoeff[1],
            oldCross.getZ() * retainmentCoeff[2] + levelingVector.getZ() * inverseRetainmentCoeff[2])
                    .normalize()
            : oldCross.normalize();

    final Rotation topDelta = new Rotation(oldTop, newTop);
    final Rotation headingDelta = new Rotation(oldHeading, newHeading);
    final Rotation crossDelta = new Rotation(oldCross, newCross);
    parent.setHeading(crossDelta.applyTo(headingDelta.applyTo(topDelta.applyTo(oldHeading))));
    parent.setTop(crossDelta.applyTo(headingDelta.applyTo(topDelta.applyTo(oldTop))));
}