2012-02-06 74 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)