level 9
device=SDL_GetTouchDevice(0);
EVE_fingernum=SDL_GetNumTouchFingers(device);
for(i=0;i<EVE_fingernum;i++)
{
finger=SDL_GetTouchFinger(device,i);
if(finger!=NULL)
{EVE_pos[i].id=finger->id;
EVE_pos[i].x=finger->x*S_w;
EVE_pos[i].y=finger->y*S_h;
}}
2016年01月01日 02点01分
8
level 9
event.tfinger.x获取的是各触点的中心坐标
2016年01月01日 02点01分
9
level 9
我现在要的是各触点的状态。
就是判断哪个触点被按下,被抬点,在滑动等
2016年01月01日 02点01分
10
level 9
#include<stdio.h>
#include <SDL2/SDL.h>
#include <SDL_UI.h>
char ch[2000];
struct xx
{
int state;
int x, y;
};
struct xx touch[10];
char *strs[3] = {"抬起", "按下", "划动"};
int main(int argc, char *argv[])
{
int i;
init("",720,1280);
ttf_init(50);
while (1)
{
while (SDL_PollEvent(&event))
{
if (event.type == SDL_FINGERDOWN)
{
touch[event.tfinger.fingerId].state = 1;
touch[event.tfinger.fingerId].x = event.tfinger.x*S_w;
touch[event.tfinger.fingerId].y = event.tfinger.y*S_h;
}
else if (event.type == SDL_FINGERUP)
{
touch[event.tfinger.fingerId].state = 0;
touch[event.tfinger.fingerId].x = event.tfinger.x*S_w;
touch[event.tfinger.fingerId].y = event.tfinger.y*S_h;
}
else if (event.type == SDL_FINGERMOTION)
{
touch[event.tfinger.fingerId].state = 2;
touch[event.tfinger.fingerId].x = event.tfinger.x*S_w;
touch[event.tfinger.fingerId].y = event.tfinger.y*S_h;
}
}
for(i=0;i<5;i++)
{
sprintf(ch, "第%d手指%s,坐标%d,%d;",i, strs[touch[i].state], touch[i].x, touch[i].y);SDL_SetRenderDrawColor(ren,255,0,0,255);
FillRect(site(touch[i].x,touch[i].y,20,20));
displaytext(site(0,i*30,0,30),ch,0x0,0);
}
reflush(0xffffff);
}
}
2016年01月02日 05点01分
21
这代码太危险,很可能存在未定义行为。不管它崩溃或是不崩溃都没什么好奇怪的。
2016年01月02日 06点01分
@铃铛兮 呵呵呵
2016年01月02日 06点01分
@简单aaaaaaa 首先touch很可能没初始化就使用,这将是未定义行为。 其次,fingerid没有人保证它就是0-10这种范围,然后,有可能直接导致崩溃的是str[touch[id].state],完全没有检查state的值,更别提sprintf本身的安全了。。
2016年01月02日 06点01分
@铃铛兮 考虑到你们可能只是嫌麻烦省去了越界检查。。或者有别的考虑。我也不想指指点点,反正问题能解决就够了。或许我还是太啰嗦了。
2016年01月02日 06点01分
level 5
楼主,你SDL怎么学的?看lazyfoo的英文教程?看API?
2016年06月11日 15点06分
36