Bizorke / Gear3Engine-Issues

For bugs and features.
1 stars 0 forks source link

Compute world position of mouse - plugins. #1313

Closed JSideris closed 2 years ago

JSideris commented 2 years ago

This use to be "trivial" but now with plugins it's more complicated.

Mouse move events are received by the InputPlugin. But mouse world position is needed by the UserController within the ClientPlugin.

But the mapping of screen-space to physical space is not trivial. Mouse world position depends on the position of the camera, which is defined in Canvas2dPlugin, or Canvas2dPlugin, and generally follows a physical object which is defined in Physics2dPlugin or Physics3dPlugin.

Suggesiton:

  1. Capture mouse event in InputPlugin.
  2. Raise an event in the GameInstance for mouse move.
  3. Receive that event in the Canvas2dPlugin and Canvas3dPlugin.
  4. Pass the mouse screen position into the camera, and let it compute the world position (in meters). Different cameras will have different methods of doing that. a. 2D camera can use pxToM in Util. b. 3D cameras can use a ray cast to determine what's being pointed at.
  5. World position of the mouse can be assigned to UserController.

This can also be used to trigger mouse-over events on objects. That should probably be a separate ticket, and may or may not involve consulting the physics engine.