【发布时间】:2014-12-22 18:40:56
【问题描述】:
您好,我正在尝试使用 lwjgl 将 OBB 构建到我的 3d java 游戏中。目前我只是尝试使用matrix4f旋转OBB并通过渲染点来测试它。因此,当我渲染它时,它的 xyx=0,0,0 和它在 x 轴上的角度 =1 它会很好地旋转。但是当我将 y 轴向上移动说 y=5 时,旋转将不再围绕中心进行。
我尝试通过翻译解决此问题,但它不起作用。我还想知道是否有办法访问opengl 的push/pop 和rotate 方法来为我的观点获取这些变量,因为opengl rotate 做得很好。
这是我的 OBB 课程:
public OBB(float x, float y, float z, float angleX, float angleY, float angleZ, float sizeX, float sizeY, float sizeZ){ 这个.x=x; 这个.y=y; this.z=z;
this.angleX=angleX;
this.angleY=angleY;
this.angleZ=angleZ;
this.sizeX=sizeX;
this.sizeY=sizeY;
this.sizeZ=sizeZ;
posUBR = new Vector3f(x-sizeX,y+sizeY,z+sizeZ);//UpperBackRight
posUBL = new Vector3f(x-sizeX,y+sizeY,z-sizeZ);//UpperBackLeft
posUFL = new Vector3f(x+sizeX,y+sizeY,z-sizeZ);//UpperForLeft
posUFR = new Vector3f(x+sizeX,y+sizeY,z+sizeZ);//UpperForRight
posLBR = new Vector3f(x-sizeX,y-sizeY,z+sizeZ);//LowerBackRight
posLBL = new Vector3f(x-sizeX,y-sizeY,z-sizeZ);//LowerBackLeft
posLFL = new Vector3f(x+sizeX,y-sizeY,z-sizeZ);//LowerForLeft
posLFR = new Vector3f(x+sizeX,y-sizeY,z+sizeZ);//LowerForRight
posUBR=rotMat(posUBR);
posUBL=rotMat(posUBL);
posUFL=rotMat(posUFL);
posUFR=rotMat(posUFR);
posLBR=rotMat(posLBR);
posLBL=rotMat(posLBL);
posLFL=rotMat(posLFL);
posLFR=rotMat(posLFR);
}
这是我的轮换方法:
public Vector3f rotMatrix(Vector3f 点) { Matrix4f rotationMatrix = new Matrix4f();
rotationMatrix.m00 = point.x;
rotationMatrix.m10 = point.y;
rotationMatrix.m20 = point.z;
rotationMatrix.translate(new Vector3f(-x,-y,-z));
rotationMatrix.rotate(angleX,new Vector3f(1,0,0));
rotationMatrix.rotate(angleY,new Vector3f(0,1,0));
rotationMatrix.rotate(angleZ,new Vector3f(0,0,1));
rotationMatrix.translate(new Vector3f(x,y,-z));
return new Vector3f(rotationMatrix.m00, rotationMatrix.m10, rotationMatrix.m20);
}
public void rotate(){
posUBR=rotMatrix(posUBR);
posUBL=rotMatrix(posUBL);
posUFL=rotMatrix(posUFL);
posUFR=rotMatrix(posUFR);
posLBR=rotMatrix(posLBR);
posLBL=rotMatrix(posLBL);
posLFL=rotMatrix(posLFL);
posLFR=rotMatrix(posLFR);
}
我的渲染函数放在这里有点长,但它基本上是渲染一个立方体。
【问题讨论】:
-
对不起,我现在感觉很笨,我需要做的就是在我的旋转函数中运行它: public void setToOrigin(){ posUBR = new Vector3f(0-sizeX,0+sizeY,0 +尺寸Z); posUBL = new Vector3f(0-sizeX,0+sizeY,0-sizeZ); posUFL = new Vector3f(0+sizeX,0+sizeY,0-sizeZ); posUFR = new Vector3f(0+sizeX,0+sizeY,0+sizeZ); posLBR = new Vector3f(0-sizeX,0-sizeY,0+sizeZ); posLBL = new Vector3f(0-sizeX,0-sizeY,0-sizeZ); posLFL = new Vector3f(0+sizeX,0-sizeY,0-sizeZ); posLFR = new Vector3f(0+sizeX,0-sizeY,0+sizeZ); }
标签: java opengl matrix 3d rotation