List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D
public Vector3D(double x, double y, double z)
From source file:org.gearvrf.keyboard.model.SphereFlag.java
public void moveToCursor() { if (followCursorAnimation != null) { getGVRContext().getAnimationEngine().stop(followCursorAnimation); }/*from w ww. j a va 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.spinner.Spinner.java
private void lookAt(GVRSceneObject currentChar) { GVRCameraRig camera = this.getGVRContext().getMainScene().getMainCameraRig(); Vector3D vectorCamera = new Vector3D(camera.getTransform().getPositionX(), camera.getTransform().getPositionY(), camera.getTransform().getPositionZ()); Vector3D vectorKeyboard = new Vector3D(this.getParent().getParent().getTransform().getPositionX(), this.getParent().getParent().getTransform().getPositionY(), this.getParent().getParent().getTransform().getPositionZ()); float newX = currentChar.getTransform().getPositionX() + currentChar.getParent().getTransform().getPositionX(); float newY = 0; float newZ = (float) Vector3D.distance(vectorKeyboard, vectorCamera); Log.d("lookatspinner", "newX " + newX); Log.d("lookatspinner", "newY " + newY); Log.d("lookatspinner", "newZ " + newZ); Vector3D emulatedSpinner = new Vector3D(newX, newY, newZ * -1); Vector3D emulateCam = new Vector3D(0, 0, 0); float angle = Util.getYRotationAngle(emulatedSpinner, emulateCam); Log.d("lookatspinner", "angle " + angle); // angle =(float) (angle*1.1); Log.d("lookatspinner", "angle new" + angle); getTransform().setRotationByAxis(angle, 0, 1, 0); }
From source file:org.gearvrf.keyboard.util.Util.java
public static Vector3D getVec3(GVRSceneObject object) { Vector3D vObject = null;// ww w . j a va 2s .c o m if (object != null) { vObject = new Vector3D(object.getTransform().getPositionX(), object.getTransform().getPositionY(), object.getTransform().getPositionZ()); } return vObject; }
From source file:org.gearvrf.keyboard.util.Util.java
public static Vector3D getVec3IgnoreY(GVRSceneObject object) { Vector3D vObject = null;/*from w ww.ja v a 2 s . co m*/ if (object != null) { vObject = new Vector3D(object.getTransform().getPositionX(), 0, object.getTransform().getPositionZ()); } return vObject; }
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 . ja v a 2 s . c o m*/ 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 ww . jav a2 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 Position getPosition() { return new Position(new Vector3D(handle.posX, handle.posY, handle.posZ), handle.rotationYaw, handle.rotationPitch);/*from w w w . j av a 2 s.com*/ }
From source file:org.hakkit.hakkitmc.entity.HakkitEntity.java
@Override public BoundingBox getBoundingBox() { return new BoundingBox( new Vector3D(handle.boundingBox.minX, handle.boundingBox.minY, handle.boundingBox.minZ), new Vector3D(handle.boundingBox.maxX, handle.boundingBox.maxY, handle.boundingBox.maxZ)); }
From source file:org.hakkit.hakkitmc.entity.HakkitEntity.java
@Override public Vector3D getVelocity() { return new Vector3D(handle.motionX, handle.motionY, handle.motionZ); }
From source file:org.hakkit.hakkitmc.entity.HakkitEntity.java
@Override public Vector3D getLookDirection() { Vec3 lookVector = handle.getLookVec(); return new Vector3D(lookVector.xCoord, lookVector.yCoord, lookVector.zCoord); }