Esempio n. 1
0
void TraceTest::testSarsaOnMountainCarMaxLengthTraces()
{
  Random<double>* random = new Random<double>;
  RLProblem<double>* problem = new MountainCar<double>(random);
  Hashing<double>* hashing = new MurmurHashing<double>(random, 10000);
  Projector<double>* projector = new TileCoderHashing<double>(hashing, problem->dimension(), 10, 10,
      false);
  Trace<double>* e = new ATrace<double>(projector->dimension());
  Trace<double>* trace = new MaxLengthTrace<double>(e, 100);
  runTest(random, problem, projector, e);
  delete trace;
  delete e;

  e = new AMaxTrace<double>(projector->dimension());
  trace = new MaxLengthTrace<double>(e, 100);
  runTest(random, problem, projector, e);
  delete trace;
  delete e;

  e = new RTrace<double>(projector->dimension());
  trace = new MaxLengthTrace<double>(e, 100);
  runTest(random, problem, projector, e);
  delete trace;
  delete e;

  delete random;
  delete problem;
  delete hashing;
  delete projector;
}
//----------------------------------------------------------------------------
void AmbientRegionActor::_UpdateDirLightCamera()
{
	AVector dir = AVector::AnglesToDirection(Mathf::DEG_TO_RAD*mHorAngle,
		Mathf::DEG_TO_RAD*mVerAngle);
	dir.Normalize();

	Scene *scene = DynamicCast<Scene>(GetTopestParent());
	if (scene)
	{
		EnvirParam *envirParam = scene->GetEnvirParam();

		Light *lightDir = envirParam->GetLight_Dir();
		Projector *projector = envirParam->GetLight_Dir_Projector();

		lightDir->Ambient = Float4(mAmbientColor[0], mAmbientColor[1],
			mAmbientColor[2], mIntensity);
		lightDir->Intensity = mIntensity;
		lightDir->Diffuse = Float4(mDiffuseColor[0], mDiffuseColor[1],
			mDiffuseColor[2], 1.0f);
		lightDir->Specular = Float4(mSpecularColor[0], mSpecularColor[1],
			mSpecularColor[2], mSpecularPow);

		float upDot = dir.Dot(-AVector::UNIT_Z);
		if (upDot >= 0.99f)
		{
		}
		else
		{
			AVector upTemp = AVector::UNIT_Z;
			AVector right = dir.UnitCross(upTemp);
			AVector up = right.UnitCross(dir);

			lightDir->DVector = dir;
			lightDir->UVector = up;
			lightDir->RVector = right;

			APoint camPos = mLightCameraLookPosition - dir*mLightCameraLookDistance;
			projector->SetFrame(camPos, lightDir->DVector,
				lightDir->UVector, lightDir->RVector);
		}

		if (!projector->IsPerspective())
		{
			projector->SetFrustum(0.1f, 100.0f,
				-mLightCameraExtent, mLightCameraExtent, -mLightCameraExtent,
				mLightCameraExtent);
		}
		else
		{
			projector->SetFrustum(mLightCameraExtent, 1.0f, 1.0f, 100.0f);
		}
	}
}
Esempio n. 3
0
//----------------------------------------------------------------------------
void ProjectedTextures::CreateScene ()
{
    mScene = new0 Node();
    mTrnNode = new0 Node();
    mScene->AttachChild(mTrnNode);

    // Load the face model.
#ifdef WM5_LITTLE_ENDIAN
    std::string path = Environment::GetPathR("FacePN.wmof");
#else
    std::string path = Environment::GetPathR("FacePN.be.wmof");
#endif
    InStream inStream;
    inStream.Load(path);
    TriMesh* mesh = StaticCast<TriMesh>(inStream.GetObjectAt(0));

    // Create a camera to project the texture.
    Projector* projector = new0 Projector(Camera::PM_DEPTH_ZERO_TO_ONE);
    projector->SetFrustum(1.0f, 10.0f, -0.4125f, 0.4125f, -0.55f, 0.55f);
    AVector proDVector(0.0f, 1.0f, 0.0f);
    AVector proUVector(0.0f, 0.0f, 1.0f);
    AVector proRVector = proDVector.Cross(proUVector);
    APoint proPosition = APoint::ORIGIN - 303.0f*proDVector;
    projector->SetFrame(proPosition, proDVector, proUVector, proRVector);

    // Create a directional light for the face.
    Light* light = new0 Light(Light::LT_DIRECTIONAL);
    light->Ambient = Float4(0.25f, 0.25f, 0.25f, 1.0f);
    light->Diffuse = Float4(1.0f, 1.0f, 1.0f, 1.0f);
    light->Specular = Float4(0.0f, 0.0f, 0.0f, 1.0f);
    light->DVector = AVector::UNIT_Y;  // scene-camera direction

    // Create a material for the face.
    Material* material = new0 Material();
    material->Emissive = Float4(0.0f, 0.0f, 0.0f, 1.0f);
    material->Ambient = Float4(0.5f, 0.5f, 0.5f, 1.0f);
    material->Diffuse = Float4(0.99607f, 0.83920f, 0.67059f, 1.0f);
    material->Specular = Float4(0.8f, 0.8f, 0.8f, 0.0f);

    // Create the effect.
    std::string effectFile = Environment::GetPathR("ProjectedTexture.wmfx");
    ProjectedTextureEffect* effect = new0 ProjectedTextureEffect(effectFile);

    std::string projectedName = Environment::GetPathR("Magician.wmtf");
    Texture2D* projectedTexture = Texture2D::LoadWMTF(projectedName);
    mesh->SetEffectInstance(effect->CreateInstance(projector, light,
        material, projectedTexture));

    mTrnNode->AttachChild(mesh);
}
 void watchMovie(std::string movie) {
     std::cout << "Get ready to watch a movie..." << std::endl;
     _popper->on();
     _popper->pop();
     _lights->dim(10);
     _screen->down();
     _projector->on();
     _projector->wideScreenMode();
     _amp->on();
     _amp->setDvd(_dvd);
     _amp->setSurroundSound();
     _amp->setVolume(5);
     _dvd->on();
     _dvd->play(movie);
 }
