void RadarAdapter::updateTime(osg::Node *node, const QVariantMap &data, double time)
{
QVariantMap scanDat = data["scan"].toMap();
double start = scanDat["start"].toDouble();
double period = scanDat["period"].toDouble();
double speed = scanDat["speed"].toDouble();
double stop = start+period;
double theta_start = scanDat["theta-start"].toDouble();
double theta_step = scanDat["theta-step"].toDouble();
double theta_end = scanDat["theta-end"].toDouble();
double theta_all = theta_end-theta_start;
double phi_start = scanDat["phi-start"].toDouble();
double phi_step = scanDat["phi-step"].toDouble();
double phi_end = scanDat["phi-end"].toDouble();
double phi_all = phi_end-phi_start;
if (time < start) //stop before beginning
time = start;
else if (time > stop) //stop at end
time = stop;
double deg_runed = time*speed;
double deg = theta_all + (theta_all/theta_step+1) * phi_all;
double time_signal = deg/speed;
// int circle = deg_runed/deg;
while(deg_runed > deg){
deg_runed = deg_runed - deg;
time = time - time_signal;
}
double theta = 0.0;
double phi = 0.0;
double deg_signal = theta_step+phi_all;
int theta_n = deg_runed/deg_signal;
double deg1 = deg_runed - theta_n*deg_signal;
int phi_n = deg1/phi_all;
// if(!(circle%2)){ //判断跑的圈数为偶数,则是从Theta_start开始
if(phi_n <= 1) //如果phi_n = 0,则说明点在phi上移动
{
if(!(theta_n%2)) //如果theta走的步进数为偶数,则当前phi是从phi_start开始
phi = deg1;
else //否则是从phi_stop开始
phi = phi_all - deg1;
theta =theta_start + theta_n * theta_step;
}else
{
theta_n += 1; //如果phi_n > 0, 则 说明点在theta上移动
if(!(theta_n%2)) //同上
phi = phi_start;
else
phi = phi_all;
theta =theta_n*theta_step + (deg1-phi_n*phi_all);
}
// }else //如果是奇数圈,则是从theta_stop开始 根据界面参数,不存在这种情况了
// {
// if(!((int)(theta_all/theta_step)%2)) //如果theta的步进数为偶数,则最后phi的点是phi_stop
// {
// if(phi_n <= 1) //如果phi
// {
// if(!(theta_n%2))
// phi = phi_all - deg1;
// else
// phi = deg1;
// theta = theta_all - (1+ theta_n) * theta_step;
// }else
// {
// theta_n += 1;
// if(!(theta_n%2))
// phi = phi_all;
// else
// phi = phi_start;
// theta = theta_all - theta_n*theta_step + (deg1-phi_n*phi_all);
// }
// }else //如果theta的步进为奇数,则最后phi的点是phi_start
// {
// if(phi_n == 0) //如果phi
// {
// if(!(theta_n%2))
// phi = phi_all - deg1;
// else
// phi = deg1;
// theta = theta_all - theta_n * theta_step;
// }else
// {
// theta_n += 1;
// if(!(theta_n%2))
// phi = phi_start;
// else
// phi = phi_all;
// theta = theta_all - theta_n*theta_step + (deg1-phi_n*phi_all);
// }
// }
// }
QVariantMap rotDat = data["rotate"].toMap();
//base rotate
double rx = rotDat.value("rot-x").toDouble()*0.017453292519943295; //deg-->rad
double ry = rotDat.value("rot-y").toDouble()*0.017453292519943295;
double rz = rotDat.value("rot-z").toDouble()*0.017453292519943295;
osg::Node *obj = getChild(node->asGroup(), "#antenna");
osg::MatrixTransform *mt = obj->asTransform()->asMatrixTransform();
//parse current, get scale
osg::Vec3 trans, scale;
osg::Quat rot, so;
mt->getMatrix().decompose(trans, rot, scale, so);
mt->setMatrix(osg::Matrix::rotate(rx, osg::X_AXIS) * \
osg::Matrix::rotate(ry, osg::Y_AXIS) * \
osg::Matrix::rotate(rz, osg::Z_AXIS) * \
osg::Matrix::rotate(theta*0.017453292519943295, osg::X_AXIS) * \
osg::Matrix::rotate(phi*0.017453292519943295, osg::Y_AXIS) * \
osg::Matrix::scale(scale) * \
osg::Matrix::translate(trans));
}