Changeset 363 in flair-src for trunk/tools/VrpnLite
- Timestamp:
- Sep 3, 2020, 8:54:16 AM (4 years ago)
- Location:
- trunk/tools/VrpnLite/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/VrpnLite/src/VrpnLite.cpp
r334 r363 37 37 Time dataSocketTimeout; 38 38 char msg[256]; 39 int src_id; 39 40 40 41 while (!ToBeStopped()) { 41 42 42 if(vrpnobjects.size()>0) { 43 43 //wait for last one to be sure all are up to date … … 51 51 } 52 52 53 ssize_t rcv=dataSocket->RecvMessage(msg,sizeof(msg),dataSocketTimeout );53 ssize_t rcv=dataSocket->RecvMessage(msg,sizeof(msg),dataSocketTimeout,NULL,NULL,&src_id); 54 54 if(rcv>0) { 55 55 string object=msg; … … 57 57 memcpy(&id,&msg[rcv-2],sizeof(id)); 58 58 dataSocket->HostToNetwork((char*)&id,sizeof(id)); 59 60 if(src_id==vrpnobjects_list.size()) { 61 vector<VrpnObject*> vect; 62 vrpnobjects_list.push_back(vect); 63 Printf("add vect %i\n",src_id); 64 } 59 65 //assume we receive it in the good order 60 if(id==vrpnobjects .size()) {61 Printf("adding object %s with id %i \n",object.c_str(),id);66 if(id==vrpnobjects_list.at(src_id).size()) { 67 Printf("adding object %s with id %i from %i\n",object.c_str(),id,src_id); 62 68 VrpnObject* vrpnobject = new VrpnObject(object,vrpnclient->GetTabWidget()); 63 69 vrpnobjects.push_back(vrpnobject); 70 vrpnobjects_list.at(src_id).push_back(vrpnobject); 64 71 }else { 65 72 Err("adding object %s failed, expected id %i, got %i\n",object.c_str(),vrpnobjects.size(),id); … … 70 77 71 78 void VrpnLite::SendObjects(void) const{ 72 int16_t position[3]; 79 return; 80 int16_t position[3]; 73 81 int16_t quaternion[4]; 74 82 Time time; 75 83 char datas[vrpnobjects.size()*(sizeof(position)+sizeof(quaternion))+ sizeof(time)]; 76 84 char *datasPtr=datas; 77 78 for (vector<VrpnObject*>::const_iterator it = vrpnobjects.begin();it < vrpnobjects.end(); it++) { 79 Vector3Df objectPosition; 80 Quaternion objectQuaternion; 81 const VrpnObject* vrpnobject=*it; 85 86 //for (vector<vector<VrpnObject*>>::const_iterator connection= vrpnobjects_list.begin();connection < vrpnobjects_list.end(); connection++) { 87 for (int i=0;i<vrpnobjects_list.size();i++) { 88 for (vector<VrpnObject*>::const_iterator it = vrpnobjects_list.at(i).begin();it < vrpnobjects_list.at(i).end(); it++) { 89 Vector3Df objectPosition; 90 Quaternion objectQuaternion; 91 const VrpnObject* vrpnobject=*it; 82 92 83 vrpnobject->GetPosition(objectPosition);84 vrpnobject->GetQuaternion(objectQuaternion);85 time=vrpnobject->GetLastPacketTime();93 vrpnobject->GetPosition(objectPosition); 94 vrpnobject->GetQuaternion(objectQuaternion); 95 time=vrpnobject->GetLastPacketTime(); 86 96 87 position[0]=ConvertPosition(objectPosition.x);88 position[1]=ConvertPosition(objectPosition.y);89 position[2]=ConvertPosition(objectPosition.z);90 quaternion[0]=ConvertQuaternion(objectQuaternion.q0);91 quaternion[1]=ConvertQuaternion(objectQuaternion.q1);92 quaternion[2]=ConvertQuaternion(objectQuaternion.q2);93 quaternion[3]=ConvertQuaternion(objectQuaternion.q3);97 position[0]=ConvertPosition(objectPosition.x); 98 position[1]=ConvertPosition(objectPosition.y); 99 position[2]=ConvertPosition(objectPosition.z); 100 quaternion[0]=ConvertQuaternion(objectQuaternion.q0); 101 quaternion[1]=ConvertQuaternion(objectQuaternion.q1); 102 quaternion[2]=ConvertQuaternion(objectQuaternion.q2); 103 quaternion[3]=ConvertQuaternion(objectQuaternion.q3); 94 104 95 for(int i=0;i<3;i++) dataSocket->HostToNetwork((char*)(&position[i]),sizeof(position[i]));96 for(int i=0;i<4;i++) dataSocket->HostToNetwork((char*)(&quaternion[i]),sizeof(quaternion[i]));105 for(int i=0;i<3;i++) dataSocket->HostToNetwork((char*)(&position[i]),sizeof(position[i])); 106 for(int i=0;i<4;i++) dataSocket->HostToNetwork((char*)(&quaternion[i]),sizeof(quaternion[i])); 97 107 98 memcpy(datasPtr,position, sizeof(position)); 99 datasPtr+=sizeof(position); 100 memcpy(datasPtr,quaternion, sizeof(quaternion)); 101 datasPtr+=sizeof(quaternion); 108 memcpy(datasPtr,position, sizeof(position)); 109 datasPtr+=sizeof(position); 110 memcpy(datasPtr,quaternion, sizeof(quaternion)); 111 datasPtr+=sizeof(quaternion); 112 } 113 dataSocket->HostToNetwork((char*)(&time),sizeof(Time)); 114 memcpy(datasPtr,&time, sizeof(time));//only one time for all VrpnObject; suppose it is the same! 115 dataSocket->SendMessage(datas,sizeof(datas),i); 102 116 } 103 104 dataSocket->HostToNetwork((char*)(&time),sizeof(Time));105 memcpy(datasPtr,&time, sizeof(time));//only one time for all VrpnObject; suppose it is the same!106 dataSocket->SendMessage(datas,sizeof(datas));107 117 } 108 118 -
trunk/tools/VrpnLite/src/VrpnLite.h
r330 r363 37 37 flair::sensor::VrpnClient* vrpnclient; 38 38 std::vector<flair::sensor::VrpnObject*> vrpnobjects; 39 std::vector<std::vector<flair::sensor::VrpnObject*>> vrpnobjects_list; 39 40 flair::core::UdpSocket* dataSocket; 40 41 void SendObjects(void) const;
Note:
See TracChangeset
for help on using the changeset viewer.