使用 x 和 y 坐标与 glTranslate
Using x and y coordinates with glTranslate
我有一个从我的电脑上运行的 c++ 程序,它连接到我手机上的 Android 应用程序,同时在我的电脑上打开 OpenGL 中的图像。目前,openGL中的图像使用键盘按钮进行翻译和放大。 X 和 y 坐标从我的安卓设备流式传输到终端。
有没有办法获取这些原始的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
解决了。我添加了此代码..
// 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 被划分为缩放到屏幕 im 使用。
相关文章:
- QGraphicsPolygonItem在拖动时未更新QPolygonF坐标
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- UE4-如何在给定4个屏幕坐标的情况下缩放纹理或材质
- OpenGL 4.3 错误地将第 4 个纹理坐标映射到与第 3 个纹理坐标相同的位置
- 比较两个节点坐标的最佳方法是什么?
- 在 OpenGL 中将笛卡尔世界坐标转换为球面局部坐标
- SDL2 调整窗口大小后如何缩放鼠标坐标?
- 如何在C++中获取坐标?
- 如何将 x.y 坐标的值存储在不同的数组中
- 如何将鼠标坐标转换为"mm"
- 重心坐标并不总是有效(3d)
- 尝试渲染像素坐标时,简单线条渲染失败
- 使用 GTK3 C++获取指针坐标
- 从 CGAL 3D 网格生成中获取顶点坐标的 -6.27744e+66:mesh_implicit_sphere示例
- 我想制作设置鼠标回调函数,以便在仍然按下鼠标左键时连续传递坐标
- 将鼠标悬停在图片框上时,如何显示带有 x-y 坐标的十字准线光标?
- 跳转到通过输入坐标定义的控制台屏幕位置
- QImage::p ixel 和 QImage::setPixel 坐标超出范围误差
- 如何从 3d 对象文件中获取 3d 坐标
- 使用 x 和 y 坐标与 glTranslate