【发布时间】:2015-05-04 17:39:36
【问题描述】:
我正在开发一款你是宇宙飞船的游戏。这艘宇宙飞船必须能够旋转。矩形有两个数组x[],y[],包含矩形的所有角位置。但是当我应用旋转公式时,我得到了一个相当奇怪的旋转。为了解释它,它看起来像是在旋转屏幕的左下角。
为了制作这些角阵列,我采用 x 位置、y 位置、宽度和高度。
角阵列的制作
public Vertex2f(float x, float y, float w, float h){
this.x[0] = x;
this.y[0] = y;
this.x[1] = x+w;
this.y[1] = y;
this.x[2] = x+w;
this.y[2] = y+h;
this.x[3] = x;
this.y[3] = y+h;
}
我的旋转功能
public void rotate(float angle){
this.rotation = angle;
double cos = Math.cos(rotation);
double sin = Math.sin(rotation);
for(int i = 0; i < x.length; i++){
x[i] = (float)(cos * x[i] - sin * y[i]);
y[i] = (float)(sin * x[i] + cos * y[i]);
}
}
如果它有助于我在 java 中使用 LWJGL/OpenGL 来处理所有图形,并使用 Slick2d 加载和初始化我正在使用的精灵。
【问题讨论】: