如何在Box2D中设置形状/夹具/主体的中心 [英] How to set centers of shapes/fixtures/bodies in Box2D

查看:215
本文介绍了如何在Box2D中设置形状/夹具/主体的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hey我试图集成SFML和Box2D,并且SFML已经为sprite,形状等设置中心非常容易。 Box2D,另一方面,我有麻烦,因为我不能弄清楚如何设置或甚至找到形状或夹具的中心。

Hey i'm trying to integrate SFML and Box2D, and SFML has made setting centers for sprites, shapes, etc. very easy. Box2D, on the other hand, I'm having trouble with as i can't figure out how to set or even find the center of a shape or fixture.

它在我看来,当手动添加顶点到b2_PolygonShape中心被设置为顶点数组中的第一个顶点,但使用快捷函数SetAsBox()或任何其他SetAs_ _ 时结果是非常不同的()。中心是形状的中间,或者盒子/形状的一半长度。

It seems to me that when adding vertices manually to a b2_PolygonShape the center is set to the first vertex in the vertex array, but the results are very different when using the shortcut functions SetAsBox() or any other SetAs__(). The Center is the middle of the shape, or half extent(s) of the box/shape.

我需要对box2D和SFML的对中系统进行通用化,但是我无法弄清楚局部坐标系对于对象是如何工作的。

I need to commonize box2D's and SFML's centering system, but i can't figure out how the local coordinate systems work for objects.

如何在Box2D中设置/获取许多对象的中心,例如形状,夹具,主体等?

推荐答案

Ok我意识到SFML和Box2D真的没有什么不同,但我只是不考虑如何在世界坐标中正确地绘制/渲染形状。

Ok I realized that SFML and Box2D really weren't all that different, but i just wasn't thinking about how shapes are made/ rendered correctly in world coordinates.

除非另有说明,否则(0,0)始终用作对象的位置在/绘制时的反射点/中心,并且每个顶点

SFML教程有点混乱,因为它说设置形状/ sprite的中心是偏移从对象的左上角,(0,0)。

the SFML tutorial was a bit confusing as it said setting the center of a shape/sprite was the offset from the top left corner of the object, not (0,0).

这篇关于如何在Box2D中设置形状/夹具/主体的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