Subversion Repositories distributed

Rev

Rev 32 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 32 Rev 43
Line 1... Line 1...
1
package test.fraktal3d;
1
package test.fraktal3d;
-
 
2
import java.awt.Color;
-
 
3
 
2
import com.jme.math.Vector3f;
4
import com.jme.math.Vector3f;
3
import com.jme.renderer.ColorRGBA;
5
import com.jme.renderer.ColorRGBA;
4
import com.jme.scene.Node;
6
import com.jme.scene.Node;
5
import com.jme.scene.shape.Box;
7
import com.jme.scene.shape.Box;
6
import com.jme.scene.state.BlendState;
8
import com.jme.scene.state.BlendState;
7
import com.jme.scene.state.MaterialState;
9
import com.jme.scene.state.MaterialState;
8
import com.jme.system.DisplaySystem;
10
import com.jme.system.DisplaySystem;
9
 
11
 
10
public class Raumplan {
12
public class Raumplan {
11
        private Box centerbox;
13
        protected Box centerbox;
12
       
14
       
13
        private static final int Abbruch_Size = 5;
-
 
14
        private static final float Size_Faktor = 0.5f;
15
        private static final float Size_Faktor = 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
        private static final float Max_Iter = 6; // Ab 7 wird's eklig!
17
       
18
       
18
        public Raumplan(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) {
19
        public Raumplan(Node rootNode, float size, float abstand, float x, float y, float z, LockDirectoryEnum e, int iter) {
19
                this.centerbox = new Box("Center-Box", new Vector3f(x, y, z), new Vector3f(size, size, size));
20
                if (iter > Max_Iter) return;
20
        }
-
 
21
       
21
               
22
        public void los(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) {
22
                Box centerbox = new Box("Center-Box", new Vector3f(x, y, z), size, size, 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);
-
 
25
                }              
-
 
26
 
23
               
-
 
24
                Node rn = getRoomNode(centerbox, iter);
27
                rootNode.attachChild(getRoomNode());
25
                rootNode.attachChild(rn);
-
 
26
               
-
 
27
                // WIESO geht es nur mit abstand??? Es sollte abstand*1 sein!
-
 
28
                float abstand2 = 0.5f*size + abstand + 0.5f*size*Size_Faktor;
-
 
29
//              System.out.println(iter);
-
 
30
//              System.out.println(size);
-
 
31
//              System.out.println((0.5f*size) + " + " + abstand + " + " + ( 0.5f*size*Size_Faktor));
-
 
32
//              
-
 
33
//              System.out.println(x-abstand2);
-
 
34
               
-
 
35
                if (e != LockDirectoryEnum.LOCK_X_NEG)
-
 
36
                        new Raumplan(rn, size*Size_Faktor, abstand*Abstand_Faktor, x-abstand2, y, z, LockDirectoryEnum.LOCK_X_POS, iter+1);
-
 
37
                if (e != LockDirectoryEnum.LOCK_X_POS)
-
 
38
                        new Raumplan(rn, size*Size_Faktor, abstand*Abstand_Faktor, x+abstand2, y, z, LockDirectoryEnum.LOCK_X_NEG, iter+1);
-
 
39
                if (e != LockDirectoryEnum.LOCK_Y_NEG)
-
 
40
                        new Raumplan(rn, size*Size_Faktor, abstand*Abstand_Faktor, x, y-abstand2, z, LockDirectoryEnum.LOCK_Y_POS, iter+1);
-
 
41
                if (e != LockDirectoryEnum.LOCK_Y_POS)
-
 
42
                        new Raumplan(rn, size*Size_Faktor, abstand*Abstand_Faktor, x, y+abstand2, z, LockDirectoryEnum.LOCK_Y_NEG, iter+1);
-
 
43
                if (e != LockDirectoryEnum.LOCK_Z_NEG)
-
 
44
                        new Raumplan(rn, size*Size_Faktor, abstand*Abstand_Faktor, x, y, z-abstand2, LockDirectoryEnum.LOCK_Z_POS, iter+1);
-
 
45
                if (e != LockDirectoryEnum.LOCK_Z_POS)
-
 
46
                        new Raumplan(rn, size*Size_Faktor, abstand*Abstand_Faktor, x, y, z+abstand2, LockDirectoryEnum.LOCK_Z_NEG, iter+1);
28
        }
47
        }
29
 
48
       
30
        protected Node getRoomNode() {
49
        protected static Node getRoomNode(Box centerbox, int iter) {
31
                Node roomNode = new Node();
50
                Node roomNode = new Node(); // Unnötiges Zwischennode?
32
               
51
               
33
                float opacityAmount = 1.0f;
52
                float opacityAmount = 1.0f;
34
                DisplaySystem display = DisplaySystem.getDisplaySystem();
53
                DisplaySystem display = DisplaySystem.getDisplaySystem();
35
               
54
               
36
                MaterialState materialState = display.getRenderer()
55
                MaterialState materialState = display.getRenderer()
37
                .createMaterialState();
56
                .createMaterialState();
38
               
57
 
39
        // the sphere material taht will be modified to make the sphere
58
        // the sphere material that will be modified to make the sphere
40
        // look opaque then transparent then opaque and so on
59
        // look opaque then transparent then opaque and so on
41
        materialState = display.getRenderer().createMaterialState();
60
        materialState = display.getRenderer().createMaterialState();
42
        materialState.setAmbient(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
61
        materialState.setAmbient(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
-
 
62
       
-
 
63
        Color x = ColorUtilities.HSLtoRGB(1.0f/iter, 1.0f, 0.5f);
-
 
64
        float r = (float)x.getRed()/255;
-
 
65
        float g = (float)x.getGreen()/255;
-
 
66
        float b = (float)x.getBlue()/255;
-
 
67
       
43
        materialState.setDiffuse(new ColorRGBA(0.1f, 0.5f, 0.8f, opacityAmount));
68
        materialState.setDiffuse(new ColorRGBA(r, g, b, opacityAmount)); // TODO
44
        materialState.setSpecular(new ColorRGBA(1.0f, 1.0f, 1.0f, opacityAmount));
69
        materialState.setSpecular(new ColorRGBA(1.0f, 1.0f, 1.0f, opacityAmount));
45
        materialState.setShininess(128.0f);
70
        materialState.setShininess(128.0f);
46
        materialState.setEmissive(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
71
        materialState.setEmissive(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
47
        materialState.setEnabled(true);
72
        materialState.setEnabled(true);
48
 
73
 
Line 52... Line 77...
52
        materialState.setMaterialFace(MaterialState.MaterialFace.FrontAndBack);
77
        materialState.setMaterialFace(MaterialState.MaterialFace.FrontAndBack);
53
 
78
 
54
        centerbox.setRenderState(materialState);
79
        centerbox.setRenderState(materialState);
55
        centerbox.updateRenderState();
80
        centerbox.updateRenderState();
56
 
81
 
57
        roomNode.attachChild(centerbox);
-
 
58
 
-
 
59
        // to handle transparency: a BlendState
82
        // to handle transparency: a BlendState
60
        // an other tutorial will be made to deal with the possibilities of this
83
        // an other tutorial will be made to deal with the possibilities of this
61
        // RenderState
84
        // RenderState
62
        final BlendState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
85
        final BlendState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
63
        alphaState.setBlendEnabled(true);
86
        alphaState.setBlendEnabled(true);
Line 68... Line 91...
68
        alphaState.setEnabled(true);
91
        alphaState.setEnabled(true);
69
 
92
 
70
        centerbox.setRenderState(alphaState);
93
        centerbox.setRenderState(alphaState);
71
        centerbox.updateRenderState();
94
        centerbox.updateRenderState();
72
               
95
               
-
 
96
        roomNode.attachChild(centerbox);
73
        return roomNode;
97
        return roomNode;
74
        }
98
        }
75
 
99
 
76
}
100
}