-1

我有一个在我的电脑上运行的 c++ 程序,它连接到我手机上的 Android 应用程序,同时在我的电脑上的 OpenGL 中打开一个图像。目前,openGL 中的图像使用键盘按钮进行翻译和放大。X 和 y 坐标从我的 android 设备流式传输到终端。

有没有办法获取这些原始 x 和 y 值并使用它们在 OpenGL 中转换我的图像?因此,用户从 Android 设备控制 PC 上的图像。我猜这些值需要以某种方式进行缩放和标准化?

如果它更清楚,我可以提供我的代码或部分代码。

using namespace std;
#define USE_TOMS_OGL


class device_info {
    public:
    char            *name;

    vrpn_Analog_Remote  *ana;


};
const unsigned MAX_DEVICES = 2;

float translateX = 0.0;
float translateY = 0.0;
float translateZ = 1.0;
float imgScale = 0.8;
float panX = 0.125; 
float panY = 0.125; 
float zoomFactor = 0.01; 



using namespace std;

struct Image {                   // stores image data
   unsigned long sizeX;
   unsigned long sizeY;
   char *data;
};

void display(void)
{


    // Translation and Scaling
    glTranslatef(translateX, translateY, translateZ);
    glScalef(imgScale, imgScale, 0.0);

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture);


void keyboard(unsigned char key, int x, int y)
{
   switch (key) {
      case 27:
         exit(0);
         break;
      case 'x':
        imgScale += zoomFactor;
        glutPostRedisplay();
         break;
      case 'z':
            imgScale -= zoomFactor;
            glutPostRedisplay();
         break;
      case 'w':
         translateY += panY;
         glutPostRedisplay();
         break;
      case 's':
         translateY -= panY;
         glutPostRedisplay();
         break;
      case 'a':
         translateX -= panX;
         glutPostRedisplay();
         break;
      case 'd':
         translateX += panX;
         glutPostRedisplay();
         break;
      default:
         break;
   }
}

void IdleFunc(void) {
    if (accepted != 1)
    {

      unsigned i;

      // Let all the devices do their things
      for (i = 0; i < num_devices; i++) {

      device_list[i].ana->mainloop();
      //cerr << i;
      }

    //  printf("Idle function test ");

    } 
    glutPostRedisplay();
}


//Callback handlers

void    VRPN_CALLBACK handle_analog (void *userdata, const vrpn_ANALOGCB a)
{
    int i;
    const char *name = (const char *)userdata;


    printf("Input from %s:\n  \n        %5.0f", name, a.channel[0]);
    for (i = 1; i < a.num_channel; i++) {
    printf(" %5.0f \n", a.channel[1]);
    }

    printf(" \n");
}













 // main interactive loop

  printf("Press ^C to exit.\n");
  while ( ! done ) {
#ifdef USE_TOMS_OGL
      glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowSize(400,300);
    glutInitWindowPosition(200,100);
    glutCreateWindow("ImageViewer");


    init();
    glutDisplayFunc(display);

    glutKeyboardFunc(keyboard);
    glutIdleFunc(IdleFunc);
    glutMainLoop();
#else
      unsigned i;

      // Let all the devices do their things
      for (i = 0; i < num_devices; i++) {

      device_list[i].ana->mainloop();
      //cerr << i;
      }
      //cerr << endl;
#endif

  }
 return 0;
}  


// a.channel[0] =  x
// a.channel[1] =  y
// a.channel[2] =  Zoom
4

1 回答 1

1

解决了。我已经添加了这个代码..

// Translate image on screen using data from device    

    yVal = a.channel[1];
    yVal = yVal/10000;
    translateY -= yVal;

    xVal = a.channel[0];

if (xVal >0 & xVal<250){

  xVal = xVal - 300;

}        

    xVal = xVal/15000;
    translateX += xVal;

xVal 和 Yval 被划分为缩放到我使用的屏幕。

于 2012-04-19T20:21:14.150 回答