/** * A method that computes normal for a triangle defined by three vertices. * @param v1 first vertex * @param v2 second vertex * @param v3 third vertex * @return a normal for the face */ public static Vector3f computeNormal(Vector3f v1, Vector3f v2, Vector3f v3) { Vector3f a1 = v1.subtract(v2); Vector3f a2 = v3.subtract(v2); return a2.crossLocal(a1).normalizeLocal(); }
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; }
public float distanceSquared(Vector3f point) { TempVars vars = TempVars.get(); Vector3f compVec1 = vars.vect1; point.subtract(origin, compVec1); float segmentParameter = direction.dot(compVec1); if (-extent < segmentParameter) { if (segmentParameter < extent) { origin.add(direction.mult(segmentParameter, compVec1), compVec1); } else { origin.add(direction.mult(extent, compVec1), compVec1); } } else { origin.subtract(direction.mult(extent, compVec1), compVec1); } compVec1.subtractLocal(point); float len = compVec1.lengthSquared(); vars.release(); return len; }
private void initCatmullRomWayPoints(List<Vector3f> list) { if (CRcontrolPoints == null) { CRcontrolPoints = new ArrayList<Vector3f>(); } else { CRcontrolPoints.clear(); } int nb = list.size() - 1; if (cycle) { CRcontrolPoints.add(list.get(list.size() - 2)); } else { CRcontrolPoints.add(list.get(0).subtract(list.get(1).subtract(list.get(0)))); } for (Iterator<Vector3f> it = list.iterator(); it.hasNext();) { Vector3f vector3f = it.next(); CRcontrolPoints.add(vector3f); } if (cycle) { CRcontrolPoints.add(list.get(1)); } else { CRcontrolPoints.add(list.get(nb).add(list.get(nb).subtract(list.get(nb - 1)))); } }
public Vector3f getNegativeEnd(Vector3f store) { if (store == null) { store = new Vector3f(); } return origin.subtract((direction.mult(extent, store)), store); }
/** * <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(); }
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; }
public Vector3f transformInverseVector(final Vector3f in, Vector3f store){ if (store == null) store = new Vector3f(); // The author of this code should look above and take the inverse of that // But for some reason, they didn't .. // in.subtract(translation, store).divideLocal(scale); // rot.inverse().mult(store, store); in.subtract(translation, store); rot.inverse().mult(store, store); store.divideLocal(scale); return store; }
/** * Centers the spatial in the origin of the world bound. * @return The spatial on which this method is called, e.g <code>this</code>. */ public Spatial center() { Vector3f worldTrans = getWorldTranslation(); Vector3f worldCenter = getWorldBound().getCenter(); Vector3f absTrans = worldTrans.subtract(worldCenter); setLocalTranslation(absTrans); return this; }
public float distanceSquared(Vector3f point) { TempVars vars = TempVars.get(); Vector3f tempVa = vars.vect1, tempVb = vars.vect2; point.subtract(origin, tempVa); float rayParam = direction.dot(tempVa); if (rayParam > 0) { origin.add(direction.mult(rayParam, tempVb), tempVb); } else { tempVb.set(origin); rayParam = 0.0f; } tempVb.subtract(point, tempVa); float len = tempVa.lengthSquared(); vars.release(); return len; }
/** * Get the location in cell-coordinates of the specified location. * Cell coordinates are integer corrdinates, usually with y=0, each * representing a cell in the world. * For example, moving right in the +X direction: * (0,0,0) (1,0,0) (2,0,0), (3,0,0) * and then down the -Z direction: * (3,0,-1) (3,0,-2) (3,0,-3) */ public Vector3f getCamCell(Vector3f location) { Vector3f tile = getTileCell(location); Vector3f offsetHalf = new Vector3f(-0.5f, 0, -0.5f); Vector3f shifted = tile.subtract(offsetHalf); return new Vector3f(FastMath.floor(shifted.x), 0, FastMath.floor(shifted.z)); }
public static boolean intersect(BoundingSphere sphere, Vector3f center, float radius) { assert Vector3f.isValidVector(center) && Vector3f.isValidVector(sphere.center); TempVars vars = TempVars.get(); try { Vector3f diff = center.subtract(sphere.center, vars.vect1); float rsum = sphere.getRadius() + radius; return (diff.dot(diff) <= rsum * rsum); } finally { vars.release(); } }
private void checkPlanetGravity() { Vector3f planetDist = planet.getWorldTranslation().subtract(characterNode.getWorldTranslation()); if (planetDist.length() < 24) { physicsCharacter.setGravity(planetDist.normalizeLocal().multLocal(9.81f)); } else { physicsCharacter.setGravity(normalGravity); } }
/** * Runs on the rendering thread * @param shifted quads are still attached to the parent and don't need to re-load */ protected void attachQuadAt(TerrainQuad q, int quadrant, Vector3f quadCell, boolean shifted) { q.setQuadrant((short) quadrant); if (!shifted) this.attachChild(q); Vector3f loc = quadCell.mult(this.quadSize - 1).subtract(quarterSize, 0, quarterSize);// quadrant location handled TerrainQuad automatically now q.setLocalTranslation(loc); if (!shifted) { for (TerrainGridListener l : listeners) { l.tileAttached(quadCell, q); } } updateModelBound(); }
public float distanceToCam(Geometry spat){ if (spat == null) return Float.NEGATIVE_INFINITY; if (spat.queueDistance != Float.NEGATIVE_INFINITY) return spat.queueDistance; Vector3f camPosition = cam.getLocation(); Vector3f viewVector = cam.getDirection(tempVec2); Vector3f spatPosition = null; if (spat.getWorldBound() != null){ spatPosition = spat.getWorldBound().getCenter(); }else{ spatPosition = spat.getWorldTranslation(); } spatPosition.subtract(camPosition, tempVec); spat.queueDistance = tempVec.dot(viewVector); return spat.queueDistance; }
@Override public void simpleUpdate(float tpf) { super.simpleUpdate(tpf); angle += tpf; angle %= FastMath.TWO_PI; spot.setPosition(new Vector3f(FastMath.cos(angle) * 30f, 34.013165f, FastMath.sin(angle) * 30f)); lightMdl.setLocalTranslation(spot.getPosition()); spot.setDirection(lightTarget.subtract(spot.getPosition())); }
@Override public void simpleUpdate(float tpf) { if (!stop) { super.simpleUpdate(tpf); angle += tpf; angle %= FastMath.TWO_PI; spot.setPosition(new Vector3f(FastMath.cos(angle) * 30f, 34.013165f, FastMath.sin(angle) * 30f)); lightMdl.setLocalTranslation(spot.getPosition()); spot.setDirection(lightTarget.subtract(spot.getPosition())); } } }
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); }
/** * Compute bounds from an array of points * * @param pts * @param transform * @return */ public static BoundingBox computeBoundForPoints(Vector3f[] pts, Transform transform) { Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY); Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY); Vector3f temp = new Vector3f(); for (int i = 0; i < pts.length; i++) { transform.transformVector(pts[i], temp); min.minLocal(temp); max.maxLocal(temp); } Vector3f center = min.add(max).multLocal(0.5f); Vector3f extent = max.subtract(min).multLocal(0.5f); return new BoundingBox(center, extent.x, extent.y, extent.z); }