3 import java.util.logging.Logger;
5 import com.jme.bounding.BoundingSphere;
6 import com.jme.math.Vector3f;
7 import com.jme.scene.Node;
8 import com.jme.scene.shape.Sphere;
9 import junit.framework.TestCase;
12 * Tests for LightState relatet stuff.
14 public class LightManagementTest extends TestCase {
15 private static final Logger logger = Logger
16 .getLogger(LightManagementTest.class.getName());
19 * Test the LightStateCreator.quickSort.
21 public void testQuickSort() {
22 LightManagement lightStateCreator = new LightManagement();
25 SpotLight a = new SpotLight();
26 lightStateCreator.addLight( a );
27 SpotLight b = new SpotLight();
28 lightStateCreator.addLight( b );
29 SpotLight c = new SpotLight();
30 lightStateCreator.addLight( c );
31 SpotLight spot1 = new SpotLight();
32 spot1.setAttenuate( true );
33 spot1.setLocation( new Vector3f( 2, 0, 0 ) );
34 spot1.setDirection( new Vector3f( 0, 0.5f, 0 ) );
36 lightStateCreator.addLight( spot1 );
37 lightStateCreator.addLight( new DirectionalLight() );
38 lightStateCreator.addLight( new SpotLight() );
39 lightStateCreator.addLight( new SpotLight() );
40 lightStateCreator.addLight( new DirectionalLight() );
41 lightStateCreator.addLight( new PointLight() );
43 for ( int i = 0; i < lightStateCreator.numberOfLights(); i++ ) {
44 Light light = lightStateCreator.get( i );
45 light.setEnabled( true );
48 assertEquals( "number of lights", 9, lightStateCreator.numberOfLights() );
50 Node node = new Node( "test" );
51 Sphere dummy = new Sphere( null, 5, 5, 1 );
52 dummy.setModelBound( new BoundingSphere( 1, new Vector3f( 1, 0, 0 ) ) );
53 node.attachChild( dummy );
54 node.updateGeometricState( 0, true );
55 lightStateCreator.sort( node );
57 assertEquals( "number of lights", 9, lightStateCreator.numberOfLights() );
59 float lastValue = Float.MAX_VALUE;
63 for ( int i = 0; i < lightStateCreator.numberOfLights(); i++ ) {
64 Light light = lightStateCreator.get( i );
65 float lightValue = lightStateCreator.getValueFor( light, node.getWorldBound() );
66 assertTrue( "order wrong", lightValue <= lastValue );
76 lastValue = lightValue;
78 assertEquals( "b after a", aIndex + 1, bIndex );
79 assertEquals( "c after b", bIndex + 1, cIndex );