目录
使用OSGEarth进行开发时,有时需要实现点击添加的三维模型,触发某个事件。
一、实现模型点击事件
下列代码实现了点击模型时,当点击的模型名称与监听的模型名称一致时,就触发某个事件。
#include "StdAfx.h"
#include "PickNodeHandler.h"
CPickHandler::CPickHandler(osgViewer::Viewer *viewer) :m_pViewer(viewer)
{
}
CPickHandler::~CPickHandler(void)
{
}
bool CPickHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
switch (ea.getEventType())
{
case(osgGA::GUIEventAdapter::RELEASE):
{
if (ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
{
pick(ea.getX(), ea.getY());
}
return tru