private void refreshFont() { Camera cam = IsoCamera.getInstance().getCam(); Vector3f start = from.getPlanet().getPosition(); Vector3f end = to.getPlanet().getPosition(); float width = label.getLineWidth(); Random r = new Random(); // float height = r.nextFloat() * end.subtract(start).z; Vector3f position = new Vector3f(width / 2, .15f, 0); Vector3f fontPos = start.add(end.subtract(start).mult(0.4f + 0.75f * r.nextFloat())); position.addLocal(fontPos); Vector3f up = cam.getUp().clone(); Vector3f dir = cam.getDirection().clone().negateLocal().normalizeLocal(); Vector3f left = cam.getLeft().clone().normalizeLocal().negateLocal(); Quaternion look = new Quaternion(); look.fromAxes(left, up, dir); label.setLocalTransform(new Transform(position, look)); // Vector3f camPos = IsoCamera.getInstance().getCam().getLocation(); // Vector3f fontPos = to.getPlanet().getPosition(). // subtract(from.getPlanet().getPosition()); // Vector3f up = IsoCamera.getInstance().getCam().getUp().clone(); // Vector3f dir = camPos.subtract(fontPos); //// Vector3f dir = Vector3f.UNIT_Y.clone().subtract(fontPos); // // Vector3f left = IsoCamera.getInstance().getCam().getLeft().clone(); // dir.normalizeLocal(); // left.negateLocal(); // left.normalizeLocal(); // up.normalizeLocal(); //// dir.negateLocal(); // // Quaternion look = new Quaternion(); // look.fromAxes(left, up, dir); // // Vector3f newPos = to.getPlanet().getPosition(). // subtract(from.getPlanet().getPosition()); // // newPos.x -= label.getLineWidth() / 2; // // Transform t = new Transform(newPos, look); // // label.setLocalTransform(t); }
@Override public void updateParticleData(ParticleData[] particles, Camera cam, Matrix3f inverseRotation) { for (int i = 0; i < particles.length; i++) { ParticleData p = particles[i]; int offset = templateVerts.capacity() * i; int colorOffset = templateColors.capacity() * i; if (p.life == 0 || !p.active) { for (int x = 0; x < templateVerts.capacity(); x += 3) { finVerts.put(offset + x, 0); finVerts.put(offset + x + 1, 0); finVerts.put(offset + x + 2, 0); } continue; } for (int x = 0; x < templateVerts.capacity(); x += 3) { switch (emitter.getBillboardMode()) { case Velocity: if (p.velocity.x != Vector3f.UNIT_Y.x && p.velocity.y != Vector3f.UNIT_Y.y && p.velocity.z != Vector3f.UNIT_Y.z) up.set(p.velocity).crossLocal(Vector3f.UNIT_Y).normalizeLocal(); else up.set(p.velocity).crossLocal(lock).normalizeLocal(); left.set(p.velocity).crossLocal(up).normalizeLocal(); dir.set(p.velocity); break; case Velocity_Z_Up: if (p.velocity.x != Vector3f.UNIT_Y.x && p.velocity.y != Vector3f.UNIT_Y.y && p.velocity.z != Vector3f.UNIT_Y.z) up.set(p.velocity).crossLocal(Vector3f.UNIT_Y).normalizeLocal(); else up.set(p.velocity).crossLocal(lock).normalizeLocal(); left.set(p.velocity).crossLocal(up).normalizeLocal(); dir.set(p.velocity); rotStore = tempQ.fromAngleAxis(-90 * FastMath.DEG_TO_RAD, left); left = rotStore.mult(left); up = rotStore.mult(up); break; case Velocity_Z_Up_Y_Left: up.set(p.velocity).crossLocal(Vector3f.UNIT_Y).normalizeLocal(); left.set(p.velocity).crossLocal(up).normalizeLocal(); dir.set(p.velocity); tempV3.set(left).crossLocal(up).normalizeLocal(); rotStore = tempQ.fromAngleAxis(90 * FastMath.DEG_TO_RAD, p.velocity); left = rotStore.mult(left); up = rotStore.mult(up); rotStore = tempQ.fromAngleAxis(-90 * FastMath.DEG_TO_RAD, left); up = rotStore.mult(up); break; case Normal: emitter.getShape().setNext(p.triangleIndex); tempV3.set(emitter.getShape().getNormal()); if (tempV3 == Vector3f.UNIT_Y) tempV3.set(p.velocity); up.set(tempV3).crossLocal(Vector3f.UNIT_Y).normalizeLocal(); left.set(tempV3).crossLocal(up).normalizeLocal(); dir.set(tempV3); break; case Normal_Y_Up: emitter.getShape().setNext(p.triangleIndex); tempV3.set(p.velocity); if (tempV3 == Vector3f.UNIT_Y) tempV3.set(Vector3f.UNIT_X); up.set(Vector3f.UNIT_Y); left.set(tempV3).crossLocal(up).normalizeLocal(); dir.set(tempV3); break; case Camera: up.set(cam.getUp()); left.set(cam.getLeft()); dir.set(cam.getDirection()); break; case UNIT_X: up.set(Vector3f.UNIT_Y); left.set(Vector3f.UNIT_Z); dir.set(Vector3f.UNIT_X); break; case UNIT_Y: up.set(Vector3f.UNIT_Z); left.set(Vector3f.UNIT_X); dir.set(Vector3f.UNIT_Y); break; case UNIT_Z: up.set(Vector3f.UNIT_X); left.set(Vector3f.UNIT_Y); dir.set(Vector3f.UNIT_Z); break; } tempV3.set(templateVerts.get(x), templateVerts.get(x + 1), templateVerts.get(x + 2)); tempV3 = rotStore.mult(tempV3); tempV3.multLocal(p.size); rotStore.fromAngles(p.angles.x, p.angles.y, p.angles.z); tempV3 = rotStore.mult(tempV3); tempV3.addLocal(p.position); if (!emitter.getParticlesFollowEmitter()) { tempV3.subtractLocal( emitter .getEmitterNode() .getWorldTranslation() .subtract(p.initialPosition)); // .divide(8f)); } finVerts.put(offset + x, tempV3.getX()); finVerts.put(offset + x + 1, tempV3.getY()); finVerts.put(offset + x + 2, tempV3.getZ()); } if (p.emitter.getApplyLightingTransform()) { for (int v = 0; v < templateNormals.capacity(); v += 3) { tempV3.set( templateNormals.get(v), templateNormals.get(v + 1), templateNormals.get(v + 2)); rotStore.fromAngles(p.angles.x, p.angles.y, p.angles.z); mat3.set(rotStore.toRotationMatrix()); float vx = tempV3.x, vy = tempV3.y, vz = tempV3.z; tempV3.x = mat3.get(0, 0) * vx + mat3.get(0, 1) * vy + mat3.get(0, 2) * vz; tempV3.y = mat3.get(1, 0) * vx + mat3.get(1, 1) * vy + mat3.get(1, 2) * vz; tempV3.z = mat3.get(2, 0) * vx + mat3.get(2, 1) * vy + mat3.get(2, 2) * vz; finNormals.put(offset + v, tempV3.getX()); finNormals.put(offset + v + 1, tempV3.getY()); finNormals.put(offset + v + 2, tempV3.getZ()); } } for (int v = 0; v < templateColors.capacity(); v += 4) { finColors .put(colorOffset + v, p.color.r) .put(colorOffset + v + 1, p.color.g) .put(colorOffset + v + 2, p.color.b) .put(colorOffset + v + 3, p.color.a * p.alpha); } } this.setBuffer(VertexBuffer.Type.Position, 3, finVerts); if (particles[0].emitter.getApplyLightingTransform()) this.setBuffer(VertexBuffer.Type.Normal, 3, finNormals); this.setBuffer(VertexBuffer.Type.Color, 4, finColors); updateBound(); }
/** * Updates the points array to contain the frustum corners of the given camera. The nearOverride * and farOverride variables can be used to override the camera's near/far values with own values. * * <p>TODO: Reduce creation of new vectors * * @param viewCam * @param nearOverride * @param farOverride */ public static void updateFrustumPoints( Camera viewCam, float nearOverride, float farOverride, float scale, Vector3f[] points) { Vector3f pos = viewCam.getLocation(); Vector3f dir = viewCam.getDirection(); Vector3f up = viewCam.getUp(); float depthHeightRatio = viewCam.getFrustumTop() / viewCam.getFrustumNear(); float near = nearOverride; float far = farOverride; float ftop = viewCam.getFrustumTop(); float fright = viewCam.getFrustumRight(); float ratio = fright / ftop; float near_height; float near_width; float far_height; float far_width; if (viewCam.isParallelProjection()) { near_height = ftop; near_width = near_height * ratio; far_height = ftop; far_width = far_height * ratio; } else { near_height = depthHeightRatio * near; near_width = near_height * ratio; far_height = depthHeightRatio * far; far_width = far_height * ratio; } Vector3f right = dir.cross(up).normalizeLocal(); Vector3f temp = new Vector3f(); temp.set(dir).multLocal(far).addLocal(pos); Vector3f farCenter = temp.clone(); temp.set(dir).multLocal(near).addLocal(pos); Vector3f nearCenter = temp.clone(); Vector3f nearUp = temp.set(up).multLocal(near_height).clone(); Vector3f farUp = temp.set(up).multLocal(far_height).clone(); Vector3f nearRight = temp.set(right).multLocal(near_width).clone(); Vector3f farRight = temp.set(right).multLocal(far_width).clone(); points[0].set(nearCenter).subtractLocal(nearUp).subtractLocal(nearRight); points[1].set(nearCenter).addLocal(nearUp).subtractLocal(nearRight); points[2].set(nearCenter).addLocal(nearUp).addLocal(nearRight); points[3].set(nearCenter).subtractLocal(nearUp).addLocal(nearRight); points[4].set(farCenter).subtractLocal(farUp).subtractLocal(farRight); points[5].set(farCenter).addLocal(farUp).subtractLocal(farRight); points[6].set(farCenter).addLocal(farUp).addLocal(farRight); points[7].set(farCenter).subtractLocal(farUp).addLocal(farRight); if (scale != 1.0f) { // find center of frustum Vector3f center = new Vector3f(); for (int i = 0; i < 8; i++) { center.addLocal(points[i]); } center.divideLocal(8f); Vector3f cDir = new Vector3f(); for (int i = 0; i < 8; i++) { cDir.set(points[i]).subtractLocal(center); cDir.multLocal(scale - 1.0f); points[i].addLocal(cDir); } } }