Ogre3d scenenode数组

时间:2017-04-06 15:11:19

标签: c++ arrays ogre ogre3d

目前我正在ogre3d的pcg城市工作,基本上靠近标记为城市的房间将在那里产生一个城市。然而,我对如何将建筑物“存储”成阵列并检查其位置以处理碰撞感到不知所措。在方法中,我得到了建筑物需要产生的平面大小,之后我创建了一个_cityNode,它将容纳所有建筑节点。这些在for循环中设置。在建筑变量中,我尝试在数组中获取buildingNode,以便我可以在另一种方法中检查碰撞。我基本上有两个问题:

  1. 如何将buildingNode转换为数组?
  2. 这种方法是“建筑节点的唯一性是正确的,还是我需要另一种方法?”

    void CityManager::generateCity(int sizeX, int sizeZ, int _numberOfBuildings)
    {
    
    #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    FILE* fp;
    freopen_s(&fp, "CONOUT$", "w", stdout);
    _rootNode = GameManager::getSingletonPtr()->getSceneManager()->getRootSceneNode();
    _cityNode = _rootNode->createChildSceneNode("cityNode");
    printf(" number of buildings: %d \n", _numberOfBuildings);
    printf(" location of X: %d  location of Z: %d \n", sizeX, sizeZ);
    for (int i = 0; i < _numberOfBuildings; i++)
    {
        Ogre::SceneNode* buildingNode = _cityNode->createChildSceneNode("buildingNode" + i);
        Ogre::Entity* _buildingEntity = GameManager::getSingletonPtr()->getSceneManager()->createEntity("cube.mesh");
    
        buildingNode->createChildSceneNode()->attachObject(_buildingEntity);
        buildingNode->setPosition(rand() % sizeX , 50, rand() % sizeZ);
        buildingNode->setScale(rand() % 6+1 , rand() % 6 + 1, rand() % 6 + 1);
    
    
        Ogre::Vector3 buildingpos = buildingNode->getPosition();
        Ogre::Vector3 buildingscale = buildingNode->getScale();
        //_buildings = new Ogre::SceneNode[buildingNode];
        checkCollision();
        checkEntryWay();
    
        printf("positions of building nodes %f, %f, %f " , buildingpos.x, buildingpos.y, buildingpos.z);
        printf("scale of building nodes %f, %f, %f \n", buildingscale.x, buildingscale.y, buildingscale.z);
    
    
    }
    fclose(fp);
    #endif
    }
    

1 个答案:

答案 0 :(得分:0)

您可以使用任何所需的STL容器,Ogre::SceneNode*与它们完全兼容。

例如,您可以在std::vector中收集节点

std::vector<Ogre::SceneNode*> buildings_;
for (int i = 0; i < _numberOfBuildings; i++)
{
  /* ... */
  buildings_.push_back(buildingNode);
}

然后像

一样访问它们
for (auto i : buildings_) {
  Ogre::Vector3 buildingpos = i->getPosition();
  Ogre::Vector3 buildingscale = i->getScale();
}