안녕하세요, lwjgl을 사용하여 내 3D 자바 게임에 OBB를 빌드하려고합니다. 현재 matrix4f를 사용하여 OBB를 회전시키고 점을 렌더링하여 테스팅을 시도하고 있습니다. 그래서 xyx = 0,0,0과 x 축의 각도 = 1로 렌더링하면 잘 회전합니다. 하지만 y 축을 y = 5라고 말하면 회전이 더 이상 중심을 벗어나지 않습니다.Java Rotation Matrices & OBB
나는 번역으로 이것을 고치려고했지만, 그것은 작동하지 않습니다. Opengl의 push/pop 및 rotate 메소드에 액세스하여 내 포인트에 해당하는 변수를 얻는 방법이 있는지 궁금합니다.
이것은 내 OBB 클래스이다
공개 OBB (플로트 X, sizeZ을 SIZEY 플로트, SIZEX 플로트 angleZ 플로트 angleY 플로트 angleX 플로트, Z 플로트, Y 플로트 플로트) { this.x = 엑스; this.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);
}
이 내 회전 방법 :
공공 Vector3f rotMatrix (Vector3f 포인트) { Matrix4f rotationMatrix = 새로운 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);
}
내 렌더링 기능은 여기에 넣기에는 약간 길지만 기본적으로 큐브를 렌더링합니다.
죄송 느낌 : 공공 무효 setToOrigin가() { \t \t posUBR = 새 Vector3f (0 크기 X, 0 크기 Y, 0 크기 Z); \t \t posUBL = new Vector3f (0-sizeX, 0 + sizeY, 0-sizeZ); \t \t posUFL = 새 Vector3f (0 + sizeX, 0 + sizeY, 0-sizeZ); \t \t posUFR = 새 Vector3f (0 + 크기 X, 0 + 크기 Y, 0 + 크기 Z); \t \t \t \t posLBR = new Vector3f (0-sizeX, 0-sizeY, 0 + sizeZ); \t \t posLBL = new Vector3f (0-sizeX, 0-sizeY, 0-sizeZ); \t \t posLFL = new Vector3f (0 + sizeX, 0-sizeY, 0-sizeZ); \t \t posLFR = new Vector3f (0 + sizeX, 0-sizeY, 0 + sizeZ); \t} – HelpMehIDonKnowLinearAlgebra