Java3D 和 HexGrid 坐标

发布于 2025-01-02 18:13:36 字数 874 浏览 0 评论 0原文

我正在尝试找出一种方法来查找 Point3f 是否位于由六边形(每个都是特定的 Shape3D 对象)组成的网格的内部或边缘。

这个想法是改变包含 Point3f 的六边形的颜色,或者如果该点位于边缘上则改变两个六边形的颜色。

为了制作网格,我使用了这个逻辑 http://playtechs.blogspot.com/2007 /04/hex-grids.html 因此应该很容易知道 Hexagon 彼此之间的位置。

我的问题与坐标有关,我在 SceneGraph 中使用了结构:

BranchGroup >变换组>六边形网格(TransformGroup)> HexaRow(变换组)>六边形 (Shape3D)

每个 TransfromGroup 都是使用 Transform3D(Vector3F) 创建的,以将其定位在 3D 空间中

我想从 BranchGroup 恢复每个六边形的坐标,因为我的 Point3f 将在 SceneGraph 的根上生成。

我尝试将顶点坐标放入 HashMap 中,其中 Point 是六边形网格中的坐标,Point3f[] 是六边形每个顶点的 3d 空间中的坐标。 我在行上添加六边形时做到了这一点,但由于是 3 个向量来放置结构,直到该步骤中每个向量都有一个局部坐标系,所以我无法让它正常工作。

有没有一种更简单的方法来查找 Shape3d 对象的坐标,而无需添加用于获取它的所有向量?

这是否是实现我的目标的正确方法? (据我了解,碰撞检测仅适用于 2 个对象,我真的需要知道我的点是否在边缘上,从而生成 3 个对象)

感谢您的帮助!

I'm trying to figure out a way to find if a Point3f is inside or on the edge of grid made of Hexagons (which are each one a specific Shape3D Object).

The idea would be to change the color of the Hexagon cointaing the Point3f or both Heaxgons if the point is on an edge.

To make the grid i used this logic http://playtechs.blogspot.com/2007/04/hex-grids.html
So it should be fairly easy to know how Hexagon are located from each others.

My problem is related to coordinates, there is the structure i use in SceneGraph :

BranchGroup > TransformGroup > Hexagrid (TransformGroup) > HexaRow (TranformGroup) > Hexagon (Shape3D)

Each TransfromGroup is created with a Transform3D(Vector3F) to position it in 3D space

I would like to recover the coordinates of each Hexagon from BranchGroup because my Point3f will be generate on the root of the SceneGraph.

I tried to put Vertex coordinates in a HashMap where Point is the coordinate in the grid of the Hexagon, and Point3f[] is the coordinates in 3d space of each vertex of the Hexagon.
I did that while adding the Hexagon on the row, but since the is 3 Vectors to place the structure until that step with each one a Local coordinate system I coulnd't have it to work properly.

Is there an easier way to find the coordinates of a Shape3d Object without having to add all the Vectors used to get to it ?

Is it even a proper way to archieve my goal ? (from what I undersood collision detection works only with 2 Object and I really need to know if my Point is on an edge , makes 3 Object)

Thanks for the help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

踏雪无痕 2025-01-09 18:13:36

好吧,最后我找到了一个更好的方法,使用 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);

Well, finaly i found a better approach, using Transform3D mul method

    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);
初心未许 2025-01-09 18:13:36

这可能有帮助:

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

This might help:

javax.media.j3d.Node/Shape3D.getLocalToVworld(Transform3D t)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文