2012-02-06 77 views
1

我試圖找出一種方法來查找如果一個Point3f是內部或由六邊形(每一個特定的Shape3D對象)組成的網格的邊緣。Java3D和HexGrid座標

這個想法是改變Hexagon的顏色,如果點位於邊緣上,則支持Point3f或兩個Heaxgons。

爲了讓我用這個邏輯http://playtechs.blogspot.com/2007/04/hex-grids.html 所以應該很容易知道六角如何從每個人所在的網格。

我的問題是關係到座標,有i的場景圖使用這種結構:

BranchGroup>的TransformGroup> Hexagrid(的TransformGroup)> HexaRow(TranformGroup)>六角(一個Shape3D)

每個TransfromGroup創建使用Transform3D(Vector3F)將其放置在3D空間中

我想從BranchGroup中恢復每個Hexagon的座標,因爲我的Point3f將在SceneGraph的根上生成。

我試圖把頂點座標放在一個HashMap中,其中Point是Hexagon網格中的座標,而Point3f []是Hexagon每個頂點的三維空間中的座標。 我這樣做,而在行上添加六角形,但自從是3矢量結構,直到該步驟與每一個本地座標系我沒有它正常工作。

有沒有更簡單的方法來找到一個Shape3d對象的座標,而不必添加所有用於獲取它的向量?

它是一個適當的方式來實現我的目標? (從我的缺點碰撞檢測只適用於2對象,我真的需要知道我的點是否在邊緣,使3個對象)

感謝您的幫助!

回答

0

好,finaly我發現了一個更好的方法,使用的Transform3D MUL方法

translateRootTG.addChild(hexaGrid); 

    Polygon myPolygon = hexaGrid.getPolygon(19,1); 
    // Get the First TransformGroup that containt the first Translation 
    TransformGroup firstTransform= (TransformGroup)myPolygon.getParent(); 
    // the the Second TransfromGroup that containt the secondary Translation 
    TransformGroup secondTransform = (TransformGroup)myPolygon.getParent().getParent().getParent().getParent(); 
    // Get the Transform3D from the first TransformGroup 
    Transform3D firstTranslation = new Transform3D(); 
    firstTransform.getTransform(firstTranslation); // put the Transform in T3D var 
    // Get the Transform3D from the second TransformGroup 
    Transform3D secondTranslation = new Transform3D(); 
    secondTransform.getTransform(secondTranslation); // put the Transform in T3D var 

    // Mul Transform3D to have complete translation 
    Transform3D t3DTotalPolygon = new Transform3D(); 
    t3DTotalPolygon.mul(firstTranslation, secondTranslation); 

    TransformGroup tgTest = new TransformGroup(t3DTotalPolygon); 
    tgTest.addChild(new ColorCube(0.03f)); 
    translateRootTG.addChild(tgTest); 
0

這可能幫助:

javax.media.j3d.Node/Shape3D.getLocalToVworld(Transform3D t)