如何围绕矩形中心旋转矩形?我在ShapeRenderer中找到了旋转函数:
void rotate(float axisX, float axisY, float axisZ, float angle);
但是它围绕0,0坐标旋转,我想要围绕它的中心旋转形状。
发布于 2013-01-01 08:03:46
如果您查看ShapeRenderer的documentation,第二个示例将向您展示如何将长方体的中心设置在{20,12,2}位置并使用translate绕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();
希望这能有所帮助。
发布于 2015-11-26 04:02:20
使用此方法(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);
https://stackoverflow.com/questions/14091734
复制相似问题