Exemplo n.º 1
0
void SkServer::getExtFrame()
{
  QByteArray data;
  double ra,dec, angle;

  if (g_cDrawing.getExtFrame(ra, dec, angle))
  {
    CMapView *view = m_mainWin->getView();
    precess(&ra, &dec, JD2000, view->m_mapView.jd);
    if (view->m_mapView.epochJ2000 && view->m_mapView.coordType == SMCT_RA_DEC)
    {
      precess(&ra, &dec, view->m_mapView.jd, JD2000);
    }
    qDebug() << "frame" << R2D(ra) << R2D(dec) << angle;

    data.append(dblToString(angle, 4));
    data.append(",");
    data.append(dblToString(R2D(ra), 6));
    data.append(",");
    data.append(dblToString(R2D(dec), 6));

    sendData(data);
    return;
  }

  sendData(SKS_NOT_FOUND);
}
Exemplo n.º 2
0
void
main(int argc, char *argv[]) {
    p3dc_FLOAT	deg = 75;
    p3dc_FLOAT  rad = PI/3;

    printf(" D2R(%g) = %g = %g\n", deg, D2R(deg), R2D(D2R(deg)));
    printf(" R2D(%g) = %g = %g\n", rad, R2D(rad), R2D(D2R(rad)));
}
Exemplo n.º 3
0
bool BOTAI_AimAtTarget( MATRIX * InvMat , VECTOR * SPos, VECTOR * TPos )
{
	VECTOR WantedDir;
	VECTOR TempDir;
	float Angle;
	float OnTarget = true;

	WantedDir.x = ( TPos->x - SPos->x );
	WantedDir.y = ( TPos->y - SPos->y );
	WantedDir.z = ( TPos->z - SPos->z );
	ApplyMatrix( InvMat, &WantedDir, &TempDir );

	NormaliseVector( &TempDir );
	Angle = (float) acos( TempDir.x );
	Angle = 90.0F - R2D( Angle );

	if( TempDir.z < 0.0F )
		Angle = 180.0F - Angle;

	if( Angle > 180.0F )
		Angle -= 360.0F;

	if( Angle > 0.0F )
	{
		BOTAI_SetAction( &bot.yaw, 1.0F, "AimAtTarget() yaw right" );
		if( Angle > 3.0F )
			OnTarget = false;
	}
	else if( Angle < 0.0F )
	{
		BOTAI_SetAction( &bot.yaw, -1.0F, "AimAtTarget() yaw left" );
		if( Angle < -3.0F )
			OnTarget = false;
	}

	Angle = (float) acos( TempDir.y );
	Angle = 90.0F - R2D( Angle );
	Angle *= -1.0F;

	if( Angle > 180.0F )
		Angle -= 360.0F;

	if( Angle < 0.0F && ( TempDir.z > 0.0F ))
	{
		BOTAI_SetAction( &bot.pitch, -1.0F, "AimAtTarget() pitch up" );
		if(Angle < -3.0F)
			OnTarget = false;
	}
	else if( Angle > 0.0F && ( TempDir.z > 0.0F ))
	{
		BOTAI_SetAction( &bot.pitch, 1.0F, "AimAtTarget() pitch down" );
		if(Angle > 3.0F)
			OnTarget = false;
	}

	return OnTarget;
}
Exemplo n.º 4
0
void CSetPosition::init(double x, double y, double fov, double rot)
///////////////////////////////////////////////////////////////////
{
  m_x = x;
  m_y = y;
  m_fov = fov;
  m_roll = rot;

  ui->doubleSpinBox->setValue(R2D(rot));

  ui->horizontalSlider->setValue(ceil(R2D(fov * FDIV)));

  int v1, v2, v3;

  // ra/dec
  getHMSFromRad(x / 15., &v1, &v2, &v3);
  ui->spinBox->setValue(v1);
  ui->spinBox_2->setValue(v2);
  ui->spinBox_3->setValue(v3);

  getDMSFromRad(fabs(y), &v1, &v2, &v3);
  ui->spinBox_5->setValue(v1 * (y >= 0 ? 1 : -1));
  ui->spinBox_4->setValue(v2);
  ui->spinBox_6->setValue(v3);

  // alt/azm
  double alt, azm;

  cAstro.convRD2AARef(x, y, &azm, &alt);

  getDMSFromRad(azm, &v1, &v2, &v3);
  ui->spinBox_7->setValue(v1);
  ui->spinBox_8->setValue(v2);
  ui->spinBox_9->setValue(v3);

  getDMSFromRad(fabs(alt), &v1, &v2, &v3);
  ui->spinBox_11->setValue(v1 * (alt >= 0 ? 1 : -1));
  ui->spinBox_10->setValue(v2);
  ui->spinBox_12->setValue(v3);

  // ecl
  double lon, lat;

  cAstro.convRD2Ecl(x, y, &lon, &lat);

  getDMSFromRad(lon, &v1, &v2, &v3);
  ui->spinBox_13->setValue(v1);
  ui->spinBox_14->setValue(v2);
  ui->spinBox_15->setValue(v3);

  getDMSFromRad(fabs(lat), &v1, &v2, &v3);
  ui->spinBox_17->setValue(v1 * (lat >= 0 ? 1 : -1));
  ui->spinBox_16->setValue(v2);
  ui->spinBox_18->setValue(v3);
}
Exemplo n.º 5
0
QString comCreateLine(comet_t *a)
/////////////////////////////////
{
  QString line;

  line += a->selected ? "   1 " : "   0 ";
  line += " | ";

  line += QString("%1").arg(a->H, 5, 'f', 2);
  line += " | ";

  line += QString("%1").arg(a->G, 5, 'f', 2);
  line += " | ";

  int y;
  int m;
  double d;

  QDateTime dt;

  jdConvertJDTo_DateTime(a->perihelionDate, &dt);

  y = dt.date().year();
  m = dt.date().month();
  d = dt.date().day();
  d += (dt.time().hour() * 3600.0 + dt.time().minute() * 60.0 + dt.time().second()) / 86400.0;

  line += QString("%1").arg(y, 4);
  line += " | ";
  line += QString("%1").arg(m, 2, 10, QChar('0'));
  line += " | ";
  line += QString("%1").arg(d, 7, 'f', 4);
  line += " | ";

  line += QString("%1").arg(R2D(a->W), 12, 'f', 8);
  line += " | ";

  line += QString("%1").arg(R2D(a->w), 12, 'f', 8);
  line += " | ";

  line += QString("%1").arg(R2D(a->i), 12, 'f', 8);
  line += " | ";

  line += QString("%1").arg(a->e, 12, 'f', 8);
  line += " | ";

  line += QString("%1").arg(a->q, 12, 'f', 8);
  line += " | ";

  line += a->name;
  line += "\n";

  return(line);
}
Exemplo n.º 6
0
void tiltCallback(const dynamixel_msgs::JointState::ConstPtr& msg)
{
  ROS_INFO("msg.curr_pos(radian): %f, (degree): %f ",msg->current_pos, R2D(msg->current_pos) );
  ROS_INFO("msg.goal_pos(radian): %f, (degree): %f ",msg->goal_pos, R2D(msg->goal_pos) );
  current_pos = R2D(msg->current_pos);
  /*
  static tf::TransformBroadcaster br;
  tf::Transform transform;  
  transform.setOrigin(tf::Vector3(0.0, 0.0, 0.0));
  transform.setRotation(tf::createQuaternionFromRPY(0.0, (msg->current_pos-middle_degree), 0.0));
  br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "base_link","tiling_servo"));
  */
}
Exemplo n.º 7
0
void CObjInfo::on_clb_sync_clicked()
////////////////////////////////////
{
  radec_t rd;

  precess(&m_infoItem.radec, &rd, JD2000, m_map->m_mapView.jd);

  double r = R2D(rd.Ra) / 15.0;
  double d = R2D(rd.Dec);

  QApplication::beep();

  g_pTelePlugin->syncTo(r, d);
}
Exemplo n.º 8
0
CSetPosition::CSetPosition(QWidget *parent) :
  QDialog(parent),
  ui(new Ui::CSetPosition)
{
  ui->setupUi(this);
  ui->horizontalSlider->setRange(1, (int)R2D(MAX_MAP_FOV) * FDIV);
}
Exemplo n.º 9
0
//-----------------------------------------------------------------------------
std::string CPose2d::toStr() const
{
  std::ostringstream strOut;

  strOut << "mX=" << mX << " mY=" << mY << " mYaw=" << R2D ( mYaw );
  return strOut.str();
}
Exemplo n.º 10
0
static inline void gen_segmented_square(CPoint* out, float side_length, float start_angle, float end_angle)
{
    CPoint p;

    float radius = side_length;

    int offset=0;

    float k=1;

    float da=D2R(-2.6*2)*k;


    p = CPointMake(sin(start_angle+end_angle)*6*k, - cos(start_angle+end_angle)*6*k);
    //p = CPointMake(0, 0);

    out[offset++] = p;
    out[offset++] = square_texture_point(p, side_length);


    //1
    p = square_point(start_angle+da, radius);
    //p.y=p.y;
    //p.y=side_length;
    out[offset++] = p;
    out[offset++] = square_texture_point(p, side_length);


    int q=0;


    int i;
    for (i=start_angle; i<floor(R2D(start_angle+end_angle+da)); i++) {
        if ((i+45)%90==0) {
            p = square_point(D2R(i), radius);
            out[offset++] = p;
            out[offset++] = square_texture_point(p, side_length);
            q++;
        }
    }


    p = square_point(start_angle + end_angle+da, radius);
    //p.x = p.x + sin(end_angle)*6*k;
    //p.y = p.y - cos(end_angle)*6*k;
    out[offset++] = p;
    out[offset++] = square_texture_point(p, side_length);


    for (i=0; i<4-q; i++) {
        p = square_point(start_angle +end_angle+da, radius);
        //p.x = p.x + sin(end_angle)*6*k;
        //p.y = p.y - cos(end_angle)*6*k;
        out[offset++] = p;
        out[offset++] = square_texture_point(p, side_length);
    }

}
Exemplo n.º 11
0
void CMob::RotateToTarget()
{
	
	glm::vec2 ref_vec(0.0f, 1.0f);
	glm::vec2 norm_direction(direction);
	norm_direction = glm::normalize(norm_direction);
	float angle = R2D(glm::orientedAngle(ref_vec, norm_direction));
	sprite_anim->SetAngleZ(angle);
}
Exemplo n.º 12
0
//-----------------------------------------------------------------------------
void AFiducialFinder::print() const
{
  printf ( "AFiducialFinder: readings %d \n", mNumReadings );

  for ( unsigned int i = 0; i < mNumReadings; i++ ) {
    printf ( "  id %d range %f bearing %f\n", mFiducialData[i].id,
             mFiducialData[i].range,  R2D ( mFiducialData[i].bearing ) );
  }
}
Exemplo n.º 13
0
void CRestoreTM::on_pushButton_2_clicked()
//////////////////////////////////////////
{
  QStandardItemModel *model = (QStandardItemModel *)ui->treeView->model();
  QModelIndexList il = ui->treeView->selectionModel()->selectedIndexes();

  if (il.count() == 0)
    return;

  QStandardItem *item = model->itemFromIndex(il.at(0));
  item_t *e = (item_t *)item->data().toLongLong();

  m_jd = e->jd;
  m_ra = e->ra;
  m_dec = e->dec;

  SkFile f(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/data/timemarks/timemarks.dat");
  QTextStream s(&f);

  if (f.open(SkFile::WriteOnly | SkFile::Text))
  {
    for (int i = 0; i < model->rowCount(); i++)
    {
      QStandardItem *item = model->item(i, 0);
      item_t *e = (item_t *)item->data().toLongLong();

      s << e->desc << ";" << QString::number(e->jd, 'f', 8);

      if (e->ra > CM_UNDEF)
      {
        s << ";" << R2D(e->ra) << ";" << R2D(e->dec);
      }

      s << "\n";

      delete e;
    }
  }

  model->removeRows(0, model->rowCount());

  done(DL_OK);
}
Exemplo n.º 14
0
void SkServer::getPos()
{
  QByteArray data;

  CMapView *view = m_mainWin->getView();

  double ra, dec;

  trfConvScrPtToXY(view->width() / 2., view->height() / 2., ra, dec);
  if (view->m_mapView.epochJ2000 && view->m_mapView.coordType == SMCT_RA_DEC)
  {
    precess(&ra, &dec, view->m_mapView.jd, JD2000);
  }

  data.append(QString::number(R2D(ra), 'f'));
  data.append(",");
  data.append(QString::number(R2D(dec), 'f'));

  sendData(data);
}
Exemplo n.º 15
0
double findAngle( coOrd p0, coOrd p1 )
/* find angle between two points */
{
    double dx = p1.x-p0.x, dy = p1.y-p0.y;
    if (small(dx)) {
        if (dy >=0) return 0.0;
        else return 180.0;
    }
    if (small(dy)) {
        if (dx >=0) return 90.0;
        else return 270.0;
    }
    return R2D(atan2( dx,dy ));
}
Exemplo n.º 16
0
 /// Return the angle (degree) between two pinhole point rays
 static double AngleBetweenRay(
   const BrownPinholeCamera & cam1,
   const BrownPinholeCamera & cam2,
   const Vec2 & x1, const Vec2 & x2)
 {
   // x = (u, v, 1.0)  // image coordinates
   // X = R.t() * K.inv() * x + C // Camera world point
   // getting the ray:
   // ray = X - C = R.t() * K.inv() * x
   Vec3 ray1 = (cam1._R.transpose() *
     (cam1._K.inverse() * Vec3(x1(0), x1(1), 1.))).normalized();
   Vec3 ray2 = (cam2._R.transpose() *
     (cam2._K.inverse() * Vec3(x2(0), x2(1), 1.))).normalized();
   double mag = std::sqrt(ray1.squaredNorm() * ray2.squaredNorm());
   double dotAngle = ray1.dot(ray2);
   return R2D(acos(clamp(dotAngle/mag, -1.0 + 1.e-8, 1.0 - 1.e-8)));
 }
Exemplo n.º 17
0
/// Return the angle (degree) between two bearing vector rays
static double AngleBetweenRay(
  const geometry::Pose3 & pose1,
  const IntrinsicBase * intrinsic1,
  const geometry::Pose3 & pose2,
  const IntrinsicBase * intrinsic2,
  const Vec2 & x1, const Vec2 & x2)
{
  // x = (u, v, 1.0)  // image coordinates
  // X = R.t() * K.inv() * x + C // Camera world point
  // getting the ray:
  // ray = X - C = R.t() * K.inv() * x
  const Vec3 ray1 = (pose1.rotation().transpose() * intrinsic1->operator()(x1)).normalized();
  const Vec3 ray2 = (pose2.rotation().transpose() * intrinsic2->operator()(x2)).normalized();
  const double mag = ray1.norm() * ray2.norm();
  const double dotAngle = ray1.dot(ray2);
  return R2D(acos(clamp(dotAngle/mag, -1.0 + 1.e-8, 1.0 - 1.e-8)));
}
Exemplo n.º 18
0
//-----------------------------------------------------------------------------
void CVelocity2dWidget::updateData(CVelocity2d velocity)
{
  if ( isChecked() ) {
    mXDotLine->setHidden ( false );
    mYDotLine->setHidden ( false );
    mYawDotLine->setHidden ( false );

    mXDotLine->setData ( velocity.mXDot );
    mYDotLine->setData ( velocity.mYDot );
    mYawDotLine->setData ( R2D ( velocity.mYawDot ) );
  }
  else {
    mXDotLine->setHidden ( true );
    mYDotLine->setHidden ( true );
    mYawDotLine->setHidden ( true );
  }
}
Exemplo n.º 19
0
static void computeCurve( coOrd pos0, coOrd pos1, double radius, coOrd * center, double * a0, double * a1 )
/* translate between curves described by 2 end-points and a radius to
   a curve described by a center, radius and angles.
*/
{
    double d, a, aa, aaa, s;

    d = findDistance( pos0, pos1 )/2.0;
    a = findAngle( pos0, pos1 );
    s = fabs(d/radius);
    if (s > 1.0)
	s = 1.0;
    aa = R2D(asin( s ));
    if (radius > 0) {
        aaa = a + (90.0 - aa);
        *a0 = normalizeAngle( aaa + 180.0 );
        translate( center, pos0, aaa, radius );
    } else {
        aaa = a - (90.0 - aa);
	*a0 = normalizeAngle( aaa + 180.0 - aa *2.0 );
        translate( center, pos0, aaa, -radius );
    }
    *a1 = aa*2.0;
}
Exemplo n.º 20
0
void XViewSpline::Draw()
{
    // TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
    if( GetChain() )
    {
        LPDIRECT3DSURFACE9 pBackBuffer = nullptr;
        GetChain()->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
        if( pBackBuffer )
        {
            D3DDEVICE->SetRenderTarget( 0, pBackBuffer );
            D3DDEVICE->Clear( 0, nullptr, D3DCLEAR_TARGET, XCOLOR_GRAY, 1.0f, 0 );
            RECT rect;
            GetClientRect( &rect );
            XE::SetProjection( rect.right-rect.left, rect.bottom-rect.top );
            if(SUCCEEDED(D3DDEVICE->BeginScene()))
            {
                // FrameMove
                FrameMove();
                //
                D3DXVECTOR2 v( 0, 0 );		//
                D3DXMATRIX mWorld, mRot, mTrans, mLocal;
                D3DXMatrixIdentity( &mWorld );
                D3DXMatrixTranslation( &mWorld, vCenter.x, vCenter.y, 0 );
                for( int i = 0; i < MAX_JOINT; ++i )
                {
                    JOINT *j = &m_listJoint[i];

                    // 관절부위에 원을 그림
                    D3DCOLOR col = XCOLOR_WHITE;
                    if( m_idxSelected == i )
                        col = XCOLOR_RED;
                    GRAPHICS->DrawCircle( j->m_vEnd.x, j->m_vEnd.y, 5.f, col );		// 관절끝 부위에 원을 그림
                    GRAPHICS->DrawLine( j->m_vStart.x, j->m_vStart.y, j->m_vEnd.x, j->m_vEnd.y, col );		// 관절 그림
                    // test
                    {
                        D3DXVECTOR2 vA;
                        vA = D3DXVECTOR2( m_vMouse.x, m_vMouse.y ) - s_vC;
                        float rDist = GetAngle( s_vB ) - GetAngle( vA );
                        if( rDist > D2R(180.f) )
                            rDist -= D2R(360.f);
                        else if( rDist < D2R(-180.f) )
                            rDist += D2R(360.f);

                        // draw
                        GRAPHICS->DrawLine( s_vC.x - 100.f, s_vC.y, s_vC.x + 100.f, s_vC.y, XCOLOR_BLUE );
                        GRAPHICS->DrawLine( s_vC.x, s_vC.y - 100.f, s_vC.x, s_vC.y + 100.f, XCOLOR_BLUE );		// 십자선
                        GRAPHICS->DrawLine( s_vC.x, s_vC.y, s_vC.x + s_vB.x, s_vC.y + s_vB.y, XCOLOR_RED );	// 목표벡터
                        GRAPHICS->DrawLine( s_vC.x, s_vC.y, s_vC.x + vA.x, s_vC.y + vA.y, XCOLOR_WHITE );	// 시작 벡터
                        SE::g_pFDBasic->DrawString( s_vC.x + 5.f, s_vC.y + 5.f, XCOLOR_WHITE, _T("%f(%f)"), R2D(rDist), rDist );

                    }

                    // info
                    SE::g_pFDBasic->DrawString( 5.f, 5.f, XCOLOR_WHITE, _T("%d-%d"), (int)m_vMouse.x, (int)m_vMouse.y );
                    /*					D3DXMatrixRotationZ( &mRot, j->m_rAngle );
                    					D3DXMatrixTranslation( &mTrans, j->m_vLocal.x, j->m_vLocal.y, 0 );
                    					mLocal = mRot * mTrans;
                    					mWorld = mLocal * mWorld;
                    					j->m_mWorld = mWorld;

                    					D3DXVECTOR2 v0 = D3DXVECTOR2( 0, 0 );			// 관절원점
                    					D3DXVECTOR2 v1 = D3DXVECTOR2( LEN_JOINT, 0 );		// 관절끝위치
                    					D3DXVECTOR2 v0T, v1T;
                    					D3DXVec2TransformCoord( &v0T, &v0, &mWorld );
                    					D3DXVec2TransformCoord( &v1T, &v1, &mWorld );
                    					// 관절부위에 원을 그림
                    					D3DCOLOR col = XCOLOR_WHITE;
                    					if( m_idxSelected == i )
                    						col = XCOLOR_RED;
                    					GRAPHICS->DrawCircle( v1T.x, v1T.y, 5.f, col );		// 관절부위에 원을 그림
                    					GRAPHICS->DrawLine( v0T.x, v0T.y, v1T.x, v1T.y, col );		// 관절 그림
                    					if( m_bDrawDebug )
                    					{
                    	//					SE::g_pFDBasic->DrawString( v1T.x + 20.f, v1T.y - 20.f, XCOLOR_WHITE, _T("%f"), j->dot );
                    						// normal
                    						D3DXVECTOR2 v2T;
                    						v1 = j->m_vNormal * 50.f + v0T;
                    				//		D3DXVec2TransformCoord( &v2T, &v1, &mWorld );
                    						GRAPHICS->DrawLine( v0T.x, v0T.y, v1.x, v1.y, XCOLOR_BLUE );		// 노말벡터
                    						// 힘벡터
                    						v1 = j->m_vForce * 300.f;
                    						v2T = v1T + v1;
                    						GRAPHICS->DrawLine( v1T.x, v1T.y, v2T.x, v2T.y, XCOLOR_GREEN );		// 노말벡터
                    					}
                    					*/
                }

                //
                D3DDEVICE->EndScene();
            }
            GetChain()->Present( nullptr, nullptr, GetSafeHwnd(), nullptr, 0 );
            pBackBuffer->Release();
        }
    }

}
Exemplo n.º 21
0
CDrawingList::CDrawingList(QWidget *parent) :
  QDialog(parent),
  ui(new Ui::CDrawingList)
{
  ui->setupUi(this);

  setWindowFlags(((windowFlags() | Qt::CustomizeWindowHint)
                 & ~Qt::WindowCloseButtonHint));

  m_model = new QStandardItemModel(0, 3);

  m_model->setHeaderData(0, Qt::Horizontal, tr("Type"));
  m_model->setHeaderData(1, Qt::Horizontal, tr("LWT"));
  m_model->setHeaderData(1, Qt::Horizontal, tr("Linked with telescope"), Qt::ToolTipRole);
  m_model->setHeaderData(2, Qt::Horizontal, tr("Description"));

  drawing_t *draw;

  for (int i = 0; ; i++)
  {
    draw = getDrawing(i);
    if (draw == NULL)
    {
      break;
    }

    QStandardItem *item = new QStandardItem;
    QStandardItem *item2 = new QStandardItem;
    QStandardItem *item1 = new QStandardItem;

    item->setCheckable(true);
    if (draw->show)
    {
      item->setCheckState(Qt::Checked);
    }

    item2->setToolTip(tr("Linked with telescope"));
    item2->setCheckable(true);
    if (draw->telescopeLink)
    {
      item2->setCheckState(Qt::Checked);
    }

    switch (draw->type)
    {
      case DT_TELESCOPE:
        item->setText(tr("Telescope"));
        item1->setText(draw->telescope_t.name);
        break;

      case DT_TELRAD:
        item->setText(tr("Telrad"));
        item1->setText("Telrad finderscope");
        break;

      case DT_TEXT:
        item->setText(tr("Text"));
        item1->setText(draw->text_t.text);
        break;

      case DT_FRM_FIELD:
        item->setText(tr("Frame field"));
        item1->setText(QString("%1' x %2'").arg(R2D(draw->frmField_t.x * 60), 0, 'f', 2).arg(R2D(draw->frmField_t.y * 60), 0, 'f', 2));
        break;

      case DT_EXT_FRAME:
        item->setText(tr("External Frame field"));
        item1->setText(QString("%1' x %2'").arg(R2D(draw->frmField_t.x * 60), 0, 'f', 2).arg(R2D(draw->frmField_t.y * 60), 0, 'f', 2));
        break;
    }
    item->setData((qint64)draw);
    m_model->setItem(i, 0, item);
    m_model->setItem(i, 1, item2);
    m_model->setItem(i, 2, item1);
  }

  ui->treeView->setModel(m_model);
  ui->treeView->setRootIsDecorated(false);
  ui->treeView->header()->resizeSection(0, 150);
  ui->treeView->header()->resizeSection(1, 60);
  ui->treeView->header()->resizeSection(2, 200);


  QShortcut *sh1 = new QShortcut(QKeySequence(Qt::Key_Delete), ui->treeView, 0, 0,  Qt::WidgetShortcut);
  connect(sh1, SIGNAL(activated()), this, SLOT(slotDelete()));
}
Exemplo n.º 22
0
void BOTAI_AvoidHomingMissiles()
{
	VECTOR NormVector;
	VECTOR DirVector;
	float xAngle;
	float yAngle;

	if(HomingMissile > -1)
	{
		// -- decide what movement to perform
		// new missile
		//if(!MissileAvoidanceSet)
		{
			//DebugPrintf("set details for missile %d\n", HomingMissile);
			MissileAvoidanceSet = true;
			NormVector.x = SecBulls[HomingMissile].Pos.x - Ships[WhoIAm].Object.Pos.x;
			NormVector.y = SecBulls[HomingMissile].Pos.y - Ships[WhoIAm].Object.Pos.y;
			NormVector.z = SecBulls[HomingMissile].Pos.z - Ships[WhoIAm].Object.Pos.z;
			ApplyMatrix( &Ships[WhoIAm].Object.FinalInvMat, &NormVector, &DirVector );
			NormaliseVector( &DirVector );
			MissileOrigDirVector = DirVector;
		}


		// left/right angle
		xAngle = (float) acos( MissileOrigDirVector.x );
		xAngle = 90.0F - R2D( xAngle );
		if( MissileOrigDirVector.z < 0.0F )
			xAngle = 180.0F - xAngle;
		if( xAngle > 180.0F )
			xAngle -= 360.0F;
		//DebugPrintf("x = %f\n", xAngle);

		// up/down angle
		yAngle = (float) acos( MissileOrigDirVector.y );
		yAngle = 90.0F - R2D( yAngle );
		yAngle *= -1.0F;
		if( yAngle > 180.0F )
			yAngle -= 360.0F;
		//DebugPrintf("y = %f\n", yAngle);

		// -- execute slide movements

		// target is directly in front or behind me
		if((xAngle > -22.5F && xAngle < 22.5F) || (xAngle < -157.5F || xAngle > 157.5F))
		{
			// slide either left or right, doesn't matter
			BOTAI_SetAction( &bot.right, 1.0F, "AvoidHomingMissiles() right" );
		}
		// target is directly to the side of me
		else if((xAngle > 67.5F && xAngle < 112.5F) || (xAngle < -67.5F && xAngle > -112.5F))
		{
			// forward or backward, doesn't matter
			BOTAI_SetAction( &bot.forward, 1.0F, "AvoidHomingMissiles() forward" );
		}

		// target is to my front left 
		else if(xAngle > -67.5F && xAngle < -22.5F)
		{
			// move forward right 
			BOTAI_SetAction( &bot.forward, 1.0F, "AvoidHomingMissiles() forward" );
			BOTAI_SetAction( &bot.right, 1.0F, "AvoidHomingMissiles() right" );
		}

		// target is to my rear left 
		else if(xAngle > -157.5F && xAngle < -112.5F)
		{
			// move back left
			BOTAI_SetAction( &bot.forward, -1.0F, "AvoidHomingMissiles() reverse" );
			BOTAI_SetAction( &bot.forward, -1.0F, "AvoidHomingMissiles() left" );
		}

		// target is to my front right
		else if(xAngle > 22.5F && xAngle < 67.5F)
		{
			// move front left 
			BOTAI_SetAction( &bot.forward, 1.0F, "AvoidHomingMissiles() forward" );
			BOTAI_SetAction( &bot.right, -1.0F, "AvoidHomingMissiles() left" );
		}

		// target is to my rear right 
		else if(xAngle > 112.5F && xAngle < 157.5F)
		{
			// move back right 
			BOTAI_SetAction( &bot.forward, -1.0F, "AvoidHomingMissiles() reverse" );
			BOTAI_SetAction( &bot.right, 1.0F, "AvoidHomingMissiles() right" );
		}

		if(yAngle > 0.0F)
			BOTAI_SetAction( &bot.up, -1.0F, "AvoidHomingMissiles() down" );
		else
			BOTAI_SetAction( &bot.up, 1.0F, "AvoidHomingMissiles() up" );
	}
}
Exemplo n.º 23
0
/** Private helper function to calculate the time when the sun will rise 
 * or set on the given day.
 * @param event Sunrise or sunset
 * @param day_of_year The day of the year we want the sunrise/set time for
 * @param latitude The latitude in degrees
 * @param longitude The longitude in degrees
 * @param utc_offset The UTC offset in hours
 *
 * Note: calculations derived from SunTime class found on CodeProject
 * Note: these angles would be better to be kept as radians all the time
 * 		 but that's gonna be tricky, so I'll do it later.
 */
int
_getSunTime(DayTimeEvent event, int day_of_year, double latitude, double longitude, double utc_offset)
{
	// number of hours away from GMT
	double long_offset = 24 * longitude / 360;

	// sorry, don't know what this one represents ("appr. time")
	double t;
	switch(event) {
		case DAY_TIME_SUNRISE:
			t = day_of_year + (6 - long_offset) / 24;
			break;
		case DAY_TIME_SUNSET:
			t = day_of_year + (18 - long_offset) / 24;
			break;
		default:
			dp(0, "bad event type %d\n", event);
			return INT_MIN;
	}

	// mean anomaly
	double mean = (T_COEFF1 * t) - MEAN_OFFSET;

	// true longitude
	double true_long = bound(mean + SIN_MEAN_COEFF * sin(D2R(mean))
			+ SIN_2MEAN_COEFF * sin(D2R(2 * mean)) + TRUE_LONG_OFFSET, 0, 360);

	// right ascension
	double right_asc = bound(R2D(atan(TRUE_LONG_COEFF * tan(D2R(true_long)))), 
			0, 360);

	// adjust quadrant of right ascension
	double base = floor(true_long / 90) * 90;
	right_asc = base + fmod(right_asc, 90.0);
	
	// convert right ascension to an hour offset
	double right_asc_offset = 24 * right_asc / 360;
	
	// more unknown temporaries
	double sinDec = SIN_TRUE_LONG_COEFF * sin(D2R(true_long));
	double cosDec = cos(asin(sinDec));

	// local hour angle
	double cos_hour = (cos(D2R(ZENITH)) - sinDec * sin(D2R(latitude)))
			/ (cosDec * cos(D2R(latitude)));

	double hour;
	switch(event) {
		case DAY_TIME_SUNRISE:
			hour = 24 * (1 - R2D(acos(cos_hour)) / 360);
			break;
		case DAY_TIME_SUNSET:
			hour = 24 * R2D(acos(cos_hour)) / 360;
			break;
		default:
			dp(0, "bad event type %d\n", event);
			return INT_MIN;
	}

	// local time
	double local_hour = hour + right_asc_offset - T_COEFF2 * t - LOCAL_OFFSET;

	// universal time
	double universal = bound(local_hour - long_offset + utc_offset, 0, 24);

	int seconds = (int)(universal * 3600);
/*	printf("N%d, lH%f, t%f, M%f, L%f, RA%f, cH%f, H%f, T%f, UT%f, s%d\n",
			day_of_year, long_offset, t, mean, true_long, right_asc, 
			cos_hour, hour, local_hour, universal, seconds);
*/
	// time in seconds
	return seconds;
}
Exemplo n.º 24
0
void CGrid::renderGrid(int type, SKMATRIX *mat, mapView_t *mapView, CSkPainter *pPainter, bool eqOnly)
//////////////////////////////////////////////////////////////////////////////////////////////////////
{
  double spc;
  double cx, cy;

  setSetFont(FONT_GRID, pPainter);
  trfGetScreenSize(scrWidth, scrHeight);

  QColor col = g_skSet.map.grid[type].color;
  pPainter->setPen(col);
  pPainter->drawRect(clipSize, clipSize, scrWidth - clipSize * 2, scrHeight - clipSize * 2);

  if (type == SMCT_ECL || type == SMCT_ALT_AZM)
  {
    radec_t rd;
    SKPOINT pt;

    double sx, sy;
    trfGetCenter(sx, sy);
    trfConvScrPtToXY(sx, sy, cx, cy);

    rd.Ra =  cx;
    rd.Dec = cy;

    precess(&rd.Ra, &rd.Dec, mapView->jd, JD2000);

    SKMATRIX matInv;
    SKMATRIXInverse(&matInv, mat);

    trfRaDecToPointNoCorrect(&rd, &pt, &matInv);

    cx = -atan2(pt.w.x, pt.w.z);
    cy =  atan2(-pt.w.y, sqrt(pt.w.x * pt.w.x + pt.w.z * pt.w.z));

    rangeDbl(&cx, R360);

    if (type == SMCT_ALT_AZM)
    {
      cy += cAstro.getAtmRef(cy);
    }
  }
  else
  {
    double sx, sy;
    trfGetCenter(sx, sy);
    trfConvScrPtToXY(sx, sy, cx, cy);
    if (mapView->coordType == SMCT_RA_DEC && mapView->epochJ2000)
    {
      precess(&cx, &cy, mapView->jd, JD2000);
    }
  }

  if (mapView->fov > D2R(45)) spc = 10;
    else
  if (mapView->fov > D2R(10)) spc = 5;
    else
  if (mapView->fov > D2R(5)) spc = 2;
    else
  if (mapView->fov > D2R(1)) spc = 1;
    else
  if (mapView->fov > D2R(0.5)) spc = 0.5;
    else
  if (mapView->fov > D2R(0.25)) spc = 0.1;
    else spc = (0.05);

  mSet.clear();

  double spcx = spc;
  double spcy = spc;

  if (qAbs(mapView->y) > D2R(80))
  {
    spcx *= 40;
  }
  else
  if (qAbs(mapView->y) > D2R(60))
  {
    spcx *= 5;
  }
  else
  if (qAbs(mapView->y) > D2R(45))
  {
    spcx *= 2;
  }

  spcx = CLAMP(spcx, 0.25, 10);
  spcy = CLAMP(spcy, 0.25, 10);

  double x = R2D(cx - fmod(cx, D2R(spcx)));
  double y;

  if (cy >= 0)
  {
    y = R2D(cy - fmod(cy, D2R(spcy)));
  }
  else
  {
    y = -(R2D(qAbs(cy) - fmod(qAbs(cy), D2R(spcy))) + spcy);
    if (y < -90) y = -90;
  }

  depth = 0;
  ren = 0;

  render(type, mat, mapView, pPainter, eqOnly, FROMRA(x), FROMDEC(y), FROMRA(spcx), FROMRA(spcy));
}
Exemplo n.º 25
0
CWPosSel::CWPosSel(QWidget *parent, mapView_t *view) :
//////////////////////////////////////////////////////
  QDialog(parent),
  ui(new Ui::CWPosSel)
{
  ui->setupUi(this);  

  m_earthTools.setCacheFolder(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/cache");
  connect(&m_earthTools, SIGNAL(sigDone(bool,double,int)), this, SLOT(slotETDone(bool,double,int)));
  connect(&m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotLocationDone(QNetworkReply*)));

  SkFile f(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/data/locations/locations.dat");
  if (f.open(SkFile::ReadOnly | SkFile::Text))
  {
    QString     str;
    QStringList l;
    do
    {
      str = f.readLine();
      if (str.isEmpty() || str.startsWith("\n"))
        break;
      l = str.split("|");
      if (l.count() != 5)
      {
        qDebug("CWPosSel read line fail!");
        continue;
      }

      location_t *loc = new location_t;

      loc->name = l.at(0);
      loc->lon = l.at(1).toDouble();
      loc->lat = l.at(2).toDouble();
      loc->alt = l.at(3).toDouble();
      loc->tz = l.at(4).toDouble();

      m_tList.append(loc);

      QListWidgetItem *w = new QListWidgetItem(loc->name, NULL, 1);
      w->setData(Qt::UserRole, (qint64)loc);
      ui->listWidget->addItem(w);
    } while (1);
    f.close();
  }  

  ui->spinBox_8->setValue(view->geo.temp);
  ui->spinBox_9->setValue(view->geo.press);
  ui->checkBox->setChecked(!view->geo.useAtmRefraction);
  ui->cb_tempType->addItem("C");
  ui->cb_tempType->addItem("F");
  ui->cb_tempType->setCurrentIndex(view->geo.tempType);

  location_t loc;

  loc.name = view->geo.name;
  loc.lon = R2D(view->geo.lon);
  loc.lat = R2D(view->geo.lat);
  loc.alt = view->geo.alt;
  loc.tz = view->geo.tzo * 24.0;
  ui->doubleSpinBox_4->setValue(view->geo.sdlt * 24.0);

  m_view = view;

  setData(&loc);

  QShortcut *sh1 = new QShortcut(QKeySequence(Qt::Key_Delete), ui->listWidget, 0, 0,  Qt::WidgetShortcut);
  connect(sh1, SIGNAL(activated()), this, SLOT(slotDeleteItem()));

  ui->widget->setModel((QSortFilterProxyModel *)ui->listWidget->model(), 0);
  connect(ui->widget, SIGNAL(sigSetSelection(QModelIndex&)), this, SLOT(slotSelChange(QModelIndex&)));

  SkFile file(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/data/locations/home.dat");

  if (file.open(QFile::ReadOnly))
  {
    QDataStream ds(&file);
    int count;

    ds >> count;
    for (int i = 0; i < count; i++)
    {
      location_t loc;

      ds >> loc.name;
      ds >> loc.alt;
      ds >> loc.lat;
      ds >> loc.lon;
      ds >> loc.tz;

      QVariant var;
      var.setValue(loc);
      ui->cb_home->addItem(loc.name, var);
    }
  }
Exemplo n.º 26
0
/* triple-chords to target pos in a straight line; returns true if reached target */
bool BOTAI_MoveToTargetNew(VECTOR * TPos)
{
	VECTOR Slide;
	VECTOR TriChordVector;
	VECTOR WantedVector;
	VECTOR NormVector;
	VECTOR DirVector;
	VECTOR FwdDirVector;
	float xAngle;
	float yAngle;
	float Cos;

	////DebugPrintf("moving to %f %f %f\n", TPos->x, TPos->y, TPos->z);

	// -- calculate direction vector from my position to target 
	NormVector.x = TPos->x - Ships[WhoIAm].Object.Pos.x;
	NormVector.y = TPos->y - Ships[WhoIAm].Object.Pos.y;
	NormVector.z = TPos->z - Ships[WhoIAm].Object.Pos.z;

	DirVector = NormVector;

	// apply that vector to my matrix to make direction relative to my direction and rotation 
	//ApplyMatrix( &Ships[WhoIAm].Object.FinalInvMat, &NormVector, &DirVector );
	NormaliseVector( &DirVector );
	//DebugPrintf("straight x = %f y = %f z = %f\n", DirVector.x, DirVector.y, DirVector.z);

	// calculate the desired vector
	// forward right
	Slide.x = 1.0F;
	Slide.y = 0.0F;
	Slide.z = 1.0F;


	// calculate the triple chord direction vector 
	ApplyMatrix( &Ships[WhoIAm].Object.FinalMat, &Slide, &TriChordVector );
	NormaliseVector( &TriChordVector );
	//DebugPrintf("trivec x = %f y = %f z = %f\n", TriChordVector.x, TriChordVector.y, TriChordVector.z);


	// difference between wanted vector and slide vector
	WantedVector.x = DirVector.x - TriChordVector.x;
	WantedVector.y = DirVector.y - TriChordVector.y;
	WantedVector.z = DirVector.z - TriChordVector.z;
	////DebugPrintf("W x = %f y = %f z = %f\n", WantedVector.x, WantedVector.y, WantedVector.z);

	// angle between trichord vector and wanted vector, == 1.0F when aligned perfectly
	Cos = DotProduct( &DirVector, &TriChordVector );
	////DebugPrintf("Cos = %f\n", Cos);

	return false;

	// left/right angle
	xAngle = (float) acos( WantedVector.x );
	xAngle = 90.0F - R2D( xAngle );
	if( WantedVector.z < 0.0F )
		xAngle = 180.0F - xAngle;
	if( xAngle > 180.0F )
		xAngle -= 360.0F;
	////DebugPrintf("X Angle %f\n", xAngle);

	// up/down angle
	yAngle = (float) acos( WantedVector.y );
	yAngle = 90.0F - R2D( yAngle );
	yAngle *= -1.0F;
	if( yAngle > 180.0F )
		yAngle -= 360.0F;
	////DebugPrintf("Y Angle %f\n", yAngle);

	if( xAngle > 0.0F )
		BOTAI_SetAction( &bot.yaw, 1.0F, "MoveToTargetNew() yaw right" );
	else if( xAngle < 0.0F )
		BOTAI_SetAction( &bot.yaw, -1.0F, "MoveToTargetNew() yaw left" );

	if( yAngle < 0.0F && ( WantedVector.z > 0.0F ))
		BOTAI_SetAction( &bot.pitch, -1.0F, "MoveToTargetNew() pitch up" );
	else if( yAngle > 0.0F && ( WantedVector.z > 0.0F ))
		BOTAI_SetAction( &bot.pitch, 1.0F, "MoveToTargetNew() pitch down" );


	// Reached Target
	if(Ships[WhoIAm].Object.Pos.x < TPos->x + TOL && Ships[WhoIAm].Object.Pos.x > TPos->x - TOL
			&& Ships[WhoIAm].Object.Pos.y < TPos->y + TOL && Ships[WhoIAm].Object.Pos.y > TPos->y - TOL
			&& Ships[WhoIAm].Object.Pos.z < TPos->z + TOL && Ships[WhoIAm].Object.Pos.z > TPos->z - TOL)
		return true;
	else
		return false;
}
Exemplo n.º 27
0
//-----------------------------------------------------------------------------
void CPose2d::print() const
{
  printf("CPose2d: x=%f y=%f yaw=%f\n", mX, mY, R2D(mYaw));
}
Exemplo n.º 28
0
/* (buggy) always triple chords up/right/forward to target */
bool BOTAI_MoveToTarget(VECTOR * TPos)
{
	VECTOR NormVector;
	VECTOR DirVector;
	float xAngle;
	float yAngle;

	//DebugPrintf("moving to %f %f %f\n", TPos->x, TPos->y, TPos->z);


	// set slide movements and check if at target pos
	if(BOTAI_SlideToTarget(TPos))
		return true;

	// adjust the aim

	// -- Calculate angles
	NormVector.x = TPos->x - Ships[WhoIAm].Object.Pos.x;
	NormVector.y = TPos->y - Ships[WhoIAm].Object.Pos.y;
	NormVector.z = TPos->z - Ships[WhoIAm].Object.Pos.z;
	ApplyMatrix( &Ships[WhoIAm].Object.FinalInvMat, &NormVector, &DirVector );
	NormaliseVector( &DirVector );
	////DebugPrintf("x = %f y = %f z = %f\n", DirVector.x, DirVector.y, DirVector.z);

	// left/right angle
	xAngle = (float) acos( DirVector.x );
	xAngle = 90.0F - R2D( xAngle );
	if( DirVector.z < 0.0F )
		xAngle = 180.0F - xAngle;
	if( xAngle > 180.0F )
		xAngle -= 360.0F;
	////DebugPrintf("X Angle %f\n", xAngle);

	// up/down angle
	yAngle = (float) acos( DirVector.y );
	yAngle = 90.0F - R2D( yAngle );
	yAngle *= -1.0F;
	if( yAngle > 180.0F )
		yAngle -= 360.0F;
	////DebugPrintf("Y Angle %f\n", yAngle);

	// -- angle aim
	// sliding right
	if( bot.right == 1.0F)
	{
		// aim left
		if(xAngle < 30.0F)
			BOTAI_SetAction( &bot.yaw, -1.0F, "MoveToTarget() yaw left" );
		// aim right
		else if(xAngle > 40.0F)
			BOTAI_SetAction( &bot.yaw, 1.0F, "MoveToTarget() yaw right" );
	}

	// sliding left
	else if( bot.right == -1.0F)
	{
		// aim left
		if(xAngle < -40.0F)
			BOTAI_SetAction( &bot.yaw, -1.0F, "MoveToTarget() yaw left" );
		// aim right
		else if(xAngle > -30.0F)
			BOTAI_SetAction( &bot.yaw, 1.0F, "MoveToTarget() yaw right" );
	}

	// sliding up
	if(bot.up == 1.0F)
	{
		// aim up
		if(yAngle < -40.0F)
			BOTAI_SetAction( &bot.pitch, -1.0F, "MoveToTarget() pitch up" );
		// aim down
		else if(yAngle > -30.0F)
			BOTAI_SetAction( &bot.pitch, 1.0F, "MoveToTarget() pitch down" );
	}

	// sliding down
	else if(bot.up == -1.0F)
	{
		// aim up
		if(yAngle > 30.0F)
			BOTAI_SetAction( &bot.pitch, -1.0F, "MoveToTarget() pitch up" );
		// aim down
		else if(yAngle < 40.0F)
			BOTAI_SetAction( &bot.pitch, 1.0F, "MoveToTarget() pitch down" );
	}

	return false;
}
Exemplo n.º 29
0
static int parse_location (char *e)
{
	int len;
	int ipat;
	char xstr[20], ystr[20], zstr[20], bstr[20], dstr[20];
	double x, y, dist, bearing;
	double lat0, lon0;
	double lat9, lon9;
	long lerr;	
	double easting, northing;
	char mh[20];	

	assert (*e == 'B');

	m_dao[2] = e[0];
	m_dao[3] = e[1];	/* Type of location.  e.g.  !TB6! */
				/* Will be changed by point types. */

				/* If this ever changes, be sure to update corresponding */
				/* section in process_comment() in decode_aprs.c */

	len = strlen(e);

	ipat = find_ttloc_match (e, xstr, ystr, zstr, bstr, dstr);
	if (ipat >= 0) {

	  //dw_printf ("ipat=%d, x=%s, y=%s, b=%s, d=%s\n", ipat, xstr, ystr, bstr, dstr);

	  switch (tt_config.ttloc_ptr[ipat].type) {
	    case TTLOC_POINT:
		
	      m_latitude = tt_config.ttloc_ptr[ipat].point.lat;
	      m_longitude = tt_config.ttloc_ptr[ipat].point.lon;

	      /* Is it one of ten or a hundred positions? */
	      /* It's not hardwired to always be B0n or B9nn.  */
	      /* This is a pretty good approximation. */

	      if (strlen(e) == 3) {	/* probably B0n -->  !Tn ! */
		m_dao[2] = e[2];
	        m_dao[3] = ' ';
	      }
	      if (strlen(e) == 4) {	/* probably B9nn -->  !Tnn! */
		m_dao[2] = e[2];
	        m_dao[3] = e[3];
	      }
	      break;

	    case TTLOC_VECTOR:

	      if (strlen(bstr) != 3) {
	        text_color_set(DW_COLOR_ERROR);
	        dw_printf ("Bearing \"%s\" should be 3 digits.\n", bstr);
	        // return error code?
	      }
	      if (strlen(dstr) < 1) {
	        text_color_set(DW_COLOR_ERROR);
	        dw_printf ("Distance \"%s\" should 1 or more digits.\n", dstr);
	        // return error code?
	      }

	      lat0 = D2R(tt_config.ttloc_ptr[ipat].vector.lat);
	      lon0 = D2R(tt_config.ttloc_ptr[ipat].vector.lon);
	      dist = atof(dstr) * tt_config.ttloc_ptr[ipat].vector.scale;
	      bearing = D2R(atof(bstr));

	      /* Equations and caluculators found here: */
	      /* http://movable-type.co.uk/scripts/latlong.html */
	      /* This should probably be a function in latlong.c in case we have another use for it someday. */

	      m_latitude = R2D(asin(sin(lat0) * cos(dist/R) + cos(lat0) * sin(dist/R) * cos(bearing)));

	      m_longitude = R2D(lon0 + atan2(sin(bearing) * sin(dist/R) * cos(lat0),
				  cos(dist/R) - sin(lat0) * sin(D2R(m_latitude))));
	      break;

	    case TTLOC_GRID:

	      if (strlen(xstr) == 0) {
	        text_color_set(DW_COLOR_ERROR);
	        dw_printf ("Missing X coordinate.\n");
		strcpy (xstr, "0");
	      }
	      if (strlen(ystr) == 0) {
	        text_color_set(DW_COLOR_ERROR);
	        dw_printf ("Missing Y coordinate.\n");
		strcpy (ystr, "0");
	      }

	      lat0 = tt_config.ttloc_ptr[ipat].grid.lat0;
	      lat9 = tt_config.ttloc_ptr[ipat].grid.lat9;
	      y = atof(ystr);
	      m_latitude = lat0 + y * (lat9-lat0) / (pow(10., strlen(ystr)) - 1.);

	      lon0 = tt_config.ttloc_ptr[ipat].grid.lon0;
	      lon9 = tt_config.ttloc_ptr[ipat].grid.lon9;
	      x = atof(xstr);
	      m_longitude = lon0 + x * (lon9-lon0) / (pow(10., strlen(xstr)) - 1.);

	      break;

	    case TTLOC_UTM:

	      if (strlen(xstr) == 0) {
	        text_color_set(DW_COLOR_ERROR);
	        dw_printf ("Missing X coordinate.\n");
	        /* Avoid divide by zero later.  Put in middle of range. */
		strcpy (xstr, "5");
	      }
	      if (strlen(ystr) == 0) {
	        text_color_set(DW_COLOR_ERROR);
	        dw_printf ("Missing Y coordinate.\n");
	        /* Avoid divide by zero later.  Put in middle of range. */
		strcpy (ystr, "5");
	      }

	      x = atof(xstr);
	      easting = x * tt_config.ttloc_ptr[ipat].utm.scale + tt_config.ttloc_ptr[ipat].utm.x_offset;

	      y = atof(ystr);
	      northing = y * tt_config.ttloc_ptr[ipat].utm.scale + tt_config.ttloc_ptr[ipat].utm.y_offset;
		
              lerr = Convert_UTM_To_Geodetic(tt_config.ttloc_ptr[ipat].utm.lzone, 
			tt_config.ttloc_ptr[ipat].utm.hemi, easting, northing, &lat0, &lon0);

              if (lerr == 0) {
                m_latitude = R2D(lat0);
                m_longitude = R2D(lon0);

                //printf ("DEBUG: from UTM, latitude = %.6f, longitude = %.6f\n", m_latitude, m_longitude);
              }
              else {
	        char message[300];

		text_color_set(DW_COLOR_ERROR);
	        utm_error_string (lerr, message);
                dw_printf ("Conversion from UTM failed:\n%s\n\n", message);
              }

	      break;


	    case TTLOC_MGRS:
	    case TTLOC_USNG:

	      if (strlen(xstr) == 0) {
	        text_color_set(DW_COLOR_ERROR);
	        dw_printf ("MGRS/USNG: Missing X (easting) coordinate.\n");
	        /* Should not be possible to get here. Fake it and carry on. */
		strcpy (xstr, "5");
	      }
	      if (strlen(ystr) == 0) {
	        text_color_set(DW_COLOR_ERROR);
	        dw_printf ("MGRS/USNG: Missing Y (northing) coordinate.\n");
	        /* Should not be possible to get here. Fake it and carry on. */
		strcpy (ystr, "5");
	      }

	      char loc[40];
	
	      strcpy (loc, tt_config.ttloc_ptr[ipat].mgrs.zone);
	      strcat (loc, xstr);
	      strcat (loc, ystr);

	      //text_color_set(DW_COLOR_DEBUG);
	      //dw_printf ("MGRS/USNG location debug:  %s\n", loc);

	      if (tt_config.ttloc_ptr[ipat].type == TTLOC_MGRS)
                lerr = Convert_MGRS_To_Geodetic(loc, &lat0, &lon0);
	      else
                lerr = Convert_USNG_To_Geodetic(loc, &lat0, &lon0);


              if (lerr == 0) {
                m_latitude = R2D(lat0);
                m_longitude = R2D(lon0);

                //printf ("DEBUG: from MGRS/USNG, latitude = %.6f, longitude = %.6f\n", m_latitude, m_longitude);
              }
              else {
	        char message[300];

		text_color_set(DW_COLOR_ERROR);
	        mgrs_error_string (lerr, message);
                dw_printf ("Conversion from MGRS/USNG failed:\n%s\n\n", message);
              }
	      break;

	    case TTLOC_SATSQ:

	      if (strlen(xstr) != 4) {
	        text_color_set(DW_COLOR_ERROR);
	        dw_printf ("Expected 4 digits for the Satellite Square.\n");
	        return (TT_ERROR_SATSQ);
	      }

	      /* Convert 4 digits to usual AA99 form, then to location. */

	      if (tt_gridsquare_to_text (xstr, 0, mh)  == 0) {
		ll_from_grid_square (mh, &m_latitude, &m_longitude);
	      }
	      break;


	    default:
	      assert (0);
	  }
	  return (0);
	}

	/* Send reject sound. */
	/* Does not match any location specification. */

	return (TT_ERROR_INVALID_LOC);

} /* end parse_location */
Exemplo n.º 30
0
/* Slides to target pos without aiming at it; returns true if reached target */
bool BOTAI_SlideToTarget(VECTOR * TPos)
{
	VECTOR NormVector;
	VECTOR DirVector;
	float xAngle;
	float yAngle;

	//DebugPrintf("sliding to target\n");

	// -- Calculate angles
	NormVector.x = TPos->x - Ships[WhoIAm].Object.Pos.x;
	NormVector.y = TPos->y - Ships[WhoIAm].Object.Pos.y;
	NormVector.z = TPos->z - Ships[WhoIAm].Object.Pos.z;
	ApplyMatrix( &Ships[WhoIAm].Object.FinalInvMat, &NormVector, &DirVector );
	NormaliseVector( &DirVector );
	////DebugPrintf("x = %f y = %f z = %f\n", DirVector.x, DirVector.y, DirVector.z);

	// left/right angle
	xAngle = (float) acos( DirVector.x );
	xAngle = 90.0F - R2D( xAngle );
	if( DirVector.z < 0.0F )
		xAngle = 180.0F - xAngle;
	if( xAngle > 180.0F )
		xAngle -= 360.0F;
	////DebugPrintf("X Angle %f\n", xAngle);

	// up/down angle
	yAngle = (float) acos( DirVector.y );
	yAngle = 90.0F - R2D( yAngle );
	yAngle *= -1.0F;
	if( yAngle > 180.0F )
		yAngle -= 360.0F;
	////DebugPrintf("Y Angle %f\n", yAngle);
	////DebugPrintf("z %f\n", DirVector.z);


	// -- execute slide movements
	// sliding right
	if(xAngle > 0.0F && DistWall[0] > 100.0F)
		BOTAI_SetAction( &bot.right, 1.0F, "SlideToTarget() right" );
	// sliding left
	else if(xAngle < 0.0F && DistWall[1] > 100.0F)
		BOTAI_SetAction( &bot.right, -1.0F, "SlideToTarget() left" );

	// sliding up
	if(DistWall[2] > 100.0F) 
	{
		if(yAngle < 0.0F )
			BOTAI_SetAction( &bot.up, 1.0F, "SlideToTarget() up" );
	}
	// sliding down
	if(DistWall[3] > 100.0F) 
	{
		if(yAngle > 0.0F)
			BOTAI_SetAction( &bot.up, -1.0F, "SlideToTarget() down" );
	}

	// forward
	if(DirVector.z > 0.0F && DistWall[8] > 100.0F) 
		BOTAI_SetAction( &bot.forward, 1.0F, "SlideToTarget() forward" );
	// backward
	else if(DirVector.z < 0.0F && DistWall[9] > 100.0F )
		BOTAI_SetAction( &bot.forward, -1.0F, "SlideToTarget() reverse" );


	// Reached Target
	if(Ships[WhoIAm].Object.Pos.x < TPos->x + TOL && Ships[WhoIAm].Object.Pos.x > TPos->x - TOL
			&& Ships[WhoIAm].Object.Pos.y < TPos->y + TOL && Ships[WhoIAm].Object.Pos.y > TPos->y - TOL
			&& Ships[WhoIAm].Object.Pos.z < TPos->z + TOL && Ships[WhoIAm].Object.Pos.z > TPos->z - TOL)
		return true;
	else
		return false;
}