我有一個圓錐我的Java 3D畫了下面的代碼:如何在Java 3D中旋轉對象?
Cone cone = new Cone(2f, 3f);
Transform3D t3d = new Transform3D();
TransformGroup coneTransform = new TransformGroup(t3d);
coneTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
t3d.setTranslation(new Vector3f(0f,0f,0f);
coneTransform.setTransform(t3d);
coneTransform.addChild(cone);
this.addChild(coneTransform);
假設我有錐坐在點(1,1,1)和我想要的錐尖指向下一個假想線穿過(0,0,0)和(1,1,1)......我該怎麼做?
這裏是什麼,我一直想一個例子:
Transform3D t3d = new Transform3D();
Vector3f direction = new Vector3f(1,2,1);
final double angleX = direction.angle(new Vector3f(1,0,0));
final double angleY = direction.angle(new Vector3f(0,1,0));
final double angleZ = direction.angle(new Vector3f(0,0,1));
t3d.rotX(angleX);
t3d.rotY(angleY);
t3d.rotZ(angleZ);
t3d.setTranslation(direction);
coneTransform.setTransform(t3d);
預先感謝所有幫助!
謝謝。 t3d.rotX(Math.PI/2);和Y類似,Z將旋轉錐體。你能描述一下如何計算旋轉X和Y的角度?例如,如果我從(0,0,0)到(1,1,1)繪製一條線,如何計算旋轉量? – Cuga 2009-08-25 20:50:44
旋轉函數將弧度值作爲輸入。有2 * PI一個完整的旋轉,或垂直線之間的PI/2度(這意味着我錯了,你只需要旋轉PI/4)。 一般而言,您不需要沿着所有三個角度旋轉,因爲您可以通過沿着兩個軸旋轉來描述任何旋轉。 – Zed 2009-08-26 06:28:49
哈哈 - 我*只是*意識到我不需要所有3輪。現在我正在紙上寫出如何計算我需要的角度。謝謝你的幫助。 – Cuga 2009-08-26 13:07:32