为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

相关文章

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

韦季李输入法_输入法和鼠标的深度融合

在数字化输入的新纪元,传统键盘输入方式正悄然进化。以往,面对实体键盘,我们常需目光游离于屏幕与键盘之间,以确认指尖下的精准位置。而屏幕键盘虽直观可见,却常因占据屏幕空间,迫使我们在操作与视野间做出妥协,频繁调整布局以兼顾输入与界面浏览。 幸而,韦季李输入法的横空出世,彻底颠覆了这一现状。它不仅对输入界面进行了革命性的重构,更巧妙地将鼠标这一传统外设融入其中,开创了一种前所未有的交互体验。 想象

C++操作符重载实例(独立函数)

C++操作符重载实例,我们把坐标值CVector的加法进行重载,计算c3=c1+c2时,也就是计算x3=x1+x2,y3=y1+y2,今天我们以独立函数的方式重载操作符+(加号),以下是C++代码: c1802.cpp源代码: D:\YcjWork\CppTour>vim c1802.cpp #include <iostream>using namespace std;/*** 以独立函数

函数式编程思想

我们经常会用到各种各样的编程思想,例如面向过程、面向对象。不过笔者在该博客简单介绍一下函数式编程思想. 如果对函数式编程思想进行概括,就是f(x) = na(x) , y=uf(x)…至于其他的编程思想,可能是y=a(x)+b(x)+c(x)…,也有可能是y=f(x)=f(x)/a + f(x)/b+f(x)/c… 面向过程的指令式编程 面向过程,简单理解就是y=a(x)+b(x)+c(x)

使用JS/Jquery获得父窗口的几个方法(笔记)

<pre name="code" class="javascript">取父窗口的元素方法:$(selector, window.parent.document);那么你取父窗口的父窗口的元素就可以用:$(selector, window.parent.parent.document);如题: $(selector, window.top.document);//获得顶级窗口里面的元素 $(

利用matlab bar函数绘制较为复杂的柱状图,并在图中进行适当标注

示例代码和结果如下:小疑问:如何自动选择合适的坐标位置对柱状图的数值大小进行标注?😂 clear; close all;x = 1:3;aa=[28.6321521955954 26.2453660695847 21.69102348512086.93747104431360 6.25442246899816 3.342835958564245.51365061796319 4.87

OpenCV结构分析与形状描述符(11)椭圆拟合函数fitEllipse()的使用

操作系统:ubuntu22.04 OpenCV版本:OpenCV4.9 IDE:Visual Studio Code 编程语言:C++11 算法描述 围绕一组2D点拟合一个椭圆。 该函数计算出一个椭圆,该椭圆在最小二乘意义上最好地拟合一组2D点。它返回一个内切椭圆的旋转矩形。使用了由[90]描述的第一个算法。开发者应该注意,由于数据点靠近包含的 Mat 元素的边界,返回的椭圆/旋转矩形数据

Unity3D自带Mouse Look鼠标视角代码解析。

Unity3D自带Mouse Look鼠标视角代码解析。 代码块 代码块语法遵循标准markdown代码,例如: using UnityEngine;using System.Collections;/// MouseLook rotates the transform based on the mouse delta./// Minimum and Maximum values can

简单的角色响应鼠标而移动

actor类 //处理移动距离,核心是找到角色坐标在世界坐标的向量的投影(x,y,z),然后在世界坐标中合成,此CC是在地面行走,所以Y轴投影始终置为0; using UnityEngine; using System.Collections; public class actor : MonoBehaviour { public float speed=0.1f; CharacterCo