@Override protected void controlUpdate(float tpf) { light.setPosition(spatial.getWorldTranslation().add(0, 0, 32)); flicker += 8 * tpf; float radius = FastMath.sin(FastMath.tan(FastMath.cos(flicker + (FastMath.rand.nextFloat() * 2)))) * 20 + 200; light.setRadius(radius); }
public void setLighting(LightList list) { // XXX: This is abuse of setLighting() to // apply fixed function bindings // and do other book keeping. if (list == null || list.size() == 0) { glDisable(GL_LIGHTING); applyFixedFuncBindings(false); setModelView(worldMatrix, viewMatrix); return; } // Number of lights set previously int numLightsSetPrev = lightList.size(); // If more than maxLights are defined, they will be ignored. // The GL1 renderer is not permitted to crash due to a // GL1 limitation. It must render anything that the GL2 renderer // can render (even incorrectly). lightList.clear(); materialAmbientColor.set(0, 0, 0, 0); for (int i = 0; i < list.size(); i++) { Light l = list.get(i); if (l.getType() == Light.Type.Ambient) { // Gather materialAmbientColor.addLocal(l.getColor()); } else { // Add to list lightList.add(l); // Once maximum lights reached, exit loop. if (lightList.size() >= maxLights) { break; } } } applyFixedFuncBindings(true); glEnable(GL_LIGHTING); fb16.clear(); fb16.put(materialAmbientColor.r) .put(materialAmbientColor.g) .put(materialAmbientColor.b) .put(1) .flip(); glLightModel(GL_LIGHT_MODEL_AMBIENT, fb16); if (context.matrixMode != GL_MODELVIEW) { glMatrixMode(GL_MODELVIEW); context.matrixMode = GL_MODELVIEW; } // Lights are already in world space, so just convert // them to view space. glLoadMatrix(storeMatrix(viewMatrix, fb16)); for (int i = 0; i < lightList.size(); i++) { int glLightIndex = GL_LIGHT0 + i; Light light = lightList.get(i); Light.Type lightType = light.getType(); ColorRGBA col = light.getColor(); Vector3f pos; // Enable the light glEnable(glLightIndex); // OGL spec states default value for light ambient is black switch (lightType) { case Directional: DirectionalLight dLight = (DirectionalLight) light; fb16.clear(); fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip(); glLight(glLightIndex, GL_DIFFUSE, fb16); glLight(glLightIndex, GL_SPECULAR, fb16); pos = tempVec.set(dLight.getDirection()).negateLocal().normalizeLocal(); fb16.clear(); fb16.put(pos.x).put(pos.y).put(pos.z).put(0.0f).flip(); glLight(glLightIndex, GL_POSITION, fb16); glLightf(glLightIndex, GL_SPOT_CUTOFF, 180); break; case Point: PointLight pLight = (PointLight) light; fb16.clear(); fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip(); glLight(glLightIndex, GL_DIFFUSE, fb16); glLight(glLightIndex, GL_SPECULAR, fb16); pos = pLight.getPosition(); fb16.clear(); fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip(); glLight(glLightIndex, GL_POSITION, fb16); glLightf(glLightIndex, GL_SPOT_CUTOFF, 180); if (pLight.getRadius() > 0) { // Note: this doesn't follow the same attenuation model // as the one used in the lighting shader. glLightf(glLightIndex, GL_CONSTANT_ATTENUATION, 1); glLightf(glLightIndex, GL_LINEAR_ATTENUATION, pLight.getInvRadius() * 2); glLightf( glLightIndex, GL_QUADRATIC_ATTENUATION, pLight.getInvRadius() * pLight.getInvRadius()); } else { glLightf(glLightIndex, GL_CONSTANT_ATTENUATION, 1); glLightf(glLightIndex, GL_LINEAR_ATTENUATION, 0); glLightf(glLightIndex, GL_QUADRATIC_ATTENUATION, 0); } break; case Spot: SpotLight sLight = (SpotLight) light; fb16.clear(); fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip(); glLight(glLightIndex, GL_DIFFUSE, fb16); glLight(glLightIndex, GL_SPECULAR, fb16); pos = sLight.getPosition(); fb16.clear(); fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip(); glLight(glLightIndex, GL_POSITION, fb16); Vector3f dir = sLight.getDirection(); fb16.clear(); fb16.put(dir.x).put(dir.y).put(dir.z).put(1.0f).flip(); glLight(glLightIndex, GL_SPOT_DIRECTION, fb16); float outerAngleRad = sLight.getSpotOuterAngle(); float innerAngleRad = sLight.getSpotInnerAngle(); float spotCut = outerAngleRad * FastMath.RAD_TO_DEG; float spotExpo = 0.0f; if (outerAngleRad > 0) { spotExpo = (1.0f - (innerAngleRad / outerAngleRad)) * 128.0f; } glLightf(glLightIndex, GL_SPOT_CUTOFF, spotCut); glLightf(glLightIndex, GL_SPOT_EXPONENT, spotExpo); if (sLight.getSpotRange() > 0) { glLightf(glLightIndex, GL_LINEAR_ATTENUATION, sLight.getInvSpotRange()); } else { glLightf(glLightIndex, GL_LINEAR_ATTENUATION, 0); } break; default: throw new UnsupportedOperationException("Unrecognized light type: " + lightType); } } // Disable lights after the index for (int i = lightList.size(); i < numLightsSetPrev; i++) { glDisable(GL_LIGHT0 + i); } // This will set view matrix as well. setModelView(worldMatrix, viewMatrix); }
/** * Initialises and sets up the camera. This should be called as soon as possible * * @param root The node to attach the camera to * @param physics The physics of the physics engine * @param cam The camera that we are going to position here */ public void loadCamera(Node root, PhysicsSpace physics, Camera cam) { // Create a node that is at the origin centralNode = new Node(nodeName); // Create a physics control, that we can move the node with centralNodeControl = new RigidBodyControl(1); // Add the control centralNode.addControl(centralNodeControl); // Set up camera CameraNode camNode = new CameraNode("cam", cam); // The node moves the camera, instead of the camera moving the node camNode.setControlDir(CameraControl.ControlDirection.SpatialToCamera); // Move it back and up a bit camNode.setLocalTranslation(new Vector3f(0, -10, 20)); // camNode.setLocalTranslation(new Vector3f(0, -10, 50)); // Look at the origin camNode.lookAt(centralNode.getLocalTranslation(), Vector3f.UNIT_Z); // Attach the camera to the node at the origin, so that the camera // follows the node centralNode.attachChild(camNode); // Plane that stays at the top of the screen to stop the ball rolling // out of sight Plane upperPlane = new Plane(Vector3f.UNIT_Y.negate(), -11f); RigidBodyControl upperCollision = new RigidBodyControl(new PlaneCollisionShape(upperPlane), 1f); Node upperPlaneNode = new Node("uplane"); upperPlaneNode.addControl(upperCollision); // And another plane for bottom of the screen Plane lowerPlane = new Plane(Vector3f.UNIT_Y, -19f); RigidBodyControl lowerCollision = new RigidBodyControl(new PlaneCollisionShape(lowerPlane), 1f); Node lowerPlaneNode = new Node("lplane"); lowerPlaneNode.addControl(lowerCollision); // Put the planes into their own group so that boxes do not collide with them upperCollision.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02); lowerCollision.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02); // Makes the planes un-affected by forces upperCollision.setKinematic(true); lowerCollision.setKinematic(true); // Attach the planes to the central point that the camera looks at // That way we can move them both by moving the central point. centralNode.attachChild(upperPlaneNode); centralNode.attachChild(lowerPlaneNode); // Add some lighting PointLight light = new PointLight(); light.setColor(ColorRGBA.White); // light.setRadius(30); LightControl lightControl = new LightControl(light); // Needs to be added to the camera, as a point in space camNode.addControl(lightControl); // And added to the root, to have an effect on everything root.addLight(light); // Finally, add the centre point to the root node root.attachChild(centralNode); // And add the planes and the centre point to the physics space physics.add(upperPlaneNode); physics.add(lowerPlaneNode); physics.add(centralNode); centralNodeControl.setGravity(Vector3f.ZERO); // No gravity centralNodeControl.setLinearVelocity(Vector3f.UNIT_Y); // Moves forward }
@Override public void simpleInitApp() { setDisplayFps(false); setDisplayStatView(false); bap = new BulletAppState(); stateManager.attach(bap); bap.getPhysicsSpace().setGravity(Vector3f.ZERO); bap.getPhysicsSpace().addCollisionListener(this); guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt"); showText = new BitmapText(guiFont, false); showText.setSize(50); showText.setColor(ColorRGBA.Red); showText.setLocalTranslation((settings.getWidth() / 2) - 200, settings.getHeight() / 2, 0); score = 0; scoreText = new BitmapText(guiFont, false); scoreText.setSize(guiFont.getCharSet().getRenderedSize()); scoreText.setColor(ColorRGBA.White); scoreText.setText("Score: " + score); scoreText.setLocalTranslation(settings.getWidth() - 200, settings.getHeight() - 30, 0); guiNode.attachChild(scoreText); lives = 3; /* livespic = new Picture[lives]; for(int i=0; i < lives; i++){ livespic[i] = new Picture("Live "+i); livespic[i].setImage(assetManager, "Textures/LifeLogo.png", true); livespic[i].setWidth(50); livespic[i].setHeight(50); livespic[i].setPosition(i*50, settings.getHeight()-50); guiNode.attachChild(livespic[i]); } * */ planets = new Planet[9]; Material mat10 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat10.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Sun.jpg")); mat10.setTexture("GlowMap", assetManager.loadTexture("Textures/Sun.jpg")); mat10.setColor("Specular", ColorRGBA.White); mat10.setBoolean("UseAlpha", true); sun = new Planet("Sun", 5f, mat10); sun.registerPhysics(bap.getPhysicsSpace()); rootNode.attachChild(sun); Material mat1 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat1.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Mercury.jpg")); mat1.setColor("Specular", ColorRGBA.White); mercury = new Planet("Mercury", 2f, mat1); mercury.setInitLocation(new Vector3f(16.0f, 0f, -6.0f)); mercury.setRotationSpeed((float) Math.random()); mercury.setTranslationSpeed(0.76f); mercury.registerPhysics(bap.getPhysicsSpace()); planets[0] = mercury; rootNode.attachChild(mercury); Material mat2 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat2.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Venus.jpg")); mat2.setColor("Specular", ColorRGBA.White); venus = new Planet("Venus", 2.6f, mat2); venus.setInitLocation(new Vector3f(23.0f, 0f, -6.0f)); venus.setRotationSpeed((float) Math.random()); venus.setTranslationSpeed(0.65f); venus.registerPhysics(bap.getPhysicsSpace()); planets[1] = venus; rootNode.attachChild(venus); Material mat3 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat3.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Earth/Color.jpg")); mat3.setTexture("ParallaxMap", assetManager.loadTexture("Textures/Earth/Bump.jpg")); mat3.setTexture("SpecularMap", assetManager.loadTexture("Textures/Earth/Specular.jpg")); earth = new Planet("Earth", 2.7f, mat3); earth.setInitLocation(new Vector3f(31.0f, 0f, -6.0f)); earth.setRotationSpeed((float) Math.random()); earth.setTranslationSpeed(0.6f); earth.registerPhysics(bap.getPhysicsSpace()); planets[2] = earth; rootNode.attachChild(earth); Material mat4 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat4.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Mars.jpg")); mat4.setColor("Specular", ColorRGBA.White); mars = new Planet("Mars", 2.5f, mat4); mars.setInitLocation(new Vector3f(40.0f, 0f, -6.0f)); mars.setRotationSpeed((float) Math.random()); mars.setTranslationSpeed(0.56f); mars.registerPhysics(bap.getPhysicsSpace()); planets[3] = mars; rootNode.attachChild(mars); Material mat5 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat5.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Jupiter.jpg")); mat5.setColor("Specular", ColorRGBA.White); jupiter = new Planet("Jupiter", 3.1f, mat5); jupiter.setInitLocation(new Vector3f(49.0f, 0f, -6.0f)); jupiter.setRotationSpeed((float) Math.random()); jupiter.setTranslationSpeed(0.5f); jupiter.registerPhysics(bap.getPhysicsSpace()); planets[4] = jupiter; rootNode.attachChild(jupiter); Material mat6 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat6.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Saturn.jpg")); mat6.setColor("Specular", ColorRGBA.White); saturn = new Planet("Saturn", 2.9f, mat6); saturn.setInitLocation(new Vector3f(57.0f, 0f, -6.0f)); saturn.setRotationSpeed((float) Math.random()); saturn.setTranslationSpeed(0.44f); saturn.registerPhysics(bap.getPhysicsSpace()); planets[5] = saturn; rootNode.attachChild(saturn); Material mat7 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat7.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Uranus.jpg")); mat7.setColor("Specular", ColorRGBA.White); uranus = new Planet("Uranus", 2.8f, mat7); uranus.setInitLocation(new Vector3f(65.0f, 0f, -6.0f)); uranus.setRotationSpeed((float) Math.random()); uranus.setTranslationSpeed(0.4f); uranus.registerPhysics(bap.getPhysicsSpace()); planets[6] = uranus; rootNode.attachChild(uranus); Material mat8 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat8.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Neptune.jpg")); mat8.setColor("Specular", ColorRGBA.White); neptune = new Planet("Neptune", 2.65f, mat8); neptune.setInitLocation(new Vector3f(75.0f, 0f, -6.0f)); neptune.setRotationSpeed((float) Math.random()); neptune.setTranslationSpeed(0.34f); neptune.registerPhysics(bap.getPhysicsSpace()); planets[7] = neptune; rootNode.attachChild(neptune); Material mat9 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat9.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Pluto.jpg")); mat9.setColor("Specular", ColorRGBA.White); pluto = new Planet("Pluto", 1.5f, mat9); pluto.setInitLocation(new Vector3f(82.0f, 0f, -6.0f)); pluto.setRotationSpeed((float) Math.random()); pluto.setTranslationSpeed(0.2f); pluto.registerPhysics(bap.getPhysicsSpace()); planets[8] = pluto; rootNode.attachChild(pluto); spaceship = new Spaceship("Spaceship", assetManager.loadModel("Models/X-WING/X-WING.j3o")); spaceship.addTurbines( new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"), assetManager.loadTexture("Effects/Explosion/flame.png")); spaceship.setLocalTranslation(0, 20, 40); spaceship.getModel().scale(0.1f); spaceship.registerPhysics(bap.getPhysicsSpace()); rootNode.attachChild(spaceship); Material laserMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); laserMaterial.setColor("GlowColor", ColorRGBA.Green); laserMaterial.setColor("Ambient", ColorRGBA.Green); laserMaterial.setColor("Diffuse", ColorRGBA.Green); laserMaterial.setBoolean("UseMaterialColors", true); spaceship.setLaserMaterial(laserMaterial); lasers = new Node("Lasers"); rootNode.attachChild(lasers); flyCam.setEnabled(false); cam.setLocation(spaceship.getRear().getWorldTranslation()); cam.lookAt(spaceship.getFront().getWorldTranslation(), Vector3f.UNIT_Y); PointLight sunLight = new PointLight(); sunLight.setColor(ColorRGBA.White); sunLight.setPosition(new Vector3f(0f, 0f, 0f)); sunLight.setRadius(100f); rootNode.addLight(sunLight); AmbientLight ambient = new AmbientLight(); rootNode.addLight(ambient); fpp = new FilterPostProcessor(assetManager); bloom = new BloomFilter(BloomFilter.GlowMode.Objects); bloom.setExposurePower(30f); bloom.setBloomIntensity(1f); fpp.addFilter(bloom); viewPort.addProcessor(fpp); rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Stars5.jpeg", true)); bloomDirection = 1; noComet = 1; moving = up = down = left = right = leftSide = rightSide = false; asteroids = new Node("Asteroids"); rootNode.attachChild(asteroids); explosions = new Node("Explosions"); rootNode.attachChild(explosions); initKeys(); initAudio(); }
protected void renderMultipassLighting(Shader shader, Geometry g, RenderManager rm) { Renderer r = rm.getRenderer(); LightList lightList = g.getWorldLightList(); Uniform lightDir = shader.getUniform("g_LightDirection"); Uniform lightColor = shader.getUniform("g_LightColor"); Uniform lightPos = shader.getUniform("g_LightPosition"); Uniform ambientColor = shader.getUniform("g_AmbientLightColor"); boolean isFirstLight = true; boolean isSecondLight = false; for (int i = 0; i < lightList.size(); i++) { Light l = lightList.get(i); if (l instanceof AmbientLight) { continue; } if (isFirstLight) { // set ambient color for first light only ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList)); isFirstLight = false; isSecondLight = true; } else if (isSecondLight) { ambientColor.setValue(VarType.Vector4, ColorRGBA.Black); // apply additive blending for 2nd and future lights r.applyRenderState(additiveLight); isSecondLight = false; } TempVars vars = TempVars.get(); Quaternion tmpLightDirection = vars.quat1; Quaternion tmpLightPosition = vars.quat2; ColorRGBA tmpLightColor = vars.color; Vector4f tmpVec = vars.vect4f; ColorRGBA color = l.getColor(); tmpLightColor.set(color); tmpLightColor.a = l.getType().getId(); lightColor.setValue(VarType.Vector4, tmpLightColor); switch (l.getType()) { case Directional: DirectionalLight dl = (DirectionalLight) l; Vector3f dir = dl.getDirection(); tmpLightPosition.set(dir.getX(), dir.getY(), dir.getZ(), -1); lightPos.setValue(VarType.Vector4, tmpLightPosition); tmpLightDirection.set(0, 0, 0, 0); lightDir.setValue(VarType.Vector4, tmpLightDirection); break; case Point: PointLight pl = (PointLight) l; Vector3f pos = pl.getPosition(); float invRadius = pl.getInvRadius(); tmpLightPosition.set(pos.getX(), pos.getY(), pos.getZ(), invRadius); lightPos.setValue(VarType.Vector4, tmpLightPosition); tmpLightDirection.set(0, 0, 0, 0); lightDir.setValue(VarType.Vector4, tmpLightDirection); break; case Spot: SpotLight sl = (SpotLight) l; Vector3f pos2 = sl.getPosition(); Vector3f dir2 = sl.getDirection(); float invRange = sl.getInvSpotRange(); float spotAngleCos = sl.getPackedAngleCos(); tmpLightPosition.set(pos2.getX(), pos2.getY(), pos2.getZ(), invRange); lightPos.setValue(VarType.Vector4, tmpLightPosition); // We transform the spot directoin in view space here to save 5 varying later in the // lighting shader // one vec4 less and a vec4 that becomes a vec3 // the downside is that spotAngleCos decoding happen now in the frag shader. tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0); rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); tmpLightDirection.set(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos); lightDir.setValue(VarType.Vector4, tmpLightDirection); break; default: throw new UnsupportedOperationException("Unknown type of light: " + l.getType()); } vars.release(); r.setShader(shader); r.renderMesh(g.getMesh(), g.getLodLevel(), 1); } if (isFirstLight && lightList.size() > 0) { // There are only ambient lights in the scene. Render // a dummy "normal light" so we can see the ambient ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList)); lightColor.setValue(VarType.Vector4, ColorRGBA.BlackNoAlpha); lightPos.setValue(VarType.Vector4, nullDirLight); r.setShader(shader); r.renderMesh(g.getMesh(), g.getLodLevel(), 1); } }
/** * Uploads the lights in the light list as two uniform arrays.<br> * <br> * * * * <p><code>uniform vec4 g_LightColor[numLights];</code><br> * // g_LightColor.rgb is the diffuse/specular color of the light.<br> * // g_Lightcolor.a is the type of light, 0 = Directional, 1 = Point, <br> * // 2 = Spot. <br> * <br> * <code>uniform vec4 g_LightPosition[numLights];</code><br> * // g_LightPosition.xyz is the position of the light (for point lights)<br> * // or the direction of the light (for directional lights).<br> * // g_LightPosition.w is the inverse radius (1/r) of the light (for attenuation) <br> */ protected void updateLightListUniforms(Shader shader, Geometry g, int numLights) { if (numLights == 0) { // this shader does not do lighting, ignore. return; } LightList lightList = g.getWorldLightList(); Uniform lightColor = shader.getUniform("g_LightColor"); Uniform lightPos = shader.getUniform("g_LightPosition"); Uniform lightDir = shader.getUniform("g_LightDirection"); lightColor.setVector4Length(numLights); lightPos.setVector4Length(numLights); lightDir.setVector4Length(numLights); Uniform ambientColor = shader.getUniform("g_AmbientLightColor"); ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList)); int lightIndex = 0; for (int i = 0; i < numLights; i++) { if (lightList.size() <= i) { lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex); lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex); } else { Light l = lightList.get(i); ColorRGBA color = l.getColor(); lightColor.setVector4InArray( color.getRed(), color.getGreen(), color.getBlue(), l.getType().getId(), i); switch (l.getType()) { case Directional: DirectionalLight dl = (DirectionalLight) l; Vector3f dir = dl.getDirection(); lightPos.setVector4InArray(dir.getX(), dir.getY(), dir.getZ(), -1, lightIndex); break; case Point: PointLight pl = (PointLight) l; Vector3f pos = pl.getPosition(); float invRadius = pl.getInvRadius(); lightPos.setVector4InArray(pos.getX(), pos.getY(), pos.getZ(), invRadius, lightIndex); break; case Spot: SpotLight sl = (SpotLight) l; Vector3f pos2 = sl.getPosition(); Vector3f dir2 = sl.getDirection(); float invRange = sl.getInvSpotRange(); float spotAngleCos = sl.getPackedAngleCos(); lightPos.setVector4InArray(pos2.getX(), pos2.getY(), pos2.getZ(), invRange, lightIndex); lightDir.setVector4InArray( dir2.getX(), dir2.getY(), dir2.getZ(), spotAngleCos, lightIndex); break; case Ambient: // skip this light. Does not increase lightIndex continue; default: throw new UnsupportedOperationException("Unknown type of light: " + l.getType()); } } lightIndex++; } while (lightIndex < numLights) { lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex); lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex); lightIndex++; } }
/** @param l */ public LightModel(Light l) { light = l; if (!(l instanceof AmbientLight)) { symbolMaterial = new Material( CurrentData.getEditorWindow().getB3DApp().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); symbolMaterial.setColor("Color", l.getColor()); representativeMaterial = new Material( CurrentData.getEditorWindow().getB3DApp().getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); if (l instanceof DirectionalLight) { /*Light*/ DirectionalLight dLight = (DirectionalLight) l; /*Representativ*/ representativeMaterial.setTexture( "DiffuseMap", CurrentData.getEditorWindow() .getB3DApp() .getAssetManager() .loadTexture("Textures/showDirectionalLightTexture.PNG")); representative = new Geometry("LightModel", new Box(1, 1, 1)); representative.setMaterial(representativeMaterial); /*Symbol*/ Vector3f end = CurrentData.getEditorWindow() .getB3DApp() .getCamera() .getLocation() .add(CurrentData.getEditorWindow().getB3DApp().getCamera().getDirection().mult(20)) .add(dLight.getDirection().mult(100)); Line symbolMesh = new Line(representative.getWorldTranslation(), end); symbolMesh.setPointSize(5); symbol = new Geometry("LightSymbol", symbolMesh); symbol.setMaterial(symbolMaterial); } else if (l instanceof PointLight) { PointLight pLight = (PointLight) l; representativeMaterial.setTexture( "DiffuseMap", CurrentData.getEditorWindow() .getB3DApp() .getAssetManager() .loadTexture("Textures/showPointLightTexture.PNG")); representative = new Geometry("LightModel", new Box(1, 1, 1)); representative.setMaterial(representativeMaterial); representative.setLocalTranslation(pLight.getPosition()); symbol = new Geometry("LightSymbol", new Sphere(15, 15, pLight.getRadius())); symbol.setMaterial(symbolMaterial); symbolMaterial.getAdditionalRenderState().setWireframe(true); } else if (l instanceof SpotLight) { /*Light*/ SpotLight sLight = (SpotLight) l; /*Representativ*/ representativeMaterial.setTexture( "DiffuseMap", CurrentData.getEditorWindow() .getB3DApp() .getAssetManager() .loadTexture("Textures/showSpotLightTexture.PNG")); representative = new Geometry("LightModel", new Box(1, 1, 1)); representative.setLocalTranslation(sLight.getPosition()); representative.setMaterial(representativeMaterial); /*Symbol*/ Vector3f end = sLight.getPosition().add(sLight.getDirection().mult(sLight.getSpotRange())); Line symbolMesh = new Line(representative.getWorldTranslation(), end); symbolMesh.setPointSize(5); symbol = new Geometry("LightSymbol", symbolMesh); symbol.setMaterial(symbolMaterial); } node.attachChild(representative); if (symbol != null) { node.attachChild(symbol); } } }