• 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óne32e3638635ea65be4c4dca7e5d0cfabbde4e226 (tree)
Tiempo2003-12-04 01:25:40
Autormojomonkey <mojomonkey@75d0...>
Commitermojomonkey

Log Message

Fix rotational issues.

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

Cambiar Resumen

Diferencia incremental

--- a/src/com/jme/math/Quaternion.java
+++ b/src/com/jme/math/Quaternion.java
@@ -41,7 +41,7 @@ package com.jme.math;
4141 * {x y z w}.
4242 *
4343 * @author Mark Powell
44- * @version $Id: Quaternion.java,v 1.2 2003-12-02 20:08:09 mojomonkey Exp $
44+ * @version $Id: Quaternion.java,v 1.3 2003-12-03 16:25:40 mojomonkey Exp $
4545 */
4646 public class Quaternion {
4747 public float x, y, z, w;
@@ -225,21 +225,33 @@ public class Quaternion {
225225 * @return the rotation matrix representation of this quaternion.
226226 */
227227 public Matrix3f toRotationMatrix( ) {
228-
228+ float[][] kRot = new float[3][3];
229+ float fTx = 2.0f*x;
230+ float fTy = 2.0f*y;
231+ float fTz = 2.0f*z;
232+ float fTwx = fTx*w;
233+ float fTwy = fTy*w;
234+ float fTwz = fTz*w;
235+ float fTxx = fTx*x;
236+ float fTxy = fTy*x;
237+ float fTxz = fTz*x;
238+ float fTyy = fTy*y;
239+ float fTyz = fTz*y;
240+ float fTzz = fTz*z;
241+
229242 Matrix3f matrix = new Matrix3f();
230- matrix.set(0, 0, (1.0f - 2.0f * (y * y + z * z)));
231- matrix.set(0, 1, (2.0f * (x * y - w * z)));
232- matrix.set(0, 2, (2.0f * (x * z + w * y)));
243+
244+ kRot[0][0] = 1.0f-(fTyy+fTzz);
245+ kRot[0][1] = fTxy-fTwz;
246+ kRot[0][2] = fTxz+fTwy;
247+ kRot[1][0] = fTxy+fTwz;
248+ kRot[1][1] = 1.0f-(fTxx+fTzz);
249+ kRot[1][2] = fTyz-fTwx;
250+ kRot[2][0] = fTxz-fTwy;
251+ kRot[2][1] = fTyz+fTwx;
252+ kRot[2][2] = 1.0f-(fTxx+fTyy);
233253
234- // Second row
235- matrix.set(1, 0, (2.0f * (x * y + w * z)));
236- matrix.set(1, 1, (1.0f - 2.0f * (x * x + z * z)));
237- matrix.set(1, 2, (2.0f * (y * z - w * x)));
238-
239- // Third row
240- matrix.set(2, 0, (2.0f * (x * z - w * y)));
241- matrix.set(2, 1, (2.0f * (y * z + w * x)));
242- matrix.set(2, 2, (1.0f - 2.0f * (x * x + y * y)));
254+ matrix.set(kRot);
243255
244256 return matrix;
245257
@@ -248,16 +260,17 @@ public class Quaternion {
248260 /**
249261 * <code>fromAngleAxis</code> sets this quaternion to the values
250262 * specified by an angle and an axis of rotation.
251- * @param angle the angle to rotate.
263+ * @param angle the angle to rotate (in radians).
252264 * @param axis the axis of rotation.
253265 */
254266 public void fromAngleAxis(float angle, Vector3f axis) {
267+ Vector3f normAxis = axis.normalize();
255268 float halfAngle = 0.5f * angle;
256269 float sin = (float) Math.sin(halfAngle);
257270 w = (float) Math.cos(halfAngle);
258- x = sin * axis.x;
259- y = sin * axis.y;
260- z = sin * axis.z;
271+ x = sin * normAxis.x;
272+ y = sin * normAxis.y;
273+ z = sin * normAxis.z;
261274 }
262275
263276 /**
@@ -443,4 +456,8 @@ public class Quaternion {
443456 z *= -1;
444457 w *= -1;
445458 }
459+
460+ public String toString() {
461+ return "com.jme.math.Quaternion: [x=" +x+" y="+y+" z="+z+" w="+w+"]";
462+ }
446463 }
--- /dev/null
+++ b/src/com/jme/test/math/TestQuaternion.java
@@ -0,0 +1,61 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+package com.jme.test.math;
33+
34+import javax.vecmath.AxisAngle4f;
35+import javax.vecmath.Quat4f;
36+
37+import com.jme.math.Quaternion;
38+import com.jme.math.Vector3f;
39+
40+/**
41+ * <code>TestQuaternion</code>
42+ * @author Mark Powell
43+ * @version
44+ */
45+public class TestQuaternion {
46+
47+ public static void main(String[] args) {
48+ Quaternion quat = new Quaternion();
49+ Quat4f vquat = new Quat4f();
50+ System.out.println("FIRST JME, SECOND VECMATH");
51+ System.out.println("Initial:" + quat);
52+ System.out.println(vquat);
53+
54+ quat.fromAngleAxis(1,new Vector3f(1,1,1));
55+ System.out.println("AXIS ANGLE: " + quat);
56+ AxisAngle4f aa = new AxisAngle4f(new javax.vecmath.Vector3f(1,1,1),1);
57+ vquat.set(aa);
58+ System.out.println(vquat);
59+ }
60+
61+}
--- a/src/com/jme/test/util/TestTimer.java
+++ b/src/com/jme/test/util/TestTimer.java
@@ -60,7 +60,7 @@ import com.jme.util.Timer;
6060 /**
6161 * <code>TestLightState</code>
6262 * @author Mark Powell
63- * @version $Id: TestTimer.java,v 1.4 2003-12-02 20:08:09 mojomonkey Exp $
63+ * @version $Id: TestTimer.java,v 1.5 2003-12-03 16:25:40 mojomonkey Exp $
6464 */
6565 public class TestTimer extends AbstractGame {
6666 private TriMesh t;
@@ -103,10 +103,12 @@ public class TestTimer extends AbstractGame {
103103 angle = 0;
104104 }
105105 }
106+
106107 rotQuat.fromAngleAxis(angle, axis);
107108 timer.update();
108109 input.update(timer.getTimePerFrame());
109110 text.print("Frame Rate: " + timer.getFrameRate());
111+
110112 scene.setLocalRotation(rotQuat);
111113 scene.updateGeometricState(0.0f, true);
112114
@@ -193,8 +195,8 @@ public class TestTimer extends AbstractGame {
193195 scene = new Node();
194196 scene.attachChild(text);
195197
196- Vector3f max = new Vector3f(10,10,10);
197- Vector3f min = new Vector3f(0,0,0);
198+ Vector3f max = new Vector3f(5,5,5);
199+ Vector3f min = new Vector3f(-5,-5,-5);
198200
199201
200202
@@ -202,7 +204,7 @@ public class TestTimer extends AbstractGame {
202204 t.setModelBound(new BoundingSphere());
203205 t.updateModelBound();
204206
205- t.setLocalTranslation(new Vector3f(0,0,-10));
207+ t.setLocalTranslation(new Vector3f(0,0,0));
206208
207209 scene = new Node();
208210 scene.attachChild(t);