坐标系和精灵变换

发布于 2024-11-03 08:14:20 字数 780 浏览 5 评论 0原文

我正在使用 andengine 通过 box2d 创建物理模拟。

物体是通过PhysicsFactory 使用Sprites 创建的。

我的想法是按照以下模式按程序定位这些精灵: rotation around externalPoint

基本上是一个代表我的世界坐标中心的中心精灵,以及一系列通过围绕 myWorld 中心(圆圈内的“X”)旋转基础精灵而创建的克隆精灵。

我尝试在 andengine 中使用 opengl 方式(平移、旋转、反向平移),

super(stamiRadious, 0, image);     //stamiDoadious is te distance from radix (world center) and "petal" attach point
this.setRotationCenter(0, 0);
this.setRotation((float) Math.toDegrees(angleRad));
this.setPosition(this.getX()+radixX, this.getY()+radixY);

但我失败了:结果不正确(最终位置错误,以及错误的 box2d 主体属性,就好像精灵比图像大得多)

我相信部分问题依赖于我对 setRotation 和 setRotationCenter 的解释,并且总体上依赖于我对 andengine 坐标系 + box2d 坐标系的理解。

有任何想法/链接到文档/解释吗?

I'm using andengine to create a physic simulation via box2d.

The bodies are created through PhysicsFactory using Sprites.

My idea is to procedurally position these sprites, following this pattern:rotation around externalPoint

basically one central sprites which represent my world coordinates center, and a series of cloned sprites that are created by rotating the base sprite around myWorld center (the "X" inside the circle).

I've tried to use opengl way inside andengine (translate, rotate, back-translate)

super(stamiRadious, 0, image);     //stamiDoadious is te distance from radix (world center) and "petal" attach point
this.setRotationCenter(0, 0);
this.setRotation((float) Math.toDegrees(angleRad));
this.setPosition(this.getX()+radixX, this.getY()+radixY);

but i failed: results are not right (wrong final position, and wrong box2d body property as if the sprite is much larger than the image)

I belive part of the problem relies on my interpretation on setRotation and setRotationCenter, and in general on my understanding of andengine coordinates system + box2d cordinates system.

Any thoughts/links to doc/explanation?

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

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

发布评论

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

评论(1

梦年海沫深 2024-11-10 08:14:20

一旦创建了 Sprite 的物理表示(主体),您应该非常小心修改 Sprite 的方式!通常你根本不再修改 Sprite,而是通过调用

someBody.setTransform(); // Note that positions must be divided by PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT!

Hope 来修改 Body,这会有所帮助:)

Once you created a Physics representation (Body) of a Sprite, you should be very careful on how you modify the Sprite! Usually you don't modify the Sprite anymore at all, but instead modify the Body, by calling

someBody.setTransform(); // Note that positions must be divided by PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT!

Hope that helped :)

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