OSDN Git Service

e3bcf4d7d25f1f4ffd32993953a090eefd9e5cb7
[mikumikustudio/MikuMikuStudio.git] / junit / com / jme / light / LightManagementTest.java
1 package com.jme.light;
2
3 import java.util.logging.Logger;
4
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;
10
11 /**
12  * Tests for LightState relatet stuff.
13  */
14 public class LightManagementTest extends TestCase {
15     private static final Logger logger = Logger
16             .getLogger(LightManagementTest.class.getName());
17     
18     /**
19      * Test the LightStateCreator.quickSort.
20      */
21     public void testQuickSort() {
22         LightManagement lightStateCreator = new LightManagement();
23
24         // create nine lights
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 ) );
35         spot1.setLinear( 2 );
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() );
42
43         for ( int i = 0; i < lightStateCreator.numberOfLights(); i++ ) {
44             Light light = lightStateCreator.get( i );
45             light.setEnabled( true );
46         }
47
48         assertEquals( "number of lights", 9, lightStateCreator.numberOfLights() );
49
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 );
56
57         assertEquals( "number of lights", 9, lightStateCreator.numberOfLights() );
58
59         float lastValue = Float.MAX_VALUE;
60         int aIndex = -1;
61         int bIndex = -1;
62         int cIndex = -1;
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 );
67             if ( light == a ) {
68                 aIndex = i;
69             }
70             if ( light == b ) {
71                 bIndex = i;
72             }
73             if ( light == c ) {
74                 cIndex = i;
75             }
76             lastValue = lightValue;
77         }
78         assertEquals( "b after a", aIndex + 1, bIndex );
79         assertEquals( "c after b", bIndex + 1, cIndex );
80     }
81 }