Subversion Repositories distributed

Rev

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