Esempio n. 5
0
  void operator()() {
    /* Set up MPI */
    setup ();

    /* Set up norm */
    compute_l2_norm ();
    
#if USE_PFUNC
    task root_task;
    attribute root_attribute (false /*nested*/, false /*grouped*/);
#endif

    /* Iterate until one of the stopping conditions is triggered */
    int num_selected = 0;
    while (true) {

      /* Create a projector and execute the loop for local result */
      space_type my_space = 
        partitioner_t::create (0, N, mpi_rank, mpi_size);
      Projector projector 
        (&R,&snp_map,&materializer,&filter,block_size,M,N,K);
#if USE_PFUNC
      ProjectReduceType root_project (my_space, projector, *global_taskmgr);
      pfunc::spawn (*global_taskmgr, root_task, root_attribute, root_project);
      pfunc::wait (*global_taskmgr, root_task);
#else
      projector (my_space);
#endif

      /* Reduce globally to get the result */
      edge_type selected = find_global_max (projector.get_result ());
      X.insert (selected);
      add_to_shadow (selected);
      ++num_selected;

      /* Re-estimate the coefficients given the new information */
      refit ();

      /* Compute the residual again */
      residual ();

      /* See if we have reached termination conditions */
      if (MAX_SELECT<num_selected || EPSILON>=fro_norm()) break;
    }

    /* Clean up MPI */
    cleanup ();
  }
Esempio n. 6
0
 void playMovie()
 {
     dvd->on();
     projector->on();
     amplifier->on();
     dvd->play();
 }
Esempio n. 7
0
void SwingPendulumTest::testOffPACSwingPendulum2()
{
  Random<double>* random = new Random<double>;
  RLProblem<double>* problem = new SwingPendulum<double>;
  Hashing<double>* hashing = new MurmurHashing<double>(random, 1000000);
  Projector<double>* projector = new TileCoderHashing<double>(hashing, problem->dimension(), 10, 10,
      true);
  StateToStateAction<double>* toStateAction = new StateActionTilings<double>(projector,
      problem->getDiscreteActions());

  double alpha_v = 0.1 / projector->vectorNorm();
  double alpha_w = .005 / projector->vectorNorm();
  double gamma = 0.99;
  Trace<double>* critice = new AMaxTrace<double>(projector->dimension());
  Trace<double>* criticeML = new MaxLengthTrace<double>(critice, 1000);
  GTDLambda<double>* critic = new GTDLambda<double>(alpha_v, alpha_w, gamma, 0.4, criticeML);
  double alpha_u = 0.5 / projector->vectorNorm();
  PolicyDistribution<double>* target = new BoltzmannDistribution<double>(random,
      problem->getDiscreteActions(), projector->dimension());

  Trace<double>* actore = new AMaxTrace<double>(projector->dimension());
  Trace<double>* actoreML = new MaxLengthTrace<double>(actore, 1000);
  Traces<double>* actoreTraces = new Traces<double>();
  actoreTraces->push_back(actoreML);
  ActorOffPolicy<double>* actor = new ActorLambdaOffPolicy<double>(alpha_u, gamma, 0.4, target,
      actoreTraces);

  /*Policy<double>* behavior = new RandomPolicy<double>(
   &problem->getActions());*/
  Policy<double>* behavior = new BoltzmannDistribution<double>(random,
      problem->getDiscreteActions(), projector->dimension());
  OffPolicyControlLearner<double>* control = new OffPAC<double>(behavior, critic, actor,
      toStateAction, projector);

  RLAgent<double>* agent = new LearnerAgent<double>(control);
  RLRunner<double>* sim = new RLRunner<double>(agent, problem, 5000, 200, 1);
  sim->setTestEpisodesAfterEachRun(true);
  sim->run();

  delete random;
  delete problem;
  delete hashing;
  delete projector;
  delete toStateAction;
  delete critice;
  delete criticeML;
  delete critic;
  delete actore;
  delete actoreML;
  delete actoreTraces;
  delete actor;
  delete behavior;
  delete target;
  delete control;
  delete agent;
  delete sim;
}
Esempio n. 8
0
 void watchMovie( std::string movie )
 {
   HUM_TRACE(ACE_TEXT("HomeTheaterFacade::watchMovie"));
   std::cout << "Get ready to watch a movie..." << std::endl;
   _popper->on();
   _popper->pop();
   _lights->dim( 10 );
   _screen->down();
   _projector->on();
   _projector->wideScreenMode();
   _amp->on();
   _amp->setDvd( _dvd );
   _amp->setSurroundSound();
   _amp->setVolume( 5 );
   _dvd->on();
   _dvd->play( movie );
 }
Esempio n. 9
0
bool
Graphic::CheckVisibility(Projector& projector)
{
    if (projector.IsVisible(     Location(), Radius()) &&
            projector.ApparentRadius(Location(), Radius()) > 1) {

        visible        = true;
    }
    else {
        visible        = false;
        screen_rect.x  = 2000;
        screen_rect.y  = 2000;
        screen_rect.w  = 0;
        screen_rect.h  = 0;
    }
    
    return visible;
}
Esempio n. 10
0
int main()
{
    DVD dvd;
    Amplifier amplifier;
    Projector projector;
    // non-facade method
    // play movie
    cout<<"################# Non-facade Pattern ####################"<<endl;
    dvd.on();
    projector.on();
    amplifier.on();
    dvd.play();

    // using facade pattern
    cout<<"################# Facade Pattern ####################"<<endl;
    FacadeThreater ft(&dvd, &amplifier, &projector);
    ft.playMovie();
    return 0;
}
Esempio n. 11
0
void SwingPendulumTest::testOnPolicyBoltzmannATraceNaturalActorCriticSwingPendulum()
{
  Random<double>* random = new Random<double>;
  RLProblem<double>* problem = new SwingPendulum<double>;
  Hashing<double>* hashing = new MurmurHashing<double>(random, 1000);
  Projector<double>* projector = new TileCoderHashing<double>(hashing, problem->dimension(), 10, 10,
      true);
  StateToStateAction<double>* toStateAction = new StateActionTilings<double>(projector,
      problem->getDiscreteActions());

  double alpha_v = 0.1 / projector->vectorNorm();
  double alpha_u = 0.001 / projector->vectorNorm();
  double lambda = 0.4;
  double gamma = 0.99;

  Trace<double>* critice = new ATrace<double>(projector->dimension());
  TDLambda<double>* critic = new TDLambda<double>(alpha_v, gamma, lambda, critice);

  PolicyDistribution<double>* acting = new BoltzmannDistribution<double>(random,
      problem->getDiscreteActions(), projector->dimension());

  ActorOnPolicy<double>* actor = new ActorNatural<double>(alpha_u, alpha_v, acting);
  OnPolicyControlLearner<double>* control = new ActorCritic<double>(critic, actor, projector,
      toStateAction);
  RLAgent<double>* agent = new LearnerAgent<double>(control);
  RLRunner<double>* sim = new RLRunner<double>(agent, problem, 5000, 50, 10);
  sim->setTestEpisodesAfterEachRun(true);
  sim->run();
  sim->computeValueFunction();

  delete random;
  delete problem;
  delete hashing;
  delete projector;
  delete toStateAction;
  delete critice;
  delete critic;
  delete actor;
  delete acting;
  delete control;
  delete agent;
  delete sim;
}
 void endMovie() {
     std::cout << "Shutting movie theater down..." << std::endl;
     _popper->off();
     _lights->on();
     _screen->up();
     _projector->off();
     _amp->off();
     _dvd->stop();
     _dvd->eject();
     _dvd->off();
 }
