vertices.add(vertex); vertex.position = new Vector3f(); vertex.textCoords = md5Vertex.getTextCoords(); MD5Mesh.MD5Weight weight = weights.get(i); MD5JointInfo.MD5JointData joint = joints.get(weight.getJointIndex()); Vector3f rotatedPos = new Vector3f(weight.getPosition()).rotate(joint.getOrientation()); Vector3f acumPos = new Vector3f(joint.getPosition()).add(rotatedPos); acumPos.mul(weight.getBias()); vertex.position.add(acumPos); vertex.jointIndices[i - startWeight] = weight.getJointIndex(); vertex.weights[i - startWeight] = weight.getBias(); Vector3f pos2 = v2.position; Vector3f normal = (new Vector3f(pos2).sub(pos0)).cross(new Vector3f(pos1).sub(pos0)); v0.normal.add(normal); v1.normal.add(normal); v2.normal.add(normal); v.normal.normalize();
private void displayMesh(Mesh m) { this.mesh = m; Vector3f lower = new Vector3f(m.xmin(), m.ymin(), m.zmin()); Vector3f upper = new Vector3f(m.xmax(), m.ymax(), m.zmax()); center = new Vector3f(lower).add(upper).mul(0.5f); scale = 2.f / (new Vector3f(upper).sub(lower).length()); // reset other camera/transform/rotate parameters zoom = 1f; arcBall.reset(); // rescale glMesh vertices and center them at (0,0,0) for (int i = 0; i < m.vertices.length; i++) { m.vertices[i] = (m.vertices[i] - center.get(i % 3)) * scale; } // since we rescaled and centered them, scale will be 1.0 and center is the origin (0,0,0) center = new Vector3f(); scale = 1.0f; // create the gl glMesh for rendering glMesh = new GLMesh(gl, m); }
public Vector3f transformDirection(Vector3f v) { v.set(m00 * v.x + m10 * v.y + m20 * v.z, m01 * v.x + m11 * v.y + m21 * v.z, m02 * v.x + m12 * v.y + m22 * v.z); return v; }
protected void lookAt(GVRTransform modeltransform, GVRTransform camera, GVRSceneObject mCharacter) { Vector3f cameraV = new Vector3f(camera.getPositionX(), camera.getPositionY(), camera .getPositionZ()); Vector3f modeltransformV = new Vector3f(modeltransform.getPositionX(), modeltransform .getPositionY(), modeltransform.getPositionZ()); Vector3f delta = cameraV.sub(modeltransformV); Vector3f direction = delta.normalize(); && Math.abs(direction.z) < 0.00001) { if (direction.y > 0) { up = new Vector3f(0.0f, 0.0f, -1.0f); // if direction points in +y } else { up = new Vector3f(0.0f, 0.0f, 1.0f); // if direction points in -y up = new Vector3f(0.0f, 1.0f, 0.0f); // y-axis is the general up up.normalize(); Vector3f right = new Vector3f(); up.cross(direction, right); right.normalize(); direction.cross(right, up); up.normalize();
private void repositionScene() { final float rotationX = mCursorController.getCursor().getParent().getParent().getParent().getTransform().getRotationX(); final float rotationY = mCursorController.getCursor().getParent().getParent().getParent().getTransform().getRotationY(); final float rotationZ = mCursorController.getCursor().getParent().getParent().getParent().getTransform().getRotationZ(); final float rotationW = mCursorController.getCursor().getParent().getParent().getParent().getTransform().getRotationW(); Quaternionf cursorRotation = new Quaternionf(rotationX, rotationY, rotationZ, rotationW); Vector3f lookat = new Vector3f(0, 0, 1); lookat.rotate(cursorRotation); lookat = lookat.normalize(); org.gearvrf.utility.Log.d(TAG, "LookAt: " + lookat.x + ", " + lookat.y + ", " + lookat.z); Vector3f up = new Vector3f(0, 1, 0); Vector3f ownerXaxis = new Vector3f(0, 0, 0); Vector3f ownerYaxis = new Vector3f(0, 0, 0); up.cross(lookat.x, lookat.y, lookat.z, ownerXaxis); ownerXaxis = ownerXaxis.normalize(); lookat.cross(ownerXaxis.x, ownerXaxis.y, ownerXaxis.z, ownerYaxis); ownerYaxis = ownerYaxis.normalize(); float[] newModelMatrix = new float[]{ ownerXaxis.x, ownerXaxis.y, ownerXaxis.z, 0.0f, ownerYaxis.x, ownerYaxis.y, ownerYaxis.z, 0.0f, lookat.x, lookat.y, lookat.z, 0.0f, 0, 0, 0, 1.0f }; mGallery.reposition(newModelMatrix); mVideoPlayer.reposition(newModelMatrix); }
@Test public void testAxisAngle() { final Vector3f xAxis = new Vector3f(1, 0, 0); final Vector3f in = new Vector3f(xAxis); final AxisAngle4f axisAngle = new AxisAngle4f((float) (Math.PI / 2.0), 0, 0, 1); final Vector3f expected = xAxis.rotate(new Quaternionf(axisAngle)); final Vector3f result = ops.linalg().rotate(in, axisAngle); assertEquals("Rotation is incorrect", expected, result); }
public Vector3f positiveY(Vector3f dir) { dir.x = m12 * m20 - m10 * m22; dir.y = m00 * m22 - m02 * m20; dir.z = m02 * m10 - m00 * m12; return dir.normalize(dir); }
private void centerAnim(Vector3f fromCenter, Vector3f toCenter) { if (isAnimationEnabled()) { if (!animator.isAnimating()) { animator.start(); } this.fromCenter = fromCenter; this.center = fromCenter; this.toCenter = toCenter; deltaCenter = new Vector3f(toCenter).sub(fromCenter).div(15f); } else { this.center = toCenter; } }
private void createParticle() { Particle particle = new Particle(this.getBaseParticle()); // Add a little bit of randomness of the parrticle float sign = Math.random() > 0.5d ? -1.0f : 1.0f; float speedInc = sign * (float)Math.random() * this.speedRndRange; float posInc = sign * (float)Math.random() * this.positionRndRange; float scaleInc = sign * (float)Math.random() * this.scaleRndRange; particle.getPosition().add(posInc, posInc, posInc); particle.getSpeed().add(speedInc, speedInc, speedInc); particle.setScale(particle.getScale() + scaleInc); particles.add(particle); }
private void setOffsetPositionFromCursor(Vector3f position, Cursor cursor) { position.set(cursor.getPositionX(),cursor.getPositionY(),cursor.getPositionZ()); if(cursor.getCursorType() == CursorType.OBJECT) { position.mul(OBJECT_CURSOR_RESET_FACTOR); } else { position.mul(LASER_CURSOR_RESET_FACTOR); } }
public void updateListenerPosition(Camera camera) { // Update camera matrix with camera data Transformation.updateGenericViewMatrix(camera.getPosition(), camera.getRotation(), cameraMatrix); listener.setPosition(camera.getPosition()); Vector3f at = new Vector3f(); cameraMatrix.positiveZ(at).negate(); Vector3f up = new Vector3f(); cameraMatrix.positiveY(up); listener.setOrientation(at, up); }
public void move(float time) { GVRSceneObject owner = getOwnerObject(); if (owner == null) { return; } getPosition(); mCurPos.x += Direction.x * Velocity * time; mCurPos.y += Direction.y * Velocity * time; mCurPos.z += Direction.z * Velocity * time; owner.getTransform().setPosition(mCurPos.x, mCurPos.y, mCurPos.z);; Distance = mCurPos.sub(mStartPos, mCurPos).length(); } }