1
我已經使用OpenGL創建了一個立方體,但此刻它有自由旋轉,因此它可以向任何方向旋轉。OpenGL Cube Rotation
我該如何編碼它,因此它只能向上,向下,向左和向右旋轉?
這裏是我的我的轉碼:
+ (void)applyRotation:(GLfloat *)m x:(GLfloat)x y:(GLfloat)y z:(GLfloat)z {
GLfloat tempMatrix[16];
if(x != 0) {
GLfloat c = cosf(x);
GLfloat s = sinf(x);
[self applyIdentity:tempMatrix];
tempMatrix[5] = c;
tempMatrix[6] = -s;
tempMatrix[9] = s;
tempMatrix[10] = c;
[self multiplyMatrix:tempMatrix by:m giving:m];
}
if(y != 0) {
GLfloat c = cosf(y);
GLfloat s = sinf(y);
[self applyIdentity:tempMatrix];
tempMatrix[0] = c;
tempMatrix[2] = s;
tempMatrix[8] = -s;
tempMatrix[10] = c;
[self multiplyMatrix:tempMatrix by:m giving:m];
}
if(z != 0) {
GLfloat c = cosf(z);
GLfloat s = sinf(z);
[self applyIdentity:tempMatrix];
tempMatrix[0] = c;
tempMatrix[1] = -s;
tempMatrix[4] = s;
tempMatrix[5] = c;
[self multiplyMatrix:tempMatrix by:m giving:m];
}
}
死亡的三角代碼牆!儘管如此,請儘量簡化您的問題,因爲在當前狀態下很難理解。 –
我要的只是立方體只能在四個方向旋轉;向上,向下,向左,向右 –
你的意思是每個旋轉周圍的軸應該只有90 * n度? –