use of com.jme3.renderer.Camera 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();
}
}
use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class ParticleTriMesh method updateParticleData.
@Override
public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) {
// System.arraycopy(particles, 0, particlesCopy, 0, particlesCopy.length);
// comparator.setCamera(cam);
// Arrays.sort(particlesCopy, comparator);
// SortUtil.qsort(particlesCopy, comparator);
// SortUtil.msort(particles, particlesCopy, comparator);
// particles = particlesCopy;
VertexBuffer pvb = getBuffer(VertexBuffer.Type.Position);
FloatBuffer positions = (FloatBuffer) pvb.getData();
VertexBuffer cvb = getBuffer(VertexBuffer.Type.Color);
ByteBuffer colors = (ByteBuffer) cvb.getData();
VertexBuffer tvb = getBuffer(VertexBuffer.Type.TexCoord);
FloatBuffer texcoords = (FloatBuffer) tvb.getData();
Vector3f camUp = cam.getUp();
Vector3f camLeft = cam.getLeft();
Vector3f camDir = cam.getDirection();
inverseRotation.multLocal(camUp);
inverseRotation.multLocal(camLeft);
inverseRotation.multLocal(camDir);
boolean facingVelocity = emitter.isFacingVelocity();
Vector3f up = new Vector3f(), left = new Vector3f();
if (!facingVelocity) {
up.set(camUp);
left.set(camLeft);
}
// update data in vertex buffers
positions.clear();
colors.clear();
texcoords.clear();
Vector3f faceNormal = emitter.getFaceNormal();
for (int i = 0; i < particles.length; i++) {
Particle p = particles[i];
boolean dead = p.life == 0;
if (dead) {
positions.put(0).put(0).put(0);
positions.put(0).put(0).put(0);
positions.put(0).put(0).put(0);
positions.put(0).put(0).put(0);
continue;
}
if (facingVelocity) {
left.set(p.velocity).normalizeLocal();
camDir.cross(left, up);
up.multLocal(p.size);
left.multLocal(p.size);
} else if (faceNormal != null) {
up.set(faceNormal).crossLocal(Vector3f.UNIT_X);
faceNormal.cross(up, left);
up.multLocal(p.size);
left.multLocal(p.size);
if (p.angle != 0) {
TempVars vars = TempVars.get();
vars.vect1.set(faceNormal).normalizeLocal();
vars.quat1.fromAngleNormalAxis(p.angle, vars.vect1);
vars.quat1.multLocal(left);
vars.quat1.multLocal(up);
vars.release();
}
} else if (p.angle != 0) {
float cos = FastMath.cos(p.angle) * p.size;
float sin = FastMath.sin(p.angle) * p.size;
left.x = camLeft.x * cos + camUp.x * sin;
left.y = camLeft.y * cos + camUp.y * sin;
left.z = camLeft.z * cos + camUp.z * sin;
up.x = camLeft.x * -sin + camUp.x * cos;
up.y = camLeft.y * -sin + camUp.y * cos;
up.z = camLeft.z * -sin + camUp.z * cos;
} else {
up.set(camUp);
left.set(camLeft);
up.multLocal(p.size);
left.multLocal(p.size);
}
positions.put(p.position.x + left.x + up.x).put(p.position.y + left.y + up.y).put(p.position.z + left.z + up.z);
positions.put(p.position.x - left.x + up.x).put(p.position.y - left.y + up.y).put(p.position.z - left.z + up.z);
positions.put(p.position.x + left.x - up.x).put(p.position.y + left.y - up.y).put(p.position.z + left.z - up.z);
positions.put(p.position.x - left.x - up.x).put(p.position.y - left.y - up.y).put(p.position.z - left.z - up.z);
if (uniqueTexCoords) {
int imgX = p.imageIndex % imagesX;
int imgY = (p.imageIndex - imgX) / imagesY;
float startX = ((float) imgX) / imagesX;
float startY = ((float) imgY) / imagesY;
float endX = startX + (1f / imagesX);
float endY = startY + (1f / imagesY);
texcoords.put(startX).put(endY);
texcoords.put(endX).put(endY);
texcoords.put(startX).put(startY);
texcoords.put(endX).put(startY);
}
int abgr = p.color.asIntABGR();
colors.putInt(abgr);
colors.putInt(abgr);
colors.putInt(abgr);
colors.putInt(abgr);
}
positions.clear();
colors.clear();
if (!uniqueTexCoords)
texcoords.clear();
else {
texcoords.clear();
tvb.updateData(texcoords);
}
// force renderer to re-send data to GPU
pvb.updateData(positions);
cvb.updateData(colors);
}
use of com.jme3.renderer.Camera 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.renderer.Camera in project jmonkeyengine by jMonkeyEngine.
the class AbstractShadowRenderer method displayShadowMap.
/**
* For debugging purposes, display depth shadow maps.
*/
protected void displayShadowMap(Renderer r) {
Camera cam = viewPort.getCamera();
renderManager.setCamera(cam, true);
int h = cam.getHeight();
for (int i = 0; i < dispPic.length; i++) {
dispPic[i].setPosition((128 * i) + (150 + 64 * (i + 1)), h / 20f);
dispPic[i].setWidth(128);
dispPic[i].setHeight(128);
dispPic[i].updateGeometricState();
renderManager.renderGeometry(dispPic[i]);
}
renderManager.setCamera(cam, false);
}
use of com.jme3.renderer.Camera 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();
}
}
Aggregations