Example #1
0
void Testdata(ostream &fo)
{

    Date now;
    string p[]=
    {
        "--","d--","dd--","-m-",
        "d-m-","dd-m-","-mm-","d-mm-",
        "dd-mm-","-mmm-","d-mmm-","dd-mmm-",
        "--yy","d--yy","dd--yy","-m-yy",
        "d-m-yy","dd-m-yy","-mm-yy","d-mm-yy",
        "dd-mm-yy","-mmm-yy","d-mmm-yy","dd-mmm-yy",
        "--yyyy","d--yyyy","dd--yyyy","-m-yyyy",
        "d-m-yyyy","dd-m-yyyy","-mm-yyyy","d-mm-yyyy",
        "dd-mm-yyyy","-mmm-yyyy","d-mmm-yyyy","dd-mmm-yyyy"
    };

    //printing all the date formats

    fo<<"********************************************************************************"<<endl;
    fo<<"Printing all types formats"<<endl;

    DateFormat *format[36];
    for(int k=0; k<36; k++)
    {
        format[k]=checkformat1(fo,p[k]);
        fo<<"\n";
    }

    fo<<"********************************************************************************"<<endl;
    fo<<"Printing all types formats if given input in different format"<<endl;
    for(int k=0; k<36; k++)
    {
        int d=p[k].find_first_of("-",0);
        int y=p[k].find_first_of("-",d+1);
        string a,b,c;
        a=p[k].substr(0,d);
        b=p[k].substr(d+1,y-d-1);
        c=p[k].substr(y+1);
        checkformat2(fo,a,b,c);
    }

    fo<<"********************************************************************************"<<endl;
    checkdate1(fo);
    fo<<"********************************************************************************"<<endl;
    checkdate2(fo);
    fo<<"********************************************************************************"<<endl;
    Date now2(now);


    fo<<"Testing ++,++(int) operators"<<endl;
    fo<<++now<<"\n"<<endl;

    fo<<now++<<"\n"<<endl;

    fo<<"********************************************************************************"<<endl;
    fo<<"Testing --,--(int) operators"<<endl;
    fo<<--now<<"\n"<<endl;

    fo<<now--<<"\n"<<endl;

    Date datevar1("10-03-2019");

    fo<<"********************************************************************************"<<endl;
    fo<<"Testing + operator"<<endl;

    Date datevar2(D09,Mar,2016);

    fo<<datevar2+1<<"--> ITS MY BIRTHDAY!!!"<<endl;

    fo<<"Wish me at  https://www.facebook.com/sricharan6996 "<<"\n"<<endl;

    try
    {
        fo<<datevar2+100000<<"\n"<<endl;
    }
    catch(exception &e)
    {
        fo<<e.what()<<"\n"<<endl;
    }

    fo<<"********************************************************************************"<<endl;
    fo<<"Testing operator(-) "<<endl;
  Date dt1  (D15,Mar,2020),dt2(D30,Sep,2025);

    fo<<dt2-dt1<<"\n"<<endl;


   fo<<"********************************************************************************"<<endl;
    fo<<"Testing Weekday operators"<<endl;

    fo<<(WeekDay)dt2<<"\n"<<endl;

    fo<<(WeekDay)(dt2+1)<<"\n"<<endl;

    fo<<"********************************************************************************"<<endl;
    fo<<"Testing weeknumber operators"<<endl;

    fo<<(WeekNumber)dt2<<"\n"<<endl;

    fo<<(WeekNumber)(dt2+1)<<"\n" <<endl;

   fo<<"********************************************************************************"<<endl;
    fo<<"Testing month operators"<<endl;

    fo<<(Month)now<<"\n"<<endl;

    fo<<(Month)(now+365)<<"\n"<<endl;

    fo<<now.leapYear()<<"\n"<<endl;

    fo<<datevar2.leapYear()<<"\n"<<endl;

    fo<<"********************************************************************************"<<endl;
    fo<<"Testing == ,!=,<=,<,>=,> operators"<<endl;

    fo<<(datevar1==datevar2)<<"\n"<<endl;

    fo<<(datevar1!=datevar2)<<"\n"<<endl;

    fo<<(datevar1<=datevar2)<<"\n"<<endl;

    fo<<(datevar1<datevar2)<<"\n"<<endl;

    fo<<(datevar1>=datevar2)<<"\n"<<endl;

    fo<<(datevar1>datevar2)<<"\n"<<endl;

    fo<<"********************************************************************************"<<endl;
    fo<<"Testing set and get formats"<<endl;
    for(int k=0; k<36; k++)
    {
        Date::setFormat(*format[k]);

        fo<<Date::getFormat().getdate()<<"\n"<<endl;

        fo<<Date::getFormat().getmonth()<<"\n"<<endl;

        fo<<Date::getFormat().getyear()<<"\n"<<endl;

    }

    fo<<"********************************************************************************"<<endl;
    fo<<"Testing assignment operator"<<endl;
    datevar2=now;

    fo<<datevar2<<"\n"<<endl;
    fo<<"********************************************************************************"<<endl;
    fo<<"Testing operators"<<endl;
    for(int k=0; k<36; k++)
    {

        fo<<p[k];
        Date::setFormat(*format[k]);
        fo<<now<<"\n"<<endl;
    }

    delete [] format;

}
Example #2
0
/*! 
SLCamera::onTouch2Move gets called whenever two fingers move on a handheld 
screen.
*/
SLbool SLCamera::onTouch2Move(const SLint x1, const SLint y1,
                              const SLint x2, const SLint y2)
{	
   SLScene* s = SLScene::current;
   SLSceneView* sv = s->activeSV();
   SLVec2f now1((SLfloat)x1, (SLfloat)y1);
   SLVec2f now2((SLfloat)x2, (SLfloat)y2);
   SLVec2f delta1(now1-_oldTouchPos1);
   SLVec2f delta2(now2-_oldTouchPos2);
   
   // Average out the deltas over the last 4 events for correct 1 pixel moves
   static SLuint  cnt=0;
   static SLVec2f d1[4];
   static SLVec2f d2[4];
   d1[cnt%4] = delta1;
   d2[cnt%4] = delta2;
   SLVec2f avgDelta1(d1[0].x+d1[1].x+d1[2].x+d1[3].x, d1[0].y+d1[1].y+d1[2].y+d1[3].y);
   SLVec2f avgDelta2(d2[0].x+d2[1].x+d2[2].x+d2[3].x, d2[0].y+d2[1].y+d2[2].y+d2[3].y);
   avgDelta1 /= 4.0f;
   avgDelta2 /= 4.0f;
   cnt++;
      
   SLfloat r1, phi1, r2, phi2;
   avgDelta1.toPolar(r1, phi1);
   avgDelta2.toPolar(r2, phi2);
    
   // Scale the mouse delta by the lookAt distance
   SLfloat lookAtDist;
   if (_lookAtRay.length < FLT_MAX)
        lookAtDist = _lookAtRay.length;
   else lookAtDist = _focalDist;
         
   // scale factor depending on the space sice at focal dist
   SLfloat spaceH = tan(SL_DEG2RAD*_fov/2) * lookAtDist * 2.0f;
   SLfloat spaceW = spaceH * sv->scrWdivH();
   
   //SL_LOG("avgDelta1: (%05.2f,%05.2f), dPhi=%05.2f\n", avgDelta1.x, avgDelta1.y, SL_abs(phi1-phi2));
   
   // if fingers move parallel slide camera vertically or horizontally
   if (SL_abs(phi1-phi2) < 0.2f)
   {  
      // Calculate center between finger points
      SLVec2f nowCenter((now1+now2)*0.5f);
      SLVec2f oldCenter((_oldTouchPos1+_oldTouchPos2)*0.5f);
      
      // For first move set oldCenter = nowCenter
      if (oldCenter == SLVec2f::ZERO) oldCenter = nowCenter;
      
      SLVec2f delta(nowCenter - oldCenter);

      // scale to 0-1
      delta.x /= (SLfloat)sv->scrW();
      delta.y /= (SLfloat)sv->scrH();

      // scale to space size
      delta.x *= spaceW;
      delta.y *= spaceH;
      
      if (_camAnim==turntableYUp || _camAnim==turntableZUp)
      {           
         // apply delta to x- and y-position
         _vm.translation(_vm.m(12) + delta.x,
                         _vm.m(13) - delta.y,
                         _vm.m(14));

         setWMandState();
      } 
      else if (_camAnim == walkingYUp || _camAnim == walkingZUp)
      {
      	_maxSpeed.x = delta.x * 100.0f,
         _maxSpeed.z = delta.y * 100.0f;
      }

   } else // Two finger pinch
   {  
      // Calculate vector between fingers
      SLVec2f nowDist(now2 - now1);
      SLVec2f oldDist(_oldTouchPos2-_oldTouchPos1);
      
      // For first move set oldDist = nowDist
      if (oldDist == SLVec2f::ZERO) oldDist = nowDist;
      
      SLfloat delta = oldDist.length() - nowDist.length();

      if (_camAnim==turntableYUp)
      {  // scale to 0-1
         delta /= (SLfloat)sv->scrH();

         // scale to space height
         delta *= spaceH*2;
         
         // apply delta to the z-position
         _vm.translation(_vm.m(12),
                         _vm.m(13),
                         _vm.m(14) - delta);

         setWMandState();
      } 
      else if (_camAnim == walkingYUp)
      {  
         // change field of view
         _fov += SL_sign(delta) * 0.5f;
         currentFOV = _fov;
      }
   }

   _oldTouchPos1.set((SLfloat)x1, (SLfloat)y1);
   _oldTouchPos2.set((SLfloat)x2, (SLfloat)y2);
   return true;
}