use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class BIHTree method collideWithRay.
private int collideWithRay(Ray r, Matrix4f worldMatrix, BoundingVolume worldBound, CollisionResults results) {
TempVars vars = TempVars.get();
try {
CollisionResults boundResults = vars.collisionResults;
boundResults.clear();
worldBound.collideWith(r, boundResults);
if (boundResults.size() > 0) {
float tMin = boundResults.getClosestCollision().getDistance();
float tMax = boundResults.getFarthestCollision().getDistance();
if (tMax <= 0) {
tMax = Float.POSITIVE_INFINITY;
} else if (tMin == tMax) {
tMin = 0;
}
if (tMin <= 0) {
tMin = 0;
}
if (r.getLimit() < Float.POSITIVE_INFINITY) {
tMax = Math.min(tMax, r.getLimit());
if (tMin > tMax) {
return 0;
}
}
// return root.intersectBrute(r, worldMatrix, this, tMin, tMax, results);
return root.intersectWhere(r, worldMatrix, this, tMin, tMax, results);
}
return 0;
} finally {
vars.release();
}
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class ParticleEmitter method emitParticles.
/**
* Instantly emits available particles, up to num.
*/
public void emitParticles(int num) {
// Force world transform to update
this.getWorldTransform();
TempVars vars = TempVars.get();
BoundingBox bbox = (BoundingBox) this.getMesh().getBound();
Vector3f min = vars.vect1;
Vector3f max = vars.vect2;
bbox.getMin(min);
bbox.getMax(max);
if (!Vector3f.isValidVector(min)) {
min.set(Vector3f.POSITIVE_INFINITY);
}
if (!Vector3f.isValidVector(max)) {
max.set(Vector3f.NEGATIVE_INFINITY);
}
for (int i = 0; i < num; i++) {
if (emitParticle(min, max) == null)
break;
}
bbox.setMinMax(min, max);
this.setBoundRefresh();
vars.release();
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class ParticleEmitter method renderFromControl.
/**
* Callback from Control.render(), do not use.
*
* @param rm
* @param vp
*/
private void renderFromControl(RenderManager rm, ViewPort vp) {
Camera cam = vp.getCamera();
if (meshType == ParticleMesh.Type.Point) {
float C = cam.getProjectionMatrix().m00;
C *= cam.getWidth() * 0.5f;
// send attenuation params
this.getMaterial().setFloat("Quadratic", C);
}
Matrix3f inverseRotation = Matrix3f.IDENTITY;
TempVars vars = null;
if (!worldSpace) {
vars = TempVars.get();
inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
}
particleMesh.updateParticleData(particles, cam, inverseRotation);
if (!worldSpace) {
vars.release();
}
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class LightProbeBlendingProcessor method computeBlendFactors.
private float computeBlendFactors(List<BlendFactor> blendFactors) {
float sumBlendFactors = 0;
for (Spatial scene : viewPort.getScenes()) {
for (Light light : scene.getWorldLightList()) {
if (light.getType() == Light.Type.Probe) {
LightProbe p = (LightProbe) light;
TempVars vars = TempVars.get();
boolean intersect = p.intersectsFrustum(viewPort.getCamera(), vars);
vars.release();
//check if the probe is inside the camera frustum
if (intersect) {
//is the poi inside the bounds of this probe
if (poi.getWorldBound().intersects(p.getBounds())) {
//computing the distance as we need it to check if th epoi in in the inner radius and later to compute the weight
float outerRadius = ((BoundingSphere) p.getBounds()).getRadius();
float innerRadius = outerRadius * 0.5f;
float distance = p.getBounds().getCenter().distance(poi.getWorldTranslation());
// if the poi in inside the inner range of this probe, then this probe is the only one that matters.
if (distance < innerRadius) {
blendFactors.clear();
blendFactors.add(new BlendFactor(p, 1.0f));
return 1.0f;
}
//else we need to compute the weight of this probe and collect it for blending
float ndf = (distance - innerRadius) / (outerRadius - innerRadius);
sumBlendFactors += ndf;
blendFactors.add(new BlendFactor(p, ndf));
}
}
}
}
}
return sumBlendFactors;
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class PoiLightProbeLightFilter 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 (light.getType() == Light.Type.Probe) {
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;
}
}
}
filteredLightList.add(light);
}
processor.populateProbe(filteredLightList);
} finally {
vars.release();
}
}
Aggregations