Rev 32 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
22 | daniel-mar | 1 | package test.fraktal3d; |
43 | daniel-mar | 2 | import java.awt.Color; |
3 | |||
22 | daniel-mar | 4 | import com.jme.math.Vector3f; |
5 | import com.jme.renderer.ColorRGBA; |
||
6 | import com.jme.scene.Node; |
||
7 | import com.jme.scene.shape.Box; |
||
8 | import com.jme.scene.state.BlendState; |
||
9 | import com.jme.scene.state.MaterialState; |
||
10 | import com.jme.system.DisplaySystem; |
||
11 | |||
26 | daniel-mar | 12 | public class Raumplan { |
43 | daniel-mar | 13 | protected Box centerbox; |
26 | daniel-mar | 14 | |
15 | private static final float Size_Faktor = 0.5f; |
||
43 | daniel-mar | 16 | private static final float Abstand_Faktor = 0.5f; |
17 | private static final float Max_Iter = 6; // Ab 7 wird's eklig! |
||
26 | daniel-mar | 18 | |
43 | daniel-mar | 19 | public Raumplan(Node rootNode, float size, float abstand, float x, float y, float z, LockDirectoryEnum e, int iter) { |
20 | if (iter > Max_Iter) return; |
||
21 | |||
22 | Box centerbox = new Box("Center-Box", new Vector3f(x, y, z), size, size, size); |
||
23 | |||
24 | Node rn = getRoomNode(centerbox, iter); |
||
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); |
||
26 | daniel-mar | 47 | } |
48 | |||
43 | daniel-mar | 49 | protected static Node getRoomNode(Box centerbox, int iter) { |
50 | Node roomNode = new Node(); // Unnötiges Zwischennode? |
||
22 | daniel-mar | 51 | |
26 | daniel-mar | 52 | float opacityAmount = 1.0f; |
22 | daniel-mar | 53 | DisplaySystem display = DisplaySystem.getDisplaySystem(); |
54 | |||
55 | MaterialState materialState = display.getRenderer() |
||
56 | .createMaterialState(); |
||
43 | daniel-mar | 57 | |
58 | // the sphere material that will be modified to make the sphere |
||
22 | daniel-mar | 59 | // look opaque then transparent then opaque and so on |
60 | materialState = display.getRenderer().createMaterialState(); |
||
61 | materialState.setAmbient(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount)); |
||
43 | daniel-mar | 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 | |||
68 | materialState.setDiffuse(new ColorRGBA(r, g, b, opacityAmount)); // TODO |
||
22 | daniel-mar | 69 | materialState.setSpecular(new ColorRGBA(1.0f, 1.0f, 1.0f, opacityAmount)); |
70 | materialState.setShininess(128.0f); |
||
71 | materialState.setEmissive(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount)); |
||
72 | materialState.setEnabled(true); |
||
73 | |||
74 | // IMPORTANT: this is used to handle the internal sphere faces when |
||
75 | // setting them to transparent, try commenting this line to see what |
||
76 | // happens |
||
77 | materialState.setMaterialFace(MaterialState.MaterialFace.FrontAndBack); |
||
78 | |||
26 | daniel-mar | 79 | centerbox.setRenderState(materialState); |
80 | centerbox.updateRenderState(); |
||
43 | daniel-mar | 81 | |
22 | daniel-mar | 82 | // to handle transparency: a BlendState |
83 | // an other tutorial will be made to deal with the possibilities of this |
||
84 | // RenderState |
||
85 | final BlendState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState(); |
||
86 | alphaState.setBlendEnabled(true); |
||
87 | alphaState.setSourceFunction(BlendState.SourceFunction.SourceAlpha); |
||
88 | alphaState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha); |
||
89 | alphaState.setTestEnabled(true); |
||
90 | alphaState.setTestFunction(BlendState.TestFunction.GreaterThan); |
||
91 | alphaState.setEnabled(true); |
||
92 | |||
26 | daniel-mar | 93 | centerbox.setRenderState(alphaState); |
94 | centerbox.updateRenderState(); |
||
22 | daniel-mar | 95 | |
43 | daniel-mar | 96 | roomNode.attachChild(centerbox); |
26 | daniel-mar | 97 | return roomNode; |
22 | daniel-mar | 98 | } |
99 | |||
100 | } |