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

Time for action – pick a brick (using the mouse pointer)

Aiming fixed crosshairs is one way to pick objects in the scene. Another option is to make the mouse pointer visible, and allow free clicks.

  1. Make a copy of the previous exercise, TargetPickCenter.java. You can keep the code that handles the mouse click actions and the key press actions for inspiration.
  2. Rename the copy of the class to TargetPickCursor.java. Remember to also refactor the first line of the main() method to the following:
    TargetPickCursor app = new TargetPickCursor();
  3. Keep the myBox() method, the constants, the analogListener object, and the two cubes. Remove the attachCenterMark() method, and the AnalogListener object implementation.
  4. By default, the mouse pointer is hidden. To make it visible, add the following to the simpleInitApp() method:
    flyCam.setDragToRotate(true);
    inputManager.setCursorVisible(true);

Run TargetPickCursor to see the intermediate result.

What just happened?

Again, you see the red cube above the blue cube. When you move the mouse, you notice that the pointer is a visible arrow now. But you also notice something else; earlier, the view rotated when you moved the mouse to the sides. This feature is part of the default camera behavior and is called mouse look, or free look. Mouse look does not get along with a visible mouse pointer. You can use the mouse either for navigating, or for pointing and clicking. Both at the same time is quite confusing for the player.

You deactivated mouse look when you set flyCam.setDragToRotate(true);. To rotate the camera and look around now, keep the left mouse button pressed while moving.

主站蜘蛛池模板: 铜陵市| 望谟县| 承德县| 石楼县| 翁牛特旗| 南昌县| 肥西县| 涡阳县| 南郑县| 曲水县| 夏河县| 珠海市| 双城市| 丘北县| 玉山县| 兴海县| 宁阳县| 兴宁市| 松滋市| 阳原县| 安多县| 个旧市| 苍梧县| 富宁县| 双峰县| 全州县| 麟游县| 万源市| 固阳县| 兴城市| 桓台县| 东乡族自治县| 吴川市| 尼玛县| 广宁县| 新安县| 襄樊市| 刚察县| 仁寿县| 虞城县| 宜丰县|