官术网_书友最值得收藏!

Time for action – navigating the scene

Let's look at things from a different perspective:

  1. Run the BasicGame template once more.
  2. Press the W, A, S, and D keys to move forward, left, backwards, and right. Move the mouse to turn around. This navigates your camera away from the default location.
  3. Press the C key while the application is running to print the current camera location and rotation to the console.

In your Java code, you can access the current camera location, which is also the location of the player in a first-person game, using getters on the cam object:

Vector3f   loc = cam.getLocation();
Quaternion rot = cam.getRotation();

If you want the camera to start out at a different location in the scene, position it using the following:

cam.setLocation(x,y,z);
cam.setRotation(q);

The default navigational keys in the included samples are optimized for QWERTY keyboards. Every game has its unique navigation that you will have to define yourself, including a way to let your users with a non-QWERTY keyboard customize the keys.

Note that cam.setRotation(q) is one of the rotation methods that accepts the Quaternion data type, which we just learned about, as an argument.

Pop quiz ? spinning around

Q2. How far does geom.rotate(0.0f, 2.1f, 0.0f); rotate the geometry around the y axis?

  1. 2.1 times = 2.1 * 360° = 756° = 36°
  2. 2.1 degrees
  3. 2.1 radians = 120°
  4. 2.1 world units
主站蜘蛛池模板: 武乡县| 娄底市| 阳朔县| 卫辉市| 乐山市| 中超| 大城县| 永新县| 山东省| 霍城县| 尉犁县| 玛多县| 东城区| 上思县| 马关县| 静安区| 浦县| 无为县| 光泽县| 宜章县| 进贤县| 巫山县| 乡城县| 广水市| 高雄县| 阿图什市| 天镇县| 都匀市| 交口县| 渝北区| 文安县| 凤台县| 惠来县| 赤水市| 灯塔市| 奉新县| 屯留县| 彭水| 崇义县| 双柏县| 朝阳区|