如何设置固定shaperenderer旋转libgdx? [英] How can i set fixed shaperenderer rotation in libgdx?
问题描述
我有这样一个三角形;
I have a triangle like this;
shapeRenderer.begin(ShapeType.Line);
shapeRenderer.setColor(1, 1, 0, 1);
shapeRenderer.polygon(new float[] { -10, 0, 10, 0, 0, 200 });
shapeRenderer.rotate(0, 0, 1, 1);
shapeRenderer.end();
和我在旋转,每个渲染1度。但我想修复旋转(例如45),以一个角度。我怎样才能做到这一点?
谢谢你。
and I rotate 1 degree in each render. But I want to fix rotation (e.g. 45) to an angle. How can I do this? Thanks.
推荐答案
要你有甲肝旋转 ShapeRenderer
只有一次固定的旋转。
有2种可能的方式我能想到的:
To have a fixed rotation you hav to rotate the ShapeRenderer
only once.
There are 2 possible ways i can think about:
- 通话
shapeRenderer.rotate(0,0,1,45);
在构造函数或创建()
/显示()
方法
这个调用转动你的ShapeRenderer
45°(最后一个参数)约于Z轴
(第三个参数) - 通话
shapeRenderer.rotate(0,0,1,45);
在rendermethod,只要你还没有旋转。所以,你必须保持一个布尔旋转
且仅当它是假
你叫旋转( )
键,将其设置为真正
。
- call
shapeRenderer.rotate(0, 0, 1, 45);
in the constructor or increate()
/show()
method This call rotates yourShapeRenderer
by 45° (last parameter) arround theZ-Axis
(The 3rd parameter) - call
shapeRenderer.rotate(0, 0, 1, 45);
in the rendermethod, only if you did not rotate yet. So you have to keep aboolean rotated
and only if it isfalse
you callrotate()
and set it totrue
.
要回答您的评论的问题:你不能直接设置旋转,你只能旋转(相对于当前旋转)。所以我建议来存储浮动旋转
,并且每次你旋转你的 ShapeRenderer
设置的新值。要设置旋转度,你必须像旋转:
To answer the question in your comment: You cannot directly set the rotation, you can only rotate (relative to the current rotation). So i would suggest to store a float rotation
, and everytime you rotate your ShapeRenderer
you set the new value. To set a rotation in degrees you have to rotate like:
shapeRenderer.rotate(0, 0, 1, newRotation - rotation);
rotation = newRotation;
这只能如果你总是旋转约于同一轴线上,你的情况 Z轴
。否则你将不得不储存3个旋转(X,Y,Z)。如果您旋转角落找寻一个自定义的轴,通过例如(0.1,0.3,0.6)定义的,你需要计算旋转所有轴。但我真的不知道该怎么做。我想有些Vectormath会做到这一点。但我不认为你需要的。
This works only if you always rotate arround the same axis, in your case the Z-axis
. Else you would have to store 3 rotations (x,y,z). If you rotate arround a custom axis, defined by for example (0.1, 0.3, 0.6) you would need to calculate the rotation for all axes. But i don't really know how to do that. I think some Vectormath would do that. But i don't think you need that.
这篇关于如何设置固定shaperenderer旋转libgdx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!