Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java libgdx shaperender如何围绕其中心旋转矩形?_Java_Libgdx - Fatal编程技术网

Java libgdx shaperender如何围绕其中心旋转矩形?

Java libgdx shaperender如何围绕其中心旋转矩形?,java,libgdx,Java,Libgdx,如何围绕其中心旋转矩形?我在ShaperEnder中找到了旋转函数: void rotate(float axisX, float axisY, float axisZ, float angle); 但是它是围绕0,0坐标旋转的,我希望形状围绕其中心旋转。如果您查看for shapenderer,第二个示例将演示如何将长方体的中心设置在位置{20,12,2}处,并使用translate围绕z轴旋转。你需要做同样的事情 this.m_ShapeRenderer.begin(ShapeType.R

如何围绕其中心旋转矩形?我在ShaperEnder中找到了旋转函数:

void rotate(float axisX, float axisY, float axisZ, float angle);
但是它是围绕0,0坐标旋转的,我希望形状围绕其中心旋转。

如果您查看for shapenderer,第二个示例将演示如何将长方体的中心设置在位置{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();
希望这有帮助。

使用此方法():

使用ShaperEnder.ShapeType.Line或ShaperEnder.ShapeType.Filled在x/y平面中绘制矩形。x和y指定左下角。“原点”和“原点”指定要围绕其旋转矩形的点

像这样使用它: (x和y是矩形中心的点)


这很有效。只要确保originX和originY是相对于矩形左下角的,而不是相对于世界空间…正如我最终发现的那样…它对我不起作用。如果我不平移,我的矩形将显示,但会快速闪烁。如果我平移它,矩形将不再可见?你知道解决办法吗?
public void rect(float x, float y,
                 float originX, float originY,
                 float width, float height,
                 float scaleX, float scaleY,
                 float degrees)
renderer.rect(x-width/2, y-height/2, 
              width/2, height/2, 
              width, height, 
              1.0f, 1.0f, 
              myRotation);