1

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

        // 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)))))));
4

0 回答 0