Mouse Targeting Method of Controlling the Movement of Objects

I have updated my demonstration of how to use the “Mouse Targeting Method” to control a spacecraft in flight. This method makes flying much simpler than using the traditional method of using a mouse, keys or a joystick to change pitch, bank and yaw.

The main WebGL page is at: Main Page
The demo program is at: SpaceMouse Demo Program
A short discussion is at: Discussion

The code is relatively short, about 50 lines and is annotated. There are occasional stutters in the demo, but I believe these are due to problems in the rotational routines in the AC.rote.js library.

Note that the program uses a few functions and constants which are in the AC.rote.js library, including:
Mod360(degrees) - a function which converts degrees to 0 to 359.
Err360(degrees) - a “kludge” which avoids errors by adding a small amount if the angle is 0, 90, 180 or 270.
PoM360(degrees) - a function which converts degrees to -127 to +127
DegRad - a constant used to convert degrees to radians.
RadDeg - a constant used to convert radians to degrees.

This demo also includes a modified version of PointerLockControls which allows you to move the mouse without bumping into borders.

Also, if you press a mouse button, you can orbit around the object. So this is a somewhat like a combination of the fly and orbit libraries.

This “Mouse Targeting Method” should be easily adaptable to non-flying objects, such as animated people or cars. As always, any suggestions for improvement are greatly appreciated.

Enjoy!
Phil

1 Like