Esempio n. 13
0
 uchar* map(float dstx, float dsty)
 {
   float sx = dstx*e1x + dsty*e1y;
   float sy = dstx*e2x + dsty*e2y;
   float dy = floor( sy / h + 0.5 );
   sy -= h*dy;
   sx += (L-offset)*dy;
   sx = sx / h * aspect * 2.0;
   sy = sy / h * aspect * 2.0;
   sx -= floor( sx/2.0 + 0.5 )*2.0;
   return child->map( sx, sy );
 }
Esempio n. 14
0
 void endMovie()
 {
   HUM_TRACE(ACE_TEXT("HomeTheaterFacade::endMovie"));
   std::cout << "Shutting movie theater down..." << std::endl;
   _popper->off();
   _lights->on();
   _screen->up();
   _projector->off();
   _amp->off();
   _dvd->stop();
   _dvd->eject();
   _dvd->off();
 }
Esempio n. 15
0
    void PeripheralSetup::setup(Projector& _proj)
    {
      QMatrix4x4 _matrix;

      qreal _theta = yaw().radians();
      qreal _ct = -cos(_theta), _st = -sin(_theta);
      QVector2D _shiftVec = QVector2D(-_st,_ct) * shift_;
      QVector2D _p = _shiftVec +  distanceCenter_ * QVector2D(_ct,_st);
      QVector3D _pos = QVector3D(_p.x(),_p.y(),towerHeight_);
      _matrix.translate(_pos);

      _matrix.rotate(yaw().degrees() + deltaYaw_.degrees(),QVector3D(0.0,0.0,1.0));
      _matrix.rotate(-pitch().degrees(),QVector3D(0.0,1.0,0.0));
      _matrix.rotate(roll().degrees(),QVector3D(1.0,0.0,0.0));
      _proj.setMatrix(_matrix);
    }
Esempio n. 16
0
 uchar* map(float dstx, float dsty)
 {
   if ( dsty > 0.5 || dsty < -0.5 ){
     return 0;
   }
   //map coordinate to equirectangular coordinate
   float phi   = dstx * M_PI;
   float theta = dsty * M_PI;
   float x,y,z;
   spherical2cartesian(phi, theta, x,y,z );
   //swap
   float t;
   for(int i=0; i<nswap; i++){
     t = z;    z = -y;    y = x;    x = -t;
   }
   //recover angles
   cartesian2spherical(x,y,z, phi, theta);
   return child->map( phi / M_PI, theta / M_PI );
 }
Esempio n. 17
0
//program main entry point
int main(int argc, char **argv)
{
  Projector projector;
  Projection * outproj = NULL; //output projection
  CLineProgress progress; //output progress
  MathLib::Point newscale;
  int pmeshname, pmeshsize;
  int myopt;
  clock_t start = 0, finish = 0;
  std::string logname, filename(std::string(" ")), 
    parameterfile(std::string(" "));
  std::string outfile;
  bool timefile = false;
  bool samescale = false;
  std::ofstream out;

  try
  {
    pmeshname = 0;
    pmeshsize = 4;
    newscale.x = 0;
    newscale.y = 0;
    //parse the arguments
    while (( myopt = getopt(argc, argv, "Ss:l:n:p:?")) != -1)
      switch(myopt)
      {
      case 'S':
        {
          samescale = true;
        }
        break;
      case 's':
        {
          if (optarg)
          {
            newscale.x = atof(optarg);
            newscale.y = newscale.x;
          }
          
        }
        break;
      case 'l':
        {
          if (optarg)
          {
            timefile = true;
            logname = optarg;
          }
        }
		break;
      case 'n':
        {
          if (optarg)
          {
            pmeshsize = atoi(optarg);
                  
          }
		  
        }
        break;
      case 'p':
        {
          if (optarg)
          {
            pmeshname = atoi(optarg);
                  
          }
          break;
        }
      case '?':
      default: // help
        {
          std::cout << "Usage: " << argv[0] << " [options] "
                    << "InputFile InputProjectionFile [outputfile]"
                    << std::endl;
          std::cout << "where options are: " << std::endl;
          std::cout << "   -p pmesh number 6=LeastSqrs 8=Bilinear "
                    << "9=bicubic" << std::endl;
          std::cout << "   -n pmeshsize" << std::endl;
          std::cout << "   -l logfile for timings " << std::endl;
          std::cout << "   -s number where number is the output scale" 
                    << std::endl;
          std::cout << "   -S forces output scale same length as input scale"
                    << std::endl;
          std::cout << "   -? this help screen" << std::endl;
          return 0;
        }
      }
    
    if (optind > argc-2 || argv[optind+1] == NULL)
    {
      std::cout << "You must specify a input file and a input projection file"
                << std::endl
                << "See -h for help" << std::endl;
      return 0;
    }
    else
    {
      filename = std::string(argv[optind++]);
   	  parameterfile = std::string(argv[optind++]);
    }
  
    if (parameterfile == std::string(" ") || filename == std::string(" "))
    {
      std::cout << "You must specify a input file and parameter file " 
                << "use -help for options" << std::endl;
      return 0;
    }
    
    outproj = SetProjection(parameterfile);
    
    if (!outproj)
    {
      std::cout << "Could not create the output projection!"
                << std::endl;
      return 0;
    }
    
    //check for the time file
    if (timefile)
    {
      out.open(logname.c_str()); //open the ouput file
      start = time(NULL);        //get the start
      out << start << std::endl; //output the start
    }
    
    if (optind == argc-1)
    {
      projector.setOutputFileName(std::string(argv[optind]));
    }

    projector.setOutputProjection(outproj);
    projector.setPmeshName(pmeshname);
    projector.setPmeshSize(pmeshsize);
    
    if (!samescale)
      projector.setOutputScale(newscale);
    else
      projector.setSameScale(true);
    
    projector.setInputFile(filename);
 
    projector.project(&progress);
   
    if (timefile)
    {
      finish = time(NULL);
      out << finish << std::endl;
      out << (finish - start);
      out.close();
    }
    return 0;
  }
  catch(ProjectorException & temp)
  {
    std::cout << temp.getExceptionMessage() << std::endl;
    return 0;
  }
  catch(...)
  {
    std::cout << "An unkown exception has been thrown" << std::endl;
    return 0;
  }
}
Esempio n. 18
0
 void stopMovie()
 {
     amplifier->off();
     projector->off();
     dvd->off();
 }
