void IntersectPoint::reshape(void)
 {
     // Adjust intersection scale
     Real scale = getSceneManipulator()->getBaseScale() / (5 * mIntersectEntity->getMesh()->getBoundingSphereRadius());
     mIntersectNode->setScale(scale, scale, scale);
 }
void
FixPaintAction::_doPaint(JunctionSelection* modifiedJunctions,GridSelection* modifiedGrids,const Point& mCurrentMousePos)
{
    Ogre::Vector3 position;
    bool hit = getSceneManipulator()->getTerrainIntersects(mCurrentMousePos.x,mCurrentMousePos.y, position);
    if (!hit)
    {
        return;
    }

    std::vector<TerrainInfo> terrainInfo;

    bool junctionChanged =false;
    bool gridChanged = false;
    Ogre::String textureName;
    int pixmapId;
    float left,top,right,bottom;//bugfix,此处原来为int

    if(mPasteHeightInfo)
    {
        std::pair<int, int> mouseJunction = mSceneManipulator->getTerrainData()->getJunction(position.x, position.z);
        FixPaintSelection::JunctionMap::const_iterator iter;
        terrainInfo.clear();

        //TerrainInfo高度数据是绝对值
        for( iter = mGridSelection.getJunctions().begin(); iter!=mGridSelection.getJunctions().end(); iter++)
        {
            int absJunctionX = iter->first.x + mouseJunction.first;
            int absJunctionZ = iter->first.y + mouseJunction.second;

            if ( false == mSceneManipulator->getTerrainData()->isValidJunction(absJunctionX, absJunctionZ) )
                continue;

            float oldHeight = mSceneManipulator->getTerrainData()->getHeight(absJunctionX, absJunctionZ);
            float absHeight;
            if(!modifiedJunctions->exist(absJunctionX,absJunctionZ))
            {
                modifiedJunctions->add(absJunctionX, absJunctionZ, 1.0);
                absHeight = iter->second.height;
            }
            else
            {
                JunctionSelection::JunctionMap::const_iterator it = modifiedJunctions->getJunctions().find(mSceneManipulator->getTerrainData()->_getJunctionIndex(absJunctionX, absJunctionZ));
                assert( it != modifiedJunctions->getJunctions().end());

                absHeight = iter->second.height;
            }

            mSceneManipulator->getTerrainData()->setHeight(absJunctionX, absJunctionZ, absHeight);

            if(oldHeight != absHeight)
            {
                TerrainInfo terrInfo;
                terrInfo.x = absJunctionX;
                terrInfo.z = absJunctionZ;
                terrInfo.oldHeight = oldHeight;
                terrInfo.nowHeight = absHeight;
                terrainInfo.push_back(terrInfo);
            }
            junctionChanged = true;
        }
    }
    if(mPasteTextureInfo)
    {
        std::pair<int, int> mouseGrid = mSceneManipulator->getTerrainData()->getGrid(position.x, position.z);

        FixPaintSelection::GridMap::const_iterator iter;
        for( iter = mGridSelection.getGrids().begin(); iter!=mGridSelection.getGrids().end(); iter++)
        {
            int absGridX = iter->first.x + mouseGrid.first;
            int absGridZ = iter->first.y + mouseGrid.second;

            if ( false == mSceneManipulator->getTerrainData()->isValidGrid(absGridX, absGridZ) )
                continue;

            if ( !modifiedGrids->exist(absGridX,absGridZ) )
            {
                modifiedGrids->add(absGridX, absGridZ);
            }

            WX::TerrainData::GridInfo gridInfo = mSceneManipulator->getTerrainData()->getGridInfo(absGridX, absGridZ);

            textureName = iter->second.info.layers[0].textureName;
            left = iter->second.info.layers[0].left;
            top = iter->second.info.layers[0].top;
            right = iter->second.info.layers[0].right;
            bottom = iter->second.info.layers[0].bottom;
            if(textureName == "UnTextured")
                pixmapId = 0;
            else
            {
                pixmapId = mSceneManipulator->getTerrainData()->_registerPixmap(textureName,left,top,right,bottom);
            }
            gridInfo.layers[0].pixmapId = pixmapId;
            gridInfo.layers[0].orientation = iter->second.info.layers[0].orientation;


            textureName = iter->second.info.layers[1].textureName;
            if(textureName != "UnTextured")
            {
                left = iter->second.info.layers[1].left;
                top = iter->second.info.layers[1].top;
                right = iter->second.info.layers[1].right;
                bottom = iter->second.info.layers[1].bottom;

                pixmapId = mSceneManipulator->getTerrainData()->_registerPixmap(textureName,left,top,right,bottom);
            }
            else
            {
                pixmapId = 0;
                left = top = right = bottom = 0;
            }
            gridInfo.layers[1].pixmapId = pixmapId;
            gridInfo.layers[1].orientation = iter->second.info.layers[1].orientation;

            mSceneManipulator->getTerrainData()->setGridInfo(absGridX, absGridZ, gridInfo);

            gridChanged = true;
        }
    }
    if(mPasteDiagonalInfo)
    {
        std::pair<int, int> mouseGrid = mSceneManipulator->getTerrainData()->getGrid(position.x, position.z);
        FixPaintSelection::GridMap::const_iterator iter;
        for( iter = mGridSelection.getGrids().begin(); iter!=mGridSelection.getGrids().end(); iter++)
        {
            int absGridX = iter->first.x + mouseGrid.first;
            int absGridZ = iter->first.y + mouseGrid.second;

            if ( false == mSceneManipulator->getTerrainData()->isValidGrid(absGridX, absGridZ) )
                continue;

            if ( !modifiedGrids->exist(absGridX,absGridZ) )
                modifiedGrids->add(absGridX, absGridZ);

            WX::TerrainData::GridInfo gridInfo = mSceneManipulator->getTerrainData()->getGridInfo(absGridX, absGridZ);
            gridInfo.flags = iter->second.info.flags;
            mSceneManipulator->getTerrainData()->setGridInfo(absGridX, absGridZ, gridInfo);

            gridChanged = true;
        }
    }

    if(junctionChanged)
    {
        getSceneManipulator()->_fireTerrainHeightChanged(terrainInfo);
        modifiedJunctions->notifyModified();
    }

    if(gridChanged)
    {
        modifiedGrids->notifyModified();
    }
}
void
FixPaintAction::doFinish(JunctionSelection* originJunctions,GridSelection* originGrids, bool canceled)
{
    assert(originJunctions || originGrids);

    if (canceled)
    {
        originJunctions->apply();
        originGrids->apply();
    }
    else
    {
        std::auto_ptr<WX::TerrainSelectionActionOperator> op( new WX::TerrainSelectionActionOperator(getSceneManipulator()) );

        if(!originJunctions->empty())
        {
            const JunctionSelection::JunctionMap& junctions = originJunctions->getJunctions();
            JunctionSelection::JunctionMap::const_iterator it;
            for (it = junctions.begin(); it != junctions.end(); ++it)
            {
                const JunctionSelection::Junction& junction = it->second;
                float oldHeight = junction.height;
                float newHeight = mSceneManipulator->getTerrainData()->getHeight(junction.x,junction.z);

                if (newHeight != oldHeight)
                {
                    op->mModifyHeightOperator->add(junction.x, junction.z, oldHeight, newHeight);
                }
            }
        }
        //因为Grid信息里包含了纹理和对角线信息,所以放在一起
        if (!originGrids->empty())
        {
            const GridSelection::GridMap& grids = originGrids->getGrids();
            GridSelection::GridMap::const_iterator it;
            for (it = grids.begin(); it != grids.end(); ++it)
            {
                const GridSelection::Grid& grid = it->second;
                const TerrainData::GridInfo &oldGridInfo = grid.info;
                const TerrainData::GridInfo &newGridInfo = mSceneManipulator->getTerrainData()->getGridInfo(grid.x, grid.z);
                if (newGridInfo != oldGridInfo)
                {
                    op->mModifyPaintOperator->add(grid.x, grid.z, oldGridInfo, newGridInfo);
                }
            }

        }

        if (!op->empty())
            getOperatorManager()->addOperator(op.release());

    }
}
	void CreateComplexObjectAction::hide(void)
	{
		mObject.reset();
		getSceneManipulator()->getHitIndicator("IntersectPoint")->hide();
	}
	void CreateComplexObjectAction::_onDrag(const Point& pt)
	{
		getSceneManipulator()->getHitIndicator("IntersectPoint")->setHitPoint(pt);
	}
 void LevelOffHeightAction::_onMove(const Point& pt)
 {
     getSceneManipulator()->getHitIndicator("JunctionPoints")->setHitPoint(pt);
     getSceneManipulator()->getHitIndicator("IntersectPoint")->setHitPoint(pt);
 }
 LevelOffHeightAction::LevelOffHeightAction(SceneManipulator* sceneManipulator)
     : HeightAction(sceneManipulator)
     , mModifiedJunctions(NULL)
 {
     mModifiedJunctions = new JunctionSelection(getSceneManipulator()->getTerrain(),sceneManipulator);
 }
 void RaiseHeightAction::_prepareUpdate(const JunctionSelection& selection, Real seconds)
 {
     mAdjust = + getSceneManipulator()->_getHeightAdjustSpeed() * seconds;
 }
    void GridInfoFlagModifyAction::_doFinish(GridSelection* origin, bool canceled)
    {
        assert(origin);

        if (canceled)
        {
            origin->apply();
        }
        else
        {
            if (!origin->empty())
            {
                std::auto_ptr<FlipTerrainDiagonalOperator> op(new FlipTerrainDiagonalOperator(getSceneManipulator()));

                const GridSelection::GridMap& grids = origin->getGrids();
                GridSelection::GridMap::const_iterator it;
                for (it = grids.begin(); it != grids.end(); ++it)
                {
                    const GridSelection::Grid& grid = it->second;
                    uint newFlipFlag = getTerrainData()->getGridInfo(grid.x, grid.z).flags;
                    uint oldFlipFlag = grid.info.flags;
                    if (newFlipFlag != oldFlipFlag)
                    {
                        op->add(grid.x, grid.z, oldFlipFlag, newFlipFlag);
                    }
                }

                if (!op->empty())
                    getOperatorManager()->addOperator(op.release());
            }
        }
    }
 void GridInfoFlagModifyAction::_onEnd(const Point& pt, bool canceled)
 {     
     _doFinish(static_cast<GridSelection*>(getSceneManipulator()->_getSelection("GridSelection")), canceled);
     getSceneManipulator()->getHitIndicator(mHitIndicatorName)->setHitPoint(pt);
 }
 void GridInfoFlagModifyAction::_onMove(const Point& pt)
 {
     getSceneManipulator()->getHitIndicator("JunctionPoints")->setHitPoint(pt);
     getSceneManipulator()->getHitIndicator(mHitIndicatorName)->setHitPoint(pt);
 }
Beispiel #12
0
    //-----------------------------------------------------------------------
    void 
    PaintAction::doFinish(GridSelection* origin, bool canceled)
    {
        assert(origin);

        if (canceled)
        {
            origin->apply();
        }
        else
        {
            if (!origin->empty())
            {
                std::auto_ptr<ModifyTerrainPaintOperator> op(new ModifyTerrainPaintOperator(getSceneManipulator()));

                const GridSelection::GridMap& grids = origin->getGrids();
                GridSelection::GridMap::const_iterator it;
                for (it = grids.begin(); it != grids.end(); ++it)
                {
                    const GridSelection::Grid& grid = it->second;
                    const TerrainData::GridInfo &newGridInfo = getTerrainData()->getGridInfo(grid.x, grid.z);
                    const TerrainData::GridInfo &oldGridInfo = grid.info;
                    if (newGridInfo != oldGridInfo)
                    {
                        op->add(grid.x, grid.z, oldGridInfo, newGridInfo);
                    }
                }

                if (!op->empty())
                    getOperatorManager()->addOperator(op.release());
            }
        }
    }