use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.
the class Face method findClosestVertex.
/**
* The method finds the closest vertex to the one specified by <b>index</b>.
* If the vertexToIgnore is positive than it will be ignored in the result.
* The closest vertex must be able to create an edge that is fully contained
* within the face and does not cross any other edges. Also if the
* vertexToIgnore is not negative then the condition that the edge between
* the found index and the one to ignore is inside the face must also be
* met.
*
* @param index
* the index of the vertex that needs to have found the nearest
* neighbour
* @param indexToIgnore
* the index to ignore in the result (pass -1 if none is to be
* ignored)
* @return the index of the closest vertex to the given one
*/
private int findClosestVertex(int index, int indexToIgnore) {
int result = -1;
List<Vector3f> vertices = temporalMesh.getVertices();
Vector3f v1 = vertices.get(index);
float distance = Float.MAX_VALUE;
for (int i : indexes) {
if (i != index && i != indexToIgnore) {
Vector3f v2 = vertices.get(i);
float d = v2.distance(v1);
if (d < distance && this.contains(new Edge(index, i, 0, true, temporalMesh)) && (indexToIgnore < 0 || this.contains(new Edge(indexToIgnore, i, 0, true, temporalMesh)))) {
result = i;
distance = d;
}
}
}
return result;
}
use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.
the class ChaseCamera method updateCamera.
/**
* Updates the camera, should only be called internally
*/
protected void updateCamera(float tpf) {
if (enabled) {
targetLocation.set(target.getWorldTranslation()).addLocal(lookAtOffset);
if (smoothMotion) {
//computation of target direction
targetDir.set(targetLocation).subtractLocal(prevPos);
float dist = targetDir.length();
//Low pass filtering on the target postition to avoid shaking when physics are enabled.
if (offsetDistance < dist) {
//target moves, start chasing.
chasing = true;
//target moves, start trailing if it has to.
if (trailingEnabled) {
trailing = true;
}
//target moves...
targetMoves = true;
} else {
//We do not if the player is rotationg the cam
if (targetMoves && !canRotate) {
if (targetRotation - rotation > trailingRotationInertia) {
targetRotation = rotation + trailingRotationInertia;
} else if (targetRotation - rotation < -trailingRotationInertia) {
targetRotation = rotation - trailingRotationInertia;
}
}
//Target stops
targetMoves = false;
}
//the user is rotating the cam by dragging the mouse
if (canRotate) {
//reseting the trailing lerp factor
trailingLerpFactor = 0;
//stop trailing user has the control
trailing = false;
}
if (trailingEnabled && trailing) {
if (targetMoves) {
//computation if the inverted direction of the target
Vector3f a = targetDir.negate().normalizeLocal();
//the x unit vector
Vector3f b = Vector3f.UNIT_X;
//2d is good enough
a.y = 0;
//computation of the rotation angle between the x axis and the trail
if (targetDir.z > 0) {
targetRotation = FastMath.TWO_PI - FastMath.acos(a.dot(b));
} else {
targetRotation = FastMath.acos(a.dot(b));
}
if (targetRotation - rotation > FastMath.PI || targetRotation - rotation < -FastMath.PI) {
targetRotation -= FastMath.TWO_PI;
}
//if there is an important change in the direction while trailing reset of the lerp factor to avoid jumpy movements
if (targetRotation != previousTargetRotation && FastMath.abs(targetRotation - previousTargetRotation) > FastMath.PI / 8) {
trailingLerpFactor = 0;
}
previousTargetRotation = targetRotation;
}
//computing lerp factor
trailingLerpFactor = Math.min(trailingLerpFactor + tpf * tpf * trailingSensitivity, 1);
//computing rotation by linear interpolation
rotation = FastMath.interpolateLinear(trailingLerpFactor, rotation, targetRotation);
//if the rotation is near the target rotation we're good, that's over
if (targetRotation + 0.01f >= rotation && targetRotation - 0.01f <= rotation) {
trailing = false;
trailingLerpFactor = 0;
}
}
//linear interpolation of the distance while chasing
if (chasing) {
distance = temp.set(targetLocation).subtractLocal(cam.getLocation()).length();
distanceLerpFactor = Math.min(distanceLerpFactor + (tpf * tpf * chasingSensitivity * 0.05f), 1);
distance = FastMath.interpolateLinear(distanceLerpFactor, distance, targetDistance);
if (targetDistance + 0.01f >= distance && targetDistance - 0.01f <= distance) {
distanceLerpFactor = 0;
chasing = false;
}
}
//linear interpolation of the distance while zooming
if (zooming) {
distanceLerpFactor = Math.min(distanceLerpFactor + (tpf * tpf * zoomSensitivity), 1);
distance = FastMath.interpolateLinear(distanceLerpFactor, distance, targetDistance);
if (targetDistance + 0.1f >= distance && targetDistance - 0.1f <= distance) {
zooming = false;
distanceLerpFactor = 0;
}
}
//linear interpolation of the rotation while rotating horizontally
if (rotating) {
rotationLerpFactor = Math.min(rotationLerpFactor + tpf * tpf * rotationSensitivity, 1);
rotation = FastMath.interpolateLinear(rotationLerpFactor, rotation, targetRotation);
if (targetRotation + 0.01f >= rotation && targetRotation - 0.01f <= rotation) {
rotating = false;
rotationLerpFactor = 0;
}
}
//linear interpolation of the rotation while rotating vertically
if (vRotating) {
vRotationLerpFactor = Math.min(vRotationLerpFactor + tpf * tpf * rotationSensitivity, 1);
vRotation = FastMath.interpolateLinear(vRotationLerpFactor, vRotation, targetVRotation);
if (targetVRotation + 0.01f >= vRotation && targetVRotation - 0.01f <= vRotation) {
vRotating = false;
vRotationLerpFactor = 0;
}
}
//computing the position
computePosition();
//setting the position at last
cam.setLocation(pos.addLocal(lookAtOffset));
} else {
//easy no smooth motion
vRotation = targetVRotation;
rotation = targetRotation;
distance = targetDistance;
computePosition();
cam.setLocation(pos.addLocal(lookAtOffset));
}
//keeping track on the previous position of the target
prevPos.set(targetLocation);
//the cam looks at the target
cam.lookAt(targetLocation, initialUpVec);
}
}
use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.
the class AbstractShadowRenderer method postFrame.
public void postFrame(FrameBuffer out) {
if (skipPostPass) {
return;
}
if (debug) {
displayShadowMap(renderManager.getRenderer());
}
getReceivers(lightReceivers);
if (lightReceivers.size() != 0) {
//setting params to recieving geometry list
setMatParams(lightReceivers);
Camera cam = viewPort.getCamera();
//some materials in the scene does not have a post shadow technique so we're using the fall back material
if (needsfallBackMaterial) {
renderManager.setForcedMaterial(postshadowMat);
}
//forcing the post shadow technique and render state
renderManager.setForcedTechnique(postTechniqueName);
//rendering the post shadow pass
viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, cam, false);
//resetting renderManager settings
renderManager.setForcedTechnique(null);
renderManager.setForcedMaterial(null);
renderManager.setCamera(cam, false);
//clearing the params in case there are some other shadow renderers
clearMatParams();
}
}
use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.
the class PssmShadowRenderer method postFrame.
public void postFrame(FrameBuffer out) {
if (debug) {
displayShadowMap(renderManager.getRenderer());
}
if (!noOccluders) {
//setting params to recieving geometry list
setMatParams();
Camera cam = viewPort.getCamera();
//some materials in the scene does not have a post shadow technique so we're using the fall back material
if (needsfallBackMaterial) {
renderManager.setForcedMaterial(postshadowMat);
}
//forcing the post shadow technique and render state
renderManager.setForcedTechnique(postTechniqueName);
//rendering the post shadow pass
viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, cam, true);
//resetting renderManager settings
renderManager.setForcedTechnique(null);
renderManager.setForcedMaterial(null);
renderManager.setCamera(cam, false);
}
}
use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method setupVRScene.
/**
* Replaces rootNode as the main cameras scene with the distortion mesh
*/
private void setupVRScene() {
if (environment != null) {
if (environment.getApplication() != null) {
// no special scene to setup if we are doing instancing
if (environment.isInstanceRendering()) {
// distortion has to be done with compositor here... we want only one pass on our end!
if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
setupMirrorBuffers(environment.getCamera(), dualEyeTex, true);
}
return;
}
leftEyeTexture = (Texture2D) leftViewport.getOutputFrameBuffer().getColorBuffer().getTexture();
rightEyeTexture = (Texture2D) rightViewport.getOutputFrameBuffer().getColorBuffer().getTexture();
leftEyeDepth = (Texture2D) leftViewport.getOutputFrameBuffer().getDepthBuffer().getTexture();
rightEyeDepth = (Texture2D) rightViewport.getOutputFrameBuffer().getDepthBuffer().getTexture();
// main viewport is either going to be a distortion scene or nothing
// mirroring is handled by copying framebuffers
Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
while (spatialIter.hasNext()) {
environment.getApplication().getViewPort().detachScene(spatialIter.next());
}
spatialIter = environment.getApplication().getGuiViewPort().getScenes().iterator();
while (spatialIter.hasNext()) {
environment.getApplication().getGuiViewPort().detachScene(spatialIter.next());
}
// only setup distortion scene if compositor isn't running (or using custom mesh distortion option)
if (environment.getVRHardware().getCompositor() == null) {
Node distortionScene = new Node();
Material leftMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
leftMat.setTexture("Texture", leftEyeTexture);
Geometry leftEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Left, environment.getVRHardware()));
leftEye.setMaterial(leftMat);
distortionScene.attachChild(leftEye);
Material rightMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
rightMat.setTexture("Texture", rightEyeTexture);
Geometry rightEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Right, environment.getVRHardware()));
rightEye.setMaterial(rightMat);
distortionScene.attachChild(rightEye);
distortionScene.updateGeometricState();
environment.getApplication().getViewPort().attachScene(distortionScene);
//if( useCustomDistortion ) setupFinalFullTexture(app.getViewPort().getCamera());
}
if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false);
}
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
Aggregations