@Override public String toString() { return "com.ardor3d.renderer.Camera: loc - " + Arrays.toString(getLocation().toArray(null)) + " dir - " + Arrays.toString(getDirection().toArray(null)) + " up - " + Arrays.toString(getUp().toArray(null)) + " left - " + Arrays.toString(getLeft().toArray(null)); }
@Override public String toString() { return "com.ardor3d.renderer.Camera: loc - " + Arrays.toString(getLocation().toArray(null)) + " dir - " + Arrays.toString(getDirection().toArray(null)) + " up - " + Arrays.toString(getUp().toArray(null)) + " left - " + Arrays.toString(getLeft().toArray(null)); }
private void updateCameraLookat() { _tRenderer.getCamera().setLocation(_cam.getLocation()); _tRenderer.getCamera().lookAt(_center, _worldUpVector); }
private void updateCameraLookat() { _tRenderer.getCamera().setLocation(_cam.getLocation()); _tRenderer.getCamera().lookAt(_center, _worldUpVector); }
private boolean shouldDoUpdate(final Camera cam) { if (_redrawRate > 0 && _elapsed >= _redrawRate) { _elapsed = _elapsed % _redrawRate; return true; } if (_cameraAngleThreshold > 0) { _tempVec.set(_center).subtractLocal(cam.getLocation()); final double currentDist = _tempVec.length(); if (_lastCamDist != 0 && Math.abs(currentDist - _lastCamDist) / _lastCamDist > _cameraDistanceThreshold) { return true; } _tempVec.normalizeLocal(); final double angle = _tempVec.smallestAngleBetween(_lastCamDir); if (angle > _cameraAngleThreshold) { return true; } } return false; }
private boolean shouldDoUpdate(final Camera cam) { if (_redrawRate > 0 && _elapsed >= _redrawRate) { _elapsed = _elapsed % _redrawRate; return true; } if (_cameraAngleThreshold > 0) { _tempVec.set(_center).subtractLocal(cam.getLocation()); final double currentDist = _tempVec.length(); if (_lastCamDist != 0 && Math.abs(currentDist - _lastCamDist) / _lastCamDist > _cameraDistanceThreshold) { return true; } _tempVec.normalizeLocal(); final double angle = _tempVec.smallestAngleBetween(_lastCamDir); if (angle > _cameraAngleThreshold) { return true; } } return false; }
@Override public IntersectionRecord intersectsPrimitivesWhere(final Ray3 ray) { if (_picker != null) { final Vector3 normalStore = new Vector3(); final Vector3 intersect = _picker.getTerrainIntersection(getWorldTransform(), _terrainCamera.getLocation(), ray, null, normalStore); if (intersect != null) { final double distance = intersect.distance(ray.getOrigin()); final IntersectionRecord record = new IntersectionRecord(new double[] { distance }, new Vector3[] { intersect }, new Vector3[] { normalStore }, null); return record; } } return null; }
@Override public IntersectionRecord intersectsPrimitivesWhere(final Ray3 ray) { if (_picker != null) { final Vector3 normalStore = new Vector3(); final Vector3 intersect = _picker.getTerrainIntersection(getWorldTransform(), _terrainCamera.getLocation(), ray, null, normalStore); if (intersect != null) { final double distance = intersect.distance(ray.getOrigin()); final IntersectionRecord record = new IntersectionRecord(new double[] { distance }, new Vector3[] { intersect }, new Vector3[] { normalStore }, null); return record; } } return null; }
/** * Calculates the distance from a spatial to the camera. Distance is a squared distance. * * @param spat * Spatial to check distance. * @return Distance from Spatial to current context's camera. */ protected double distanceToCam(final Spatial spat) { if (spat._queueDistance != Double.NEGATIVE_INFINITY) { return spat._queueDistance; } final Camera cam = Camera.getCurrentCamera(); if (spat.getWorldBound() != null && Vector3.isValid(spat.getWorldBound().getCenter())) { spat._queueDistance = spat.getWorldBound().distanceToEdge(cam.getLocation()); } else { final ReadOnlyVector3 spatPosition = spat.getWorldTranslation(); if (!Vector3.isValid(spatPosition)) { spat._queueDistance = Double.POSITIVE_INFINITY; } else { spat._queueDistance = cam.getLocation().distance(spatPosition); } } return spat._queueDistance; }
/** * Initialize/Update shaders */ public void updateShader(final Renderer r) { if (_geometryClipmapShader != null) { getWorldTransform().applyInverse(_terrainCamera.getLocation(), transformedFrustumPos); _geometryClipmapShader.setUniform("eyePosition", transformedFrustumPos); for (final TextureClipmap textureClipmap : _textureClipmaps) { textureClipmap.update(r, transformedFrustumPos); } if (_normalClipmap != null) { _normalClipmap.update(r, transformedFrustumPos); } return; } reloadShader(); }
@Override public void updateWorldBound(final boolean recurse) { final BoundingBox worldBound = (BoundingBox) _worldBound; final Vector3 center = _boundsCenter.set(_terrainCamera.getLocation()); final double distanceToEdge = _clipSideSize * MathUtils.pow2(_clips.size() - 1) * 0.5; final double heightScale = _clips.get(0).getHeightScale(); final double heightMin = _clips.get(0).getHeightRangeMin() * heightScale; final double heightMax = _clips.get(0).getHeightRangeMax() * heightScale; final Vector3 extents = _boundsExtents.set(distanceToEdge, (heightMax - heightMin) * 0.5, distanceToEdge); worldToLocal(center, center); worldBound.setXExtent(extents.getX()); worldBound.setYExtent(extents.getY()); worldBound.setZExtent(extents.getZ()); worldBound.setCenter(center.getX(), (heightMax + heightMin) * 0.5, center.getZ()); worldBound.transform(_worldTransform, worldBound); clearDirty(DirtyType.Bounding); }
@Override public void updateWorldBound(final boolean recurse) { final BoundingBox worldBound = (BoundingBox) _worldBound; final Vector3 center = _boundsCenter.set(_terrainCamera.getLocation()); final double distanceToEdge = _clipSideSize * MathUtils.pow2(_clips.size() - 1) * 0.5; final double heightScale = _clips.get(0).getHeightScale(); final double heightMin = _clips.get(0).getHeightRangeMin() * heightScale; final double heightMax = _clips.get(0).getHeightRangeMax() * heightScale; final Vector3 extents = _boundsExtents.set(distanceToEdge, (heightMax - heightMin) * 0.5, distanceToEdge); worldToLocal(center, center); worldBound.setXExtent(extents.getX()); worldBound.setYExtent(extents.getY()); worldBound.setZExtent(extents.getZ()); worldBound.setCenter(center.getX(), (heightMax + heightMin) * 0.5, center.getZ()); worldBound.transform(_worldTransform, worldBound); clearDirty(DirtyType.Bounding); }
/** * Sets the axes and location of the camera using those of a given source camera * * @param source * a source camera. */ public void setFrame(final Camera source) { _left.set(source.getLeft()); _up.set(source.getUp()); _direction.set(source.getDirection()); _location.set(source.getLocation()); onFrameChange(); }
/** * Sets the axes and location of the camera using those of a given source camera * * @param source * a source camera. */ public void setFrame(final Camera source) { _left.set(source.getLeft()); _up.set(source.getUp()); _direction.set(source.getDirection()); _location.set(source.getLocation()); onFrameChange(); }
/** * Forces rotation and translation of this node to be sync'd with the attached camera. (Assumes the node is in world * space.) */ public void updateFromCamera() { final ReadOnlyVector3 camLeft = _camera.getLeft(); final ReadOnlyVector3 camUp = _camera.getUp(); final ReadOnlyVector3 camDir = _camera.getDirection(); final ReadOnlyVector3 camLoc = _camera.getLocation(); final Matrix3 rotation = Matrix3.fetchTempInstance(); rotation.fromAxes(camLeft, camUp, camDir); setRotation(rotation); setTranslation(camLoc); Matrix3.releaseTempInstance(rotation); }
/** * Forces rotation and translation of this node to be sync'd with the attached camera. (Assumes the node is in world * space.) */ public void updateFromCamera() { final ReadOnlyVector3 camLeft = _camera.getLeft(); final ReadOnlyVector3 camUp = _camera.getUp(); final ReadOnlyVector3 camDir = _camera.getDirection(); final ReadOnlyVector3 camLoc = _camera.getLocation(); final Matrix3 rotation = Matrix3.fetchTempInstance(); rotation.fromAxes(camLeft, camUp, camDir); setRotation(rotation); setTranslation(camLoc); Matrix3.releaseTempInstance(rotation); }
public void updateCache() { getWorldTransform().applyInverse(clipmapTestFrustum.getLocation(), transformedFrustumPos); final int cx = (int) transformedFrustumPos.getX(); final int cz = (int) transformedFrustumPos.getZ(); // Calculate the new position int clipX = cx - (clipSideSize + 1) * vertexDistance / 2; int clipY = cz - (clipSideSize + 1) * vertexDistance / 2; // Calculate the modulo to doubleVertexDistance of the new position. // This makes sure that the current level always fits in the hole of the // coarser level. The gridspacing of the coarser level is vertexDistance * 2, so here doubleVertexDistance. final int modX = MathUtils.moduloPositive(clipX, doubleVertexDistance); final int modY = MathUtils.moduloPositive(clipY, doubleVertexDistance); clipX = clipX + doubleVertexDistance - modX; clipY = clipY + doubleVertexDistance - modY; cache.setCurrentPosition(clipX / vertexDistance, clipY / vertexDistance); // TODO cache.handleUpdateRequests(); }
public void updateCache() { getWorldTransform().applyInverse(clipmapTestFrustum.getLocation(), transformedFrustumPos); final int cx = (int) transformedFrustumPos.getX(); final int cz = (int) transformedFrustumPos.getZ(); // Calculate the new position int clipX = cx - (clipSideSize + 1) * vertexDistance / 2; int clipY = cz - (clipSideSize + 1) * vertexDistance / 2; // Calculate the modulo to doubleVertexDistance of the new position. // This makes sure that the current level always fits in the hole of the // coarser level. The gridspacing of the coarser level is vertexDistance * 2, so here doubleVertexDistance. final int modX = MathUtils.moduloPositive(clipX, doubleVertexDistance); final int modY = MathUtils.moduloPositive(clipY, doubleVertexDistance); clipX = clipX + doubleVertexDistance - modX; clipY = clipY + doubleVertexDistance - modY; cache.setCurrentPosition(clipX / vertexDistance, clipY / vertexDistance); // TODO cache.handleUpdateRequests(); }
/** * Aligns this Billboard Node so that it points to the camera position. */ private void rotateCameraAligned() { final Camera camera = Camera.getCurrentCamera(); _look.set(camera.getLocation()).subtractLocal(_worldTransform.getTranslation()).normalizeLocal(); _left.set(camera.getUp()).crossLocal(_look); final Vector3 up = Vector3.fetchTempInstance(); up.set(_look).crossLocal(_left); _orient.fromAxes(_left, up, _look); if(_localRot != null) _orient.multiplyLocal(_localRot); _worldTransform.setRotation(_orient); Vector3.releaseTempInstance(up); }
@Override public void draw(final Renderer r) { if (_timer != null && _redrawRate > 0) { _elapsed += _timer.getTimePerFrame(); } if (_tRenderer == null) { init(r); } if (_cam == null) { _cam = Camera.getCurrentCamera(); _tRenderer.getCamera().setFrustum(_cam.getFrustumNear(), _cam.getFrustumFar(), _cam.getFrustumLeft(), _cam.getFrustumRight(), _cam.getFrustumTop(), _cam.getFrustumBottom()); _tRenderer.getCamera().setFrame(_cam.getLocation(), _cam.getLeft(), _cam.getUp(), _cam.getDirection()); } if (_doUpdate && (!_haveDrawn || shouldDoUpdate(_cam)) && _targetScene.getWorldBound() != null) { final BoundingVolume b = _targetScene.getWorldBound(); _center.set(b.getCenter()); updateCameraLookat(); calculateImposter(); updateCameraLookat(); updateCameraFrustum(); renderImposter(); _haveDrawn = true; } _imposterQuad.draw(r); }