MapX 기반 미사일 공격 샌 드 디스크 데모 시스템 코드
- ///////////////////////////////////////////////////// ////////////////////////////////
- //
- typedef struct _Position
- {
- double m_longtidude; //
- double m_latitude; //
- bool flag; //
-
- } Position;
-
- typedef std::vector<Position> _planePositionVector; //
- typedef std::vector<Position> _missilePositionVector; //
-
- ///////////////////////////////////////////////////////////////////////////////////////////
둘. 인터페이스
- ////////////////////////////////// ///////////////////
-
- public:
- int LoadGeoData(CString file); //
- void CreateLayer(CMapXLayer* layer, CString str, int id ); //
- void DrawPoint(CMapXLayer* layer,Position position, CString bitName); //
- void DrawLine(CMapXLayer* layer, Position startPoint, Position endPoint, int lineColor, int lineStyle);//
-
-
- void ShowPlaneTrace(_planePositionVector &planeVector); //
- void ShowMissileTrace(_missilePositionVector &missileVector); //
-
- void RecordPlaneTrace(_planePositionVector &planeVector, Position &positionStart, int count); //
- void RecordMissileTrace(_missilePositionVector &missileVector, Position &positionStart, int count); //
-
- void PlaneNextPosition(Position &startPosition, Position &endPosition); //
- void MissileNextPosition(Position &startPosition, Position &endPosition); //
-
- public:
-
- CMapXLayer m_planeLayer; //
- CMapXLayer m_missileLayer; //
- CMapXLayer m_trackLayer; //
- CMapX m_map; //
인터페이스 구현
-
- //
- int CLmtestView::LoadGeoData(CString file)
- {
- if (!m_map.Create(NULL,WS_VISIBLE,CRect(50,50,400,400),this, IDC_MAP))
- {
- //
- return -1;
- }
- m_map.SetGeoSet(file);
- m_map.SetTitleText(" V1.0");
- //CreateDefenseLayer(); //
- CreateLayer(&m_planeLayer,"PLANE_LAYER",2); //
- CreateLayer(&m_missileLayer,"MISSILE_LAYER",3); //
- CreateLayer(&m_trackLayer,"TRACK_LAYER",4); //
- m_map.SetCurrentTool(miPanTool);
- return 0;
- }
-
- //
- void CLmtestView::CreateLayer(CMapXLayer* layer, CString str, int id )
- {
- CString geo=m_map.GetGeoSet();
- if(geo.IsEmpty())
- {
- AfxMessageBox(_T(" , "));
- return;
- }
- try
- {
- m_map.GetLayers().CreateLayer(_T(str), NULL, id);
- *layer = m_map.GetLayers().Item(_T(str));
- }
- catch(COleDispatchException *e)
- {
- e->ReportError();
- e->Delete();
- }
- catch(COleException *e)
- {
- e->ReportError();
- e->Delete();
- }
-
- }
-
-
- //
-
- void CLmtestView::OnPlane()
- {
- // TODO: Add your command handler code here
-
- //
- SetTimer(ID_TIMER_PLANE,1000,NULL);
- }
-
- void CLmtestView::OnMissile()
- {
- // TODO: Add your command handler code here
- SetTimer(ID_TIMER_MISSILE,1000,NULL);
- }
-
- void CLmtestView::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- //
-
- if (ID_TIMER_PLANE == nIDEvent)
- {
- static bool binit = false;
- if (!binit) //
- {
- //
- Position planePositionStart ={87.1875,43.961191,FALSE};
-
- //
- RecordPlaneTrace(planePositionVector,planePositionStart,10);
-
- binit = true;
-
- }
- //
- ShowPlaneTrace(planePositionVector);
- }
-
- else if(ID_TIMER_MISSILE == nIDEvent)
- {
- static bool binit = false;
- if (!binit) //
- {
- //
- Position missilePositionStart ={128.71582,46.498392,FALSE};
-
- //
- RecordMissileTrace(missilePositionVector,missilePositionStart,10);
-
- binit = true;
-
- }
- //
- ShowMissileTrace(missilePositionVector);
- }
-
- CView::OnTimer(nIDEvent);
- }
-
-
- //
- void CLmtestView::DrawLine(CMapXLayer* layer, Position startPoint, Position endPoint, int lineColor, int lineStyle)
- {
- CMapXStyle lineSty; //
-
- COleVariant vt;
- vt.vt=VT_DISPATCH;
-
- CMapXFeature newFeature; //
-
- CMapXPoint pt; //
- CMapXPoints pts; //
- pt.CreateDispatch(pt.GetClsid());
- pts.CreateDispatch(pts.GetClsid());
-
- pts.RemoveAll();
- pt.Set(startPoint.m_longtidude, startPoint.m_latitude); //
- pts.Add(pt);
- pt.Set(endPoint.m_longtidude,endPoint.m_latitude); //
- pts.Add(pt);
-
- vt.pdispVal=pts.m_lpDispatch;
- vt.pdispVal->AddRef();//
-
- CMapXFeature sidefeature=m_map.GetFeatureFactory().CreateLine(vt); //
-
- lineSty=sidefeature.GetStyle(); //
- lineSty.SetLineColor(lineColor);
- lineSty.SetLineStyle(lineStyle);
- sidefeature.SetStyle(lineSty.m_lpDispatch);
- sidefeature=(*layer).AddFeature(sidefeature); //
- sidefeature.Update();
- // long sid=sidefeature.GetFeatureID();// ID , ID ,
- // m_sidearray.Add(sid);
-
- m_map.Refresh();
-
- }
-
- void CLmtestView::DrawPoint(CMapXLayer* layer,Position position, CString bitName) //
- {
- //
-
- CMapXFeature ftr;
- if(!ftr.CreateDispatch (ftr.GetClsid ()))
- {
-
- TRACE(_T("SetMissilePositon FAILED
"));
-
- }
- try
- {
- ftr.Attach (m_map.GetDispatch ());
- //
- CMapXStyle style=ftr.GetStyle ();
- style.SetSymbolType(miSymbolTypeBitmap);
- style.SetSymbolBitmapSize (24);
- style.SetSymbolBitmapTransparent (TRUE);
- style.SetSymbolBitmapName(_T(bitName));
- ftr.GetPoint ().Set(position.m_longtidude, position.m_latitude); //
- ftr=(*layer).AddFeature(ftr);//
- m_map.Refresh ();
- }
- catch(COleDispatchException *e)
- {
- e->ReportError();
- e->Delete();
-
- }
- catch(COleException *e)
- {
- e->ReportError();
- e->Delete();
-
- }
-
- }
-
-
- //
- void CLmtestView::PlaneNextPosition(Position &startPosition, Position &endPosition)
- {
- static int flag = 1; //
- if (flag<3)
- {
- static double longtidudeStep = 2.03;
- static double latitudeStep = 2.26;
-
- endPosition.flag = false;
- endPosition.m_longtidude = startPosition.m_longtidude + longtidudeStep; // +5
- endPosition.m_latitude = startPosition.m_latitude - latitudeStep; // -6
-
- longtidudeStep += 0.89;
- latitudeStep += 0.35;
- flag++;
- }
- else if(flag <4)
- {
- static double longtidudeStep = 2.03;
- static double latitudeStep = 4.26;
-
- endPosition.flag = false;
- endPosition.m_longtidude = startPosition.m_longtidude + longtidudeStep; // +5
- endPosition.m_latitude = startPosition.m_latitude + latitudeStep; // -6
-
- longtidudeStep += 0.89;
- latitudeStep += 0.35;
- flag++;
- }
- else
- {
- static double longtidudeStep = 2.03;
- static double latitudeStep = 2.26;
-
- endPosition.flag = false;
- endPosition.m_longtidude = startPosition.m_longtidude + longtidudeStep; // +5
- endPosition.m_latitude = startPosition.m_latitude - latitudeStep; // -6
-
- longtidudeStep += 0.89;
- latitudeStep += 0.35;
- flag = 1;
-
- }
-
- // endPosition.flag = false;
- // endPosition.m_longtidude = startPosition.m_longtidude + 1.35;
- // endPosition.m_latitude = 7.347826*(endPosition.m_longtidude)*(endPosition.m_longtidude)-1563.31770723*(endPosition.m_longtidude)+82873.51;
- //
-
- }
-
- //
- void CLmtestView::MissileNextPosition(Position &startPosition, Position &endPosition)
- {
- static int flag = 1; //
- if (flag<3)
- {
- static double longtidudeStep = 2.03;
- static double latitudeStep = 2.26;
-
- endPosition.flag = false;
- endPosition.m_longtidude = startPosition.m_longtidude - longtidudeStep; // +5
- endPosition.m_latitude = startPosition.m_latitude - latitudeStep; // -6
-
- longtidudeStep += 0.89;
- latitudeStep += 0.35;
- flag++;
- }
- else if(flag <4)
- {
- static double longtidudeStep = 2.03;
- static double latitudeStep = 4.26;
-
- endPosition.flag = false;
- endPosition.m_longtidude = startPosition.m_longtidude- longtidudeStep; // +5
- endPosition.m_latitude = startPosition.m_latitude + latitudeStep; // -6
-
- longtidudeStep += 0.89;
- latitudeStep += 0.35;
- flag++;
- }
- else
- {
- static double longtidudeStep = 2.03;
- static double latitudeStep = 2.26;
-
- endPosition.flag = false;
- endPosition.m_longtidude = startPosition.m_longtidude - longtidudeStep; // +5
- endPosition.m_latitude = startPosition.m_latitude - latitudeStep; // -6
-
- longtidudeStep += 0.89;
- latitudeStep += 0.35;
- flag = 1;
-
- }
-
-
-
- }
-
- //
- void CLmtestView::ShowPlaneTrace(_planePositionVector &planeVector)
- {
- static int i = 0;
- planeVector[0].flag =TRUE;
-
- for (i; i<planeVector.size(); i++)
- {
- if (TRUE == planeVector[i].flag)
- {
- //
- DrawPoint(&m_planeLayer,planeVector[i],"FIRE1-32.BMP");
-
- //
- m_map.GetLayers().Item(2).GetSelection().ClearSelection();
- CMapXFeatures fts = m_map.GetLayers().Item(2).AllFeatures();
- m_map.GetLayers().Item(2).GetSelection().Add(fts.Item(i+1));
- }
- else
- {
- break;
- }
- }
- if (i<planeVector.size())
- {
- planeVector[i].flag = true; //
- }
-
- //
- if (i>1)
- {
- DrawLine(&m_trackLayer, planeVector[i-2], planeVector[i-1],miColorBlue,99);
- }
-
- }
-
- //
- void CLmtestView::ShowMissileTrace(_missilePositionVector &missileVector)
- {
- static int i = 0;
- missileVector[0].flag =TRUE;
-
- for (i; i<missileVector.size(); i++)
- {
- if (TRUE == missileVector[i].flag)
- {
- //
- DrawPoint(&m_missileLayer,missileVector[i],"MISSILE.BMP");
-
- //
- m_map.GetLayers().Item(3).GetSelection().ClearSelection();
- CMapXFeatures fts = m_map.GetLayers().Item(3).AllFeatures();
- m_map.GetLayers().Item(3).GetSelection().Add(fts.Item(i+1));
- }
- else
- {
- break;
- }
- }
- if (i<missileVector.size())
- {
- missileVector[i].flag = true; //
- }
-
- //
- if (i>1)
- {
- DrawLine(&m_trackLayer, missileVector[i-2], missileVector[i-1],miColorRed,57);
- }
- }
-
- //
- void CLmtestView::RecordPlaneTrace(_planePositionVector &planeVector,Position &positionStart,int count)
- {
- int vectorlength; //
-
- Position tempStartPosition; //
- tempStartPosition = positionStart;
-
- //
- planeVector.push_back(positionStart);
-
- while ((vectorlength=planeVector.size()) < count)
- {
- Position tempEndPosition; //
- PlaneNextPosition(tempStartPosition,tempEndPosition); //
- planeVector.push_back(tempEndPosition);//
- tempStartPosition = tempEndPosition;
- }
- }
-
- //
- void CLmtestView::RecordMissileTrace(_missilePositionVector &missileVector,Position &positionStart, int count)
- {
- int vectorlength; //
-
- Position tempStartPosition; //
- tempStartPosition = positionStart;
-
- //
- missileVector.push_back(positionStart);
-
- while ((vectorlength=missileVector.size()) < count)
- {
- Position tempEndPosition; //
- MissileNextPosition(tempStartPosition,tempEndPosition); //
- missileVector.push_back(tempEndPosition);//
- tempStartPosition = tempEndPosition;
- }
- }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
양식 제출 후 제출 버튼 비활성화텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.