コード例 #1
0
ファイル: aiTurretShape.cpp プロジェクト: nev7n/Torque3D
void AITurretShape::_setScanBox()
{
   mTransformedScanBox = mScanBox;
   MatrixF mat;
   getScanTransform(mat);
   mat.mul(mTransformedScanBox);
}
コード例 #2
0
ファイル: aiTurretShape.cpp プロジェクト: nev7n/Torque3D
void AITurretShape::_performScan()
{
   // Only on server
   if (isClientObject())
      return;

   // Are we ready for a scan?
   --mTicksToNextScan;
   if (mTicksToNextScan > 0)
      return;

   _cleanupPotentialTargets();

   _setScanBox();

   // Set up for the scan
   getScanTransform(mScanWorkspaceScanMat);
   mScanWorkspaceScanWorldMat = mScanWorkspaceScanMat;
   mScanWorkspaceScanWorldMat.affineInverse();

   disableCollision();
   for ( SimSetIterator iter(&mIgnoreObjects); *iter; ++iter )
   {
      ShapeBase* obj = static_cast<ShapeBase*>( *iter );
      obj->disableCollision();
   }

   gServerContainer.findObjects( mTransformedScanBox, sScanTypeMask, _scanCallback, (void*)this );

   for ( SimSetIterator iter(&mIgnoreObjects); *iter; ++iter )
   {
      ShapeBase* obj = static_cast<ShapeBase*>( *iter );
      obj->enableCollision();
   }
   enableCollision();

   if (mPotentialTargets.size() == 0)
   {
      // No targets in range.  Clear out our current target, if necessary.
      _lostTarget();
   }
   else
   {
      // Sort the targets
      comparePoint = getPosition();
      dQsort(mPotentialTargets.address(),mPotentialTargets.size(),sizeof(SimObjectList::value_type),_sortCallback);

      // Go through the targets in order to find one that is not blocked from view
      Point3F start;
      mScanWorkspaceScanMat.getColumn(3, &start);
      S32 index = 0;
      bool los = false;

      disableCollision();
      for (index=0; index < mPotentialTargets.size(); ++index)
      {
         ShapeBase* shape = (ShapeBase*)mPotentialTargets[index];

         Point3F sightPoint;
         los = _testTargetLineOfSight(start, shape, sightPoint);

         // Check if we have a clear line of sight
         if (los)
            break;
      }
      enableCollision();

      // If we found a valid, visible target (no hits between here and there), latch on to it
      if (los)
      {
         _gainedTarget((ShapeBase*)mPotentialTargets[index]);
      }
   }

   // Prepare for next scan period
   mTicksToNextScan = mScanTickFrequency;
   if (mScanTickFrequencyVariance > 0)
   {
      mTicksToNextScan += gRandGen.randI(0, mScanTickFrequencyVariance);
   }
}
コード例 #3
0
void qtUnwrap(Mapa &m, int i, int j, int ancho){
    
    suma_t suma;
    
    if (ancho == 2){
        suma = suma_t(thresshold(0.5,m.getElem(i  ,j  )-m.getElem((i  ),(j+1))),
                      thresshold(0.5,m.getElem(i  ,j+1)-m.getElem((i+1),(j+1))),
                      thresshold(0.5,m.getElem(i+1,j+1)-m.getElem((i+1),(j  ))),
                      thresshold(0.5,m.getElem(i+1,j  )-m.getElem((i  ),(j ))));
        
        transformacion_t t = getScanTransform (suma);
        
     //   cout << "para [" << i << "," << j << "] suma: " << suma << " t: " << t << endl;
        
        m.setElem( i  , j+1, m.getElem(i  ,j+1) + t[0] );  // up right
        m.setElem( i+1, j  , m.getElem(i+1,j  ) + t[1] );  // down left
        m.setElem( i+1, j+1, m.getElem(i+1,j+1) + t[2] );  // down right
    }

    else{ /* ancho variable */
        int medio = ancho/2;
    
        int *unoDos    = (int*)malloc (medio*sizeof(int));
        int *dosCuatro = (int*)malloc (medio*sizeof(int));
        int *cuatroTres= (int*)malloc (medio*sizeof(int));
        int *tresUno   = (int*)malloc (medio*sizeof(int));
        
        // define las fronteras
        int f1 = medio-1;
        int f2  = medio;
        
        for (int e =0; e <medio; e++){
            unoDos[e]    =thresshold(0.5,m.getElem(i+e ,j+f1)-
														   m.getElem(i+e,j+f2));
        }
        for (int e =0; e <medio; e++){
            dosCuatro[e] =thresshold(0.5,m.getElem(i+f1,j+f2+e)-
													    m.getElem(i+f2,j+f2+e));
        }
        for (int e =0; e <medio; e++){
            cuatroTres[e]=thresshold(0.5, m.getElem(i+f2+e,j+f2)-
													    m.getElem(i+f2+e,j+f1));
        }
        for (int e =0; e <medio; e++){
            tresUno[e]   =thresshold(0.5, m.getElem(i+f2 ,j+e)-
													      m.getElem(i+f1, j+e));
        }
        
        suma.setZero();
        for (int n= 0; n < medio; n++){
            suma[0] += unoDos    [n];
            suma[1] += dosCuatro [n];
            suma[2] += cuatroTres[n];
            suma[3] += tresUno   [n];
        }
        suma[0] = thresshold(0.5, (suma[0])/medio);
        suma[1] = thresshold(0.5, (suma[1])/medio);
        suma[2] = thresshold(0.5, (suma[2])/medio);
        suma[3] = thresshold(0.5, (suma[3])/medio);   
        
		transformacion_t t = getScanTransform(suma);
        
        cout << "for [" << i << "," << j << "] sum: " << 
				suma << " t: " << t << endl;
        
        //        aplicar transformación:
        
        for (int a =0; a <medio; a++){
            for (int b =0; b <medio; b++){
                m.setElem(i+a, j+medio+b, m.getElem(i+a,j+medio+b) + t[0]);
            }
        }
        for (int a =0; a <medio; a++){
            for (int b =0; b <medio; b++){
                m.setElem(i+medio+a, j+b, m.getElem(i+medio+a,j+b) + t[1]);
            }
        }
        for (int a =0; a <medio; a++){
            for (int b =0; b <medio; b++){
                m.setElem(i+medio+a, j+medio+b, m.getElem(i+medio+a,j+medio+b) + t[2]);
            }
        }  
        
        free(unoDos);
        free(dosCuatro);
        free(cuatroTres);
        free(tresUno);
    }
}