• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Main repository of MikuMikuStudio


Commit MetaInfo

Revisión304915a96d88e87f918e57c1979a60d2f05c2476 (tree)
Tiempo2003-11-14 01:15:35
Autormojomonkey <mojomonkey@75d0...>
Commitermojomonkey

Log Message

Box is now working.

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@150 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

Cambiar Resumen

Diferencia incremental

--- a/src/com/jme/math/Vector2f.java
+++ b/src/com/jme/math/Vector2f.java
@@ -34,7 +34,7 @@ package com.jme.math;
3434 /**
3535 * <code>Vector2f</code> defines a Vector for a two float value vector.
3636 * @author Mark Powell
37- * @version $Id: Vector2f.java,v 1.1 2003-10-02 15:01:17 mojomonkey Exp $
37+ * @version $Id: Vector2f.java,v 1.2 2003-11-13 16:15:35 mojomonkey Exp $
3838 *
3939 */
4040 public class Vector2f {
@@ -47,6 +47,15 @@ public class Vector2f {
4747 */
4848 public float y;
4949
50+ public Vector2f(float x, float y) {
51+ this.x = x;
52+ this.y = y;
53+ }
54+
55+ public Vector2f() {
56+
57+ }
58+
5059 /**
5160 * <code>toString</code> returns the string representation of this
5261 * vector object. The format of the string is such:
--- a/src/com/jme/scene/Box.java
+++ b/src/com/jme/scene/Box.java
@@ -31,133 +31,263 @@
3131 */
3232 package com.jme.scene;
3333
34+import com.jme.math.Vector2f;
3435 import com.jme.math.Vector3f;
3536 import com.jme.renderer.ColorRGBA;
3637
3738 /**
38- * <code>Box</code> provides an extension of <code>TriMesh</code>
39+ * <code>Box</code> provides an extension of <code>TriMesh</code>. A
40+ * <code>Box</code> is defined by a minimal point and a maximum point. The
41+ * eight vertices that make the box are then computed. They are computed in
42+ * such a way as to generate an axis-aligned box.
3943 * @author Mark Powell
40- * @version $Id: Box.java,v 1.2 2003-10-31 22:02:54 mojomonkey Exp $
44+ * @version $Id: Box.java,v 1.3 2003-11-13 16:15:35 mojomonkey Exp $
4145 */
4246 public class Box extends TriMesh {
47+ private Vector3f min;
48+ private Vector3f max;
49+
50+ /**
51+ * Constructor instantiates a new <code>Box</code> object. The minimum and
52+ * maximum point are provided. These two points define the shape and size
53+ * of the box, but not it's orientation or position. You should use the
54+ * <code>setLocalTranslation</code> and <code>setLocalRotation</code> for
55+ * those attributes.
56+ * @param min the minimum point that defines the box.
57+ * @param max the maximum point that defines the box.
58+ */
4359 public Box(Vector3f min, Vector3f max) {
60+ this.min = min;
61+ this.max = max;
62+
63+ setVertexData();
64+ setNormalData();
65+ setColorData();
66+ setTextureData();
67+ setIndexData();
68+ }
69+
70+ /**
71+ *
72+ * <code>setVertexData</code> sets the vertex positions that define the
73+ * box. These eight points are determined from the minimum and maximum
74+ * point.
75+ *
76+ */
77+ private void setVertexData() {
4478 Vector3f[] verts = new Vector3f[24];
4579 Vector3f vert0 = min;
46- Vector3f vert1 = new Vector3f(max.x,min.y,min.z);
47- Vector3f vert2 = new Vector3f(max.x,max.y,min.z);
48- Vector3f vert3 = new Vector3f(min.x,max.y,min.z);
49- Vector3f vert4 = new Vector3f(min.x,min.y,max.z);
50- Vector3f vert5 = new Vector3f(max.x,min.y,max.z);
51- Vector3f vert6 = new Vector3f(min.x,max.y,max.z);
52- Vector3f vert7 = max;
53-
80+ Vector3f vert1 = new Vector3f(max.x, min.y, min.z);
81+ Vector3f vert2 = new Vector3f(max.x, max.y, min.z);
82+ Vector3f vert3 = new Vector3f(min.x, max.y, min.z);
83+ Vector3f vert4 = new Vector3f(max.x, min.y, max.z);
84+ Vector3f vert5 = new Vector3f(min.x, min.y, max.z);
85+ Vector3f vert6 = max;
86+ Vector3f vert7 = new Vector3f(min.x, max.y, max.z);
87+
5488 //Front
5589 verts[0] = vert0;
5690 verts[1] = vert1;
5791 verts[2] = vert2;
5892 verts[3] = vert3;
59-
93+
6094 //Right
61- verts[4] = vert1;
95+ verts[4] = vert1;
6296 verts[5] = vert4;
63- verts[6] = vert3;
64- verts[7] = vert6;
65-
97+ verts[6] = vert6;
98+ verts[7] = vert2;
99+
66100 //Back
67101 verts[8] = vert4;
68102 verts[9] = vert5;
69- verts[10] = vert6;
70- verts[11] = vert7;
71-
103+ verts[10] = vert7;
104+ verts[11] = vert6;
105+
72106 //Left
73- verts[12] = vert2;
74- verts[13] = vert7;
75- verts[14] = vert0;
76- verts[15] = vert5;
77-
107+ verts[12] = vert5;
108+ verts[13] = vert0;
109+ verts[14] = vert3;
110+ verts[15] = vert7;
111+
78112 //Top
79- verts[16] = vert3;
113+ verts[16] = vert2;
80114 verts[17] = vert6;
81- verts[18] = vert2;
82- verts[19] = vert7;
83-
115+ verts[18] = vert7;
116+ verts[19] = vert3;
117+
84118 //Bottom
85119 verts[20] = vert0;
86120 verts[21] = vert5;
87- verts[22] = vert1;
88- verts[23] = vert4;
89-
121+ verts[22] = vert4;
122+ verts[23] = vert1;
90123 setVertices(verts);
91-
124+
125+ }
126+
127+ /**
128+ *
129+ * <code>setNormalData</code> sets the normals of each of the box's planes.
130+ *
131+ *
132+ */
133+ private void setNormalData() {
92134 Vector3f[] normals = new Vector3f[24];
93- Vector3f front = new Vector3f(0,0,-1);
94- Vector3f right = new Vector3f(1,0,0);
95- Vector3f back = new Vector3f(0,0,1);
96- Vector3f left = new Vector3f(-1,0,0);
97- Vector3f top = new Vector3f(0,1,0);
98- Vector3f bottom = new Vector3f(0,-1,0);
99-
100- //front
135+ Vector3f front = new Vector3f(0, 0, 1);
136+ Vector3f right = new Vector3f(1, 0, 0);
137+ Vector3f back = new Vector3f(0, 0, -1);
138+ Vector3f left = new Vector3f(-1, 0, 0);
139+ Vector3f top = new Vector3f(0, 1, 0);
140+ Vector3f bottom = new Vector3f(0, -1, 0);
141+
142+ // front
101143 normals[0] = front;
102144 normals[1] = front;
103145 normals[2] = front;
104146 normals[3] = front;
105-
147+
106148 //right
107149 normals[4] = right;
108150 normals[5] = right;
109151 normals[6] = right;
110152 normals[7] = right;
111-
153+
112154 //back
113155 normals[8] = back;
114156 normals[9] = back;
115157 normals[10] = back;
116158 normals[11] = back;
117-
159+
118160 //left
119161 normals[12] = left;
120162 normals[13] = left;
121163 normals[14] = left;
122164 normals[15] = left;
123-
165+
124166 //top
125167 normals[16] = top;
126168 normals[17] = top;
127169 normals[18] = top;
128170 normals[19] = top;
129-
171+
130172 //bottom
131173 normals[20] = bottom;
132174 normals[21] = bottom;
133175 normals[22] = bottom;
134176 normals[23] = bottom;
135-
177+
136178 setNormals(normals);
137-
138- int[] indices = {
139- 0,1,3,
140- 0,3,2,
141- 4,5,7,
142- 4,7,6,
143- 8,9,11,
144- 8,11,10,
145- 12,13,15,
146- 12,15,14,
147- 16,17,19,
148- 16,19,18,
149- 20,21,23,
150- 20,23,22
151- };
152-
153- setIndices(indices);
154-
179+
180+ }
181+
182+ /**
183+ *
184+ * <code>setTextureData</code> sets the points that define the texture of
185+ * the box. It's a one-to-one ratio, where each plane of the box has it's
186+ * own copy of the texture. That is, the texture is repeated one time for
187+ * each six faces.
188+ *
189+ */
190+ private void setTextureData() {
191+ Vector2f[] textures = new Vector2f[24];
192+ Vector2f br = new Vector2f(0, 0);
193+ Vector2f bl = new Vector2f(1, 0);
194+ Vector2f tl = new Vector2f(1, 1);
195+ Vector2f tr = new Vector2f(0, 1);
196+
197+ textures[0] = bl;
198+ textures[1] = br;
199+ textures[2] = tr;
200+ textures[3] = tl;
201+
202+ textures[4] = bl;
203+ textures[5] = br;
204+ textures[6] = tr;
205+ textures[7] = tl;
206+
207+ textures[8] = bl;
208+ textures[9] = br;
209+ textures[10] = tr;
210+ textures[11] = tl;
211+
212+ textures[12] = bl;
213+ textures[13] = br;
214+ textures[14] = tr;
215+ textures[15] = tl;
216+
217+ textures[16] = bl;
218+ textures[17] = br;
219+ textures[18] = tr;
220+ textures[19] = tl;
221+
222+ textures[20] = bl;
223+ textures[21] = br;
224+ textures[22] = tr;
225+ textures[23] = tl;
226+
227+ setTextures(textures);
228+
229+ }
230+
231+ /**
232+ *
233+ * <code>setColorData</code> sets the color values for each vertex of the
234+ * box. Currently, these are set to white.
235+ *
236+ */
237+ private void setColorData() {
155238 ColorRGBA[] color = new ColorRGBA[24];
156- for(int i = 0; i < color.length; i++) {
157- color[i] = new ColorRGBA(1,1,1,1);
239+ for (int i = 0; i < color.length; i++) {
240+ color[i] = new ColorRGBA(1, 1, 1, 1);
158241 }
159-
160- this.setColors(color);
161-
242+ setColors(color);
243+ }
244+
245+ /**
246+ *
247+ * <code>setIndexData</code> sets the indices into the list of vertices,
248+ * defining all triangles that constitute the box.
249+ *
250+ */
251+ private void setIndexData() {
252+ int[] indices =
253+ {
254+ 0,
255+ 1,
256+ 2,
257+ 0,
258+ 2,
259+ 3,
260+ 4,
261+ 5,
262+ 6,
263+ 4,
264+ 6,
265+ 7,
266+ 8,
267+ 9,
268+ 10,
269+ 8,
270+ 10,
271+ 11,
272+ 12,
273+ 13,
274+ 14,
275+ 12,
276+ 14,
277+ 15,
278+ 16,
279+ 17,
280+ 18,
281+ 16,
282+ 18,
283+ 19,
284+ 20,
285+ 21,
286+ 22,
287+ 20,
288+ 22,
289+ 23 };
290+ setIndices(indices);
291+
162292 }
163293 }
--- a/src/com/jme/test/renderer/state/TestLightState.java
+++ b/src/com/jme/test/renderer/state/TestLightState.java
@@ -32,6 +32,7 @@
3232 package com.jme.test.renderer.state;
3333
3434 import com.jme.app.AbstractGame;
35+import com.jme.image.Texture;
3536 import com.jme.input.FirstPersonController;
3637 import com.jme.input.InputController;
3738 import com.jme.light.DirectionalLight;
@@ -44,14 +45,17 @@ import com.jme.scene.Box;
4445 import com.jme.scene.Node;
4546 import com.jme.scene.TriMesh;
4647 import com.jme.scene.state.LightState;
48+import com.jme.scene.state.TextureState;
49+import com.jme.scene.state.WireframeState;
4750 import com.jme.scene.state.ZBufferState;
4851 import com.jme.system.DisplaySystem;
4952 import com.jme.system.JmeException;
53+import com.jme.util.TextureManager;
5054
5155 /**
5256 * <code>TestLightState</code>
5357 * @author Mark Powell
54- * @version $Id: TestLightState.java,v 1.2 2003-10-31 22:02:54 mojomonkey Exp $
58+ * @version $Id: TestLightState.java,v 1.3 2003-11-13 16:15:35 mojomonkey Exp $
5559 */
5660 public class TestLightState extends AbstractGame {
5761 private TriMesh t;
@@ -129,136 +133,24 @@ public class TestLightState extends AbstractGame {
129133 * @see com.jme.app.AbstractGame#initGame()
130134 */
131135 protected void initGame() {
132- Vector3f max = new Vector3f(10,10,-20);
133- Vector3f min = new Vector3f(0,0,-10);
134- Vector3f[] verts = new Vector3f[24];
135- Vector3f vert0 = min;
136- Vector3f vert1 = new Vector3f(max.x, min.y, min.z);
137- Vector3f vert2 = new Vector3f(max.x, max.y, min.z);
138- Vector3f vert3 = new Vector3f(min.x, max.y, min.z);
139- Vector3f vert4 = new Vector3f(max.x, min.y, max.z);
140- Vector3f vert5 = new Vector3f(min.x, min.y, max.z);
141- Vector3f vert6 = max;
142- Vector3f vert7 = new Vector3f(min.x, max.y, max.z);
143-
144- //Front
145- verts[0] = vert0;
146- verts[1] = vert1;
147- verts[2] = vert2;
148- verts[3] = vert3;
149-
150- //Right
151- verts[4] = vert1;
152- verts[5] = vert4;
153- verts[6] = vert6;
154- verts[7] = vert2;
155-
156- //Back
157- verts[8] = vert4;
158- verts[9] = vert5;
159- verts[10] = vert7;
160- verts[11] = vert6;
161-
162- //Left
163- verts[12] = vert5;
164- verts[13] = vert0;
165- verts[14] = vert3;
166- verts[15] = vert7;
167-
168- //Top
169- verts[16] = vert2;
170- verts[17] = vert6;
171- verts[18] = vert7;
172- verts[19] = vert3;
173-
174- //Bottom
175- verts[20] = vert0;
176- verts[21] = vert5;
177- verts[22] = vert4;
178- verts[23] = vert1;
179-
136+ Vector3f max = new Vector3f(10,10,10);
137+ Vector3f min = new Vector3f(0,0,0);
180138
181- Vector3f[] normals = new Vector3f[24];
182- //Vector3f front = new Vector3f(0, 0, -1);
183- //Vector3f right = new Vector3f(1, 0, 0);
184- //Vector3f back = new Vector3f(0, 0, 1);
185- Vector3f left = new Vector3f(-1, 0, 0);
186- Vector3f top = new Vector3f(0, 1, 0);
187- Vector3f bottom = new Vector3f(0, -1, 0);
188-// Vector3f front = vert0.cross(vert3).normalize();
189-// Vector3f right = vert3.cross(vert4).normalize();
190-// Vector3f back = vert6.cross(vert5).normalize();
191-// Vector3f left = vert0.cross(vert7).normalize();
192- // System.out.println(back);
193- System.out.println(left);
194-
195- //front
196- normals[0] = vert1.cross(vert3).normalize();
197- normals[1] = vert2.cross(vert0).normalize();
198- normals[2] = vert3.cross(vert1).normalize();
199- normals[3] = vert0.cross(vert2).normalize();
200-
201- //right
202- normals[4] = vert4.cross(vert2).normalize();
203- normals[5] = vert6.cross(vert1).normalize();
204- normals[6] = vert2.cross(vert4).normalize();
205- normals[7] = vert1.cross(vert6).normalize();
206-
207- //back
208- normals[8] = vert5.cross(vert6).normalize();
209- normals[9] = vert7.cross(vert4).normalize();
210- normals[10] = vert6.cross(vert5).normalize();
211- normals[11] = vert4.cross(vert7).normalize();
212-
213- //left
214- normals[12] = vert0.cross(vert7).normalize();
215- normals[13] = vert3.cross(vert5).normalize();
216- normals[14] = vert7.cross(vert0).normalize();
217- normals[15] = vert5.cross(vert3).normalize();
218-
219- //top
220- normals[16] = vert6.cross(vert3).normalize();
221- normals[17] = vert7.cross(vert2).normalize();
222- normals[18] = vert3.cross(vert6).normalize();
223- normals[19] = vert2.cross(vert7).normalize();
224-
225- //bottom
226- normals[20] = vert5.cross(vert1).normalize();
227- normals[21] = vert4.cross(vert0).normalize();
228- normals[22] = vert1.cross(vert5).normalize();
229- normals[23] = vert0.cross(vert4).normalize();
230-
231-
232- int[] indices = {
233- 0,1,2,
234- 0,2,3,
235- 4,5,6,
236- 4,6,7,
237- 8,9,10,
238- 8,10,11,
239- 12,13,14,
240- 12,14,15,
241- 16,17,18,
242- 16,18,19,
243- 20,21,22,
244- 20,22,23
245-
246- };
247-
248-
249- ColorRGBA[] color = new ColorRGBA[24];
250- for (int i = 0; i < color.length; i++) {
251- color[i] = new ColorRGBA(1, 1, 1, 1);
252- }
253-
254- t = new TriMesh(verts, normals, color, null, indices);
255- //t = new Box(new Vector3f(-10, 0, 0), new Vector3f(-20, 10, 10));
139+ t = new Box(min,max);
256140 t.setModelBound(new BoundingSphere());
257141 t.updateModelBound();
258-
142+
143+ Box t2 = new Box(min, max);
144+ t2.setModelBound(new BoundingSphere());
145+ t2.updateModelBound();
146+
147+ t.setLocalTranslation(new Vector3f(0,0,-10));
148+
149+ t2.setLocalTranslation(new Vector3f(-20,0,0));
259150
260151 scene = new Node();
261152 scene.attachChild(t);
153+ scene.attachChild(t2);
262154
263155 ZBufferState buf = display.getRenderer().getZBufferState();
264156 buf.setEnabled(true);
@@ -266,26 +158,51 @@ public class TestLightState extends AbstractGame {
266158
267159 SpotLight am = new SpotLight();
268160 am.setDiffuse(new ColorRGBA(0.0f, 1.0f, 0.0f, 1.0f));
269- am.setAmbient(new ColorRGBA(0.0f, 0.5f, 1.0f, 1.0f));
270- am.setSpecular(new ColorRGBA(0.0f, 0.0f, 1.0f, 1.0f));
271- am.setDirection(new Vector3f(-40, -50, 0));
272- am.setLocation(new Vector3f(-20, -100, 0));
273- am.setAngle(90);
161+ am.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
162+ am.setDirection(new Vector3f(0, 0, 0));
163+ am.setLocation(new Vector3f(25, 10, 0));
164+ am.setAngle(15);
165+
166+ SpotLight am2 = new SpotLight();
167+ am2.setDiffuse(new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
168+ am2.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
169+ am2.setDirection(new Vector3f(0, 0, 0));
170+ am2.setLocation(new Vector3f(-25, 10, 0));
171+ am2.setAngle(15);
172+
274173
275174 DirectionalLight dr = new DirectionalLight();
276- dr.setDiffuse(new ColorRGBA(0.0f, 0.0f, 1.0f, 1.0f));
277- dr.setAmbient(new ColorRGBA(1.0f, 0.5f, 0.0f, 1.0f));
278- dr.setSpecular(new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
279- dr.setDirection(new Vector3f(-40, -25, 0));
175+ dr.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
176+ dr.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
177+ //dr.setSpecular(new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
178+ dr.setDirection(new Vector3f(150, 0 , 150));
280179
281180 LightState state = display.getRenderer().getLightState();
282181 state.attach(am);
283182 state.attach(dr);
183+ state.attach(am2);
284184 am.setEnabled(true);
185+ am2.setEnabled(true);
285186 dr.setEnabled(true);
286187 scene.setRenderState(state);
287188 scene.setRenderState(buf);
288189 cam.update();
190+
191+ TextureState ts = display.getRenderer().getTextureState();
192+ ts.setEnabled(true);
193+ ts.setTexture(
194+ TextureManager.loadTexture(
195+ "data/Images/Monkey.jpg",
196+ Texture.MM_LINEAR,
197+ Texture.FM_LINEAR,
198+ true));
199+
200+ WireframeState ws = display.getRenderer().getWireframeState();
201+ ws.setEnabled(true);
202+ t2.setRenderState(ws);
203+
204+ scene.setRenderState(ts);
205+
289206
290207 scene.updateGeometricState(0.0f, true);
291208