use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class SpotLight method intersectsBox.
@Override
public boolean intersectsBox(BoundingBox box, TempVars vars) {
if (this.spotRange > 0f) {
// 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;
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class BIHTree method setMinMax.
private void setMinMax(BoundingBox bbox, boolean doMin, int axis, float value) {
Vector3f min = bbox.getMin(null);
Vector3f max = bbox.getMax(null);
if (doMin) {
min.set(axis, value);
} else {
max.set(axis, value);
}
bbox.setMinMax(min, max);
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class ParticleEmitter method updateParticleState.
private void updateParticleState(float tpf) {
// Force world transform to update
this.getWorldTransform();
TempVars vars = TempVars.get();
Vector3f min = vars.vect1.set(Vector3f.POSITIVE_INFINITY);
Vector3f max = vars.vect2.set(Vector3f.NEGATIVE_INFINITY);
for (int i = 0; i < particles.length; ++i) {
Particle p = particles[i];
if (p.life == 0) {
// assert i <= firstUnUsed;
continue;
}
p.life -= tpf;
if (p.life <= 0) {
this.freeParticle(i);
continue;
}
updateParticle(p, tpf, min, max);
if (firstUnUsed < i) {
this.swap(firstUnUsed, i);
if (i == lastUsed) {
lastUsed = firstUnUsed;
}
firstUnUsed++;
}
}
// Spawns particles within the tpf timeslot with proper age
float interval = 1f / particlesPerSec;
float originalTpf = tpf;
tpf += timeDifference;
while (tpf > interval) {
tpf -= interval;
Particle p = emitParticle(min, max);
if (p != null) {
p.life -= tpf;
if (lastPos != null && isInWorldSpace()) {
p.position.interpolateLocal(lastPos, 1 - tpf / originalTpf);
}
if (p.life <= 0) {
freeParticle(lastUsed);
} else {
updateParticle(p, tpf, min, max);
}
}
}
timeDifference = tpf;
if (lastPos == null) {
lastPos = new Vector3f();
}
lastPos.set(getWorldTranslation());
//This check avoids a NaN bounds when all the particles are dead during the first update.
if (!min.equals(Vector3f.POSITIVE_INFINITY) && !max.equals(Vector3f.NEGATIVE_INFINITY)) {
BoundingBox bbox = (BoundingBox) this.getMesh().getBound();
bbox.setMinMax(min, max);
this.setBoundRefresh();
}
vars.release();
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class DefaultLightFilter method filterLights.
@Override
public void filterLights(Geometry geometry, LightList filteredLightList) {
TempVars vars = TempVars.get();
try {
LightList worldLights = geometry.getWorldLightList();
for (int i = 0; i < worldLights.size(); i++) {
Light light = worldLights.get(i);
// If this light is not enabled it will be ignored.
if (!light.isEnabled()) {
continue;
}
if (light.frustumCheckNeeded) {
processedLights.add(light);
light.frustumCheckNeeded = false;
light.intersectsFrustum = light.intersectsFrustum(camera, vars);
}
if (!light.intersectsFrustum) {
continue;
}
BoundingVolume bv = geometry.getWorldBound();
if (bv instanceof BoundingBox) {
if (!light.intersectsBox((BoundingBox) bv, vars)) {
continue;
}
} else if (bv instanceof BoundingSphere) {
if (!Float.isInfinite(((BoundingSphere) bv).getRadius())) {
if (!light.intersectsSphere((BoundingSphere) bv, vars)) {
continue;
}
}
}
if (light.getType() == Light.Type.Probe) {
probeBlendStrat.registerProbe((LightProbe) light);
} else {
filteredLightList.add(light);
}
}
probeBlendStrat.populateProbes(geometry, filteredLightList);
} finally {
vars.release();
}
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class TemporalMesh method getWorldBound.
@Override
public BoundingVolume getWorldBound() {
this.updateModelBound();
Node parent = this.getParent();
if (parent != null) {
BoundingVolume bv = boundingBox.clone();
bv.setCenter(parent.getWorldTranslation());
return bv;
} else {
return boundingBox;
}
}
Aggregations