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

2023-12-14 12:08
文章标签 函数 窗口 鼠标 prime 2.0 vega

本文主要是介绍为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);
        }

 

 

这篇关于为Vega Prime 2.0窗口添加鼠标函数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/492460

相关文章

Python itertools中accumulate函数用法及使用运用详细讲解

《Pythonitertools中accumulate函数用法及使用运用详细讲解》:本文主要介绍Python的itertools库中的accumulate函数,该函数可以计算累积和或通过指定函数... 目录1.1前言:1.2定义:1.3衍生用法:1.3Leetcode的实际运用:总结 1.1前言:本文将详

轻松上手MYSQL之JSON函数实现高效数据查询与操作

《轻松上手MYSQL之JSON函数实现高效数据查询与操作》:本文主要介绍轻松上手MYSQL之JSON函数实现高效数据查询与操作的相关资料,MySQL提供了多个JSON函数,用于处理和查询JSON数... 目录一、jsON_EXTRACT 提取指定数据二、JSON_UNQUOTE 取消双引号三、JSON_KE

MySQL数据库函数之JSON_EXTRACT示例代码

《MySQL数据库函数之JSON_EXTRACT示例代码》:本文主要介绍MySQL数据库函数之JSON_EXTRACT的相关资料,JSON_EXTRACT()函数用于从JSON文档中提取值,支持对... 目录前言基本语法路径表达式示例示例 1: 提取简单值示例 2: 提取嵌套值示例 3: 提取数组中的值注意

Java function函数式接口的使用方法与实例

《Javafunction函数式接口的使用方法与实例》:本文主要介绍Javafunction函数式接口的使用方法与实例,函数式接口如一支未完成的诗篇,用Lambda表达式作韵脚,将代码的机械美感... 目录引言-当代码遇见诗性一、函数式接口的生物学解构1.1 函数式接口的基因密码1.2 六大核心接口的形态学

Oracle的to_date()函数详解

《Oracle的to_date()函数详解》Oracle的to_date()函数用于日期格式转换,需要注意Oracle中不区分大小写的MM和mm格式代码,应使用mi代替分钟,此外,Oracle还支持毫... 目录oracle的to_date()函数一.在使用Oracle的to_date函数来做日期转换二.日

bat脚本启动git bash窗口,并执行命令方式

《bat脚本启动gitbash窗口,并执行命令方式》本文介绍了如何在Windows服务器上使用cmd启动jar包时出现乱码的问题,并提供了解决方法——使用GitBash窗口启动并设置编码,通过编写s... 目录一、简介二、使用说明2.1 start.BAT脚本2.2 参数说明2.3 效果总结一、简介某些情

基于Redis有序集合实现滑动窗口限流的步骤

《基于Redis有序集合实现滑动窗口限流的步骤》滑动窗口算法是一种基于时间窗口的限流算法,通过动态地滑动窗口,可以动态调整限流的速率,Redis有序集合可以用来实现滑动窗口限流,本文介绍基于Redis... 滑动窗口算法是一种基于时间窗口的限流算法,它将时间划分为若干个固定大小的窗口,每个窗口内记录了该时间

C++11的函数包装器std::function使用示例

《C++11的函数包装器std::function使用示例》C++11引入的std::function是最常用的函数包装器,它可以存储任何可调用对象并提供统一的调用接口,以下是关于函数包装器的详细讲解... 目录一、std::function 的基本用法1. 基本语法二、如何使用 std::function

hdu1171(母函数或多重背包)

题意:把物品分成两份,使得价值最接近 可以用背包,或者是母函数来解,母函数(1 + x^v+x^2v+.....+x^num*v)(1 + x^v+x^2v+.....+x^num*v)(1 + x^v+x^2v+.....+x^num*v) 其中指数为价值,每一项的数目为(该物品数+1)个 代码如下: #include<iostream>#include<algorithm>

usaco 1.3 Prime Cryptarithm(简单哈希表暴搜剪枝)

思路: 1. 用一个 hash[ ] 数组存放输入的数字,令 hash[ tmp ]=1 。 2. 一个自定义函数 check( ) ,检查各位是否为输入的数字。 3. 暴搜。第一行数从 100到999,第二行数从 10到99。 4. 剪枝。 代码: /*ID: who jayLANG: C++TASK: crypt1*/#include<stdio.h>bool h