- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在我的游戏中实现重力。我目前有一个应该绕行星运行的月亮(在我的游戏中都使用 Cell 类)。
使用以下代码(缩短):
在单元格类中:
private Cell graviator;
private Vector2 pos;
private Vector2 vel;
private Vector2 drg;
private int mass;
private float drgSpeed;
private GravityField grav=new GravityField(this);
public void move(){
calculateDrag();
if(orbiting){
orbit();
}
pos.add(vel);
pos.add(drg);
}
private void calculateDrag() {
drg.scl(drgSpeed);
}
private void orbit(){
Vector2 temp=new Vector2(drg.x,drg.y);
temp.rotate90(0);
temp.nor();
speed=(float)Math.sqrt((mass+graviator.getMass())/getGraviatorDistance()); // v= sqrt((M*m)/r)
temp.scl(speed);
vel=temp;
}
在重力场类中:
private Cell cell;
public void computeGravity(Cell cell2) {
float force = getForce(cell2);
if (cell != cell2.getGraviator()) {
if (cell2.getMass() < cell.getMass()) {
if (force > cell2.getLargestForce()) {
cell2.setGraviator(cell);
cell2.setLargestForce(force);
cell2.setDrg(getDragVector(cell2));
cell2.setDrgAcc(getAcceleration(cell2));
}
}
} else {
cell2.setLargestForce(force);
cell2.setDrg(getDragVector(cell2));
cell2.setDrgAcc(getAcceleration(cell2));
}
}
public Vector2 getDragVector(Cell cell2) {
Vector2 temp = new Vector2(cell.getPos().x - cell2.getPos().x, cell.getPos().y - cell2.getPos().y);
temp.nor();
return temp;
}
public Vector2 getDirection(Cell cell2) {
return new Vector2(cell.getPos().x - cell2.getPos().x, cell.getPos().y - cell2.getPos().y);
}
public float getDistance(Vector2 direction) {
return direction.len();
}
public float getForce(Cell cell2) {
Vector2 temp = new Vector2(cell.getPos().x - cell2.getPos().x, cell.getPos().y - cell2.getPos().y);
return cell.getMass() * cell2.getMass() / (temp.len() * temp.len()); //f = M*m/r^2
}
public float getAcceleration(Cell cell2) {
Vector2 temp = new Vector2(cell.getPos().x - cell2.getPos().x, cell.getPos().y - cell2.getPos().y);
float force = cell.getMass() * cell2.getMass() / (temp.len() * temp.len());
float acceleration = force / cell2.getMass(); // a= f/m
return acceleration;
}
因此,通过我的 GravityField,我基本上将一个 DragVector 应用于拉动的 Cell。
在 Cell 中,Cell 朝重力器移动
pos.add(drg);
并朝着它自己的运动 vector 速度
pos.add(vel);
在我的 Orbit() 方法中,我试图找到并设置 vel 来形成圆形轨道。
我的问题是我无法实现完美的轨道。月球仍然稍微靠近地球,并且随着距离的缩短,它越来越加速地接近地球。
我不明白为什么它不起作用。我使用了正确的公式吗?
写出我使用的:
v= sqrt((M*m)/r)
表示我的 OrbitVector 速度f = M*m/r^2
用于拉向行星的力a= f/m
表示朝向行星的加速度
感谢您的帮助!
最佳答案
这非常简单。您需要 2 个纹理:轨道和月亮。你所要做的就是继续让月球在轨道上旋转。
如果您使用 sprite ,您可以这样做:
sprite.setRotation(rotationVaue);
rotationValue+=1;
但是这里需要注意的一个非常重要的事情是两个图像应该具有相同的分辨率。
我最近做了同样的事情,我什至在 stackoverflow 上问了一个关于它的问题,这里是链接:
关于java - 在 libgdx 中创建圆形轨道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43785527/
我想使用 Orbited 进行聊天。我还找到了 Orbited2。有什么不同? Orbited 死了没有?我想用solid solution,不用担心会被关闭或不支持。我还没有找到任何关于 Orbit
我最近开始学习SFML,我有一个问题,如何使第二个物体在轨道上运动,请帮助。 #include using namespace sf; int main() { RenderWindow wi
我正在尝试使用 Tweepy 获取所有带有关键字的推文,但它没有返回某些关键字的任何内容。例如,如果使用 Obama 作为关键字,我会收到很多推文,如果我使用 Arduino,我不会收到任何返回信息,
在我看来,我有一个复选框和一个标签。我正在使用 SLIM,所以代码是 = check_box_tag 'All Products' = label_tag 'All Products' 生成的等效 H
正如倾斜所暗示的那样,我试图弄清楚如何嵌入 soundcloud 文件,以及如何轻松更改嵌入的声音.. 我有一个网站,目前,让用户写一个故事,然后附加一个图像或视频。对于视频,我使用 vimeo 和
我创建了一个在应用程序的实际背景上绘制的 slider 轨道,并且还绘制了 UISlider 拇指图像。我知道如何设置 slider 的缩略图。但如何隐藏 UISlider 轨道呢? 最佳答案 如果你
从 HTTP 链接下载的 Windows Media DRM 轨道是否可以合法渐进播放? 我已经设法在没有 DRM 的情况下做到了这一点,但这里有人告诉我,使用 DRM 是不可能的。这是真的? 如果是
我有一个简单的 vtt 轨道文件编辑器,其中构建的 vtt 文件内容保存在 var vtt 中. 目前我通过保存vtt的内容来添加轨道。到文件,然后将文件读取为 我想省略保存到文件的步骤,直接将变量
我有一个简单的应用程序,用户可以在其中的文本字段中输入内容以获得各种结果。我想要一个功能,如果用户输入某些内容然后关闭浏览器选项卡,下次他们来时,我可以向他们展示他们之前/最近的搜索。即使他们关闭整个
我试图在不同的线程中同时运行 4 个 MP3 轨道。我正在使用 JLayer1.0 MP3 library播放 MP3。鉴于我无法控制线程何时启动,我使用 CountDownLatch 至少让它们同时
我可以在我的 Android 应用程序中播放来自 SoundCloud 的轨道吗?我正在尝试这段代码,但它不起作用: String res = "https://api.soundcloud.com/
我正在使用 Apple Music API 的 recent played endpoint返回最近播放的媒体 Assets 列表。 然后我使用其中之一并在 MPMusicPlayerControll
我正在使用 Foundation Orbit slider 。它工作正常,只是我需要将一些 css(移动标题)应用于页面上的特定 slider 。 如果我使用以下选择器,它会进行更改,唯一的问题是它是
我最难搞清楚如何在 Foundation 的 Orbit slider 中制作两个文本元素和一个按钮。对于这样的初学者问题,我深表歉意,但我是 Foundation 的新手,有些语法让我感到困惑。 这
我需要来自 SoundCloud 的“最流行”或“ HitTest 门的轨道”,但我找不到任何方法来做到这一点。我可以从 http://api.soundcloud.com/tracks?filter
我刚刚从 Rails 3.2 切换到 Rails 4。我正在努力确保我尽可能了解安全问题,并且我现在担心 session 。看起来 Rails 4 已经不再支持除基于 cookie 的 session
我正在开发一个应用程序,用户可以在其中流式传输或下载视频。我使用 ExoPlayer 2.9.6 实现了相同的功能。目前,在播放下载的内容时,当我尝试切换质量时,它仅显示下载的轨道。我知道它的默认行为
有谁知道制作这样的标题的最佳方法 http://i.imgur.com/NOSF0.png ?我试过使用 Firebug 并实现了这个 http://i.imgur.com/cMB3Y.png但是当我
我正在使用 Zurb 轨道 slider :http://www.zurb.com/playground/jquery_image_slider_plugin 我使用以下设置进行幻灯片放映: $(wi
所以我们在这里:http://greeceinsiders.com/VLASIOS/offcanvas/studio.html 我按照说明在页面中放置轨道 slider ,但这个似乎不起作用。我从其他
我是一名优秀的程序员,十分优秀!