@Override public void simpleInitApp() { makeTerrain(); flyCam.setMoveSpeed(50); sl = new SpotLight(); sl.setSpotRange(100); sl.setSpotOuterAngle(20 * FastMath.DEG_TO_RAD); sl.setSpotInnerAngle(15 * FastMath.DEG_TO_RAD); sl.setDirection(new Vector3f(-0.39820394f, -0.73094344f, 0.55421597f)); sl.setPosition(new Vector3f(-64.61567f, -87.615425f, -202.41328f)); rootNode.addLight(sl); AmbientLight ambLight = new AmbientLight(); ambLight.setColor(ColorRGBA.Black); rootNode.addLight(ambLight); cam.setLocation(new Vector3f(-41.219646f, 0.8363f, -171.67267f)); cam.setRotation(new Quaternion(-0.04562731f, 0.89917684f, -0.09668826f, -0.4243236f)); sl.setDirection(cam.getDirection()); sl.setPosition(cam.getLocation()); }
sl.setPosition(pos); Vector3f dir = sl.getDirection(); q.multLocal(dir); sl.setDirection(dir);
@Override protected void updateShadowCams(Camera viewCam) { if (light == null) { logger.warning("The light can't be null for a " + getClass().getName()); return; } float zFar = zFarOverride; if (zFar == 0) { zFar = viewCam.getFrustumFar(); } //We prevent computing the frustum points and splits with zeroed or negative near clip value float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f); ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points); //shadowCam.setDirection(direction); shadowCam.setFrustumPerspective(light.getSpotOuterAngle() * FastMath.RAD_TO_DEG * 2.0f, 1, 1f, light.getSpotRange()); shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp()); shadowCam.setLocation(light.getPosition()); shadowCam.update(); shadowCam.updateViewProjection(); }
/** * Creates a SpotLight at the given position, with the given direction, and the * given range. * @param position the position in world space. * @param direction the direction of the light. * @param range the spot light range */ public SpotLight(Vector3f position, Vector3f direction, float range) { this(); setPosition(position); setDirection(direction); setSpotRange(range); }
/** * Creates a SpotLight at the given position and with the given direction. * @param position the position in world space. * @param direction the direction of the light. */ public SpotLight(Vector3f position, Vector3f direction) { this(); setPosition(position); setDirection(direction); }
/** * Creates a SpotLight at the given position, with the given direction and * the given color. * @param position the position in world space. * @param direction the direction of the light. * @param color the light's color. */ public SpotLight(Vector3f position, Vector3f direction, ColorRGBA color) { super(color); computeAngleParameters(); setPosition(position); setDirection(direction); }
ColorRGBA color = light.getColor(); Vector3f pos = light.getPosition(); Vector3f dir = light.getDirection(); tempPosition.set(light.getPosition()); tempDirection.set(light.getDirection()); transformPosition(viewMatrix, tempPosition); transformDirection(viewMatrix, tempDirection); float invRange = light.getInvSpotRange(); float spotAngleCos = light.getPackedAngleCos(); lightData.setVector4InArray(color.r, color.g, color.b, 1f, index++); lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRange, index++);
@Test public void testSpotFiltering() { SpotLight sl = new SpotLight(Vector3f.ZERO, Vector3f.UNIT_Z); sl.setSpotRange(0); geom.addLight(sl); checkFilteredLights(1); // Infinite spot lights are only filtered sl.setSpotRange(1f - FastMath.ZERO_TOLERANCE); assert !sl.intersectsFrustum(cam, vars); sl.setSpotRange(1f); assert sl.intersectsFrustum(cam, vars); } finally { vars.release(); sl.setSpotRange(9f); checkFilteredLights(0); sl.setSpotRange(9f + FastMath.ZERO_TOLERANCE); checkFilteredLights(1); sl.setDirection(new Vector3f(0.316f, 0, 0.948f).normalizeLocal()); checkFilteredLights(0); sl.setSpotRange(20); checkFilteredLights(0); sl.setPosition(Vector3f.ZERO); sl.setDirection(Vector3f.UNIT_Z);
/** * Creates a SpotLight at the given position, with the given direction, * the given range and the given color. * @param position the position in world space. * @param direction the direction of the light. * @param range the spot light range * @param color the light's color. */ public SpotLight(Vector3f position, Vector3f direction, float range, ColorRGBA color) { super(color); computeAngleParameters(); setPosition(position); setDirection(direction); setSpotRange(range); }
break; case 2:// Spot light = new SpotLight(); ((SpotLight) light).setSpotRange(((Number) structure.getFieldValue("dist")).floatValue()); ((SpotLight) light).setSpotOuterAngle(outerAngle); spotblend = FastMath.clamp(spotblend, 0, 1); float innerAngle = outerAngle * (1 - spotblend); ((SpotLight) light).setSpotInnerAngle(innerAngle); break; case 3:// Hemi
spotLight = new SpotLight(); spotLight.setSpotRange(25); spotLight.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD); float radius = FastMath.tan(spotLight.getSpotOuterAngle()) * spotLight.getSpotRange(); Cylinder cylinder = new Cylinder(5, 16, 0.01f, radius, spotLight.getSpotRange(), true, false); geom = new Geometry("light", cylinder); geom.setMaterial(new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md")); final LightNode ln = new LightNode("lb", spotLight); ln.attachChild(geom); geom.setLocalTranslation(0, -spotLight.getSpotRange() / 2f, 0); geom.rotate(-FastMath.HALF_PI, 0, 0); rootNode.attachChild(ln); System.err.println("light " + spotLight.getPosition());
@Override public void simpleUpdate(float tpf) { super.simpleUpdate(tpf); angle += tpf; angle %= FastMath.TWO_PI; spot.setPosition(new Vector3f(FastMath.cos(angle) * 30f, 34.013165f, FastMath.sin(angle) * 30f)); lightMdl.setLocalTranslation(spot.getPosition()); spot.setDirection(lightTarget.subtract(spot.getPosition())); }
private void parseLightSpotLightRange(Attributes attribs) throws SAXException { checkTopNode("light"); float outer = SAXUtil.parseFloat(attribs.getValue("outer")); float inner = SAXUtil.parseFloat(attribs.getValue("inner")); if (!(light instanceof SpotLight)) { throw new SAXException("dotScene parse error: spotLightRange " + "can only appear under 'spot' light elements"); } SpotLight sl = (SpotLight) light; sl.setSpotInnerAngle(inner * 0.5f); sl.setSpotOuterAngle(outer * 0.5f); }
public void onAction(String name, boolean isPressed, float tpf) { if (name.equals("stop") && isPressed) { stop = !stop; // slsr.displayFrustum(); System.out.println("pos : " + spot.getPosition()); System.out.println("dir : " + spot.getDirection()); } } }, "stop");
private void parseLightAttenuation(Attributes attribs) throws SAXException { // NOTE: Derives range based on "linear" if it is used solely // for the attenuation. Otherwise derives it from "range" checkTopNode("light"); if (light instanceof PointLight || light instanceof SpotLight) { float range = parseFloat(attribs.getValue("range")); float constant = parseFloat(attribs.getValue("constant")); float linear = parseFloat(attribs.getValue("linear")); String quadraticStr = attribs.getValue("quadratic"); if (quadraticStr == null) { quadraticStr = attribs.getValue("quadric"); } float quadratic = parseFloat(quadraticStr); if (constant == 1 && quadratic == 0 && linear > 0) { range = 1f / linear; } if (light instanceof PointLight) { ((PointLight) light).setRadius(range); } else { ((SpotLight) light).setSpotRange(range); } } }
private void parseLightNormal(Attributes attribs) throws SAXException { checkTopNode("light"); // SpotLight will be supporting a direction-normal, too. if (light instanceof DirectionalLight) { ((DirectionalLight) light).setDirection(parseVector3(attribs)); } else if (light instanceof SpotLight) { ((SpotLight) light).setDirection(parseVector3(attribs)); } }
private void parseLight(Attributes attribs) throws SAXException { if (node == null || node.getParent() == null) { throw new SAXException("dotScene parse error: light can only appear under a node"); } checkTopNode("node"); String lightType = parseString(attribs.getValue("type"), "point"); if (lightType.equals("point")) { light = new PointLight(); } else if (lightType.equals("directional") || lightType.equals("sun")) { light = new DirectionalLight(); // Assuming "normal" property is not provided ((DirectionalLight) light).setDirection(Vector3f.UNIT_Z); } else if (lightType.equals("spotLight") || lightType.equals("spot")) { light = new SpotLight(); } else if (lightType.equals("omni")) { // XXX: It doesn't seem any exporters actually emit this type? light = new AmbientLight(); } else { logger.log(Level.WARNING, "No matching jME3 LightType found for OGRE LightType: {0}", lightType); } logger.log(Level.FINEST, "{0} created.", light); if (!parseBool(attribs.getValue("visible"), true)) { // set to disabled } // "attach" it to the parent of this node if (light != null) { node.getParent().addLight(light); } }
/** * * @param viewCam * @return */ @Override protected boolean checkCulling(Camera viewCam) { 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; }
case Spot: SpotLight sl = (SpotLight) l; Vector3f pos2 = sl.getPosition(); Vector3f dir2 = sl.getDirection(); float invRange = sl.getInvSpotRange(); float spotAngleCos = sl.getPackedAngleCos(); tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f);
/** * Creates a SpotLight at the given position, with the given direction, * the given color and the given inner and outer angles * (controls the falloff of the light) * * @param position the position in world space. * @param direction the direction of the light. * @param range the spot light range * @param color the light's color. * @param innerAngle the inner angle of the spot light. * @param outerAngle the outer angle of the spot light. * * @see SpotLight#setSpotInnerAngle(float) * @see SpotLight#setSpotOuterAngle(float) */ public SpotLight(Vector3f position, Vector3f direction, float range, ColorRGBA color, float innerAngle, float outerAngle) { super(color); this.spotInnerAngle = innerAngle; this.spotOuterAngle = outerAngle; computeAngleParameters(); setPosition(position); setDirection(direction); setSpotRange(range); }