Java 如何在不使用glRotateF内置函数的情况下围绕JOGL中的Z轴旋转图像

Java 如何在不使用glRotateF内置函数的情况下围绕JOGL中的Z轴旋转图像,java,opengl,jogl,Java,Opengl,Jogl,如果不使用glRotatef函数,如何在JOGL中围绕Z轴旋转图像?我不知道如何获取z',因为没有e.getZ()函数。如何计算z_素数?现在,当我试着绕z轴旋转时,它就像是绕着Begging中的z轴旋转,然后开始绕y轴旋转,然后回到z轴(这很有意义,因为我有z_rot+=y_prime。我怎么能只绕z旋转它,然后计算出z' public void transform(float[] vertices_in, float[] vertices_out){

如果不使用
glRotatef
函数,如何在JOGL中围绕Z轴旋转图像?我不知道如何获取z',因为没有
e.getZ()
函数。如何计算z_素数?现在,当我试着绕z轴旋转时,它就像是绕着Begging中的z轴旋转,然后开始绕y轴旋转,然后回到z轴(这很有意义,因为我有
z_rot+=y_prime
。我怎么能只绕z旋转它,然后计算出z'

        public void transform(float[] vertices_in, float[] vertices_out){

            // perform your transformation

            int length = vertices_in.length;
            float[] transformMatrix = 
                {
                   r11, r12, r13, tx,
                   r21, r22, r23, ty,
                   r31, r32, r33, tz,
                   0,   0,   0, 1
                };




            // Fill in the empty verticesout vector
            for(int i = 0; i < vertices_in.length; i++)
            {
                vertices_out[i] = vertices_in[i];
            }
            // loop through and set the new matrix (after translation)
            // because
            // 1 0 0 0
            // 0 1 0 0
            // 0 0 1 0

            // X Rotation
            for(int i = 0; i < vertices_out.length; i += 3)
            {
                vertices_out[i+1] = vertices_out[i+1] * (float)Math.cos(xRot) - vertices_out[i+2] * (float)Math.sin(xRot); //New Y
                vertices_out[i+2] = vertices_out[i+1] * (float)Math.sin(xRot) + vertices_out[i+2] * (float)Math.cos(xRot); //New Z
            }

            // Y Rotation
            for(int i = 0; i < vertices_out.length; i += 3)
            {
                vertices_out[i] = vertices_out[i] * (float)Math.cos(yRot) + vertices_out[i+2] * (float)Math.sin(yRot);
                vertices_out[i+2] = vertices_out[i]*-(float)Math.sin(yRot) + vertices_out[i+2]*(float)Math.cos(yRot);
            }

            // Z Rotation
            for(int i = 0; i < vertices_out.length; i += 3)
            {
                vertices_out[i] = vertices_out[i] * (float)Math.cos(zRot) - vertices_out[i+1] * (float)Math.sin(zRot);
                vertices_out[i+1] = vertices_out[i] * (float)Math.sin(zRot) + vertices_out[i+1] * (float)Math.cos(zRot);
            }

            // Translation & Scaling
            for(int i = 0; i < vertices_in.length; i+=3)
            {
                vertices_out[i] = vertices_out[i] * transformMatrix[0] + transformMatrix[3]; //x'
                vertices_out[i+1] = vertices_out[i+1] * transformMatrix[5] + transformMatrix[7]; //y'
                vertices_out[i+2] = vertices_out[i+2] * transformMatrix[10] + transformMatrix[11]; //z'
            }

        }

@Override
public void mouseDragged(MouseEvent e)
{
        if(rotating)
        {
            float XX = (e.getX()-windowWidth*0.5f)*orthoX/windowWidth;
            float YY = -(e.getY()-windowHeight*0.5f)*orthoX/windowWidth;

            float x_prime = (StartXX - XX);
            float y_prime = (StartYY - YY);

            if(rightMouseClick)
            {
                zRot += y_prime/50;

            }
            else
            {
                xRot += y_prime/50;
                yRot += x_prime/50;
                StartYY = YY;
                StartXX = XX;   
            }

        }
}
public void变换(float[]顶点\u向内,float[]顶点\u向外){
//执行您的转换
int length=顶点长度;
浮点[]转换矩阵=
{
r11、r12、r13、tx、,
r21,r22,r23,ty,
r31,r32,r33,tz,
0,   0,   0, 1
};
//填写空的verticesout向量
对于(int i=0;i
所有这些旋转都使用了不一致的中间状态。例如(我只是替换了较短的变量名)

第一行是正确的。但是,当第二行应该使用旧变量时,它已经使用了新的
y
。因此,您必须将旧变量保存在某个位置以使其工作。这同样适用于所有其他旋转


代码的其余部分看起来还可以。

什么?你想实现一个轨迹球吗?不,我想绕z轴旋转我的图像。看起来我做错了,图像看起来是先绕z轴增加,然后看起来是绕y轴增加,然后再绕z轴增加-我只想让它绕z轴旋转,是吗有意义吗?还是不可能@NicoSchertler?这正是问题所在!谢谢
y = y * (float)Math.cos(xRot) - z * (float)Math.sin(xRot); //New Y
z = y * (float)Math.sin(xRot) + z * (float)Math.cos(xRot); //New Z