/** * Sets the ambient and diffuse colors of a light source. * @param i a light source [0-2]. * @param rgba array[4] of color components. */ public void setAmbientAndDiffuse(int i, float[] rgba) { setAmbient(i,rgba); setDiffuse(i,rgba); }
/** * Sets the {@link LightSourceType} for the primary light source. * @param type a {@link LightSourceType}. */ public void setLightSourceType(LightSourceType type) { setLightSourceType(0,type); }
/** * Sets the position of the primary light source. * @param lx the x-coordinate. * @param ly the y-coordinate. * @param lz the z-coordinate. */ public void setPosition(float lx, float ly, float lz) { setPosition(0,lx,ly,lz); }
OrbitViewLighting l = new OrbitViewLighting(); float[] newpos = new float[] { 5.0f, 5.0f, 5.0f }; l.setAmbientAndDiffuse(RED); l.setSpecular(GREEN); l.setLightSourceType(lp); l.setPosition(newpos); assertArrayEquals(l.getAmbient(), l.getAmbient(0),0); assertArrayEquals(l.getDiffuse(), l.getDiffuse(0),0); assertArrayEquals(l.getSpecular(),l.getSpecular(0),0); assertArrayEquals(l.getPosition(),l.getPosition(0),0); assertEquals(l.getLightSourceType(),l.getLightSourceType(0)); assertArrayEquals(l.getAmbient(0), RED,0); assertArrayEquals(l.getDiffuse(0), RED,0); assertArrayEquals(l.getSpecular(0),GREEN,0); assertArrayEquals(l.getPosition(0),newpos,0); assertEquals(l.getLightSourceType(0),lp); assertArrayEquals(l.getAmbient(1), BLACK,0); assertArrayEquals(l.getDiffuse(1), WHITE,0); assertArrayEquals(l.getSpecular(1),WHITE,0); assertArrayEquals(l.getPosition(1),POS,0); assertEquals(l.getLightSourceType(1),ld); assertArrayEquals(l.getAmbient(2), BLACK,0); assertArrayEquals(l.getDiffuse(2), WHITE,0); assertArrayEquals(l.getSpecular(2),WHITE,0);
public void testEquality() { OrbitViewLighting sl0 = new OrbitViewLighting(); OrbitViewLighting sl1 = new OrbitViewLighting(); assertEquals(sl0,sl1); sl1.setPosition(1,new float[] { 2.0f, 0.0f, 0.0f }); assertNotEquals(sl0,sl1); sl1 = new OrbitViewLighting(); sl1.setAmbient(1, RED); assertNotEquals(sl0,sl1); sl1 = new OrbitViewLighting(); sl1.setDiffuse(1, RED); assertNotEquals(sl0,sl1); sl1 = new OrbitViewLighting(); sl1.setSpecular(1, RED); assertNotEquals(sl0,sl1); sl1 = new OrbitViewLighting(); sl1.setLightSourceType(1, lp); assertNotEquals(sl0,sl1); sl1 = new OrbitViewLighting(); sl1.setAmbientAndDiffuse(RED); sl0.setAmbientAndDiffuse(RED); assertEquals(sl0,sl1); }
/** * Demos activating all three lights and assigning colors. */ private static void demo2() { Sphere sphere = new Sphere(); StateSet states = StateSet.forTwoSidedShinySurface(Color.WHITE); sphere.setStates(states); World world = new World(); world.addChild(sphere); SimpleFrame sf = new SimpleFrame(world); OrbitViewLighting ovl = new OrbitViewLighting(); ovl.setPosition(0,-2.0f, 2.0f,0.0f); ovl.setPosition(1, 2.0f, 2.0f,0.0f); ovl.setPosition(2, 0.0f,-2.0f,0.0f); ovl.setLightSourceType(0, LightSourceType.POSITIONAL); ovl.setLightSourceType(1, LightSourceType.POSITIONAL); ovl.setLightSourceType(2, LightSourceType.POSITIONAL); ovl.setDiffuse(0,RED); ovl.setDiffuse(1,GREEN); ovl.setDiffuse(2,BLUE); ovl.toggleLight(1); ovl.toggleLight(2); sf.getOrbitView().setOrbitViewLighting(ovl); sf.setTitle("OrbitViewLighting Demo: Three Lights"); }
/** * To maintain functionality with the legacy l in the JTK, the * default l should have: * 1. Single directional light source at (-0.1,-0.1,1.0) * 2. Ambient light set to (0,0,0,1) * 3. Diffuse light set to (1,1,1,1) * 4. Specular light set to (1,1,1,1) */ public void testDefaultParameters() { OrbitViewLighting l = new OrbitViewLighting(); assertEquals(l.getLightSourceType(0), ld); assertArrayEquals(l.getAmbient(0), BLACK,0); assertArrayEquals(l.getSpecular(0), WHITE,0); assertArrayEquals(l.getDiffuse(0), WHITE,0); assertArrayEquals(l.getPosition(0), POS, 0); assertTrue(l.isLightOn(0)); assertEquals(l.getLightSourceType(1), ld); assertArrayEquals(l.getAmbient(1), BLACK,0); assertArrayEquals(l.getSpecular(1), WHITE,0); assertArrayEquals(l.getDiffuse(1), WHITE,0); assertArrayEquals(l.getPosition(1), POS, 0); assertFalse(l.isLightOn(1)); assertEquals(l.getLightSourceType(2), ld); assertArrayEquals(l.getAmbient(2), BLACK,0); assertArrayEquals(l.getSpecular(2), WHITE,0); assertArrayEquals(l.getDiffuse(2), WHITE,0); assertArrayEquals(l.getPosition(2), POS, 0); assertFalse(l.isLightOn(2)); }
/** * Demos re-positioning the light source to the top-right corner. */ private static void demo1() { Sphere sphere = new Sphere(); StateSet states = StateSet.forTwoSidedShinySurface(Color.WHITE); sphere.setStates(states); World world = new World(); world.addChild(sphere); SimpleFrame sf = new SimpleFrame(world); OrbitViewLighting ovl = new OrbitViewLighting(); ovl.setPosition(0,1.0f,1.0f,0.0f); ovl.setLightSourceType(LightSourceType.DIRECTIONAL); sf.getOrbitView().setOrbitViewLighting(ovl); sf.setTitle("OrbitViewLighting Demo: Re-positioned primary light"); }
public void testLightToggle() { OrbitViewLighting l = new OrbitViewLighting(); assertTrue(l.isLightOn()); l.toggleLight(0); assertFalse(l.isLightOn()); l.toggleLight(0); assertTrue(l.isLightOn()); }
/** * Toggles the primary light source. */ public void toggleLight() { toggleLight(0); }
/** * Sets the diffuse color of the primary light source. * @param rgba diffuse color of the primary light source. */ public void setDiffuse(float[] rgba) { setDiffuse(0,rgba); }
/** * Gets the specular color of the primary light source. * @return the specular color of the primary light source. */ public float[] getSpecular() { return getSpecular(0); }
/** * Gets the diffuse color of the primary light source. * @return diffuse color of the primary light source. */ public float[] getDiffuse() { return getDiffuse(0); }
/** * Gets the {@link LightSourceType} for the primary light source. * @return the {@link LightSourceType}. */ public LightSourceType getLightSourceType() { return getLightSourceType(0); }
/** * Gets the ambient color of the primary light source. * @return ambient color of the primary light source. */ public float[] getAmbient() { return getAmbient(0); }
/** * Gets the position of the primary light source. * @return the (x,y,z,w) coordinates of the primary light source. */ public float[] getPosition() { return getPosition(0); }
/** * Sets the position of the primary light source. * @param pos array[3] of (x,y,z) coordinates. */ public void setPosition(float[] pos) { setPosition(0,pos); }
/** * Sets the position of a light source. * @param i a light source [0-2]. * @param lx the x-coordinate. * @param ly the y-coordinate. * @param lz the z-coordinate. */ public void setPosition(int i, float lx, float ly, float lz) { setPosition(i, new float[] { lx, ly, lz}); }