Esempio n. 19
0
  uchar* map(float dstx, float dsty)
  {
    dsty += 1.0;
    int dan = (int)floor( dsty / bw);
    float loopwidth = bw * M_PI / 2.0;
    float danwidth = 2.0 - bw + loopwidth;
    float sx,sy;
    float h = bw / 2.0;
    if ( dan % 2 == 0 ){
      //even line
      sx = dan * danwidth + dstx;
      sy = dsty - dan*bw - h;
      //right end
      if ( dstx > 1.0 - h ){
	float delta = dstx - 1.0 + h;
	float a0 = asin( delta / h);
	float a1 = M_PI - a0;
	float c0 = cos(a0);
	float c1 = cos(a1);
	float y  = sy + 0.5*bw;
	float b0 = y - h*c0;
	float b1 = y - h*c1;
	a0 = a0 * h;
	if ( b1 < h ){
	  return 0;
	}
	else
	{
	  sx = sx - delta + a0;
	  sy -= h*(1.0-c0);
	}
      }
      //left end
      if ( dstx < -1.0 + h ){
	float delta = -(dstx + 1.0 - h);//width on the screen
	float a0 = asin( delta / h);
	float a1 = M_PI - a0; // width along the ribbon
	float c0 = cos(a0);
	float c1 = cos(a1);
	float y  = sy + h;
	float b0 = y - h*c0;
	float b1 = y - h*c1;
	//cout << delta << endl;
	a0 = a0 * h;
	a1 = a1 * h;
	if ( b0 > h ){
	  return 0;
	}
	else
	if ( b1 < h ){
	  //left; lower; turn
	  sx = sx + delta - a1;
	  sy += h*(1.0-c1);
	}
	else{
	  //left; lower
	  sx = sx + delta - a0;
	  sy += h*(1.0-c0);
	}
      }
    }
    else{
      //odd line
      sx = dan * danwidth - dstx;
      sy = dsty - dan * bw - 0.5*bw;
      //right end
      if ( dstx > 1.0 - h ){
	float delta = dstx - 1.0 + h;
	float a0 = asin( delta / h);
	float a1 = M_PI - a0;
	float c0 = cos(a0);
	float c1 = cos(a1);
	float y  = sy + 0.5*bw;
	float b0 = y  - h*c0;
	float b1 = y  - h*c1;
	a0 = a0 * h;
	a1 = a1 * h;
	if ( b0 > h ){
	  return 0;
	}
	else
	if ( b1 < h ){
	  //right; lower; turn
	  sx = sx + delta - a1;
	  sy += h*(1.0-c1);
	}
	else {
	  //right; lower end
	  sx = sx + delta - a0;
	  sy += h*(1.0-c0);
	}
      }
      //left end
      if ( dstx < -1.0 + h ){
	float delta = (dstx + 1.0 - h);
	float a0 = asin( delta / h);
	float a1 = M_PI - a0;
	float c0 = cos(a0);
	float c1 = cos(a1);
	float y  = sy + 0.5*bw;
	float b0 = y  - h*c0;
	float b1 = y  - h*c1;
	a0 = a0 * h;
	if ( b1 < h ){
	  return 0;
	}
	else
	{
	  //left; upper end
	  sx = sx + delta - a0;
	  sy -= h*(1.0-c0);
	}
      }
    }
    float stripw = bw / aspect;
    sx = sx - stripw / 2;
    sx += (danwidth - loopwidth)/2;
    if ( repeat==0 && ( sx < -stripw*0.5 || sx > stripw*0.5 ) )
      return 0;
    sx -= floor( sx / stripw + 0.5)*stripw;
    sx = sx*2.0 / stripw;
    sy = sy*2.0 / stripw;
    return child->map( sx, sy );
  }
Esempio n. 20
0
 uchar* map(float dstx, float dsty)
 {
   float tx    = dstx;
   float ty    = 2.0*atan(exp(dsty*M_PI))/M_PI - 0.5;
   return child->map(tx,ty);
 }
