开发者

Streaming data in c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 9 years ago.

Improve this question

This is the code that streams the data i see when i run sampleclient.exe for a rigid body? What if I wanted to use the x y z qx qy qz qw point for other calculation? are they stored in an array i can access to do calculations in real time? I'm kinda of new at this, isn't RigidBodies[i] an array, but it value keeps pointing to a different value...

printf("Rigid Bodies [Count=%d]\n", data->nRigidBodies);

for(i=0; i < data->nRigidBodies; i++)
{
    printf("Rigid Body [ID=%d  Error=%3.2f]\n", data->RigidBodies[i].ID,  
    data->RigidBodies[i].MeanError);

    printf("\tx\ty\tz\tqx\tqy\tqz\tqw\n");

    printf("\t%3.2f\t%3.2f\t%3.2f\t%3.2f\t%开发者_JS百科3.2f\t%3.2f\t%3.2f\n",
        data->RigidBodies[i].x,
        data->RigidBodies[i].y,
        data->RigidBodies[i].z,
        data->RigidBodies[i].qx,
        data->RigidBodies[i].qy,
        data->RigidBodies[i].qz,
        data->RigidBodies[i].qw);

}


I assume you mean that the for loop prints different values each time. This is because of the line:

for(i=0; i < data->nRigidBodies; i++)   

Each time the loop runs i is incremented by one such that the array data->RigidBodies is accessed at a different index.

We could even "expand" the loop to be the following:

i=0;
printf("Rigid Body [ID=%d  Error=%3.2f]\n", data->RigidBodies[i].ID,  
data->RigidBodies[i].MeanError);
..
i=i+1;
printf("Rigid Body [ID=%d  Error=%3.2f]\n", data->RigidBodies[i].ID,  
data->RigidBodies[i].MeanError);
..

While you are using the same array each time, you are accessing a different element inside of it. The index tells us what item in the array we want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