坐标系和精灵变换
我正在使用 andengine 通过 box2d 创建物理模拟。
物体是通过PhysicsFactory 使用Sprites 创建的。
我的想法是按照以下模式按程序定位这些精灵:
基本上是一个代表我的世界坐标中心的中心精灵,以及一系列通过围绕 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦创建了 Sprite 的物理表示(主体),您应该非常小心修改 Sprite 的方式!通常你根本不再修改 Sprite,而是通过调用
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
Hope that helped :)