three.js - 如何使用 Cannon.js 制作吸引点
问题描述
我正在使用 Three.js 和 Cannon.js。
另外,我正在尝试复制这个对象(多球那个)。基本上,球从其原点移动到压力点并停止,或围绕压力点旋转(这称为质量弹簧)。
目前我可以通过速度设置球的方向,但球不会停在压力点,距离越远,速度就越高(我需要恒定的速度)。
我在 Github 上问过这个问题,有人告诉我看看这个例子。唯一的问题是它只围绕我正在寻找如何将球移动到听起来不一样的某个点的行星旋转。任何帮助是极大的赞赏
解决方案
也许你需要一个像这样的物理模型:
friction model
m = 2 (it could be also m = 1 or m = 3 or whatever looks good)
coefficients:
cf = coefficient of friction
cs = coefficient of spring
Dynamics / update of position and velocity with time-increment dt
x_cursor = x coordinate of cursor's position
y_cursor = y coordinate of cursor's position
x = x + dt * v_x
y = y + dt * v_y
v_norm = sqrt(v_x^2 + v_y^2)^(m-1)
v_x = v_x - dt * cf * v_norm * v_x - dt * cs * ( x - x_cursor )
v_y = v_y - dt * cf * v_norm * v_y - dt * cs * ( y - y_cursor )
推荐阅读
- spring-boot - 删除错误请求响应的附加详细信息
- javascript - react native中的androidsurfaceview原生ui组件渲染问题
- go - 为什么我在 go.mod 中指定了旧的 go 版本,却可以使用新版本的 go 的 API?
- google-apps-script - 如何在 Google Apps Script 中添加抄送、定制发件人姓名和获取主题行数据?
- python - 为什么它只打印二维列表中的 4 个值?
- javascript - 未调用时正在执行的函数
- javascript - ReactJS React-DnD 连接现有的 dom 元素作为源
- pytorch - 是否可以按以下方式保持权重?
- r - 用大小不等的子组解释相对频率直方图
- c# - 尝试在每个数据库上下文上创建我的数据库时出错