【发布时间】:2016-05-15 11:06:40
【问题描述】:
如何围绕中心旋转矩形?我在 ShapeRenderer 中找到了旋转功能:
void rotate(float axisX, float axisY, float axisZ, float angle);
但它围绕 0,0 坐标旋转,我想围绕其中心旋转形状。
【问题讨论】:
如何围绕中心旋转矩形?我在 ShapeRenderer 中找到了旋转功能:
void rotate(float axisX, float axisY, float axisZ, float angle);
但它围绕 0,0 坐标旋转,我想围绕其中心旋转形状。
【问题讨论】:
如果您查看 ShapeRenderer 的 documentation,第二个示例将向您展示如何将框的中心设置在位置 {20,12,2} 并使用平移围绕 z 轴旋转。你需要做同样的事情,例如
this.m_ShapeRenderer.begin(ShapeType.Rectangle);
this.m_ShapeRenderer.setColor(1.f, 1.f, 1.f, 1.f);
this.m_ShapeRenderer.identity();
this.m_ShapeRenderer.translate(20.f, 10.f, 0.f);
this.m_ShapeRenderer.rotate(0.f, 0.f, 1.f, 45.f);
this.m_ShapeRenderer.rect(x, y, 40.f, 20.f);
this.m_ShapeRenderer.end();
希望这会有所帮助。
【讨论】:
使用这个方法(official docs):
public void rect(float x, float y,
float originX, float originY,
float width, float height,
float scaleX, float scaleY,
float degrees)
使用 ShapeRenderer.ShapeType.Line 或 ShapeRenderer.ShapeType.Filled 在 x/y 平面中绘制一个矩形。 x 和 y 指定左下角。 originX 和 originY 指定旋转矩形的点。
像这样使用它: (x和y是矩形中心的点)
renderer.rect(x-width/2, y-height/2,
width/2, height/2,
width, height,
1.0f, 1.0f,
myRotation);
【讨论】: