• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
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

修订版43740aa7143d09fb7e81aba0b7a19f18aae0bf8a (tree)
时间2003-12-03 05:08:09
作者mojomonkey <mojomonkey@75d0...>
Commitermojomonkey

Log Message

added quaternion to matrix code.
Allow spatial to be rotated via quaternions.

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

更改概述

差异

--- 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.1 2003-11-24 15:07:44 mojomonkey Exp $
44+ * @version $Id: Quaternion.java,v 1.2 2003-12-02 20:08:09 mojomonkey Exp $
4545 */
4646 public class Quaternion {
4747 public float x, y, z, w;
@@ -217,6 +217,33 @@ public class Quaternion {
217217 }
218218
219219 }
220+
221+ /**
222+ *
223+ * <code>toRotationMatrix</code> converts this quaternion to a rotational
224+ * matrix.
225+ * @return the rotation matrix representation of this quaternion.
226+ */
227+ public Matrix3f toRotationMatrix( ) {
228+
229+ 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)));
233+
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)));
243+
244+ return matrix;
245+
246+ }
220247
221248 /**
222249 * <code>fromAngleAxis</code> sets this quaternion to the values
--- a/src/com/jme/renderer/LWJGLRenderer.java
+++ b/src/com/jme/renderer/LWJGLRenderer.java
@@ -74,7 +74,7 @@ import com.jme.util.LoggingSystem;
7474 * <code>Renderer</code> interface using the LWJGL API.
7575 * @see com.jme.renderer.Renderer
7676 * @author Mark Powell
77- * @version $Id: LWJGLRenderer.java,v 1.6 2003-12-01 13:18:58 mojomonkey Exp $
77+ * @version $Id: LWJGLRenderer.java,v 1.7 2003-12-02 20:08:09 mojomonkey Exp $
7878 */
7979 public class LWJGLRenderer implements Renderer {
8080 //clear color
@@ -689,6 +689,7 @@ public class LWJGLRenderer implements Renderer {
689689 Matrix3f rotation = t.getWorldRotation();
690690 Vector3f translation = t.getWorldTranslation();
691691 float scale = t.getWorldScale();
692+
692693 float[] modelToWorld =
693694 {
694695 scale * rotation.get(0, 0),
--- a/src/com/jme/scene/Spatial.java
+++ b/src/com/jme/scene/Spatial.java
@@ -34,6 +34,7 @@ package com.jme.scene;
3434 import java.io.Serializable;
3535
3636 import com.jme.math.Matrix3f;
37+import com.jme.math.Quaternion;
3738 import com.jme.math.Vector3f;
3839 import com.jme.renderer.Camera;
3940 import com.jme.renderer.Renderer;
@@ -45,7 +46,7 @@ import com.jme.scene.state.RenderState;
4546 * transforms. All other nodes, such as <code>Node</code> and
4647 * <code>Geometry</code> are subclasses of <code>Spatial</code>.
4748 * @author Mark Powell
48- * @version $Id: Spatial.java,v 1.4 2003-10-23 21:24:18 mojomonkey Exp $
49+ * @version $Id: Spatial.java,v 1.5 2003-12-02 20:08:09 mojomonkey Exp $
4950 */
5051 public abstract class Spatial implements Serializable {
5152 //rotation matrices
@@ -308,6 +309,16 @@ public abstract class Spatial implements Serializable {
308309 public void setLocalRotation(Matrix3f localRotation) {
309310 this.localRotation = localRotation;
310311 }
312+
313+ /**
314+ *
315+ * <code>setLocalRotation</code> sets the local rotation of this node, using
316+ * a quaterion to build the matrix.
317+ * @param quaternion the quaternion that defines the matrix.
318+ */
319+ public void setLocalRotation(Quaternion quaternion) {
320+ this.localRotation = quaternion.toRotationMatrix();
321+ }
311322
312323 /**
313324 * <code>getLocalScale</code> retrieves the local scale of this node.
--- a/src/com/jme/test/util/TestTimer.java
+++ b/src/com/jme/test/util/TestTimer.java
@@ -37,6 +37,7 @@ import com.jme.input.FirstPersonController;
3737 import com.jme.input.InputController;
3838 import com.jme.light.DirectionalLight;
3939 import com.jme.light.SpotLight;
40+import com.jme.math.Quaternion;
4041 import com.jme.math.Vector3f;
4142 import com.jme.renderer.Camera;
4243 import com.jme.renderer.ColorRGBA;
@@ -59,7 +60,7 @@ import com.jme.util.Timer;
5960 /**
6061 * <code>TestLightState</code>
6162 * @author Mark Powell
62- * @version $Id: TestTimer.java,v 1.3 2003-12-01 13:18:58 mojomonkey Exp $
63+ * @version $Id: TestTimer.java,v 1.4 2003-12-02 20:08:09 mojomonkey Exp $
6364 */
6465 public class TestTimer extends AbstractGame {
6566 private TriMesh t;
@@ -70,6 +71,9 @@ public class TestTimer extends AbstractGame {
7071 private InputController input;
7172 private Thread thread;
7273 private Timer timer;
74+ private Quaternion rotQuat;
75+ private float angle = 0;
76+ private Vector3f axis;
7377
7478 /**
7579 * Entry point for the test,
@@ -93,9 +97,18 @@ public class TestTimer extends AbstractGame {
9397 * @see com.jme.app.AbstractGame#update()
9498 */
9599 protected void update() {
100+ if(timer.getTimePerFrame() < 1) {
101+ angle = angle + (timer.getTimePerFrame() * 1);
102+ if(angle > 360) {
103+ angle = 0;
104+ }
105+ }
106+ rotQuat.fromAngleAxis(angle, axis);
96107 timer.update();
97108 input.update(timer.getTimePerFrame());
98109 text.print("Frame Rate: " + timer.getFrameRate());
110+ scene.setLocalRotation(rotQuat);
111+ scene.updateGeometricState(0.0f, true);
99112
100113
101114 }
@@ -136,7 +149,7 @@ public class TestTimer extends AbstractGame {
136149 ColorRGBA blackColor = new ColorRGBA(0, 0, 0, 1);
137150 display.getRenderer().setBackgroundColor(blackColor);
138151 cam.setFrustum(1.0f, 1000.0f, -0.55f, 0.55f, 0.4125f, -0.4125f);
139- Vector3f loc = new Vector3f(0.0f, 0.0f, 4.0f);
152+ Vector3f loc = new Vector3f(0.0f, 0.0f, 75.0f);
140153 Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
141154 Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
142155 Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
@@ -149,6 +162,8 @@ public class TestTimer extends AbstractGame {
149162 timer = Timer.getTimer("LWJGL");
150163
151164 display.getRenderer().setCullingMode(Renderer.CULL_BACK);
165+ rotQuat = new Quaternion();
166+ axis = new Vector3f(1,1,1);
152167
153168 }
154169