2011-12-24 62 views
1

我正在寫一個Java Applet唱歌Java3D,並希望在單擊按鈕時重置鼠標在MouseRotate行爲中的旋轉。相關代碼如下:如何在Java3D中重置鼠標旋轉?

BoundingSphere bound = 
      new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);  

     MouseRotate mouseRotate = new MouseRotate(); 
        TransformGroup modelGroup = new TransformGroup(); 
        mouseRotate.setTransformGroup(modelGroup); 
        modelGroup.addChild(mouseRotate); 
        mouseRotate.setSchedulingBounds(bound); 

回答

0

對不起,我的錯。似乎沒有重新編寫MouseRotate的方法。

第二次嘗試:在場景圖中包含另一個TransformGroup作爲modelGroup的父級,並在重置被拒絕時將其變換設置爲modelGroup的反轉變換。

TransformGroup modelGroupReset = new TransformGroup(); 
TransformGroup modelGroup = new TransformGroup(); 
modelGroupReset.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 
modelGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 
modelGroupReset.addChild(modelGroup); 

JButton resetButton = new JButton(); 
resetButton.addActionListener(new ActionListener() { 
    public void actionPerformed(ActionEvent e) { 
     Transform3D t3d = new Transform3D(); 
     modelGroup.getTransform(t3d); 
     t3d.invert(); 
     modelGroupReset.setTransform(t3d); 
    } 
}); 

;

0

試試這個:回想mouseRotate.setTransformGroup(modelGroup);其次mouseRotate.initialize();。未經測試!

+0

謝謝,但它沒有奏效。每當我使用initialize()方法時,出現以下錯誤: 線程「AWT-EventQueue-0」中的異常java.lang.IllegalStateException:必須從initialize或processStimulus調用wakeupOn – Hassan 2011-12-25 06:17:49

2

它的工作原理。非常感謝!然而,在實施你提出的方法時,我意外地發現了一個更簡單的方法。代碼來到下面。 此方法似乎正在爲我的目的而工作,並且不需要父TransformGrop。該方法是顯而易見的,我想我以前試過。也許我確實嘗試過,但由於其他原因,它不起作用。乾杯,哈桑

TransformGroup modelGroup = new TransformGroup(); 
modelGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); 
modelGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 

JButton resetButton = new JButton(); 
resetButton.addActionListener(new ActionListener() { 
public void actionPerformed(ActionEvent e) { 
    modelGroup.setTransform(new Transform3D()); 
} 
});