In a planar simulation scenario, I can modify the position of nodes by using getDisplayString() ->setTagArg.
cModule* parents = getParentModule(); //找到应用层app是UdpSink的节点
auto dispStr = parents->getDisplayString(); //显示字符串
std::cout<<dispStr<<std::endl;
double x_coord = atof(dispStr.getTagArg("p", 0));
double y_coord= atof(dispStr.getTagArg("p", 1));
double z_coord= atof(dispStr.getTagArg("p", 2));
//更新移动节点的位置
dispStr.setTagArg("p", 0, std::to_string(x).c_str());
dispStr.setTagArg("p", 1, std::to_string(y).c_str());
dispStr.setTagArg("p", 2, std::to_string(z).c_str());
parents->setDisplayString(dispStr.str());
std::cout<<x_coord<<std::endl;
"However, my simulation requires a 3D scene, so I modeled the example of showcases/mobility/spatial and set the scene of" Integrated OsgVisualizer "under OSG, but I printed the display string of the node."
auto dispStr = parents->getDisplayString(); // display string
std::cout<<dispStr<<std::endl;
It appears to have no p attribute. Is it like this? Therefore, I cannot update the node position in a 3D scene in this way now. If I want to continue through this method, what should I do. I hope to receive your advice and help. Thank you
You can add the tag that you require using insertTag()
, for example:
cModule* parents = getParentModule();
auto &dispStr = parents->getDisplayString();
dispStr.insertTag("p");
dispStr.setTagArg("p", 0, x); // x is int
dispStr.setTagArg("p", 1, y);
Notes:
setTagArg()
may take a long number as an argumentp[2]
represents an arrangement of submodule vectors, not z index