Moving objects in the center of mass viewing

I am modeling a physical force simulation where several particles interact with each other. Particles can move in such a way that the static viewport can easily lose them (imagine that the entire group of particles moves from the screen to the right, and the viewport displays an empty background).

My current solution is to simply track the "center" of the particles by finding min / max for x and y and making the middle viewport. It works great (no need to look for a true center of mass). Here visually:

Viewport

My problem is that I am trying to add the ability to manually move particles with the mouse. I did not find an elegant way to do this. The problem is that the translation between the coordinates of the viewport and the coordinates of the simulation is constantly changing, because the viewing window follows the center of the particles.

When I click on a particle, I want it to have a fixed location in the simulation (it ignores all the forces on it). When I move the mouse with the button pressed, I want the particle to move in the simulation. I have achieved this. However, it causes unpleasant side effects due to the viewport and other particles that are still in motion. A particle does not move in the simulation when the mouse is pressed and motionless, but it moves on the screen because the center of all particles changes and the viewport is adjusted accordingly. The cursor is stationary, so the particle "moves" from under it. When the mouse moves so little, the particle teleports back under the cursor, because the new cursor position represents radically different modeling coordinates.

, ?


:

  • , .
  • ( )

.

, , , "viewport", " " " ". .

+3
2

, , . , . , , , .

, , .

+1

, . , , ( ) , // , .

, , "", . , ( ). , , . ( ), , .

, . , , , . , , 2 :)

+1

Source: https://habr.com/ru/post/1711837/


All Articles