在3D环境下获取面上的点击位置,该处理需要依托于输入面的Agent:
// 面输入Agent
_pPlaneAgent = new CATPathElementAgent ("PlaneAgent");
if (NULL != _pPlaneAgent)
{
_pPlaneAgent -> SetOrderedElementType (CATPlane::ClassName());
_pPlaneAgent->SetBehavior(CATDlgEngWithPrevaluation | CATDlgEngWithCSO | CATDlgEngOneShot);
}
建立其关联响应函数:
AddTransition( initialState, initialState,
IsOutputSetCondition (_pPlaneAgent),
Action ((ActionMethod) &TSTFaceDirectionCmd::ActionFaceInout));
头文件中添加:
#include "CATEventSubscriberTypedefs.h"
#include "CATViewer.h"
······
CATViewer* _pCurrentView;
CATCallback _ViewFeedBack;
Cpp中:对于Pick点坐标的求解需要附加到相对应的面输入的Agent响应函数:
_pPlaneAgent->InitializeAcquisition();
//////////////////////////////////////////////////////////////////////////
// pick点的实验代码
// 添加一个Callback响应点的获取
CATFrmLayout* pCurrentLayout = CATFrmLayout::GetCurrentLayout();
if (NULL == pCurrentLayout)
{
return FALSE;
}
CATFrmWindow* pCurrentWindow = pCurrentLayout->GetCurrentWindow();
if (NULL == pCurrentWindow)
{
return FALSE;
}
_pCurrentView = pCurrentWindow->GetViewer();
if (NULL == _pCurrentView)
{
return FALSE;
}
_pCurrentView->SetFeedbackMode(TRUE);
_ViewFeedBack = ::AddCallback (this,_pCurrentView, CATViewer::VIEWER_FEEDBACK_UPDATE(),
(CATSubscriberMethod)&TSTFaceDirectionCmd::OnViewFeedbackCB);
添加相对应的响应函数:
void TSTFaceDirectionCmd::OnViewFeedbackCB(
CATCallbackEvent event,
void* client,
CATNotification *iNotification,
CATSubscriberData data,
CATCallback callbcak)
{
_pCurrentView->SetFeedbackMode(FALSE);
::RemoveCallback(this,_pCurrentView,_ViewFeedBack);
CATVisViewerFeedbackEvent* pFeedbackEvent = NULL;
pFeedbackEvent = (CATVisViewerFeedbackEvent*) iNotification;
CATGraphicElementIntersection* pIntersection = pFeedbackEvent->GetIntersection();
double PtrPoint[3];
PtrPoint[0] = pIntersection->point.GetX();
PtrPoint[1] = pIntersection->point.GetY();
PtrPoint[2] = pIntersection->point.GetZ();
return;
}