Java3D에서 가상 세계에서 화면을 직접 가리키는 법선 벡터를 찾는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/40028

  •  09-06-2019
  •  | 
  •  

문제

장면 그래프의 변환 행렬을 z-normal (0, 0, 1)에 적용하면 될 것 같은데 동작하지 않습니다.내 코드는 다음과 같습니다.

Vector3f toScreenVector = new Vector3f(0, 0, 1);
Transform3D t3d = new Transform3D();
tg.getTransform(t3d); //tg is Transform Group of all objects in a scene
t3d.transform(toScreenVector);

그런 다음 나도 다음과 같은 것을 시도했습니다.

Point3d eyePos = new Point3d();
Point3d mousePos = new Point3d();
canvas.getCenterEyeInImagePlate(eyePos);
canvas.getPixelLocationInImagePlate(new Point2d(Main.WIDTH/2, Main.HEIGHT/2), mousePos); //Main is the class for main window.

Transform3D motion = new Transform3D();
canvas.getImagePlateToVworld(motion);
motion.transform(eyePos);
motion.transform(mousePos);

Vector3d toScreenVector = new Vector3f(eyePos);
toScreenVector.sub(mousePos);
toScreenVector.normalize();

그러나 여전히 이것은 올바르게 작동하지 않습니다.그런 벡터를 만드는 쉬운 방법이 있을 것 같아요.내 코드에 어떤 문제가 있는지, 아니면 더 나은 방법이 있는지 알고 있나요?

도움이 되었습니까?

해결책 2

네, 제 질문이 맞았어요.어제 좀 혼란스러워서 미안해요.이제 귀하의 제안에 따라 질문의 두 코드 조각을 함께 혼합하여 코드를 수정했습니다.

Vector3f toScreenVector = new Vector3f(0, 0, 1);

Transform3D t3d = new Transform3D();
canvas.getImagePlateToVworld(t3d);
t3d.transform(toScreenVector);

tg.getTransform(t3d); //tg is Transform Group of all objects in a scene
t3d.transform(toScreenVector);

감사합니다.

다른 팁

이것이 맞다면 화면 평면에 수직이지만 세계 좌표에 있는 벡터를 원하십니까?

그 경우에는 당신이 원하는 INVERT 의 변형 World -> Screen and do Screen -> World ~의 (0,0,-1) 또는 (0,0,1) 화면이 아래를 가리키는 축에 따라 다릅니다.

ModelView 행렬은 단지 회전 행렬이기 때문에(동질 변환 부분 무시) 회전 부분의 전치를 취하거나 맨 아래 행에서 간단히 읽어서 간단히 꺼낼 수 있습니다. Z 전치 중인 좌표 열.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top