- jMonkeyEngine 3.0 Beginner’s Guide
- Ruth Kusterer
- 303字
- 2021-08-13 17:02:08
Time for action – rotate it!
Your cubes are at the right location and have the right size. Now you want to turn them to face in a specific direction. In an actual game, for example, you may want to turn characters to face an interesting part of the scene. Again, you can either use absolute or relative rotation.
For every rotation, you have to specify three float values—x
, y
, and z
, one for each axis, around which you want to rotate. In contrast to translation and scale, rotations are not expressed in world units, but in radians. Don't worry—to convert between the familiar 360 degrees to radians, simply multiply the degree value by the built-in FastMath.DEG_TO_RAD
constant, or FastMath.RAD_TO_DEG
to convert it back. You can find this constant in the com.jme3.math.FastMath
package.
As an example, let's rotate the two cubes by 45 degrees around the x and y axes, respectively:
- Convert 45 degrees to radians:
float r = FastMath.DEG_TO_RAD * 45f;
- To rotate
geom2
around the x axis, add the following call at the end of thesimpleInitApp()
method:geom2.rotate(r, 0.0f, 0.0f);
- To rotate
geom
around the y axis, add the following call below:geom.rotate(0.0f, r, 0.0f);
- Clean and build the
BasicGame
template, and right-click on it to run the file.
What just happened?
The yellow cube should be pitched forward around the x axis, facing you with a horizontal edge. The blue cube should have turned around its y axis, facing you with one of its vertical edges. Using the x, y, and z axes for the three directions should look familiar to you by now.

Use the method rotate()
for relative rotation around the three axes.
Absolute rotation in 3D space, however, is a bit more sophisticated. Absolute rotations use a special data type called quaternion.
- Android開發精要
- Vue.js 2 and Bootstrap 4 Web Development
- Xcode 7 Essentials(Second Edition)
- 數據結構簡明教程(第2版)微課版
- Linux環境編程:從應用到內核
- Unity Game Development Scripting
- R Deep Learning Cookbook
- Python語言實用教程
- Spring Boot+Vue全棧開發實戰
- Web性能實戰
- Clojure for Java Developers
- Sails.js Essentials
- 深入實踐DDD:以DSL驅動復雜軟件開發
- Magento 2 Beginners Guide
- PowerDesigner 16 從入門到精通