Esempio n. 21
0
  uchar* map(float dstx, float dsty)
  {
    // in image coord (2(a+b) x 2(a+b))
    dstx *= (boxx+boxy);
    dsty *= (boxx+boxy);
    //dsty = dsty + (eye - 0.5) * boxz;
    float h,v;//angles
    //angles for the center of each face
    float h0 = atan( boxx*eyex/(boxy*eyey) ) - M_PI;
    float h1 = h0 + M_PI/2;
    float h2 = h1 + M_PI/2;
    float h3 = h2 + M_PI/2;
    if ( ( -boxz / 2 <= dsty ) && ( dsty <= boxz / 2 ) ){
      //in the horizontal belt
      if ( dstx < -boxy ){
	dsty = dsty + (eyez - 0.5) * boxz;
	//panel 0
	// x offset from the center of panel
	dstx += boxy + boxx*(1.0-eyex);
	h = atan( dstx / (boxy*eyey) );
	v = atan( dsty / sqrt( (boxy*eyey)*(boxy*eyey) + dstx*dstx ) );
	h += h0;
	dstx = h / M_PI;
	dsty = v / M_PI; 
      }
      else if ( dstx < 0 ){
	dsty = dsty + (eyez - 0.5) * boxz;
	//panel 1
	dstx += boxy*(1.0-eyey);
	h = atan( dstx / (boxx*(1-eyex)) );
	v = atan( dsty / sqrt( (boxx*(1-eyex))*(boxx*(1-eyex)) + dstx*dstx ) );
	h += h1;
	dstx = h / M_PI;
	dsty = v / M_PI; 
      }
      else if ( dstx < boxx ){
	dsty = dsty + (eyez - 0.5) * boxz;
	//panel 2
	dstx -= boxx*(1-eyex);
	h = atan( dstx / (boxy*(1-eyey)) );
	v = atan( dsty / sqrt( (boxy*(1-eyey))*(boxy*(1-eyey)) + dstx*dstx ) );
	h += h2;
	dstx = h / M_PI;
	dsty = v / M_PI; 
      }
      else{
	dsty = dsty + (eyez - 0.5) * boxz;
	//panel 3
	dstx -= (boxy*(1-eyey) + boxx);
	h = atan( dstx / (boxx*eyex) );
	v = atan( dsty / sqrt( (boxx*eyex)*(boxx*eyex) + dstx*dstx ) );
	h += h3;
	dstx = h / M_PI;
	dsty = v / M_PI; 
      }
    }
    else if ( ( boxz/2 < dsty ) && ( dsty < boxz/2+boxx ) &&
	      ( -boxy < dstx ) && (dstx < 0) ){
      //dsty = dsty + (eye - 0.5) * c;
      //panel 4 nadir
      dstx += boxy*(1-eyey);
      dsty -= (boxz/2+boxx*(1-eyex));
      h = atan(dsty / dstx);
      if (dstx < 0 ){
	h += M_PI;
      }
      float r = sqrt( dstx*dstx + dsty*dsty );
      v = atan( eyez*boxz / r );
      h += h2;
      dstx = h / M_PI;
      dsty = v / M_PI; 
    }
    else if ( ( -boxz/2 - boxx < dsty ) && ( dsty < -boxz/2 ) &&
	      ( -boxy < dstx ) && (dstx < 0) ){
      //dsty = dsty + (eye - 0.5) * boxz;
      //panel 5 zenith
      dstx += boxy*(1-eyey);
      dsty += boxz/2+boxx*(1-eyex);
      h = atan(dsty / dstx);
      if (dstx < 0 ){
	h += M_PI;
      }
      float r = sqrt( dstx*dstx + dsty*dsty );
      v = -atan( (boxz-eyez*boxz) / r );
      h = h2 - h;
      dstx = h / M_PI;
      dsty = v / M_PI; 
    }
    else{
      //return child->map( 0,0 );
      return 0;
    }
    return child->map( dstx, dsty );
  }
