Rev 22 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 22 | Rev 26 | ||
---|---|---|---|
Line 5... | Line 5... | ||
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 Room { |
10 | public class Raumplan { |
11 | private Box bottom; |
11 | private Box centerbox; |
12 | private Box top; |
- | |
13 | private Box left; |
- | |
14 | private Box right; |
- | |
15 | private Box front; |
- | |
16 | private Box back; |
- | |
17 | 12 | ||
18 | private float thickness; |
13 | private static final int Abbruch_Size = 5; |
19 | - | ||
20 | public Room(float length, float width, float depth, float thickness) { |
14 | private static final float Size_Faktor = 0.5f; |
21 | this.thickness = thickness; |
15 | private static final float Abstand_Initial = 0.5f; |
22 | - | ||
23 | this.bottom = new Box("Bottom", new Vector3f(), width + thickness, |
16 | private static final float Abstand_Faktor = 0.5f; |
24 | thickness, depth); |
- | |
25 | 17 | ||
26 | this.top = new Box("Top", new Vector3f(), width + thickness, thickness, |
18 | public Raumplan(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) { |
27 | depth); |
- | |
28 | this.top.setLocalTranslation(new Vector3f(0, length * 2, 0)); |
19 | this.centerbox = new Box("Center-Box", new Vector3f(x, y, z), new Vector3f(size, size, size)); |
29 | 20 | } |
|
30 | this.left = new Box("Left Border", new Vector3f(), thickness, length, |
- | |
31 | depth); |
- | |
32 | this.left.setLocalTranslation(new Vector3f(-(width), length, 0)); |
- | |
33 | 21 | ||
34 | this.right = new Box("Right Border", new Vector3f(), thickness, length, |
22 | public void los(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) { |
35 | depth); |
23 | if (size > Abbruch_Size) { |
36 | this.right.setLocalTranslation(new Vector3f(width, length, 0)); |
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); |
37 | - | ||
38 | this.back = new Box("Back Border", new Vector3f(), width, length, |
- | |
39 | thickness); |
25 | } |
40 | this.back.setLocalTranslation(new Vector3f(0, length, -depth)); |
- | |
41 | 26 | ||
42 | this.front = new Box("Front Border", new Vector3f(), width, length, |
- | |
43 | thickness); |
- | |
44 | this.front.setLocalTranslation(new Vector3f(0, length, depth)); |
27 | rootNode.attachChild(getRoomNode()); |
45 | } |
28 | } |
46 | 29 | ||
47 | public Node getRoomNode() { |
30 | protected Node getRoomNode() { |
48 | Node roomNode = new Node(); |
31 | Node roomNode = new Node(); |
49 | 32 | ||
50 | float opacityAmount = 0.1f; |
33 | float opacityAmount = 1.0f; |
51 | DisplaySystem display = DisplaySystem.getDisplaySystem(); |
34 | DisplaySystem display = DisplaySystem.getDisplaySystem(); |
52 | 35 | ||
53 | MaterialState materialState = display.getRenderer() |
36 | MaterialState materialState = display.getRenderer() |
54 | .createMaterialState(); |
37 | .createMaterialState(); |
55 | 38 | ||
Line 66... | Line 49... | ||
66 | // IMPORTANT: this is used to handle the internal sphere faces when |
49 | // IMPORTANT: this is used to handle the internal sphere faces when |
67 | // setting them to transparent, try commenting this line to see what |
50 | // setting them to transparent, try commenting this line to see what |
68 | // happens |
51 | // happens |
69 | materialState.setMaterialFace(MaterialState.MaterialFace.FrontAndBack); |
52 | materialState.setMaterialFace(MaterialState.MaterialFace.FrontAndBack); |
70 | 53 | ||
71 | back.setRenderState(materialState); |
54 | centerbox.setRenderState(materialState); |
72 | back.updateRenderState(); |
55 | centerbox.updateRenderState(); |
73 | 56 | ||
74 | roomNode.attachChild(back); |
57 | roomNode.attachChild(centerbox); |
75 | 58 | ||
76 | // to handle transparency: a BlendState |
59 | // to handle transparency: a BlendState |
77 | // 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 |
78 | // RenderState |
61 | // RenderState |
79 | final BlendState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState(); |
62 | final BlendState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState(); |
Line 82... | Line 65... | ||
82 | alphaState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha); |
65 | alphaState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha); |
83 | alphaState.setTestEnabled(true); |
66 | alphaState.setTestEnabled(true); |
84 | alphaState.setTestFunction(BlendState.TestFunction.GreaterThan); |
67 | alphaState.setTestFunction(BlendState.TestFunction.GreaterThan); |
85 | alphaState.setEnabled(true); |
68 | alphaState.setEnabled(true); |
86 | 69 | ||
87 | back.setRenderState(alphaState); |
70 | centerbox.setRenderState(alphaState); |
88 | back.updateRenderState(); |
71 | centerbox.updateRenderState(); |
89 | - | ||
90 | - | ||
91 | - | ||
92 | roomNode.attachChild(bottom); |
- | |
93 | roomNode.attachChild(top); |
- | |
94 | roomNode.attachChild(right); |
- | |
95 | roomNode.attachChild(left); |
- | |
96 | roomNode.attachChild(back); |
- | |
97 | 72 | ||
98 | return roomNode; |
73 | return roomNode; |
99 | } |
74 | } |
100 | 75 | ||
101 | public Vector3f getBorderPosition(RoomBorderEnum border) { |
- | |
102 | Vector3f vec = new Vector3f(); |
- | |
103 | - | ||
104 | if (border == RoomBorderEnum.UP) { |
- | |
105 | vec = new Vector3f(this.top.getLocalTranslation()); |
- | |
106 | vec.y -= this.thickness; |
- | |
107 | - | ||
108 | } else if (border == RoomBorderEnum.DOWN) { |
- | |
109 | vec = new Vector3f(this.bottom.getLocalTranslation()); |
- | |
110 | vec.y += this.thickness; |
- | |
111 | } |
- | |
112 | - | ||
113 | else if (border == RoomBorderEnum.LEFT) { |
- | |
114 | vec = new Vector3f(this.left.getLocalTranslation()); |
- | |
115 | vec.x += this.thickness; |
- | |
116 | } |
- | |
117 | - | ||
118 | else if (border == RoomBorderEnum.RIGHT) { |
- | |
119 | vec = new Vector3f(this.right.getLocalTranslation()); |
- | |
120 | vec.x -= this.thickness; |
- | |
121 | } |
- | |
122 | - | ||
123 | else if (border == RoomBorderEnum.FRONT) { |
- | |
124 | vec = new Vector3f(this.front.getLocalTranslation()); |
- | |
125 | vec.z -= this.thickness; |
- | |
126 | } |
- | |
127 | - | ||
128 | else if (border == RoomBorderEnum.BACK) { |
- | |
129 | vec = new Vector3f(this.back.getLocalTranslation()); |
- | |
130 | vec.z += this.thickness; |
- | |
131 | } |
- | |
132 | - | ||
133 | return vec; |
- | |
134 | } |
- | |
135 | } |
76 | } |