Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过重新计算每个顶点来旋转立方体_Java_Opengl - Fatal编程技术网

Java 通过重新计算每个顶点来旋转立方体

Java 通过重新计算每个顶点来旋转立方体,java,opengl,Java,Opengl,我暴露了我的问题! 我正在旋转立方体,在每次旋转时重新计算每个顶点的单独坐标,我必须说 我的成绩很好。但是,如果立方体沿着一个轴旋转,一切都会变得完美, 沿两个或三个轴旋转顶点,使立方体经过一点旋转 时间具有平流层大小。 下面是旋转的代码,我认为它隐藏在旋转的后面 问题 旋转矩阵各行各顶点分量的乘积 使顶点脱离其轨迹,但我不明白为什么 //for each cube for(contatoreOnDraw=0;contatoreOnDraw<numberOfCube;con

我暴露了我的问题! 我正在旋转立方体,在每次旋转时重新计算每个顶点的单独坐标,我必须说 我的成绩很好。但是,如果立方体沿着一个轴旋转,一切都会变得完美, 沿两个或三个轴旋转顶点,使立方体经过一点旋转 时间具有平流层大小。 下面是旋转的代码,我认为它隐藏在旋转的后面 问题 旋转矩阵各行各顶点分量的乘积 使顶点脱离其轨迹,但我不明白为什么

    //for each cube
    for(contatoreOnDraw=0;contatoreOnDraw<numberOfCube;contatoreOnDraw++)
    {

        x=contatoreOnDraw*3;
        y=(contatoreOnDraw*3)+1;
        z=(contatoreOnDraw*3)+2;
        gl.glPushMatrix();
        gl.glTranslatef(translation[row][x], translation[row][y], translation[row][z]);
        float angle=2;


        //Rotation matrix 3x3
        c =(float) Math.cos(angle*(Math.PI/180));
        s =(float) Math.sin(angle*(Math.PI/180));
        rotation[0][0] = (rX*rX*(1-c)) + c;
        rotation[0][1] = (rX*rY*(1-c))-rZ*s;
        rotation[0][2] = (rX*rZ*(1-c))+rY*s;
        rotation[1][0] = (rY*rX*(1-c))+rZ*s;
        rotation[1][1] = (rY*rY*(1-c)) + c;
        rotation[1][2] = (rY*rZ*(1-c))-rX*s;
        rotation[2][0] = (rX*rZ*(1-c))-rY*s;
        rotation[2][1] = (rY*rZ*(1-c))+rX*s;
        rotation[2][2] = (rZ*rZ*(1-c)) + c;

        //Updating each vertex component
        for(int i=0;i<70;i=i+3)
        {
            vX_tmp=(rotation[0][0]*cubes[contatoreOnDraw].getVertices(i))+(rotation[0][1]*cubes[contatoreOnDraw].getVertices(i+1))+(rotation[0][2]*cubes[contatoreOnDraw].getVertices(i+2));
            vY_tmp=(rotation[1][0]*cubes[contatoreOnDraw].getVertices(i))+(rotation[1][1]*cubes[contatoreOnDraw].getVertices(i+1))+(rotation[1][2]*cubes[contatoreOnDraw].getVertices(i+2));
            vZ_tmp=(rotation[2][0]*cubes[contatoreOnDraw].getVertices(i))+(rotation[2][1]*cubes[contatoreOnDraw].getVertices(i+1))+(rotation[2][2]*cubes[contatoreOnDraw].getVertices(i+2));
            cubes[contatoreOnDraw].setVertices(i, vX_tmp);
            cubes[contatoreOnDraw].setVertices(i+1, vY_tmp);
            cubes[contatoreOnDraw].setVertices(i+2, vZ_tmp);

        }
        cubes[contatoreOnDraw].draw(gl);
        gl.glPopMatrix();

    }
//对于每个多维数据集

对于(contatoreOnDraw=0;contatoreOnDraw我已经找到了解决方案,我没有规范化向量(rX,rY,rZ)。 正常化后所有工作完美

@达滕沃尔夫:
谢谢你的回复,我已经在GPU上做了同样的操作,但是我想在CPU上执行它,还有一个问题!

为什么你会这样旋转?为什么不直接使用
glRotate
函数?因为我需要直接操作旋转矩阵。我已经用glRotate做了这个版本,现在我需要这个版本。@ExEcUtIvE:you可以使用glMultMatrix或glLoadMatrix加载您自己的变换矩阵。不要在CPU上执行变换。利用GPU的计算能力,GPU的计算能力很容易优于CPU。还可以查看着色器。