在质心视口中移动对象

发布于 2024-07-26 07:00:26 字数 912 浏览 4 评论 0原文

我正在对基于力的物理模拟进行建模,其中多个粒子相互作用。 粒子的移动方式使得静态视口很容易失去它们的踪迹(想象一下整组粒子从屏幕向右移动,视口显示空白背景)。

我当前的解决方案是通过查找 x 和 y 的最小值/最大值来简单地跟踪粒子的“中心”,并使视口的中间遵循该中心。 它工作得很好(不需要找到真正的质心)。 这是一个视觉效果:

Viewport

我的问题是我正在尝试添加手动拖动粒子的功能用鼠标左右。 我还没有找到一种优雅的方法来做到这一点。 问题是视口坐标和模拟坐标之间的转换不断变化,因为视口遵循粒子的中心。

当我将鼠标放在粒子上时,我希望它在模拟中具有固定位置(它忽略其上的所有力)。 当我按下按钮移动鼠标时,我希望粒子在模拟中移动。 我已经做到了这一点。 然而,由于视口和其他仍在运动的粒子,它会产生令人不快的副作用。 当鼠标按下并静止时,粒子在模拟中不会移动,但它会在屏幕上移动,因为所有粒子的中心都会发生变化,视口也会相应调整。 光标是静止的,因此粒子从其下方“移”出。 当鼠标稍微移动时,粒子会传送回光标下方,因为光标的新位置代表完全不同的模拟坐标。

对于没有上述副作用的良好、连贯的用户体验有什么建议吗?


我已经想到了:

  • 鼠标按下时暂停模拟 鼠标按下
  • 时暂停视口更改
  • 将鼠标光标移动为视口发生变化(非常糟糕)

,但它们都会产生其他不良副作用或剥夺模拟的价值。

另外,我认为这个问题与语言和平台无关,因此不要将字面意义和特定于实现的含义附加到“视口”、“视口坐标”或“模拟坐标”。 将它们视为通用图形概念。

I'm modeling a force-based physics simulation where several particles are interacting with each other. The particles can move in such a way that a static viewport can easily lose track of them (imagine the whole group of particles moving off the screen to the right and the viewport displaying a blank background).

My current solution is to simply track the "center" of the particles by finding the min/max of the x's and y's and make the viewport's middle follow that. It works fine (no need to find the true center of mass). Here's a visual:

Viewport

My problem is I'm attempting to add the ability to manually drag particles around with the mouse. I haven't found an elegant way to do this. The problem is the translation between viewport coordinates and simulation coordinates is constantly changing because the viewport follows the particles' center.

When I mouse down on a particle I want it to have a fixed location in the simulation (it ignores all forces on it). When I move the mouse with the button depressed I want the particle to move in the simulation. I have achieved this. However, it produces unpleasant side-effects because of the viewport and the other particles that are still in motion. The particle isn't moving in the simulation when the mouse is depressed and stationary but it is moving on screen because the center of all the particles changes and the viewport adjusts accordingly. The cursor is stationary so the particle "moves" out from under it. When the mouse is moved ever-so-slightly, the particle teleports back under the cursor because the cursor's new position represents radically different simulation coordinates.

Any suggestions for a nice, coherent user experience without the above side effects?


I've already thought of:

  • Pausing the simulation while the mouse is down
  • Suspending viewport changes while the mouse is down
  • Moving the mouse cursor as the viewport changes (really bad)

But they all have other bad side-effects or take away value from the simulation.

Also, I think this question is language and platform agnostic so don't attach literal and implementation-specific meanings to "viewport", "viewport coordinates", or "simulation coordinates". Treat them as generic graphics concepts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁把谁当真 2024-08-02 07:00:26

更改调整视口的算法以使用光标的位置作为变换的原点。 这样,光标处的视口和模拟坐标将保持固定。 您可以只在按下鼠标时执行此操作,但如果始终执行此操作,也可能会产生令人满意的结果。

它使数学有些复杂,但似乎你没有太多选择。

Change the algorithm that adjusts the viewport to use the cursor's position as the origin of the transformation. That way the viewport and simulation coordinates at the cursor would remain fixed. You could just do this when the mouse is pressed, but it may also have pleasing results if it were done at all times.

It complicates the maths somewhat, but it doesn't seem like you're left with too many options.

葬心 2024-08-02 07:00:26

我认为没有必要暂停模拟。 正如您所描述的,似乎您的鼠标输入(视图输入)直接更改了模型数据,并且在下次更新/刷新/发出任何内容时,视图也会相应更新。

也许您可以插入一个新的单个粒子,该粒子仅在“动画”期间使用,并且不与任何其他粒子耦合。 在引入这个粒子时,您可以隐藏真实的粒子(及其边缘)。 因此,在移动鼠标时,您只是更新了该动画粒子的数据。 当动画结束时(松开鼠标),动画对象将被删除,真实粒子将使用其数据进行更新并再次显示。

在某种程度上,这是一种暂停形式,因为您欺骗了更新系统。 粒子系统的数据在动画过程中不会更新,它看起来就像你在移动真实系统的粒子,而实际上你只是在图形上欺骗用户。 希望这有道理,凌晨 2 点在这里:)

I don't think there's a need to pause the simulation. As you are describing it, it seems that your mouse input (view input) directly changes the model data and the view is updated accordingly when next update/flush/whatever is issued.

Perhaps you could insert a new single particle that's only used during "animation", and that's not coupled to any of the other particles. While introducing this particle, you could hide the real particle (and it's edges). So while moving the mouse you are only updating the data of this animated particle. When the animation ends (you let the mouse go), the animated object is deleted, the real particle is updated with its data and shown again.

In one way this is a form of pause, since you are cheating the updating system. The data of the particle system is not updated during animation, it just looks like you are moving the particle of the real system, when you're in fact just cheating the user graphically. Hope this makes some sense, 2 am here :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文