Esempio n. 22
0
void OctLevel::CalcRenderOrderRecurse(const Vect &eye, const ViewClip &clip, MeshOrderInfo &meshOrder, OctNode *curNode, BOOL bFullyVisible)
{
    OctNode *node = (curNode != NULL) ? curNode : objectTree->GetRoot();

    DWORD i;
    BOOL bCheckBounds = (node->numChildren > 1) || (node->Leaves.Num() > 0);
    if(!bFullyVisible && bCheckBounds)
    {
        int testVal = clip.BoundsTest(node->bounds);
        if(testVal == BOUNDS_INSIDE)
            bFullyVisible = TRUE;
        else if(testVal == BOUNDS_OUTSIDE)
            return;
    }

    if(node->numChildren)
    {
        for(i=0; i<8; i++)
        {
            if(!node->children[i])
                continue;

            OctNode *child = node->children[i];
            CalcRenderOrderRecurse(eye, clip, meshOrder, child, bFullyVisible);
        }
    }

    for(i=0; i<node->Leaves.Num(); i++)
    {
        LevelObject *leaf = node->Leaves[i];

        if(!bFullyVisible && !clip.BoundsVisible(leaf->bounds))
            continue;

        if(leaf->type == ObjectType_Entity)
        {
            if(leaf->ent->IsOf(GetClass(MeshEntity)))
            {
                MeshEntity *meshEnt = (MeshEntity*)leaf->ent;

                if(meshEnt->bRenderable)
                {
                    EntityVisible(meshEnt) = TRUE;
                    meshOrder.AddEntity(meshEnt);
                }
            }
            else if(leaf->ent->IsOf(GetClass(Projector)))
            {
                Projector *projector = (Projector*)leaf->ent;
                if(projector->bRenderable)
                {
                    if(projector->IsOf(GetClass(LitDecal)))
                        renderLitDecals << (LitDecal*)projector;
                    else
                        renderProjectors << projector;

                    EntityVisible(projector) = TRUE;
                }
            }
            else if(leaf->ent->IsOf(GetClass(Light)))
            {
                Light *light = (Light*)leaf->ent;

                if(light->IsOf(GetClass(SpotLight)))
                {
                    SpotLight *spotLight = (SpotLight*)light;
                    if(spotLight->IsLightmapped() && !spotLight->NumLitEntities())
                        continue;

                    renderSpotLights << spotLight;
                }
                else if(light->IsOf(GetClass(PointLight)))
                {
                    PointLight *pointLight = (PointLight*)light;
                    if(pointLight->IsLightmapped() && !pointLight->NumLitEntities())
                        continue;

                    renderPointLights << pointLight;
                }
            }
            else
            {
                Entity *ent = leaf->ent;

                if(ent->bRenderable)
                {
                    EntityVisible(ent) = TRUE;
                    renderEntities << ent;
                }
            }
        }
        else if(leaf->type == ObjectType_Brush)
        {
            Brush *brush = leaf->brush;

            brush->bVisible = TRUE;
            renderBrushes << brush;
        }
    }
}
Esempio n. 23
0
void NAOTest::testTrain()
{
  // OffLine
  {
    Random<float>* random = new Random<float>;
    RLProblem<float>* problem = new MountainCar<float>(random);
    Hashing<float>* hashing = new MurmurHashing<float>(random, 1000000);
    Projector<float>* projector = new TileCoderHashing<float>(hashing, problem->dimension(), 10,
        10);
    StateToStateAction<float>* toStateAction = new StateActionTilings<float>(projector,
        problem->getDiscreteActions());

    double alpha_v = 0.05 / projector->vectorNorm();
    double alpha_w = 0.0001 / projector->vectorNorm();
    double lambda = 0.0;  //0.4;
    double gamma = 0.99;
    Trace<float>* critice = new ATrace<float>(projector->dimension());
    OffPolicyTD<float>* critic = new GTDLambda<float>(alpha_v, alpha_w, gamma, lambda, critice);
    double alpha_u = 1.0 / projector->vectorNorm();
    PolicyDistribution<float>* target = new BoltzmannDistribution<float>(random,
        problem->getDiscreteActions(), projector->dimension());

    Trace<float>* actore = new ATrace<float>(projector->dimension());
    Traces<float>* actoreTraces = new Traces<float>();
    actoreTraces->push_back(actore);
    ActorOffPolicy<float>* actor = new ActorLambdaOffPolicy<float>(alpha_u, gamma, lambda, target,
        actoreTraces);

    Policy<float>* behavior = new RandomPolicy<float>(random, problem->getDiscreteActions());

    OffPolicyControlLearner<float>* control = new OffPAC<float>(behavior, critic, actor,
        toStateAction, projector);

    RLAgent<float>* agent = new LearnerAgent<float>(control);
    Simulator<float>* sim = new Simulator<float>(agent, problem, 5000, 100, 1);
    //sim->setVerbose(false);
    sim->run();
    control->persist("NAOTest_x32_M.bin");

    delete random;
    delete problem;
    delete hashing;
    delete projector;
    delete toStateAction;
    delete critice;
    delete critic;
    delete actore;
    delete actoreTraces;
    delete actor;
    delete behavior;
    delete target;
    delete control;
    delete agent;
    delete sim;
  }
  // OnLine
  {
    Random<double>* random = new Random<double>;
    RLProblem<double>* problem = new SwingPendulum<double>(random);
    Hashing<double>* hashing = new MurmurHashing<double>(random, 1000);
    Projector<double>* projector = new TileCoderHashing<double>(hashing, problem->dimension(), 10,
        10, false);
    StateToStateAction<double>* toStateAction = new StateActionTilings<double>(projector,
        problem->getContinuousActions());

    double alpha_v = 0.1 / projector->vectorNorm();
    double alpha_u = 0.001 / projector->vectorNorm();
    double alpha_r = .0001;
    double gamma = 1.0;
    double lambda = 0.5;

    Trace<double>* critice = new ATrace<double>(projector->dimension());
    TDLambda<double>* critic = new TDLambda<double>(alpha_v, gamma, lambda, critice);

    PolicyDistribution<double>* policyDistribution = new NormalDistributionScaled<double>(random,
        problem->getContinuousActions(), 0, 1.0, projector->dimension());
    Range<double> policyRange(-2.0, 2.0);
    Range<double> problemRange(-2.0, 2.0);
    PolicyDistribution<double>* acting = new ScaledPolicyDistribution<double>(
        problem->getContinuousActions(), policyDistribution, &policyRange, &problemRange);

    Trace<double>* actore1 = new ATrace<double>(projector->dimension());
    Trace<double>* actore2 = new ATrace<double>(projector->dimension());
    Traces<double>* actoreTraces = new Traces<double>();
    actoreTraces->push_back(actore1);
    actoreTraces->push_back(actore2);
    ActorOnPolicy<double>* actor = new ActorLambda<double>(alpha_u, gamma, lambda, acting,
        actoreTraces);

    OnPolicyControlLearner<double>* control = new AverageRewardActorCritic<double>(critic, actor,
        projector, toStateAction, alpha_r);

    RLAgent<double>* agent = new LearnerAgent<double>(control);
    Simulator<double>* sim = new Simulator<double>(agent, problem, 5000, 100, 1);
    sim->run();
    control->persist("NAOTest_x32_S.bin");

    delete random;
    delete problem;
    delete hashing;
    delete projector;
    delete toStateAction;
    delete critice;
    delete critic;
    delete actore1;
    delete actore2;
    delete actoreTraces;
    delete actor;
    delete policyDistribution;
    delete acting;
    delete control;
    delete agent;
    delete sim;
  }
}
Esempio n. 24
0
void NAOTest::testEvaluate()
{
  {
    Random<float>* random = new Random<float>;
    RLProblem<float>* problem = new MountainCar<float>(random);
    Hashing<float>* hashing = new MurmurHashing<float>(random, 1000000);
    Projector<float>* projector = new TileCoderHashing<float>(hashing, problem->dimension(), 10, 10,
        true);
    StateToStateAction<float>* toStateAction = new StateActionTilings<float>(projector,
        problem->getDiscreteActions());

    Trace<float>* critice = new ATrace<float>(projector->dimension());
    OffPolicyTD<float>* critic = new GTDLambda<float>(0, 0, 0, 0, critice);
    PolicyDistribution<float>* target = new BoltzmannDistribution<float>(random,
        problem->getDiscreteActions(), projector->dimension());

    Trace<float>* actore = new ATrace<float>(projector->dimension());
    Traces<float>* actoreTraces = new Traces<float>();
    actoreTraces->push_back(actore);
    ActorOffPolicy<float>* actor = new ActorLambdaOffPolicy<float>(0, 0, 0, target, actoreTraces);

    Policy<float>* behavior = new RandomPolicy<float>(random, problem->getDiscreteActions());

    OffPolicyControlLearner<float>* control = new OffPAC<float>(behavior, critic, actor,
        toStateAction, projector);

    RLAgent<float>* agent = new ControlAgent<float>(control);
    Simulator<float>* sim = new Simulator<float>(agent, problem, 5000, 10, 10);

    control->reset();
    control->resurrect("NAOTest_x32_M.bin");
    sim->runEvaluate(10, 10);

    delete random;
    delete problem;
    delete hashing;
    delete projector;
    delete toStateAction;
    delete critice;
    delete critic;
    delete actore;
    delete actoreTraces;
    delete actor;
    delete behavior;
    delete target;
    delete control;
    delete agent;
    delete sim;
  }
  // OnLine
  {
    Random<double>* random = new Random<double>;
    RLProblem<double>* problem = new SwingPendulum<double>(random);
    Hashing<double>* hashing = new MurmurHashing<double>(random, 1000);
    Projector<double>* projector = new TileCoderHashing<double>(hashing, problem->dimension(), 10,
        10, false);
    StateToStateAction<double>* toStateAction = new StateActionTilings<double>(projector,
        problem->getContinuousActions());

    Trace<double>* critice = new ATrace<double>(projector->dimension());
    TDLambda<double>* critic = new TDLambda<double>(0, 0, 0, critice);

    PolicyDistribution<double>* policyDistribution = new NormalDistributionScaled<double>(random,
        problem->getContinuousActions(), 0, 1.0, projector->dimension());
    Range<double> policyRange(-2.0, 2.0);
    Range<double> problemRange(-2.0, 2.0);
    PolicyDistribution<double>* acting = new ScaledPolicyDistribution<double>(
        problem->getContinuousActions(), policyDistribution, &policyRange, &problemRange);

    Trace<double>* actore1 = new ATrace<double>(projector->dimension());
    Trace<double>* actore2 = new ATrace<double>(projector->dimension());
    Traces<double>* actoreTraces = new Traces<double>();
    actoreTraces->push_back(actore1);
    actoreTraces->push_back(actore2);
    ActorOnPolicy<double>* actor = new ActorLambda<double>(0, 0, 0, acting, actoreTraces);

    OnPolicyControlLearner<double>* control = new AverageRewardActorCritic<double>(critic, actor,
        projector, toStateAction, 0);

    RLAgent<double>* agent = new ControlAgent<double>(control);
    Simulator<double>* sim = new Simulator<double>(agent, problem, 5000, 10, 10);

    control->reset();
    control->resurrect("NAOTest_x32_S.bin");
    sim->run();

    delete random;
    delete problem;
    delete hashing;
    delete projector;
    delete toStateAction;
    delete critice;
    delete critic;
    delete actore1;
    delete actore2;
    delete actoreTraces;
    delete actor;
    delete policyDistribution;
    delete acting;
    delete control;
    delete agent;
    delete sim;
  }
}
Esempio n. 25
0
void SwingPendulumTest::testOnPolicySwingPendulum()
{
  Random<double>* random = new Random<double>;
  RLProblem<double>* problem = new SwingPendulum<double>;
  Hashing<double>* hashing = new MurmurHashing<double>(random, 1000);
  Projector<double>* projector = new TileCoderHashing<double>(hashing, problem->dimension(), 10, 10,
      false);
  StateToStateAction<double>* toStateAction = new StateActionTilings<double>(projector,
      problem->getContinuousActions());

  double alpha_v = 0.1 / projector->vectorNorm();
  double alpha_u = 0.001 / projector->vectorNorm();
  double alpha_r = .0001;
  double gamma = 1.0;
  double lambda = 0.5;

  Trace<double>* critice = new ATrace<double>(projector->dimension());
  TDLambda<double>* critic = new TDLambda<double>(alpha_v, gamma, lambda, critice);

  PolicyDistribution<double>* policyDistribution = new NormalDistributionScaled<double>(random,
      problem->getContinuousActions(), 0, 1.0, projector->dimension());
  Range<double> policyRange(-2.0, 2.0);
  Range<double> problemRange(-2.0, 2.0);
  PolicyDistribution<double>* acting = new ScaledPolicyDistribution<double>(
      problem->getContinuousActions(), policyDistribution, &policyRange, &problemRange);

  Trace<double>* actore1 = new ATrace<double>(projector->dimension());
  Trace<double>* actore2 = new ATrace<double>(projector->dimension());
  Traces<double>* actoreTraces = new Traces<double>();
  actoreTraces->push_back(actore1);
  actoreTraces->push_back(actore2);
  ActorOnPolicy<double>* actor = new ActorLambda<double>(alpha_u, gamma, lambda, acting,
      actoreTraces);

  OnPolicyControlLearner<double>* control = new AverageRewardActorCritic<double>(critic, actor,
      projector, toStateAction, alpha_r);

  RLAgent<double>* agent = new LearnerAgent<double>(control);
  RLRunner<double>* sim = new RLRunner<double>(agent, problem, 5000, 100, 10);
  sim->setVerbose(true);
  sim->run();

  sim->runEvaluate(100);
  sim->computeValueFunction();

  delete random;
  delete problem;
  delete hashing;
  delete projector;
  delete toStateAction;
  delete critice;
  delete critic;
  delete actore1;
  delete actore2;
  delete actoreTraces;
  delete actor;
  delete policyDistribution;
  delete acting;
  delete control;
  delete agent;
  delete sim;
}
Esempio n. 26
0
//----------------------------------------------------------------------------
void ShadowMaps::CreateShaders ()
{
    // Create the shader constants.  Some of these are shared.

    // Create the light projector.
    Projector* projector = new0 Projector(Camera::PM_DEPTH_ZERO_TO_ONE);
    projector->SetFrustum(60.0f, 1.0f, 0.1f, 100.0f);
    APoint projPosition(4.0f, 4.0f, 4.0f);
    AVector projDVector(-1.0f, -1.0f, -1.0f);
    projDVector.Normalize();
    AVector projUVector(-1.0f, -1.0f, 2.0f);
    projUVector.Normalize();
    AVector projRVector = projDVector.Cross(projUVector);
    projector->SetFrame(projPosition, projDVector, projUVector, projRVector);

    // For SMSceneEffect and SMUnlitEffect.
    ProjectorMatrixConstant* lightPVMatrix =
        new0 ProjectorMatrixConstant(projector, false, 0);

    ShaderFloat* lightBSMatrixUnlit = new0 ShaderFloat(4);
    ShaderFloat* lightBSMatrixScene = new0 ShaderFloat(4);
    ShaderFloat* screenBSMatrix = new0 ShaderFloat(4);
    const float* src;
    if (VertexShader::GetProfile() == VertexShader::VP_ARBVP1)
    {
        src = (const float*)Projector::BiasScaleMatrix[1];
        memcpy(lightBSMatrixUnlit->GetData(), src, 16*sizeof(float));
        memcpy(lightBSMatrixScene->GetData(), src, 16*sizeof(float));
        memcpy(screenBSMatrix->GetData(), src, 16*sizeof(float));
    }
    else
    {
        src = (const float*)Projector::BiasScaleMatrix[0];
        memcpy(lightBSMatrixUnlit->GetData(), src, 16*sizeof(float));
        memcpy(screenBSMatrix->GetData(), src, 16*sizeof(float));
        src = (const float*)Projector::BiasScaleMatrix[1];
        memcpy(lightBSMatrixScene->GetData(), src, 16*sizeof(float));
    }

    // For SMSceneEffect.
    ProjectorWorldPositionConstant* lightWorldPosition =
        new0 ProjectorWorldPositionConstant(projector);

    ShaderFloat* lightColor = new0 ShaderFloat(1);
    (*lightColor)[0] = 1.0f;
    (*lightColor)[1] = 1.0f;
    (*lightColor)[2] = 1.0f;
    (*lightColor)[3] = 1.0f;

    // For SMUnlitEffect.
    ShaderFloat* depthBiasConstant = new0 ShaderFloat(1);
    (*depthBiasConstant)[0] = 0.1f;
    ShaderFloat* texelSizeConstant = new0 ShaderFloat(1);
    (*texelSizeConstant)[0] = 1.0f/(float)mScreenTargetSize;
    (*texelSizeConstant)[1] = 1.0f/(float)mScreenTargetSize;

    // For SMBlurEffect.
    const int numRegisters = 11;
    ShaderFloat* weights = new0 ShaderFloat(numRegisters);
    ShaderFloat* hOffsets = new0 ShaderFloat(numRegisters);
    ShaderFloat* vOffsets = new0 ShaderFloat(numRegisters);

    // Compute the weights.  They must sum to 1.
    Float4* weightsData = (Float4*)weights->GetData();
    const float stdDev = 1.0f;
    const float invTwoVariance = 1.0f/(2.0f*stdDev*stdDev);
    float totalWeight = 0.0f;
    int i, j;
    for (i = 0, j = -numRegisters/2; i < numRegisters; ++i, ++j)
    {
        float weight = Mathf::Exp(-j*j*invTwoVariance);
        weightsData[i] = Float4(weight, weight, weight, 0.0f);
        totalWeight += weight;
    }
    float invTotalWeight = 1.0f/totalWeight;
    for (i = 0; i < numRegisters; ++i)
    {
        weightsData[i][0] *= invTotalWeight;
        weightsData[i][1] *= invTotalWeight;
        weightsData[i][2] *= invTotalWeight;
    }

    // Compute the horizontal and vertical offsets.
    Float4* hOffsetsData = (Float4*)hOffsets->GetData();
    Float4* vOffsetsData = (Float4*)vOffsets->GetData();
    float uDelta = 1.0f/(float)GetWidth();
    float vDelta = 1.0f/(float)GetHeight();
    for (i = 0, j = -numRegisters/2; i < numRegisters; ++i, ++j)
    {
        hOffsetsData[i] = Float4(j*uDelta, 0.0f, 0.0f, 0.0f);
        vOffsetsData[i] = Float4(0.0f, j*vDelta, 0.0f, 0.0f);
    }

    // Create the scene effect.
    std::string effectFile = Environment::GetPathR("SMScene.wmfx");
    SMSceneEffect* sceneEffect = new0 SMSceneEffect(effectFile);

    std::string stoneName = Environment::GetPathR("Stone.wmtf");
    Texture2D* stoneTexture = Texture2D::LoadWMTF(stoneName);
    std::string ballName = Environment::GetPathR("BallTexture.wmtf");
    Texture2D* ballTexture = Texture2D::LoadWMTF(ballName);
    std::string projectedName = Environment::GetPathR("Magician.wmtf");
    Texture2D* projectedTexture = Texture2D::LoadWMTF(projectedName);

    mPlaneSceneInstance = sceneEffect->CreateInstance(lightWorldPosition,
        lightPVMatrix, lightBSMatrixScene, screenBSMatrix, lightColor,
        stoneTexture, mVBlurTarget->GetColorTexture(0), projectedTexture);

    mSphereSceneInstance = sceneEffect->CreateInstance(lightWorldPosition,
        lightPVMatrix, lightBSMatrixScene, screenBSMatrix, lightColor,
        ballTexture, mVBlurTarget->GetColorTexture(0), projectedTexture);

    // Create the shadow effect.
    effectFile = Environment::GetPathR("SMShadow.wmfx");
    mShadowEffect = new0 SMShadowEffect(effectFile, lightPVMatrix);

    // Create the unlit effect.
    effectFile = Environment::GetPathR("SMUnlit.wmfx");
    mUnlitEffect = new0 SMUnlitEffect(effectFile, lightPVMatrix,
        lightBSMatrixUnlit, depthBiasConstant, texelSizeConstant,
        mShadowTarget->GetColorTexture(0));

    // Create the blur effect and instantiate for horizontal and vertical
    // blurring.
    effectFile = Environment::GetPathR("SMBlur.wmfx");
    SMBlurEffect* blurEffect = new0 SMBlurEffect(effectFile);

    mHBlurInstance = blurEffect->CreateInstance(weights, hOffsets,
        mUnlitTarget->GetColorTexture(0));

    mVBlurInstance = blurEffect->CreateInstance(weights, vOffsets,
        mHBlurTarget->GetColorTexture(0));
}
Esempio n. 27
-1
 uchar* map(float dstx, float dsty)
 {
   return child->map(dstx+x,dsty+y);
 }