Main repository of MikuMikuStudio
Revisión | e32e3638635ea65be4c4dca7e5d0cfabbde4e226 (tree) |
---|---|
Tiempo | 2003-12-04 01:25:40 |
Autor | mojomonkey <mojomonkey@75d0...> |
Commiter | mojomonkey |
Fix rotational issues.
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@161 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -41,7 +41,7 @@ package com.jme.math; | ||
41 | 41 | * {x y z w}. |
42 | 42 | * |
43 | 43 | * @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 $ | |
45 | 45 | */ |
46 | 46 | public class Quaternion { |
47 | 47 | public float x, y, z, w; |
@@ -225,21 +225,33 @@ public class Quaternion { | ||
225 | 225 | * @return the rotation matrix representation of this quaternion. |
226 | 226 | */ |
227 | 227 | 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 | + | |
229 | 242 | 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); | |
233 | 253 | |
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); | |
243 | 255 | |
244 | 256 | return matrix; |
245 | 257 |
@@ -248,16 +260,17 @@ public class Quaternion { | ||
248 | 260 | /** |
249 | 261 | * <code>fromAngleAxis</code> sets this quaternion to the values |
250 | 262 | * 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). | |
252 | 264 | * @param axis the axis of rotation. |
253 | 265 | */ |
254 | 266 | public void fromAngleAxis(float angle, Vector3f axis) { |
267 | + Vector3f normAxis = axis.normalize(); | |
255 | 268 | float halfAngle = 0.5f * angle; |
256 | 269 | float sin = (float) Math.sin(halfAngle); |
257 | 270 | 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; | |
261 | 274 | } |
262 | 275 | |
263 | 276 | /** |
@@ -443,4 +456,8 @@ public class Quaternion { | ||
443 | 456 | z *= -1; |
444 | 457 | w *= -1; |
445 | 458 | } |
459 | + | |
460 | + public String toString() { | |
461 | + return "com.jme.math.Quaternion: [x=" +x+" y="+y+" z="+z+" w="+w+"]"; | |
462 | + } | |
446 | 463 | } |
@@ -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 | +} |
@@ -60,7 +60,7 @@ import com.jme.util.Timer; | ||
60 | 60 | /** |
61 | 61 | * <code>TestLightState</code> |
62 | 62 | * @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 $ | |
64 | 64 | */ |
65 | 65 | public class TestTimer extends AbstractGame { |
66 | 66 | private TriMesh t; |
@@ -103,10 +103,12 @@ public class TestTimer extends AbstractGame { | ||
103 | 103 | angle = 0; |
104 | 104 | } |
105 | 105 | } |
106 | + | |
106 | 107 | rotQuat.fromAngleAxis(angle, axis); |
107 | 108 | timer.update(); |
108 | 109 | input.update(timer.getTimePerFrame()); |
109 | 110 | text.print("Frame Rate: " + timer.getFrameRate()); |
111 | + | |
110 | 112 | scene.setLocalRotation(rotQuat); |
111 | 113 | scene.updateGeometricState(0.0f, true); |
112 | 114 |
@@ -193,8 +195,8 @@ public class TestTimer extends AbstractGame { | ||
193 | 195 | scene = new Node(); |
194 | 196 | scene.attachChild(text); |
195 | 197 | |
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); | |
198 | 200 | |
199 | 201 | |
200 | 202 |
@@ -202,7 +204,7 @@ public class TestTimer extends AbstractGame { | ||
202 | 204 | t.setModelBound(new BoundingSphere()); |
203 | 205 | t.updateModelBound(); |
204 | 206 | |
205 | - t.setLocalTranslation(new Vector3f(0,0,-10)); | |
207 | + t.setLocalTranslation(new Vector3f(0,0,0)); | |
206 | 208 | |
207 | 209 | scene = new Node(); |
208 | 210 | scene.attachChild(t); |