c++ - OgreBullet 不正确的 HeightmapCollisionShape 形状比例?

标签 c++ ogre bulletphysics

我试图通过(主要)使用演示代码在 OgreBullet 中加载 HeightmapTerrainShape,但我的地形网格与 HeightmapTerrainShape 有偏移。我不知道为什么会这样。这是我的代码:

void TerrainLoader::setTerrainPhysics(Ogre::Image *imgPtr)

{
    unsigned page_size = terrainGroup->getTerrainSize();
    Ogre::Vector3 terrainScale(4096 / (page_size-1), 600, 4096 / (page_size-1));
    float *heights = new float[page_size*page_size];
    for(unsigned y = 0; y < page_size; ++y)
    {
        for(unsigned x = 0; x < page_size; ++x)
        {
            Ogre::ColourValue color = imgPtr->getColourAt(x, y, 0);
            heights[x + y * page_size] = color.r;
        }
    }

OgreBulletCollisions::HeightmapCollisionShape *terrainShape = new OgreBulletCollisions::HeightmapCollisionShape(
    page_size,
    page_size,
    terrainScale,
    heights,
    true
);
OgreBulletDynamics::RigidBody *terrainBody = new OgreBulletDynamics::RigidBody(
    "Terrain",
    OgreInit::level->physicsManager->getWorld()
);
imgPtr = NULL;

Ogre::Vector3 terrainShiftPos(terrainScale.x/(page_size-1), 0, terrainScale.z/(page_size-1));
terrainShiftPos.y = terrainScale.y / 2 * terrainScale.y;

Ogre::SceneNode *pTerrainNode = OgreInit::sceneManager->getRootSceneNode()->createChildSceneNode();
terrainBody->setStaticShape(pTerrainNode, terrainShape, 0.0f, 0.8f, terrainShiftPos);
//terrainBody->setPosition(terrainBody->getWorldPosition()-Ogre::Vector3(0.005, 0, 0.005));
OgreInit::level->physicsManager->addBody(terrainBody);
OgreInit::level->physicsManager->addShape(terrainShape);
}

这是打开调试抽屉后的样子: enter image description here enter image description here enter image description here

我的世界大小是4096*600*4096,每个chunk是64*600*64

最佳答案

heights[x + y * page_size] = color.r;

这条线给你负值。如果将负地形高度值与 ogre 子弹地形结合使用,则会出现错误的边界框对话。

高度值需要使用 0-1 区间。

Perlin 噪音过滤器也有同样的问题,它给你的值从 -1 到 1。

关于c++ - OgreBullet 不正确的 HeightmapCollisionShape 形状比例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12503388/

相关文章:

c++ - 用于增强现实的 OpenCV 相机内在矩阵到 Ogre 投影矩阵

c++ - 在其边缘旋转刚体?

c++ - 编译时错误 : Multiple definition of 'main'

c++ - '.' 标记前缺少模板参数

c++ - 如何只链接到 Conan 包中的某些库?

c++ - 代表盒子的推荐类别是什么?

python - py2exe 之后与 Twisted 的不一致连接失败

java - 如何在 JBullet 中定义自定义网格?

java - LWJGL 网格到 JBullet 碰撞器

c++ - DBT_DEVICEARRIVAL 消息正在发送无法识别的类 GUID