如何优化3D AABB旋转(Java)

时间:2016-08-14 05:30:12

标签: java optimization 3d game-engine aabb

最近我一直在我的游戏引擎中实现3D AABB,以完成旋转我使用一种简单的方法,使用我的Vector3f.rotate()方法围绕框的中心旋转所有8个计算角。但正如您可能会注意到的那样,效率非常低。如果你想排序虽然这里的整个类是github(https://github.com/EquilibriumGames/Flounder-Engine/blob/master/src/flounder/physics/AABB.java),否则这里是我需要帮助的片段,我觉得那里可能有更简单的方法,但我想知道你的想法。谢谢!

        // Creates the 8 AABB corners and rotates them.
    Vector3f FLL = new Vector3f(destination.minExtents.x, destination.minExtents.y, destination.minExtents.z);
    Vector3f.rotate(FLL, rotation, FLL);

    Vector3f FLR = new Vector3f(destination.maxExtents.x, destination.minExtents.y, destination.minExtents.z);
    Vector3f.rotate(FLR, rotation, FLR);

    Vector3f FUL = new Vector3f(destination.minExtents.x, destination.maxExtents.y, destination.minExtents.z);
    Vector3f.rotate(FUL, rotation, FUL);

    Vector3f FUR = new Vector3f(destination.maxExtents.x, destination.maxExtents.y, destination.minExtents.z);
    Vector3f.rotate(FUR, rotation, FUR);

    Vector3f BUR = new Vector3f(destination.maxExtents.x, destination.maxExtents.y, destination.maxExtents.z);
    Vector3f.rotate(BUR, rotation, BUR);

    Vector3f BUL = new Vector3f(destination.minExtents.x, destination.maxExtents.y, destination.maxExtents.z);
    Vector3f.rotate(BUL, rotation, BUL);

    Vector3f BLR = new Vector3f(destination.maxExtents.x, destination.minExtents.y, destination.maxExtents.z);
    Vector3f.rotate(BLR, rotation, BLR);

    Vector3f BLL = new Vector3f(destination.minExtents.x, destination.minExtents.y, destination.maxExtents.z);
    Vector3f.rotate(BLL, rotation, BLL);

    destination.minExtents = Maths.min(FLL, Maths.min(FLR, Maths.min(FUL, Maths.min(FUR, Maths.min(BUR, Maths.min(BUL, Maths.min(BLR, BLL)))))));
    destination.maxExtents = Maths.max(FLL, Maths.max(FLR, Maths.max(FUL, Maths.max(FUR, Maths.max(BUR, Maths.max(BUL, Maths.max(BLR, BLL)))))));

0 个答案:

没有答案