List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D getY
public double getY()
From source file:org.forYoink.math.CommonsVector3D.java
@Override public Vector ebeMultiply(Vector m) { Vector3D tempM = (Vector3D) m.getInternalVector(); double x = tempM.getX() * this.internalVector.getX(); double y = tempM.getY() * this.internalVector.getY(); double z = tempM.getZ() * this.internalVector.getZ(); tempVector = new Vector3D(x, y, z); Vector temp = new CommonsVector3D(); temp.setInternalVector(tempVector);/* w w w . ja v a 2 s .c o m*/ return temp; }
From source file:org.gearvrf.keyboard.model.SphereFlag.java
public void moveToCursor() { if (followCursorAnimation != null) { getGVRContext().getAnimationEngine().stop(followCursorAnimation); }// w w w. jav a 2 s . c o m GVRCameraRig cameraObject = getGVRContext().getMainScene().getMainCameraRig(); float desiredDistance = (float) Math.max(0.7 * Util.distance(getParent(), cameraObject.getTransform()), Constants.MINIMUM_DISTANCE_FROM_CAMERA); float[] lookAt = getGVRContext().getMainScene().getMainCameraRig().getLookAt(); Vector3D lookAtVector = new Vector3D(lookAt[0], lookAt[1], lookAt[2]); final float desiredX = (float) lookAtVector.getX() * desiredDistance; final float desiredY = (float) lookAtVector.getY() * desiredDistance + CURSOR_POSITION_OFFSET_Y; final float desiredZ = (float) lookAtVector.getZ() * desiredDistance; float x = desiredX - getParent().getTransform().getPositionX(); float y = desiredY - getParent().getTransform().getPositionY(); float z = desiredZ - getParent().getTransform().getPositionZ(); followCursorAnimation = new GVRRelativeMotionAnimation(getParent(), 0.8f, x, y, z) .setInterpolator(new InterpolatorExpoEaseOut()).start(getGVRContext().getAnimationEngine()); }
From source file:org.gearvrf.keyboard.model.SphereStaticList.java
private void getSpheres(GVRContext gvrContext, int array) { listFlag = new ArrayList<GVRSceneObject>(); Resources res = gvrContext.getContext().getResources(); TypedArray spheres = res.obtainTypedArray(array); for (int i = 0; i < spheres.length(); i++) { int type = spheres.getResourceId(i, -1); TypedArray sphere = res.obtainTypedArray(type); SphereFlag objectSphere = new SphereFlag(gvrContext, sphere); Vector3D parentPosition = objectSphere.getInitialPositionVector(); GVRSceneObject parent = new GVRSceneObject(gvrContext, new GVRAndroidResource(gvrContext, R.drawable.hit_area_half), new GVRAndroidResource(gvrContext, R.raw.empty)); parent.setName(SceneObjectNames.SPHERE_FLAG_PARENT); parent.getTransform().setPosition((float) parentPosition.getX(), (float) parentPosition.getY(), (float) parentPosition.getZ()); parent.addChildObject(objectSphere); listFlag.add(parent);/*from w w w . j a v a2s . c o m*/ } }
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 ava 2 s . 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 www . j a va 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 w ww. j a v a2 s .c o m*/ handle.motionY = velocity.getY(); handle.motionZ = velocity.getZ(); }