【问题标题】:OgreBullet incorrect HeightmapCollisionShape shape scale?OgreBullet 不正确的 HeightmapCollisionShape 形状比例?
【发布时间】:2012-09-19 21:46:56
【问题描述】:

我正在尝试通过(主要)使用演示代码在 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);
}

这是打开调试抽屉后的样子:

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

【问题讨论】:

    标签: c++ ogre bulletphysics


    【解决方案1】:
    heights[x + y * page_size] = color.r;
    

    这条线给你负值。如果将负地形高度值与食人魔子弹地形相结合,则会得到错误的边界框对话。

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

    与 perlin 噪声过滤器有同样的问题,它为您提供从 -1 到 1 的值。

    【讨论】:

    • 您介意张贴一点您的意思吗?我仍然很困惑:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-26
    • 1970-01-01
    • 2020-09-04
    • 2014-01-06
    相关资源
    最近更新 更多