com.jme3.util.TempVars Java Examples
The following examples show how to use
com.jme3.util.TempVars.
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: Spatial.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * <code>rotateUpTo</code> is a utility function that alters the * local rotation to point the Y axis in the direction given by newUp. * * @param newUp * the up vector to use - assumed to be a unit vector. */ public void rotateUpTo(Vector3f newUp) { TempVars vars = TempVars.get(); Vector3f compVecA = vars.vect1; Quaternion q = vars.quat1; // First figure out the current up vector. Vector3f upY = compVecA.set(Vector3f.UNIT_Y); Quaternion rot = localTransform.getRotation(); rot.multLocal(upY); // get angle between vectors float angle = upY.angleBetween(newUp); // figure out rotation axis by taking cross product Vector3f rotAxis = upY.crossLocal(newUp).normalizeLocal(); // Build a rotation quat and apply current local rotation. q.fromAngleNormalAxis(angle, rotAxis); q.mult(rot, rot); vars.release(); setTransformRefresh(); }
Example #2
Source File: MyParticleEmitter.java From OpenRTS with MIT License | 6 votes |
/** * 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(); } }
Example #3
Source File: Geometry.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Recomputes the matrix returned by {@link Geometry#getWorldMatrix() }. * This will require a localized transform update for this geometry. */ public void computeWorldMatrix() { // Force a local update of the geometry's transform checkDoTransformUpdate(); // Compute the cached world matrix cachedWorldMat.loadIdentity(); if (ignoreTransform) { return; } cachedWorldMat.setRotationQuaternion(worldTransform.getRotation()); cachedWorldMat.setTranslation(worldTransform.getTranslation()); TempVars vars = TempVars.get(); Matrix4f scaleMat = vars.tempMat4; scaleMat.loadIdentity(); scaleMat.scale(worldTransform.getScale()); cachedWorldMat.multLocal(scaleMat); vars.release(); }
Example #4
Source File: BatchNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void doCopyBuffer(FloatBuffer inBuf, int offset, FloatBuffer outBuf, int componentSize) { TempVars vars = TempVars.get(); Vector3f pos = vars.vect1; // offset is given in element units // convert to be in component units offset *= componentSize; for (int i = 0; i < inBuf.limit() / componentSize; i++) { pos.x = inBuf.get(i * componentSize); pos.y = inBuf.get(i * componentSize + 1); pos.z = inBuf.get(i * componentSize + 2); outBuf.put(offset + i * componentSize, pos.x); outBuf.put(offset + i * componentSize + 1, pos.y); outBuf.put(offset + i * componentSize + 2, pos.z); } vars.release(); }
Example #5
Source File: ParticleEmitter.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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(); } }
Example #6
Source File: TestObbVsBounds.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleUpdate(float tpf) { area.setCenter(ln.getLocalTranslation()); area.setRotation(ln.getLocalRotation()); TempVars vars = TempVars.get(); boolean intersectBox = area.intersectsBox(aabb, vars); boolean intersectFrustum = area.intersectsFrustum(frustumCam, vars); boolean intersectSphere = area.intersectsSphere(sphere, vars); vars.release(); boolean intersect = intersectBox || intersectFrustum || intersectSphere; areaGeom.getMaterial().setColor("Color", intersect ? ColorRGBA.Green : ColorRGBA.White); sphereGeom.getMaterial().setColor("Color", intersectSphere ? ColorRGBA.Cyan : ColorRGBA.White); frustumGeom.getMaterial().setColor("Color", intersectFrustum ? ColorRGBA.Cyan : ColorRGBA.White); aabbGeom.getMaterial().setColor("Color", intersectBox ? ColorRGBA.Cyan : ColorRGBA.White); }
Example #7
Source File: TestConeVSFrustum.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleUpdate(float tpf) { TempVars vars = TempVars.get(); boolean intersect = spotLight.intersectsFrustum(frustumCam, vars); if (intersect) { geom.getMaterial().setColor("Diffuse", ColorRGBA.Green); } else { geom.getMaterial().setColor("Diffuse", ColorRGBA.White); } Vector3f farPoint = vars.vect1.set(spotLight.getPosition()).addLocal(vars.vect2.set(spotLight.getDirection()).multLocal(spotLight.getSpotRange())); //computing the radius of the base disc float farRadius = (spotLight.getSpotRange() / FastMath.cos(spotLight.getSpotOuterAngle())) * FastMath.sin(spotLight.getSpotOuterAngle()); //computing the projection direction : perpendicular to the light direction and coplanar with the direction vector and the normal vector Vector3f perpDirection = vars.vect2.set(spotLight.getDirection()).crossLocal(frustumCam.getWorldPlane(3).getNormal()).normalizeLocal().crossLocal(spotLight.getDirection()); //projecting the far point on the base disc perimeter Vector3f projectedPoint = vars.vect3.set(farPoint).addLocal(perpDirection.multLocal(farRadius)); vars.release(); // boxGeo.setLocalTranslation(spotLight.getPosition()); // boxGeo.setLocalTranslation(projectedPoint); }
Example #8
Source File: Matrix4f.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * <code>fillFloatBuffer</code> fills a FloatBuffer object with the matrix * data. * * @param fb * the buffer to fill, starting at current position. Must have * room for 16 more floats. * @param columnMajor * if true, this buffer should be filled with column major data, * otherwise it will be filled row major. * @return matrix data as a FloatBuffer. (position is advanced by 16 and any * limit set is not changed). */ public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) { // if (columnMajor) { // fb.put(m00).put(m10).put(m20).put(m30); // fb.put(m01).put(m11).put(m21).put(m31); // fb.put(m02).put(m12).put(m22).put(m32); // fb.put(m03).put(m13).put(m23).put(m33); // } else { // fb.put(m00).put(m01).put(m02).put(m03); // fb.put(m10).put(m11).put(m12).put(m13); // fb.put(m20).put(m21).put(m22).put(m23); // fb.put(m30).put(m31).put(m32).put(m33); // } TempVars vars = TempVars.get(); fillFloatArray(vars.matrixWrite, columnMajor); fb.put(vars.matrixWrite, 0, 16); vars.release(); return fb; }
Example #9
Source File: Matrix3f.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * <code>fillFloatBuffer</code> fills a FloatBuffer object with the matrix * data. * * @param fb * the buffer to fill, starting at current position. Must have * room for 9 more floats. * @param columnMajor * true → column-major order, false → row-major order * @return matrix data as a FloatBuffer. (position is advanced by 9 and any * limit set is not changed). */ public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) { // if (columnMajor){ // fb.put(m00).put(m10).put(m20); // fb.put(m01).put(m11).put(m21); // fb.put(m02).put(m12).put(m22); // }else{ // fb.put(m00).put(m01).put(m02); // fb.put(m10).put(m11).put(m12); // fb.put(m20).put(m21).put(m22); // } TempVars vars = TempVars.get(); fillFloatArray(vars.matrixWrite, columnMajor); fb.put(vars.matrixWrite, 0, 9); vars.release(); return fb; }
Example #10
Source File: AudioTrack.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Internal use only * * @see Track#setTime(float, float, com.jme3.animation.AnimControl, * com.jme3.animation.AnimChannel, com.jme3.util.TempVars) */ @Override public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) { if (time >= length) { return; } if (!initialized) { control.addListener(new OnEndListener()); initialized = true; } if (!started && time >= startOffset) { started = true; audio.playInstance(); } }
Example #11
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Compute bounds from an array of points * @param pts * @param mat * @return a new BoundingBox */ public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrix4f mat) { Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY); Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY); TempVars vars = TempVars.get(); Vector3f temp = vars.vect1; for (int i = 0; i < pts.length; i++) { float w = mat.multProj(pts[i], temp); temp.x /= w; temp.y /= w; // Why was this commented out? temp.z /= w; min.minLocal(temp); max.maxLocal(temp); } vars.release(); Vector3f center = min.add(max).multLocal(0.5f); Vector3f extent = max.subtract(min).multLocal(0.5f); //Nehon 08/18/2010 : Added an offset to the extend to avoid banding artifacts when the frustum are aligned return new BoundingBox(center, extent.x + 2.0f, extent.y + 2.0f, extent.z + 2.5f); }
Example #12
Source File: BIHTree.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private BoundingBox createBox(int l, int r) { TempVars vars = TempVars.get(); Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)); Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY)); Vector3f v1 = vars.vect3, v2 = vars.vect4, v3 = vars.vect5; for (int i = l; i <= r; i++) { getTriangle(i, v1, v2, v3); BoundingBox.checkMinMax(min, max, v1); BoundingBox.checkMinMax(min, max, v2); BoundingBox.checkMinMax(min, max, v3); } BoundingBox bbox = new BoundingBox(min, max); vars.release(); return bbox; }
Example #13
Source File: PointLightShadowRenderer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * * @param viewCam * @return true if intersects */ @Override protected boolean checkCulling(Camera viewCam) { if (light == null) { return false; } Camera cam = viewCam; if(frustumCam != null){ cam = frustumCam; cam.setLocation(viewCam.getLocation()); cam.setRotation(viewCam.getRotation()); } TempVars vars = TempVars.get(); boolean intersects = light.intersectsFrustum(cam,vars); vars.release(); return intersects; }
Example #14
Source File: PoseTrack.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) { // TODO: When MeshControl is created, it will gather targets // list automatically which is then retrieved here. /* Mesh target = targets[targetMeshIndex]; if (time < times[0]) { applyFrame(target, 0, weight); } else if (time > times[times.length - 1]) { applyFrame(target, times.length - 1, weight); } else { int startFrame = 0; for (int i = 0; i < times.length; i++) { if (times[i] < time) { startFrame = i; } } int endFrame = startFrame + 1; float blend = (time - times[startFrame]) / (times[endFrame] - times[startFrame]); applyFrame(target, startFrame, blend * weight); applyFrame(target, endFrame, (1f - blend) * weight); } */ }
Example #15
Source File: Spatial.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * <code>rotateUpTo</code> is a utility function that alters the * local rotation to point the Y axis in the direction given by newUp. * * @param newUp * the up vector to use - assumed to be a unit vector. */ public void rotateUpTo(Vector3f newUp) { TempVars vars = TempVars.get(); Vector3f compVecA = vars.vect1; Quaternion q = vars.quat1; // First figure out the current up vector. Vector3f upY = compVecA.set(Vector3f.UNIT_Y); Quaternion rot = localTransform.getRotation(); rot.multLocal(upY); // get angle between vectors float angle = upY.angleBetween(newUp); // figure out rotation axis by taking cross product Vector3f rotAxis = upY.crossLocal(newUp).normalizeLocal(); // Build a rotation quat and apply current local rotation. q.fromAngleNormalAxis(angle, rotAxis); q.mult(rot, rot); vars.release(); setTransformRefresh(); }
Example #16
Source File: BoundingBox.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public BoundingVolume transform(Matrix4f trans, BoundingVolume store) { BoundingBox box; if (store == null || store.getType() != Type.AABB) { box = new BoundingBox(); } else { box = (BoundingBox) store; } TempVars vars = TempVars.get(); float w = trans.multProj(center, box.center); box.center.divideLocal(w); Matrix3f transMatrix = vars.tempMat3; trans.toRotationMatrix(transMatrix); // Make the rotation matrix all positive to get the maximum x/y/z extent transMatrix.absoluteLocal(); vars.vect1.set(xExtent, yExtent, zExtent); transMatrix.mult(vars.vect1, vars.vect1); // Assign the biggest rotations after scales. box.xExtent = FastMath.abs(vars.vect1.getX()); box.yExtent = FastMath.abs(vars.vect1.getY()); box.zExtent = FastMath.abs(vars.vect1.getZ()); vars.release(); return box; }
Example #17
Source File: BoundingVolume.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public int collideWith(Collidable other) { TempVars tempVars = TempVars.get(); try { CollisionResults tempResults = tempVars.collisionResults; tempResults.clear(); return collideWith(other, tempResults); } finally { tempVars.release(); } }
Example #18
Source File: Matrix4f.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void fromFrame(Vector3f location, Vector3f direction, Vector3f up, Vector3f left) { TempVars vars = TempVars.get(); try { Vector3f fwdVector = vars.vect1.set(direction); Vector3f leftVector = vars.vect2.set(fwdVector).crossLocal(up); Vector3f upVector = vars.vect3.set(leftVector).crossLocal(fwdVector); m00 = leftVector.x; m01 = leftVector.y; m02 = leftVector.z; m03 = -leftVector.dot(location); m10 = upVector.x; m11 = upVector.y; m12 = upVector.z; m13 = -upVector.dot(location); m20 = -fwdVector.x; m21 = -fwdVector.y; m22 = -fwdVector.z; m23 = fwdVector.dot(location); m30 = 0f; m31 = 0f; m32 = 0f; m33 = 1f; } finally { vars.release(); } }
Example #19
Source File: BetterCharacterControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * This method works similar to Camera.lookAt but where lookAt sets the * priority on the direction, this method sets the priority on the up vector * so that the result direction vector and rotation is guaranteed to be * perpendicular to the up vector. * * @param rotation The rotation to set the result on or null to create a new * Quaternion, this will be set to the new "z-forward" rotation if not null * @param direction The direction to base the new look direction on, will be * set to the new direction * @param worldUpVector The up vector to use, the result direction will be * perpendicular to this */ protected final void calculateNewForward(Quaternion rotation, Vector3f direction, Vector3f worldUpVector) { if (direction == null) { return; } TempVars vars = TempVars.get(); Vector3f newLeft = vars.vect1; Vector3f newLeftNegate = vars.vect2; newLeft.set(worldUpVector).crossLocal(direction).normalizeLocal(); if (newLeft.equals(Vector3f.ZERO)) { if (direction.x != 0) { newLeft.set(direction.y, -direction.x, 0f).normalizeLocal(); } else { newLeft.set(0f, direction.z, -direction.y).normalizeLocal(); } logger.log(Level.INFO, "Zero left for direction {0}, up {1}", new Object[]{direction, worldUpVector}); } newLeftNegate.set(newLeft).negateLocal(); direction.set(worldUpVector).crossLocal(newLeftNegate).normalizeLocal(); if (direction.equals(Vector3f.ZERO)) { direction.set(Vector3f.UNIT_Z); logger.log(Level.INFO, "Zero left for left {0}, up {1}", new Object[]{newLeft, worldUpVector}); } if (rotation != null) { rotation.fromAxes(newLeft, worldUpVector, direction); } vars.release(); }
Example #20
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public OccludersExtractor(Matrix4f vpm, int cc, BoundingBox sBB, BoundingBox cBB, GeometryList sOCC, TempVars v) { viewProjMatrix = vpm; casterCount = cc; splitBB = sBB; casterBB = cBB; splitOccluders = sOCC; vars = v; }
Example #21
Source File: BoundingBox.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * <code>transform</code> modifies the center of the box to reflect the * change made via a rotation, translation and scale. * * @param trans * the transform to apply * @param store * box to store result in */ @Override public BoundingVolume transform(Transform trans, BoundingVolume store) { BoundingBox box; if (store == null || store.getType() != Type.AABB) { box = new BoundingBox(); } else { box = (BoundingBox) store; } center.mult(trans.getScale(), box.center); trans.getRotation().mult(box.center, box.center); box.center.addLocal(trans.getTranslation()); TempVars vars = TempVars.get(); Matrix3f transMatrix = vars.tempMat3; transMatrix.set(trans.getRotation()); // Make the rotation matrix all positive to get the maximum x/y/z extent transMatrix.absoluteLocal(); Vector3f scale = trans.getScale(); vars.vect1.set(xExtent * FastMath.abs(scale.x), yExtent * FastMath.abs(scale.y), zExtent * FastMath.abs(scale.z)); transMatrix.mult(vars.vect1, vars.vect2); // Assign the biggest rotations after scales. box.xExtent = FastMath.abs(vars.vect2.getX()); box.yExtent = FastMath.abs(vars.vect2.getY()); box.zExtent = FastMath.abs(vars.vect2.getZ()); vars.release(); return box; }
Example #22
Source File: EffectTrack.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Internal use only * * @see Track#setTime(float, float, com.jme3.animation.AnimControl, * com.jme3.animation.AnimChannel, com.jme3.util.TempVars) */ @Override public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) { if (time >= length) { return; } //first time adding the Animation listener to stop the track at the end of the animation if (!initialized) { control.addListener(new OnEndListener()); initialized = true; } //checking for time to trigger the effect if (!emitted && time >= startOffset) { emitted = true; emitter.setCullHint(CullHint.Dynamic); emitter.setEnabled(true); //if the emitter has 0 particles per seconds emmit all particles in one shot if (particlesPerSeconds == 0) { emitter.emitAllParticles(); if (!killParticles.stopRequested) { emitter.addControl(killParticles); killParticles.stopRequested = true; } } else { //else reset its former particlePerSec value to let it emmit. emitter.setParticlesPerSec(particlesPerSeconds); } } }
Example #23
Source File: MotionPath.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * interpolate the path giving the time since the beginning and the motionControl * this methods sets the new localTranslation to the spatial of the MotionEvent control. * @param time the time since the animation started * @param control the control over the moving spatial */ public float interpolatePath(float time, MotionEvent control, float tpf) { float traveledDistance = 0; TempVars vars = TempVars.get(); Vector3f temp = vars.vect1; Vector3f tmpVector = vars.vect2; Vector2f v = vars.vect2d; //computing traveled distance according to new time traveledDistance = time * (getLength() / control.getInitialDuration()); //getting waypoint index and current value from new traveled distance v = getWayPointIndexForDistance(traveledDistance,v); //setting values control.setCurrentWayPoint((int) v.x); control.setCurrentValue(v.y); //interpolating new position getSpline().interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp); if (control.needsDirection()) { tmpVector.set(temp); control.setDirection(tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).normalizeLocal()); } checkWayPoint(control, tpf); control.getSpatial().setLocalTranslation(temp); vars.release(); return traveledDistance; }
Example #24
Source File: Camera.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * <code>lookAt</code> is a convenience method for auto-setting the frame * based on a world position the user desires the camera to look at. It * repoints the camera towards the given position using the difference * between the position and the current camera location as a direction * vector and the worldUpVector to compute up and left camera vectors. * * @param pos where to look at in terms of world coordinates * @param worldUpVector a normalized vector indicating the up direction of the world. * (typically {0, 1, 0} in jME.) */ public void lookAt(Vector3f pos, Vector3f worldUpVector) { TempVars vars = TempVars.get(); Vector3f newDirection = vars.vect1; Vector3f newUp = vars.vect2; Vector3f newLeft = vars.vect3; newDirection.set(pos).subtractLocal(location).normalizeLocal(); newUp.set(worldUpVector).normalizeLocal(); if (newUp.equals(Vector3f.ZERO)) { newUp.set(Vector3f.UNIT_Y); } newLeft.set(newUp).crossLocal(newDirection).normalizeLocal(); if (newLeft.equals(Vector3f.ZERO)) { if (newDirection.x != 0) { newLeft.set(newDirection.y, -newDirection.x, 0f); } else { newLeft.set(0f, newDirection.z, -newDirection.y); } } newUp.set(newDirection).crossLocal(newLeft).normalizeLocal(); this.rotation.fromAxes(newLeft, newUp, newDirection); this.rotation.normalizeLocal(); vars.release(); onFrameChange(); }
Example #25
Source File: PointLight.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean intersectsSphere(BoundingSphere sphere, TempVars vars) { if (this.radius == 0) { return true; } else { // Sphere v. sphere collision return Intersection.intersect(sphere, position, radius); } }
Example #26
Source File: PointLight.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean intersectsFrustum(Camera camera, TempVars vars) { if (this.radius == 0) { return true; } else { return Intersection.intersect(camera, position, radius); } }
Example #27
Source File: OrientedBoxProbeArea.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean intersectsSphere(BoundingSphere sphere, TempVars vars) { Vector3f closestPoint = getClosestPoint(vars, sphere.getCenter()); // check if the point intersects with the sphere bound if (sphere.intersects(closestPoint)) { return true; } return false; }
Example #28
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Compute bounds of a geomList * @param list * @param mat * @return a new instance */ public static BoundingBox computeUnionBound(GeometryList list, Matrix4f mat) { BoundingBox bbox = new BoundingBox(); TempVars tempv = TempVars.get(); for (int i = 0; i < list.size(); i++) { BoundingVolume vol = list.get(i).getWorldBound(); BoundingVolume store = vol.transform(mat, tempv.bbox); //Nehon : prevent NaN and infinity values to screw the final bounding box if (!Float.isNaN(store.getCenter().x) && !Float.isInfinite(store.getCenter().x)) { bbox.mergeLocal(store); } } tempv.release(); return bbox; }
Example #29
Source File: OrientedBoxProbeArea.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void updateMatrix() { TempVars vars = TempVars.get(); Matrix3f r = vars.tempMat3; Matrix4f u = uniformMatrix; transform.getRotation().toRotationMatrix(r); u.m00 = r.get(0,0); u.m10 = r.get(1,0); u.m20 = r.get(2,0); u.m01 = r.get(0,1); u.m11 = r.get(1,1); u.m21 = r.get(2,1); u.m02 = r.get(0,2); u.m12 = r.get(1,2); u.m22 = r.get(2,2); //scale u.m30 = transform.getScale().x; u.m31 = transform.getScale().y; u.m32 = transform.getScale().z; //position u.m03 = transform.getTranslation().x; u.m13 = transform.getTranslation().y; u.m23 = transform.getTranslation().z; vars.release(); }
Example #30
Source File: ShadowUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Compute bounds of a geomList * @param list * @param transform * @return a new instance */ public static BoundingBox computeUnionBound(GeometryList list, Transform transform) { BoundingBox bbox = new BoundingBox(); TempVars tempv = TempVars.get(); for (int i = 0; i < list.size(); i++) { BoundingVolume vol = list.get(i).getWorldBound(); BoundingVolume newVol = vol.transform(transform, tempv.bbox); //Nehon : prevent NaN and infinity values to screw the final bounding box if (!Float.isNaN(newVol.getCenter().x) && !Float.isInfinite(newVol.getCenter().x)) { bbox.mergeLocal(newVol); } } tempv.release(); return bbox; }