Subversion Repositories distributed

Rev

Rev 26 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26 Rev 32
1
package test.fraktal3d;
1
package test.fraktal3d;
2
import com.jme.math.Vector3f;
2
import com.jme.math.Vector3f;
3
import com.jme.renderer.ColorRGBA;
3
import com.jme.renderer.ColorRGBA;
4
import com.jme.scene.Node;
4
import com.jme.scene.Node;
5
import com.jme.scene.shape.Box;
5
import com.jme.scene.shape.Box;
6
import com.jme.scene.state.BlendState;
6
import com.jme.scene.state.BlendState;
7
import com.jme.scene.state.MaterialState;
7
import com.jme.scene.state.MaterialState;
8
import com.jme.system.DisplaySystem;
8
import com.jme.system.DisplaySystem;
9
 
9
 
10
public class Raumplan {
10
public class Raumplan {
11
        private Box centerbox;
11
        private Box centerbox;
12
       
12
       
13
        private static final int Abbruch_Size = 5;
13
        private static final int Abbruch_Size = 5;
14
        private static final float Size_Faktor = 0.5f;
14
        private static final float Size_Faktor = 0.5f;
15
        private static final float Abstand_Initial = 0.5f;
15
        private static final float Abstand_Initial = 0.5f;
16
        private static final float Abstand_Faktor = 0.5f;
16
        // private static final float Abstand_Faktor = 0.5f;
17
       
17
       
18
        public Raumplan(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) {
18
        public Raumplan(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) {
19
                this.centerbox = new Box("Center-Box", new Vector3f(x, y, z), new Vector3f(size, size, size));
19
                this.centerbox = new Box("Center-Box", new Vector3f(x, y, z), new Vector3f(size, size, size));
20
        }
20
        }
21
       
21
       
22
        public void los(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) {
22
        public void los(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) {
23
                if (size > Abbruch_Size) {             
23
                if (size > Abbruch_Size) {             
24
                        new Raumplan(getRoomNode(), size, x-Abstand_Initial, y-Abstand_Initial, z-Abstand_Initial, LockDirectoryEnum.LOCK_X_POS).los(this.getRoomNode(), size*Size_Faktor, x-Abstand_Initial, y-Abstand_Initial, z-Abstand_Initial, LockDirectoryEnum.LOCK_X_POS);
24
                        new Raumplan(getRoomNode(), size, x-Abstand_Initial, y-Abstand_Initial, z-Abstand_Initial, LockDirectoryEnum.LOCK_X_POS).los(this.getRoomNode(), size*Size_Faktor, x-Abstand_Initial, y-Abstand_Initial, z-Abstand_Initial, LockDirectoryEnum.LOCK_X_POS);
25
                }              
25
                }              
26
 
26
 
27
                rootNode.attachChild(getRoomNode());
27
                rootNode.attachChild(getRoomNode());
28
        }
28
        }
29
 
29
 
30
        protected Node getRoomNode() {
30
        protected Node getRoomNode() {
31
                Node roomNode = new Node();
31
                Node roomNode = new Node();
32
               
32
               
33
                float opacityAmount = 1.0f;
33
                float opacityAmount = 1.0f;
34
                DisplaySystem display = DisplaySystem.getDisplaySystem();
34
                DisplaySystem display = DisplaySystem.getDisplaySystem();
35
               
35
               
36
                MaterialState materialState = display.getRenderer()
36
                MaterialState materialState = display.getRenderer()
37
                .createMaterialState();
37
                .createMaterialState();
38
               
38
               
39
        // the sphere material taht will be modified to make the sphere
39
        // the sphere material taht will be modified to make the sphere
40
        // look opaque then transparent then opaque and so on
40
        // look opaque then transparent then opaque and so on
41
        materialState = display.getRenderer().createMaterialState();
41
        materialState = display.getRenderer().createMaterialState();
42
        materialState.setAmbient(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
42
        materialState.setAmbient(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
43
        materialState.setDiffuse(new ColorRGBA(0.1f, 0.5f, 0.8f, opacityAmount));
43
        materialState.setDiffuse(new ColorRGBA(0.1f, 0.5f, 0.8f, opacityAmount));
44
        materialState.setSpecular(new ColorRGBA(1.0f, 1.0f, 1.0f, opacityAmount));
44
        materialState.setSpecular(new ColorRGBA(1.0f, 1.0f, 1.0f, opacityAmount));
45
        materialState.setShininess(128.0f);
45
        materialState.setShininess(128.0f);
46
        materialState.setEmissive(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
46
        materialState.setEmissive(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
47
        materialState.setEnabled(true);
47
        materialState.setEnabled(true);
48
 
48
 
49
        // IMPORTANT: this is used to handle the internal sphere faces when
49
        // IMPORTANT: this is used to handle the internal sphere faces when
50
        // setting them to transparent, try commenting this line to see what
50
        // setting them to transparent, try commenting this line to see what
51
        // happens
51
        // happens
52
        materialState.setMaterialFace(MaterialState.MaterialFace.FrontAndBack);
52
        materialState.setMaterialFace(MaterialState.MaterialFace.FrontAndBack);
53
 
53
 
54
        centerbox.setRenderState(materialState);
54
        centerbox.setRenderState(materialState);
55
        centerbox.updateRenderState();
55
        centerbox.updateRenderState();
56
 
56
 
57
        roomNode.attachChild(centerbox);
57
        roomNode.attachChild(centerbox);
58
 
58
 
59
        // to handle transparency: a BlendState
59
        // to handle transparency: a BlendState
60
        // an other tutorial will be made to deal with the possibilities of this
60
        // an other tutorial will be made to deal with the possibilities of this
61
        // RenderState
61
        // RenderState
62
        final BlendState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
62
        final BlendState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
63
        alphaState.setBlendEnabled(true);
63
        alphaState.setBlendEnabled(true);
64
        alphaState.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
64
        alphaState.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
65
        alphaState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
65
        alphaState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
66
        alphaState.setTestEnabled(true);
66
        alphaState.setTestEnabled(true);
67
        alphaState.setTestFunction(BlendState.TestFunction.GreaterThan);
67
        alphaState.setTestFunction(BlendState.TestFunction.GreaterThan);
68
        alphaState.setEnabled(true);
68
        alphaState.setEnabled(true);
69
 
69
 
70
        centerbox.setRenderState(alphaState);
70
        centerbox.setRenderState(alphaState);
71
        centerbox.updateRenderState();
71
        centerbox.updateRenderState();
72
               
72
               
73
        return roomNode;
73
        return roomNode;
74
        }
74
        }
75
 
75
 
76
}
76
}
77
 
77