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; }
@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); } },
private void setupLight() { // AmbientLight al = new AmbientLight(); // al.setColor(ColorRGBA.White.mult(1)); // rootNode.addLight(al); DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal()); dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f)); rootNode.addLight(dl); }
/** * <p>Creates a new LineSegment with a given origin and end. This constructor will calculate the * center, the direction and the extent.</p> */ public LineSegment(Vector3f start, Vector3f end) { this.origin = new Vector3f(0.5f * (start.x + end.x), 0.5f * (start.y + end.y), 0.5f * (start.z + end.z)); this.direction = end.subtract(start); this.extent = direction.length() * 0.5f; direction.normalizeLocal(); }
private void scaleAsParent(float percent, Vector3f playerPos, Vector3f dist) { float scale = mapValue(percent, 1.0f, poiRadius); Vector3f distToHorizon = dist.subtract(dist.normalize()); Vector3f offLocation = playerPos.add(distToHorizon); Vector3f rootOff = offLocation.mult(scale).negate(); rootOff.addLocal(dist); debugTools.setGreenArrow(Vector3f.ZERO, offLocation); getRootNode().setLocalScale(scale); getRootNode().setLocalTranslation(rootOff); }
public Vector3f getMin(Vector3f store) { if (store == null) { store = new Vector3f(); } store.set(center).subtractLocal(xExtent, yExtent, zExtent); return store; }
/** * Projects this vector onto another vector * * @param other The vector to project this vector onto * @return A new vector with the projection result */ public Vector3f project(Vector3f other){ float n = this.dot(other); // A . B float d = other.lengthSquared(); // |B|^2 return new Vector3f(other).multLocal(n/d); }
/** * 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); }
public float distanceSquared(Vector3f point) { TempVars vars = TempVars.get(); Vector3f compVec1 = vars.vect1; Vector3f compVec2 = vars.vect2; point.subtract(origin, compVec1); float lineParameter = direction.dot(compVec1); origin.add(direction.mult(lineParameter, compVec2), compVec2); compVec2.subtract(point, compVec1); float len = compVec1.lengthSquared(); vars.release(); return len; }
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; }
/** * @return the centroid of the face */ public Vector3f computeCentroid() { Vector3f result = new Vector3f(); List<Vector3f> vertices = temporalMesh.getVertices(); for (Integer index : indexes) { result.addLocal(vertices.get(index)); } return result.divideLocal(indexes.size()); }