/*
Obligatory empty constructor, clears all of the vectors, and
sets all of the arrays to zero dimensional arrays

updates required
-The hard coded image needs to be user defined
-
*/
renderer::renderer(void)
{
	//This clears the arrays
	clearArrays();
	
	tempVertices.clear();
	tempColors.clear();
	//This needs to be user selected, or an agreed upon
	//null image needs to be made
	tileData = new image[1];
	tileData -> changeName("rough_tiles.png");
	
	playerData = new image[1];
	playerData -> addCharacter();
	//playerData.setupTexture();
	//Initialize the image binary to a 0
	//dimensional array to avoid memory issues
	//characterData = new image[50];

	/*Player data will always be in 6 doubles
	and 6 triples (2 triangles, not in strips).
	So this is a valid to always set the size
	of the player character, if two player is implemented
	revision will be needed to handle an array of player
	arrays*/
	playerArray = new int*[12];
	int temp = 1;
	double dTemp = 1;
	for(int i = 0; i < 18; i++) playerArray[i] = &temp;
	//for(int i = 0; i < 18; i++) playerColors[i] = &dTemp;

	/*Object Data, and NPC data needs to be added to this function*/
	buildOk = true;
}
Beispiel #2
0
//------------------------------------------------------------------------------
// Resize the target data arrays (0 .. Gimbal::MAX_PLAYERS)
// -- old data is lost
//------------------------------------------------------------------------------
bool Tdb::resizeArrays(const unsigned int newSize)
{
   bool ok = false;
   if (newSize <= Gimbal::MAX_PLAYERS) {

      // Clear out the old data
      clearArrays();

      if (newSize != maxTargets) {

         // Free up the old memory
         if (ranges != 0)   { delete[] ranges;   ranges = 0; }
         if (rngRates != 0) { delete[] rngRates; rngRates = 0; }
         if (losG != 0)     { delete[] losG;     losG = 0; }
         if (losO2T != 0)   { delete[] losO2T;   losO2T = 0; }
         if (losT2O != 0)   { delete[] losT2O;   losT2O = 0; }
         if (aar != 0)      { delete[] aar;      aar = 0; }
         if (aazr != 0)     { delete[] aazr;     aazr = 0; }
         if (aelr != 0)     { delete[] aelr;     aelr = 0; }

         if (targets != 0)  { delete[] targets;  targets = 0; }
         maxTargets = 0;

         if (xa != 0)  { delete[] xa;  xa = 0; }
         if (ya != 0)  { delete[] ya;  ya = 0; }
         if (za != 0)  { delete[] za;  za = 0; }
         if (ra2 != 0)  { delete[] ra2;  ra2 = 0; }
         if (ra != 0)  { delete[] ra;  ra = 0; }

         // Allocate new memory
         if (newSize > 0) {
            ranges   = new double[newSize];
            rngRates = new double[newSize];
            losG     = new osg::Vec3d[newSize];
            losO2T   = new osg::Vec3d[newSize];
            losT2O   = new osg::Vec3d[newSize];
            aar      = new double[newSize];
            aazr     = new double[newSize];
            aelr     = new double[newSize];
            targets  = new Player*[newSize];
            for (unsigned int i = 0; i < newSize; i++) {
               targets[i] = 0;
            }
            maxTargets = newSize;
            xa = new double[newSize];
            ya = new double[newSize];
            za = new double[newSize];
            ra2 = new double[newSize];
            ra = new double[newSize];
         }

      }

      ok = true;
   }
   return ok;
}
/*
Build arrays sets up the arrays that hold all of the draw information
Arrays are only built if two conditions are met, the first of which is 
ther has been a change to the current world information and the second
is there needs to be available world information to be written

Updates required
-Addition of character arrays
-Addition of object arrays

*/
void renderer::buildArrays(void)
{
	if(!tempVertices.empty())
	{
		clearArrays();
		tileArray = new int[tempVertices.size()*2];
		tileColors = new double[tempColors.size()*3];
		for(unsigned int i = 0; i < tempVertices.size(); i++)
		{
			tileArray[i*2] = tempVertices.at(i)[0];
			tileArray[i*2 + 1] = tempVertices.at(i)[1];
			tileColors[i*3] = tempColors.at(i)[0];
			tileColors[i*3 + 1] = tempColors.at(i)[1];
			tileColors[i*3 + 2] = tempColors.at(i)[2];
		}
		//This line indicates that all of the current world is
		//up-to-date and is not needed to be recalculated
		buildOk = false;
	}
}
Beispiel #4
0
//------------------------------------------------------------------------------
// Process players-of-interest --- Scan the provided player list and compute range,
// range rate, normalized Line-Of-Sight (LOS) vectors for each target player.
// (Background task)
//------------------------------------------------------------------------------
unsigned int TdbIr::processPlayers(Basic::PairStream* const players)
{
   // Clear the old data
   clearArrays();

   // ---
   // Early out checks (no ownship, no players of interest, no target data arrays)
   // ---
   if (gimbal == 0 || ownship == 0 || players == 0 || maxTargets == 0) return 0;
    
   //const Basic::Pair* p = ((Player*)ownship)->getIrSystemByType( typeid(IrSensor) );
   //if (p == 0) return 0;

   // FAB - refactored
   //const IrSensor* irSensor = (const IrSensor*)( p->object() );
   //if (irSensor == 0) 
      //return 0;

   // FAB - limit is +/- (1/2 FORtheta + 1/2 IFOVtheta) (but both get..Theta() actually return 1/2 Theta)		   
   //LCreal fieldOfRegardTheta = irSensor->getFieldOfRegardTheta() + irSensor->getIFOVTheta();
   //LCreal maxRange = irSensor->getMaximumRange();

   // FAB - basically the same as TDB/gimbal version:
   const double maxRange = gimbal->getMaxRange2PlayersOfInterest();
   const double maxAngle = gimbal->getMaxAngle2PlayersOfInterest();

   // ---
   // Get our position and velocity vectors
   // ## using ownship position for now; should include the location of the gimbal ##
   // ---
   osg::Vec3 p0 = ownship->getPosition();  // Position Vector
   osg::Vec3 v0 = ownship->getVelocity();  // Ownship Velocity Vector

   // ---
   // 1) Scan the player list --- compute the normalized Line-Of-Sight (LOS) vectors,
   // range, and range rate for each target.
   // ---
   for (Basic::List::Item* item = players->getFirstItem(); item != 0 && numTgts < maxTargets; item = item->getNext()) {

      
      // Get the pointer to the target player
      Basic::Pair* pair = (Basic::Pair*)(item->getValue());
      Player* target = (Player*)(pair->object());

     // FAB - testing - exclude our launch vehicle in tdb
     //if (ownship->isMajorType(Player::WEAPON) && ((Weapon*)ownship)->getLaunchVehicle() == target)
     //continue;

      if (target != ownship && target->isActive()) {
         bool aboveHorizon = true; 
         aboveHorizon = horizonCheck (ownship->getPosition(), target->getPosition());

         // FAB - refactored - don't continue if we know we're excluding this target
         if (!aboveHorizon) continue;

         // Determine if target is within azimuth and elevation checks. If it is, keep it.
         // Otherwise, reject.

         osg::Vec3 targetPosition = target->getPosition();
         osg::Vec3 losVector = targetPosition - p0;
         //osg::Vec3 xlos = -losVector;
       LCreal aazr;
       LCreal aelr;
       LCreal ra;

      if (irSensor->getSeeker()->getOwnHeadingOnly()) {
         // FAB - this calc for gimbal ownHeadingOnly true
         // compute ranges
         LCreal gndRng2 = losVector.x()*losVector.x() + losVector.y()*losVector.y();
         ra = lcSqrt(gndRng2);
         
         // compute angles
         LCreal los_az = lcAtan2(losVector.y(),losVector.x());
         double hdng = ownship->getHeadingR();
         aazr = lcAepcRad(los_az - (float)hdng);
         aelr = lcAtan2(-losVector.z(), ra);
      }
      else {
         // FAB - this calc for gimbal ownHeadingOnly false
         //osg::Vec4 los0( losVector.x(), losVector.y(), losVector.z(), 0.0 );
         //osg::Vec4 aoi = ownship->getRotMat() * los0;
         osg::Vec3 aoi = ownship->getRotMat() * losVector;
         // 3) Compute the azimuth and elevation angles of incidence (AOI)

         // 3-a) Get the aoi vector values & compute range squared
         LCreal xa = aoi.x();
         LCreal ya = aoi.y();
         LCreal za = -aoi.z();

         ra = lcSqrt(xa*xa + ya*ya);
         // 3-b) Compute azimuth: az = atan2(ya, xa)
         aazr = lcAtan2(ya, xa);
         // 3-c) Compute elevation: el = atan2(za, ra), where 'ra' is sqrt of xa*xa & ya*ya
         aelr = lcAtan2(za,ra);
      }

         LCreal absoluteAzimuth = aazr; 

         if (aazr < 0) absoluteAzimuth = -aazr; 

         LCreal absoluteElevation = aelr;
         if (aelr < 0) absoluteElevation = -aelr;

         bool withinView = true; 

      //   LCreal fieldOfRegardTheta = 0;
      //   LCreal sensorMaxRange = 0;
      //   {
      //      //const Basic::Pair* p = ((Player*)ownship)->getIrSystemByType( typeid(IrSensor) );
      //      //if (p != 0) {
      //         //const IrSensor* irSensor = (const IrSensor*)( p->object() );
      //         // fieldOfRegardTheta = irSensor->getFieldOfRegardTheta();
          //// FAB - limit is +/- (1/2 FORtheta + 1/2 IFOVtheta) (but both get..Theta() actually return 1/2 Theta)
          //fieldOfRegardTheta = irSensor->getFieldOfRegardTheta() + irSensor->getIFOVTheta();
      //         sensorMaxRange = irSensor->getMaximumRange();
      //      //}
      //   }

         if ((absoluteAzimuth > maxAngle) ||  // outside field of view
            (absoluteElevation > maxAngle) ||
            (ra > maxRange) ||    // beyond max range of sensor
            !aboveHorizon)
            withinView = false; 
 
         if (withinView) {

            // Ref() and save the target pointer
            // (## It must be unref()'d by the owner/manager of the Tdb array ##)
            target->ref();
            targets[numTgts] = target;

          // FAB - these seem to be unnecessary - recalc'd by Tdb::computeBoresightData anyway
            // Line-Of-Sight (LOS) vector (world)
            //losO2T[numTgts] = target->getPosition() - p0;

            // Normalized and compute length [unit vector and range(meters)]
            //ranges[numTgts] = losO2T[numTgts].normalize();

            // Computer range rate (meters/sec)
            //rngRates[numTgts] = (LCreal) ((target->getVelocity() - v0) * losO2T[numTgts]);

            // Save the target pointer (for quick access)
            numTgts++;
         }
      } //(target != ownship && target->isActive())
   }

   return numTgts;
}
Beispiel #5
0
bool CQMathMatrixWidget::update(ListViews::ObjectType C_UNUSED(objectType), ListViews::Action
                                C_UNUSED(action), const std::string & C_UNUSED(key))
{
  clearArrays();
  return true;
}
Beispiel #6
0
bool CQMathMatrixWidget::updateProtected(ListViews::ObjectType objectType, ListViews::Action action, const CCommonName & cn)
{
  clearArrays();
  updateJacobianIfTabSelected();
  return true;
}