public EmitterBoxShape(Vector3f min, Vector3f max) { if (min == null || max == null) { throw new IllegalArgumentException("min or max cannot be null"); } this.min = min; this.len = new Vector3f(); this.len.set(max).subtractLocal(min); }
public Vector3f getMin(Vector3f store) { if (store == null) { store = new Vector3f(); } store.set(center).subtractLocal(xExtent, yExtent, zExtent); return store; }
void computeNormal() { // Cross-product 2 edges tmpV1.set(vertex[1].position).subtractLocal(vertex[0].position); tmpV2.set(vertex[2].position).subtractLocal(vertex[1].position); normal = tmpV1.cross(tmpV2); normal.normalizeLocal(); }
private boolean pointsOnSameSide(Vector3f p1, Vector3f p2, Vector3f line1, Vector3f line2) { // V1 = (line2 - line1) x (p1 - line1) // V2 = (p2 - line1) x (line2 - line1) temp1.set(line2).subtractLocal(line1); temp3.set(temp1); temp2.set(p1).subtractLocal(line1); temp1.crossLocal(temp2); temp2.set(p2).subtractLocal(line1); temp3.crossLocal(temp2); // V1 . V2 >= 0 return temp1.dot(temp3) >= 0; }
public Vector3f getNormal(){ Vector3f normal = new Vector3f(pointb); normal.subtractLocal(pointa).crossLocal(pointc.x-pointa.x, pointc.y-pointa.y, pointc.z-pointa.z); normal.normalizeLocal(); return normal; }
@Override public void cast(Vector3f pointToCast, float radius) { //computed using the Thales' theorem float length = 2 * pointToCast.subtractLocal(0.5f, 0.5f, 0.5f).length() * radius; pointToCast.normalizeLocal().addLocal(0.5f, 0.5f, 0.5f).multLocal(length); } },
public static Vector3f computeTriangleNormal(Vector3f v1, Vector3f v2, Vector3f v3, Vector3f store) { if (store == null) { store = new Vector3f(v2); } else { store.set(v2); } store.subtractLocal(v1).crossLocal(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z); return store.normalizeLocal(); }
/** * calculateNormal generates the normal for this triangle * */ public void calculateNormal() { if (normal == null) { normal = new Vector3f(pointb); } else { normal.set(pointb); } normal.subtractLocal(pointa).crossLocal(pointc.x - pointa.x, pointc.y - pointa.y, pointc.z - pointa.z); normal.normalizeLocal(); }
/** * Initialize the Plane using the given 3 points as coplanar. * * @param v1 * the first point * @param v2 * the second point * @param v3 * the third point */ public void setPlanePoints(Vector3f v1, Vector3f v2, Vector3f v3) { normal.set(v2).subtractLocal(v1); normal.crossLocal(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z) .normalizeLocal(); constant = normal.dot(v1); }
private Vector3f calculateNormal(Vector3f firstPoint, Vector3f rootPoint, Vector3f secondPoint) { Vector3f normal = new Vector3f(); normal.set(firstPoint).subtractLocal(rootPoint) .crossLocal(secondPoint.subtract(rootPoint)).normalizeLocal(); return normal; }
/** * the method applies scale for the given bevel points. The points table is * being modified so expect your result there. * * @param points * the bevel points * @param centerPoint * the center point of the bevel * @param scale * the scale to be applied */ private void applyScale(Vector3f[] points, Vector3f centerPoint, float scale) { Vector3f taperScaleVector = new Vector3f(); for (Vector3f p : points) { taperScaleVector.set(centerPoint).subtractLocal(p).multLocal(1 - scale); p.addLocal(taperScaleVector); } }
private static CollisionResults pick(Camera cam, Vector2f mouseLoc, Node node) { CollisionResults results = new CollisionResults(); Ray ray = new Ray(); Vector3f pos = new Vector3f(mouseLoc.x, mouseLoc.y, -1); Vector3f dir = new Vector3f(mouseLoc.x, mouseLoc.y, 1); dir.subtractLocal(pos).normalizeLocal(); ray.setOrigin(pos); ray.setDirection(dir); node.collideWith(ray, results); return results; } }
/** * This method applies the variation to the particle with already set velocity. * @param particle * the particle to be affected */ @Override protected void applyVelocityVariation(Particle particle) { particle.velocity.set(initialVelocity); temp.set(particle.position).subtractLocal(origin).normalizeLocal().multLocal(radialVelocity); if (horizontal) { temp.y = 0; } particle.velocity.addLocal(temp); temp.set(FastMath.nextRandomFloat(), FastMath.nextRandomFloat(), FastMath.nextRandomFloat()); temp.multLocal(2f); temp.subtractLocal(1f, 1f, 1f); temp.multLocal(initialVelocity.length()); particle.velocity.interpolateLocal(temp, velocityVariation); }
@Override public void updateGeometricState() { super.updateGeometricState(); if (channel < 0 || this.getParent() == null) return; Vector3f currentWorldTranslation = worldTransform.getTranslation(); if (!previousWorldTranslation.equals(currentWorldTranslation)) { getRenderer().updateSourceParam(this, AudioParam.Position); if (velocityFromTranslation && !Float.isNaN(previousWorldTranslation.x)) { velocity.set(currentWorldTranslation).subtractLocal(previousWorldTranslation).multLocal(1f / lastTpf); getRenderer().updateSourceParam(this, AudioParam.Velocity); } previousWorldTranslation.set(currentWorldTranslation); } }
private void lightToSpatial(Light light) { TempVars vars = TempVars.get(); if (light instanceof PointLight) { PointLight pLight = (PointLight) light; Vector3f vecDiff = vars.vect1.set(pLight.getPosition()).subtractLocal(spatial.getWorldTranslation()); spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation())); } if (light instanceof DirectionalLight) { DirectionalLight dLight = (DirectionalLight) light; vars.vect1.set(dLight.getDirection()).multLocal(-1.0f); Vector3f vecDiff = vars.vect1.subtractLocal(spatial.getWorldTranslation()); spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation())); } vars.release(); //TODO add code for Spot light here when it's done }
/** * This method applies the variation to the particle with already set velocity. * @param particle * the particle to be affected */ protected void applyVelocityVariation(Particle particle) { particle.velocity.set(initialVelocity); temp.set(FastMath.nextRandomFloat(), FastMath.nextRandomFloat(), FastMath.nextRandomFloat()); temp.multLocal(2f); temp.subtractLocal(1f, 1f, 1f); temp.multLocal(initialVelocity.length()); particle.velocity.interpolateLocal(temp, velocityVariation); }
@Override public void simpleUpdate(float tpf) { time += tpf; if (time > nextTime) { Vector3f v = new Vector3f(); v.setX(FastMath.nextRandomFloat()); v.setY(FastMath.nextRandomFloat()); v.setZ(FastMath.nextRandomFloat()); v.multLocal(40, 2, 40); v.subtractLocal(20, 1, 20); audioSource.setLocalTranslation(v); audioSource.playInstance(); time = 0; nextTime = FastMath.nextRandomFloat() * 2 + 0.5f; } } }
public boolean intersects(Ray ray) { assert Vector3f.isValidVector(center); TempVars vars = TempVars.get(); Vector3f diff = vars.vect1.set(ray.getOrigin()).subtractLocal(center); float radiusSquared = getRadius() * getRadius(); float a = diff.dot(diff) - radiusSquared; if (a <= 0.0) { vars.release(); // in sphere return true; } // outside sphere float b = ray.getDirection().dot(diff); vars.release(); if (b >= 0.0) { return false; } return b * b >= a; }
private Vector3f getWorldIntersection() { Vector3f origin = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.0f); Vector3f direction = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.3f); direction.subtractLocal(origin).normalizeLocal(); Ray ray = new Ray(origin, direction); CollisionResults results = new CollisionResults(); int numCollisions = terrain.collideWith(ray, results); if (numCollisions > 0) { CollisionResult hit = results.getClosestCollision(); return hit.getContactPoint(); } return null; }
@Override public void simpleUpdate(float tpf) { Vector3f origin = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.0f); Vector3f direction = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.3f); direction.subtractLocal(origin).normalizeLocal(); Ray ray = new Ray(origin, direction); CollisionResults results = new CollisionResults(); int numCollisions = terrain.collideWith(ray, results); if (numCollisions > 0) { CollisionResult hit = results.getClosestCollision(); fpsText.setText(""+hit.getDistance()); dofFilter.setFocusDistance(hit.getDistance()/10.0f); } } }