为Vega Prime 2.0窗口添加鼠标函数

//自定义一个类

 


#include <vpInputMouse.h>
class WxpMouseInputObserver: public vpInputSourceBoolean::Subscriber,
                                                           public vpInputSourceFloat::Subscriber,
                                                           public vpInputSourceInteger::Subscriber,
                                                           public vsChannel::Subscriber
{
public:


WxpMouseInputObserver::WxpMouseInputObserver(void)
{
  ValX=0;
  ValY=0;
  LeftButtonDown=false;
  RightButtonDown=false;
}

WxpMouseInputObserver::~WxpMouseInputObserver(void)
{
}

 private:
         int ValX;                                           //   X坐标
         int ValY;                                            //  Y坐标
         bool LeftButtonDown;                  //   左键按下
         bool RightButtonDown;              //   右键按下


 
 void notify(vsChannel::Event event, const vsChannel *channel, vrDrawContext *context)
 {}
 
 virtual void notify(vsChannel::Event, const vsChannel *,vsTraversalCull *)
  {
  }
  /**
     * notify method to catch boolean source subscriber events
     */
    void notify(vpInputSourceBoolean::Event event, vpInputSourceBoolean *source)
    {
   //PublicMember::TPS_pObject_observer->setTranslateZ(2,true);
  CString name=source->getName();
  int val=source->getValue();

  if(name=="vpInputMouse::SOURCE_BOOLEAN_BUTTON_LEFT")
  {
   if(val==1)   
   LeftButtonDown=true;
   
   if(val==0)
     LeftButtonDown=false;


  }

  //
  if(name=="vpInputMouse::SOURCE_BOOLEAN_BUTTON_RIGHT")
  {
   if(val==1)
       RightButtonDown=true; 
   if(val==0)
       RightButtonDown=false; 
     
  }

       
    }
   
    /**
     * notify method to catch float source subscriber events
     */
    void notify(vpInputSourceFloat::Event, vpInputSourceFloat *source)
    {
       

    }

    /**
     * notify method to catch integer source subscriber events
     */
    void notify(vpInputSourceInteger::Event, vpInputSourceInteger *source)
    {

   char tt[200];
   sprintf(tt,"name:%s \nvalue:%f\n", source->getName(), source->getValue());
  //AfxMessageBox(tt);


  CString name=source->getName();
  int val=source->getValue();

        if(val>1740)
    return ;
  //左键控制 y  z面的位置
  if ( (name=="vpInputMouse::SOURCE_INTEGER_POSITION_X") &&  LeftButtonDown )
  {
   if(val>ValX)
   {
   
               PublicMember::TPS_pObject_observer->setTranslateX(-1,true); 
   }

   if(val<ValX)
   {
   
               PublicMember::TPS_pObject_observer->setTranslateX(1,true); 
   }
   ValX=val;
   
  }

  if ( (name=="vpInputMouse::SOURCE_INTEGER_POSITION_Y") &&  LeftButtonDown )
  {
   if(val>ValY)
   {
   
               PublicMember::TPS_pObject_observer->setTranslateZ(-1,true); 
   }

   if(val<ValY)
   {
   
               PublicMember::TPS_pObject_observer->setTranslateZ(1,true); 
   }
   ValY=val;
   
  }

        //右键控制H  P  方向的转动
  if ( (name=="vpInputMouse::SOURCE_INTEGER_POSITION_X") &&  RightButtonDown )
  {
   if(val>ValX)
   {
      PublicMember::TPS_pObject_observer->setRotateR(-0.20,true); 
              
   }

   if(val<ValX)
   {
   
     PublicMember::TPS_pObject_observer->setRotateR(0.20,true); 
             
   }
   ValX=val;
   
  }

  if ( (name=="vpInputMouse::SOURCE_INTEGER_POSITION_Y") &&  RightButtonDown )
  {
   if(val>ValY)
   {
      PublicMember::TPS_pObject_observer->setRotateP(-0.20,true); 
              
   }

   if(val<ValY)
   {
   
     PublicMember::TPS_pObject_observer->setRotateP(0.20,true); 
             
   }
   ValY=val;
   
  }

       //中键滑动控制远近
   if  (name=="vpInputMouse::SOURCE_INTEGER_WHEEL_DIRECTION")
    if(val==1)
   {
    PublicMember::TPS_pObject_observer->setTranslateY(-10,true); 
   
             
   }

   if(val==-1)
   {
   
                PublicMember::TPS_pObject_observer->setTranslateY(10,true); 
   }
  
  
   
    }

 //end of class

};

 

//配置鼠标

 

 

//设置窗体
  vpWindow * vpWin= * vpWindow::begin();
  vpWin->setParent(TPS_RunningWindow);
  vpWin->setBorderEnable(false);
  vpWin->setFullScreenEnable(true);

  //设置键盘
  vpWin->setInputEnable(true);
  vpWin->setKeyboardFunc((vrWindow::KeyboardFunc)TPS_KeyboardMotor,NULL); 

  //设置鼠标函数
   WxpMouseInputObserver * wang=new WxpMouseInputObserver();

  vpChannel *chan = *vpChannel::begin();  
   chan->addSubscriber(vsChannel::EVENT_POST_DRAW,wang);
   // grab our mouse input from the first window
        vpWindow* window = vpWindow::empty() ? NULL : *vpWindow::begin();
        assert(window);

        vpChannel* channel = vpChannel::empty() ? NULL : *vpChannel::begin();
        assert(channel);

        // create a mouse
   vpInputMouse *m_mouse;
        m_mouse = new vpInputMouse();
        m_mouse->setWindow(window);
        m_mouse->setChannel(channel);
        m_mouse->ref();

        // add subscribers to the input sources so we know when a value
        // has changed
        vpInputMouse::const_iterator_source_boolean bit;
        for (bit=m_mouse->begin_source_boolean();
             bit!=m_mouse->end_source_boolean();++bit) {
            (*bit)->addSubscriber(
                vpInputSourceBoolean::EVENT_VALUE_CHANGED, wang);
        }

        vpInputMouse::const_iterator_source_float fit;
        for (fit=m_mouse->begin_source_float();
             fit!=m_mouse->end_source_float();++fit) {
            (*fit)->addSubscriber(
                vpInputSourceFloat::EVENT_VALUE_CHANGED, wang);
        }

        vpInputMouse::const_iterator_source_integer iit;
        for (iit=m_mouse->begin_source_integer();
             iit!=m_mouse->end_source_integer();++iit) {
            (*iit)->addSubscriber(
                vpInputSourceInteger::EVENT_VALUE_CHANGED, wang);
        }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值