// 在当前编辑的区域中添加一个新的点 unsigned long CNpcPatrolAction::AddNewPoint(Ogre::Vector3 position) { if(0 == m_UnreachRegionMap.count(m_ulCurEditRegionId)) { return 0 ; } CUnreachRegion* pRegion = NULL; pRegion = m_UnreachRegionMap[m_ulCurEditRegionId]; if(pRegion) { m_ulCurEditPointId = pRegion->AddNewPoint(position); if( m_ulCurEditPointId > 0 ) { //添加成功了 if( position.y == -100000.0f ) { pRegion->GetPointInfoById( m_ulCurEditPointId )->SetValuedY( false ); } } return m_ulCurEditPointId; } return 0; }
void CNpcPatrolAction::ChangeCurEditPointPos(unsigned long ulRegionId, unsigned long ulPointId, Ogre::Vector3 position) { CUnreachRegion* pRegion = NULL; CPointInfo* pPoint = NULL; // 得到当前正在编辑的区域的信息. pRegion = GetRegionById(ulRegionId); if(pRegion) { pPoint = pRegion->GetPointInfoById(ulPointId); if(pPoint) { // 查找这个点的下标值. int iIndex = -1; POINT_MAP::iterator it; POINT_MAP::iterator itEnd; itEnd = pRegion->m_pointMap.end(); for(it = pRegion->m_pointMap.begin(); it != itEnd; it++) { iIndex++; if(ulPointId == it->first) { break; } } pPoint->SetPos(position); // 如果下标存在 if((-1 != iIndex)&&(iIndex < (int)pRegion->m_pLineShape->m_pointArray.size())) { pRegion->m_pLineShape->m_pointArray[iIndex] = position; pRegion->m_pLineShape->FillPointData(); //pRegion->ReShapeArea(); } }// if(pPoint) }// if(pRegion) }
// 记录当前操作前一次点的位置. void CNpcPatrolAction::RecordPreDoPointPos() { CUnreachRegion* pRegion = NULL; CPointInfo* pPoint = NULL; // 得到当前正在编辑的区域的信息. pRegion = GetRegionById(m_ulCurEditRegionId); if(pRegion) { pPoint = pRegion->GetPointInfoById(m_ulCurEditPointId); if(pPoint) { m_preDoPointPos = pPoint->m_Position; }// if(pPoint) }// if(pRegion) }
// 选择一个点. void CNpcPatrolAction::SelPoint(unsigned long ulPointId) { m_ulCurEditPointId = ulPointId; CUnreachRegion* pRegion = NULL; CPointInfo* pPoint = NULL; // 得到当前正在编辑的区域的信息. pRegion = GetRegionById(m_ulCurEditRegionId); if(pRegion) { pRegion->SetPrePointMaterial(); pRegion->m_ulCurEditPointId = m_ulCurEditPointId; pPoint = pRegion->GetPointInfoById(ulPointId); if(pPoint) { pPoint->SetSelMaterial(); } } }
// 改变当前编辑的点的位置 void CNpcPatrolAction::ChangeCurEditPointPos(const Point& pt) { CUnreachRegion* pRegion = NULL; CPointInfo* pPoint = NULL; // 得到当前正在编辑的区域的信息. pRegion = GetRegionById(m_ulCurEditRegionId); if(pRegion) { pPoint = pRegion->GetPointInfoById(m_ulCurEditPointId); if(pPoint) { // 查找这个点的下标值. int iIndex = -1; POINT_MAP::iterator it; POINT_MAP::iterator itEnd; itEnd = pRegion->m_pointMap.end(); for(it = pRegion->m_pointMap.begin(); it != itEnd; it++) { iIndex++; if(m_ulCurEditPointId == it->first) { break; } } // 得到修改后的位置. Ogre::Vector3 position; bool hit = getSceneManipulator()->getTerrainIntersects(pt.x, pt.y, position); if(hit) { //暂时把判断能否添加一个点去掉. //if(pRegion->CanChangePointPos(iIndex, position)) { // 修改新的点的位置. pPoint->SetPos(position); // 当前编辑的点的位置. m_curPointPos = position; if(it != itEnd) { // 如果下标存在 if((-1 != iIndex)&&(iIndex < (int)pRegion->m_pLineShape->m_pointArray.size())) { pRegion->m_pLineShape->m_pointArray[iIndex] = position; pRegion->m_pLineShape->FillPointData(); //pRegion->ReShapeArea(); } } }// if(pRegion->CanChangePointPos(iIndex, position)) }// if(hit) }// if(pPoint) }// if(pRegion) }