This example shows a simple lunar lander with main thruster controlled by the space bar and trim thrusters controlled by the WASD keys. There seems to currently be a bug that causes some carry-over between successive runs of the application, so to get a clean start, it's best to run it by pressing the "Popup Canvas" button. This example demonstrates encapsulation of a graphical object controlled by physics as a JavaScript object and how to apply forces in a physics-based simulation.
Forces must be specified in world coordinates. For a lander, the thrust forces are most easily specified with respect to the body (lander) frame. Therefore, they must be converted to the world frame by multiplication by a transform, which occurs in the body2world
function.
Note also that in this application, torques are explicitly applied to the lander. It would be worth trying the applyForce(force,relpos)
function to avoid this requirement. Note that while relpos
is the position relative to the origin of the object, it is specified in world coordinates, and so is force
.