【发布时间】:2011-07-23 12:57:52
【问题描述】:
我有一个真正的机器人,它在 open gl 中订购我的虚拟机器人。我想在线显示我的主机器人(真实机器人)在奴隶(open gl中的虚拟机器人)中的每一个动作,所以我需要不断更新我的过剩窗口,实际上只要真实机器人移动我的虚拟机器人也会移动,所有这些运动应该是在线的。
我总是使用获取数据功能从主控器获取数据,但我不知道应该如何更新窗口。
这是我的代码:
************* *************** ****************强>/
void OnIdle(void){
initSocket();
printf("\n Defining Step Time Parameters and Initial Conditions for solving Dynamic equations\n");
xi=0;
xf=0.1;
printf("\n end value x : %f ",xf);
i=0; yi[i]=0;
i++;yi[i]=-1.570796;
i++;yi[i]=-1.570796;
i++;yi[i]=0;
i++;yi[i]=0;
i++;yi[i]=0;
ndata=2; fi=1;
double counter=0.1;
Eqdifp(v1,v2,v3,v4,v5,v6,xi,xf,yi,ndata,p,fi);
for(int i=0;i<50;i++)
//while(1)
{
getData();
printf("\n");
for(int i=0;i<6; i++)
{
printf("%d = %.3f\n", i,drecvbuf[i]);
}
printf("\n");
yi[0]=v1[ndata];
yi[1]=v2[ndata];
yi[2]=v3[ndata];
yi[3]=v4[ndata];
yi[4]=v5[ndata];
yi[5]=v6[ndata];
printf("my nadata %f\n",v1[ndata]);
counter=counter+0.1;
Eqdifp(v1,v2,v3,v4,v5,v6,xi,xf,yi,ndata,p,fi);
glutPostRedisplay();
}
}
/////////////////////////////////////////////////////
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(900,500);
int u=glutCreateWindow("3DOF robot");
myinit();
createMenu();
glutIdleFunc (OnIdle);
glutDisplayFunc(Display);
glutReshapeFunc(reshape);
glutKeyboardFunc(KeyDown);
glutMainLoop();
System::Timers::Timer^ aTimer = gcnew System::Timers::Timer( 100 );
// Hook up the Elapsed event for the timer.
aTimer->Elapsed += gcnew System::Timers::ElapsedEventHandler( OnTimedEvent );
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer->Enabled = true;
return 0;
}
【问题讨论】:
-
不想这样标记它,因为我不熟悉,但
System::Timers::Timer^ aTimer = gcnew System::Timers::Timer( 100 );对我来说似乎是 C++/CLI? -
@Bart 一看到
^,那肯定是C++/CLI。 -
实际上,
gcnew是 C++/CLI 更强大的指标。^是标准 C++ 中的有效运算符。 -
@Ben 是的,你是对的,没有考虑过异或。