示例#1
0
int addPositionToObject(
                              struct VirtualStream * stream ,
                              char * name  ,
                              unsigned int time ,
                              float * coord ,
                              unsigned int coordLength
                       )
{

 unsigned int ObjFound = 0;
 unsigned int ObjID = getObjectID(stream,name,&ObjFound);

  if (!ObjFound) {
                   fprintf(stderr,"Could not Find object %s \n",name);
                   return 0;
                 }


  if (stream->object[ObjID].MAX_numberOfFrames<=stream->object[ObjID].numberOfFrames+1) { growVirtualStreamFrames(&stream->object[ObjID],FRAMES_TO_ADD_STEP); }
  //Now we should definately have enough space for our new frame
  if (stream->object[ObjID].MAX_numberOfFrames<=stream->object[ObjID].numberOfFrames+1) { fprintf(stderr,"Cannot add new POS instruction to Object %u \n",ObjID); return 0; }

  //We have the space so lets fill our new frame spot ..!
  unsigned int pos = stream->object[ObjID].numberOfFrames;

  // 1 is object name
  stream->object[ObjID].frame[pos].time = time;
  if (coordLength > 0 ) {  stream->object[ObjID].frame[pos].x = coord[0]; }
  if (coordLength > 1 ) {  stream->object[ObjID].frame[pos].y = coord[1]; }
  if (coordLength > 2 ) {  stream->object[ObjID].frame[pos].z = coord[2]; }

  if (coordLength > 3 ) {stream->object[ObjID].frame[pos].rot1 = coord[3]; }
  if (coordLength > 4 ) {stream->object[ObjID].frame[pos].rot2 = coord[4]; }
  if (coordLength > 5 ) {stream->object[ObjID].frame[pos].rot3 = coord[5]; }
  if (coordLength > 6 ) {stream->object[ObjID].frame[pos].rot4 = coord[6]; }

  if (stream->object[ObjID].MAX_timeOfFrames <= stream->object[ObjID].frame[pos].time)
    {
     stream->object[ObjID].MAX_timeOfFrames = stream->object[ObjID].frame[pos].time;
    } else
    {
     fprintf(stderr,"Error in configuration file , object positions not in correct time order (this %u , last max %u).. \n",
             stream->object[ObjID].frame[pos].time,
             stream->object[ObjID].MAX_timeOfFrames);
    }

  #if PRINT_DEBUGGING_INFO
   fprintf(stderr,"String %s resolves to : \n",line);
   fprintf(stderr,"X %02f Y %02f Z %02f ROT %02f %02f %02f %02f\n",stream->object[ObjID].frame[pos].x,stream->object[ObjID].frame[pos].y,stream->object[ObjID].frame[pos].z ,
   stream->object[ObjID].frame[pos].rot1 , stream->object[ObjID].frame[pos].rot2 , stream->object[ObjID].frame[pos].rot3 , stream->object[ObjID].frame[pos].rot4 );
  #endif


  ++stream->object[ObjID].numberOfFrames;
  return 1;
}
示例#2
0
int affixSatteliteToPlanetFromFrameForLength(struct VirtualStream * stream,unsigned int satteliteObj,unsigned int planetObj , unsigned int frameNumber , unsigned int duration)
{
  fprintf(stderr,"affixSatteliteToPlanetFromFrameForLength(sat=%u,planet=%u) from frame %u to frame %u \n",satteliteObj,planetObj,frameNumber,frameNumber+duration);
  if ( satteliteObj >= stream->numberOfObjects ) { fprintf(stderr,RED "affixSatteliteToPlanetFromFrameForLength referencing non existent Object %u\n" NORMAL,satteliteObj); return 0; }
  if ( planetObj >= stream->numberOfObjects )    { fprintf(stderr,RED "affixSatteliteToPlanetFromFrameForLength referencing non existent Object %u\n" NORMAL,planetObj);    return 0; }

  unsigned int satteliteObjFrameNumber = stream->object[satteliteObj].numberOfFrames;
  unsigned int planetObjFrameNumber    = stream->object[planetObj].numberOfFrames;

  unsigned int satteliteObjMaxFrameNumber = stream->object[satteliteObj].MAX_numberOfFrames;
  unsigned int planetObjMaxFrameNumber    = stream->object[planetObj].MAX_numberOfFrames;

  if ( satteliteObjMaxFrameNumber <  planetObjFrameNumber )
     {
       unsigned int growthSize = planetObjFrameNumber-satteliteObjMaxFrameNumber+frameNumber+1;
       fprintf(stderr,GREEN" sattelite : growing sattelite stream to accomodate %u poses , as many as the planet stream\n" NORMAL,growthSize);
       //GROW STREAM HERE
       growVirtualStreamFrames(&stream->object[satteliteObj],growthSize);
       satteliteObjFrameNumber = stream->object[satteliteObj].numberOfFrames;
       satteliteObjMaxFrameNumber = stream->object[satteliteObj].MAX_numberOfFrames;
     }



  if ( satteliteObjFrameNumber <= frameNumber )
     {
       fprintf(stderr,RED " sattelite : referencing non existent frames ( %u ) \n" NORMAL,frameNumber);
       return 0;
     }
  if ( satteliteObjMaxFrameNumber < frameNumber+duration )
     {
       fprintf(stderr,RED " sattelite : referencing non existent frames ( want %u + %u frames , but max frame is %u ) \n" NORMAL,frameNumber,duration,satteliteObjMaxFrameNumber);
       duration = satteliteObjMaxFrameNumber-frameNumber;
       fprintf(stderr,RED " sattelite : correcting duration to %u\n" NORMAL,duration);
     }

  // PLANET CODE --------------------------------------------------------------
  if ( planetObjFrameNumber <= frameNumber )
     {
       fprintf(stderr,RED " planet : referencing non existent frames ( %u ) \n" NORMAL,frameNumber);
       return 0;
     }
  if ( planetObjFrameNumber < frameNumber+duration )
     {
       fprintf(stderr,RED " planet : referencing non existent frames ( want %u + %u frames , but max frame is %u ) \n" NORMAL,frameNumber,duration,planetObjFrameNumber);
       duration = planetObjFrameNumber-frameNumber;
       fprintf(stderr,RED " planet : correcting duration to %u\n" NORMAL,duration);
     }

    //There is literally no good reason to go from rotation -> quaternion -> 3x3 -> quaternion -> rotation this could be optimized
    //==================================================================================
    double satPosAbsolute[4]={0};
    satPosAbsolute[0] = (double) stream->object[satteliteObj].frame[frameNumber].x;
    satPosAbsolute[1] = (double) stream->object[satteliteObj].frame[frameNumber].y;
    satPosAbsolute[2] = (double) stream->object[satteliteObj].frame[frameNumber].z;
    satPosAbsolute[3] = 1.0;
    //==================================================================================
    double planetPosAbsolute[4]={0};
    planetPosAbsolute[0] = (double) stream->object[planetObj].frame[frameNumber].x;
    planetPosAbsolute[1] = (double) stream->object[planetObj].frame[frameNumber].y;
    planetPosAbsolute[2] = (double) stream->object[planetObj].frame[frameNumber].z;
    planetPosAbsolute[3] = 1.0;

    double planetRotAbsolute[4]={0};
    planetRotAbsolute[0] = (double) stream->object[planetObj].frame[frameNumber].rot1;
    planetRotAbsolute[1] = (double) stream->object[planetObj].frame[frameNumber].rot2;
    planetRotAbsolute[2] = (double) stream->object[planetObj].frame[frameNumber].rot3;


    parseAbsoluteRotation(stream,planetRotAbsolute,planetObj,frameNumber);
    //==================================================================================


    double satPosRelative[4]={0};
    pointFromAbsoluteToRelationWithObject_PosXYZRotationXYZ(satPosRelative,planetPosAbsolute,planetRotAbsolute,satPosAbsolute);

    unsigned int pos=0;
    fprintf(stderr,YELLOW " Will align satelite to planet from frame %u to %u\n" NORMAL ,frameNumber+1 , frameNumber+duration );
    for (pos=frameNumber+1; pos<frameNumber+duration; pos++)
    {
       planetPosAbsolute[0] = (double) stream->object[planetObj].frame[pos].x;
       planetPosAbsolute[1] = (double) stream->object[planetObj].frame[pos].y;
       planetPosAbsolute[2] = (double) stream->object[planetObj].frame[pos].z;
       planetPosAbsolute[3] = 1.0;

       parseAbsoluteRotation(stream,planetRotAbsolute,planetObj,frameNumber);

       if ( pointFromRelationWithObjectToAbsolute_PosXYZRotationXYZ(satPosAbsolute,planetPosAbsolute,planetRotAbsolute,satPosRelative) )
       {
         stream->object[satteliteObj].frame[pos].x = (float) satPosAbsolute[0];
         stream->object[satteliteObj].frame[pos].y = (float) satPosAbsolute[1];
         stream->object[satteliteObj].frame[pos].z = (float) satPosAbsolute[2];
         stream->object[satteliteObj].frame[pos].time = stream->object[planetObj].frame[pos].time;
         //stream->object[satteliteObj].frame[pos].isQuaternion = 0;
       }

       //  stream->object[satteliteObj].frame[pos].x = stream->object[planetObj].frame[pos].x;
      //   stream->object[satteliteObj].frame[pos].y = stream->object[planetObj].frame[pos].y;
      //   stream->object[satteliteObj].frame[pos].z = stream->object[planetObj].frame[pos].z-0.5;
    }

    //Everything is set now to mark the sattelite new end
    stream->object[satteliteObj].numberOfFrames = stream->object[planetObj].numberOfFrames;// frameNumber+duration; //stream->object[planetObj].numberOfFrames;
    stream->object[satteliteObj].lastFrame = stream->object[planetObj].lastFrame;
    stream->object[satteliteObj].MAX_timeOfFrames = stream->object[planetObj].MAX_timeOfFrames;
    stream->object[satteliteObj].numberOfFrames = stream->object[planetObj].numberOfFrames;
 return 1;

}