如何设置固定shaperenderer旋转libgdx? [英] How can i set fixed shaperenderer rotation in libgdx?

查看:180
本文介绍了如何设置固定shaperenderer旋转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:


  1. 通话 shapeRenderer.rotate(0,0,1,45); 在构造函数或创建() / 显示()方法
    这个调用转动你的 ShapeRenderer 45°(最后一个参数)约于 Z轴(第三个参数)

  2. 通话 shapeRenderer.rotate(0,0,1,45); 在rendermethod,只要你还没有旋转。所以,你必须保持一个布尔旋转且仅当它是你叫旋转( )键,将其设置为真正

  1. call shapeRenderer.rotate(0, 0, 1, 45); in the constructor or in create() / show() method This call rotates your ShapeRenderer by 45° (last parameter) arround the Z-Axis (The 3rd parameter)
  2. call shapeRenderer.rotate(0, 0, 1, 45); in the rendermethod, only if you did not rotate yet. So you have to keep a boolean rotated and only if it is false you call rotate() and set it to true.

要回答您的评论的问题:你不能直接设置旋转,你只能旋转(相对于当前旋转)。所以我建议来存储浮动旋转,并且每次你旋转你的 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屋!

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