Java Code Examples for com.jme3.math.Vector3f#lengthSquared()
The following examples show how to use
com.jme3.math.Vector3f#lengthSquared() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeparationBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see AbstractSteeringBehavior#calculateSteering() */ @Override protected Vector3f calculateRawSteering() { //Propities whom behaviour belongs. Vector3f agentLocation = super.agent.getLocalTranslation(); Vector3f steering = new Vector3f(); for (GameEntity obstacle : this.obstacles) { //If the obstacle is not himself if (obstacle != this.agent && obstacle.distanceRelativeToGameEntity(this.agent) < this.minDistance) { Vector3f location = obstacle.getLocalTranslation().subtract(agentLocation); float lengthSquared = location.lengthSquared(); location.normalizeLocal(); steering.addLocal(location.negate().mult(1f / ((float) FastMath.pow(lengthSquared, 2)))); } } return steering; }
Example 2
Source File: SpotLight.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean intersectsBox(BoundingBox box, TempVars vars) { if (this.spotRange > 0f) { // Check spot range first. // Sphere v. box collision if (!Intersection.intersect(box, position, spotRange)) { return false; } } Vector3f otherCenter = box.getCenter(); Vector3f radVect = vars.vect4; radVect.set(box.getXExtent(), box.getYExtent(), box.getZExtent()); float otherRadiusSquared = radVect.lengthSquared(); float otherRadius = FastMath.sqrt(otherRadiusSquared); // Check if sphere is within spot angle. // Cone v. sphere collision. Vector3f E = direction.mult(otherRadius * outerAngleSinRcp, vars.vect1); Vector3f U = position.subtract(E, vars.vect2); Vector3f D = otherCenter.subtract(U, vars.vect3); float dsqr = D.dot(D); float e = direction.dot(D); if (e > 0f && e * e >= dsqr * outerAngleCosSqr) { D = otherCenter.subtract(position, vars.vect3); dsqr = D.dot(D); e = -direction.dot(D); if (e > 0f && e * e >= dsqr * outerAngleSinSqr) { return dsqr <= otherRadiusSquared; } else { return true; } } return false; }
Example 3
Source File: EmitterSphereShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void getRandomPoint(Vector3f store) { do { store.x = (FastMath.nextRandomFloat() * 2f - 1f); store.y = (FastMath.nextRandomFloat() * 2f - 1f); store.z = (FastMath.nextRandomFloat() * 2f - 1f); } while (store.lengthSquared() > 1); store.multLocal(radius); store.addLocal(center); }
Example 4
Source File: SweepSphere.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private float collideWithSegment(Vector3f sCenter, Vector3f sVelocity, float velocitySquared, Vector3f l1, Vector3f l2, float t, Vector3f store) { Vector3f edge = temp1.set(l2).subtractLocal(l1); Vector3f base = temp2.set(l1).subtractLocal(sCenter); float edgeSquared = edge.lengthSquared(); float baseSquared = base.lengthSquared(); float EdotV = edge.dot(sVelocity); float EdotB = edge.dot(base); float a = (edgeSquared * -velocitySquared) + EdotV * EdotV; float b = (edgeSquared * 2f * sVelocity.dot(base)) - (2f * EdotV * EdotB); float c = (edgeSquared * (1f - baseSquared)) + EdotB * EdotB; float newT = getLowestRoot(a, b, c, t); if (!Float.isNaN(newT)){ float f = (EdotV * newT - EdotB) / edgeSquared; if (f >= 0f && f < 1f){ store.scaleAdd(f, edge, l1); return newT; } } return Float.NaN; }