示例#1
0
inline void OmniApp::onMessage(osc::Message& m) {
	float x;
	if (m.addressPattern() == "/mx") {
		m >> x;
		nav().moveR(-x * mNavSpeed);

	} else if (m.addressPattern() == "/my") {
示例#2
0
void ProtoApp::init(){
	// setup audio
	if(usingAudio()){
		gam::Sync::master().spu(audioIO().fps());
	}

	// setup GUI
	mAppLabel.setValue(App::name());

	mGUI << mGUITable;

	mTopBar.arrange();
	mParamPanel.arrange();
	mGUITable.arrange();

	// setup model manager
	if(!App::name().empty()){
		glv::ModelManager& MM = mGUI.modelManager();
		
		//
		std::string idName = App::name();
		toIdentifier(idName);
		
		MM.name(idName + "Presets");
		MM.fileDir(mResourceDir);
		
		mGUI.refreshModels();
		MM.add("pose", *new PoseModel(nav()));
		
		paramPanel().presetControl()
			.modelManager(MM)
			.loadFile()
		;
	}
}
示例#3
0
gamePicture::gamePicture(D3DXVECTOR3 seed,LPDIRECT3DDEVICE9 d3dDev, D3DXVECTOR2 cCount):GameObject(D3DXVECTOR3())
{
	D3DXVECTOR3 vel(0,-2.0f,0);			// Start off velocity 
	D3DXVECTOR3 acc(0,0,0);
	D3DXVECTOR3 nav(0, -250.0f, 0);			// Used for rotating
	this->cellSize = D3DXVECTOR2(1,1);
	this->size = D3DXVECTOR2(1,1);
	this->pVtxBuf = NULL;
	this->cellCount = cCount;
	this->cellSize.x = 1/cCount.x;
	this->cellSize.y = 1/cCount.y;
	this->vel = vel;
	this->acc = acc;
	this->navVector = nav;
	this->orient=-90;
	this->rotationStep = 0;
	this->speed = 8;
	this->curTexture = gamePicture::textureList.at(1);
	this->cellPosition.x = 0;
	this->cellPosition.y = 0;
	this->initGeom(seed,d3dDev);

	// get the velocity vector from an initial speed
	vel.x = this->speed * cos(D3DXToRadian(this->orient));
	vel.y = this->speed * sin(D3DXToRadian(this->orient));

}
示例#4
0
inline bool OmniApp::onFrame() {
	FPS::onFrame();

	while(oscRecv().recv()) {}
	
	nav().step();
	
	onAnimate(dt);
	
	Viewport vp(width(), height());
	
	if (bOmniEnable) {
		mOmni.onFrame(*this, lens(), nav(), vp);
	} else {
		mOmni.onFrameFront(*this, lens(), nav(), vp);
	}
	return true;
}
示例#5
0
void ProtoApp::init(
	const Window::Dim& dim,
	const std::string& title,
	double fps,
	Window::DisplayMode mode,
	double sampleRate,
	int blockSize,
	int chansOut,
	int chansIn
){

	initAudio(sampleRate, blockSize, chansOut, chansIn);

	// setup audio
	if(usingAudio()){
		//gam::Sync::master().spu(audioIO().fps());
	}


	Window * win = initWindow(dim, title, fps, mode);
	mGUI.parentWindow(*win);

	// setup GUI
	mAppLabel.setValue(App::name());

	mGUI << mGUITable;

	mTopBar.arrange();
	mParamPanel.arrange();
	mGUITable.arrange();

	// setup model manager
	if(!App::name().empty()){
		glv::ModelManager& MM = mGUI.modelManager();
		
		//
		std::string idName = App::name();
		toIdentifier(idName);
		
		MM.name(idName + "Presets");
		MM.fileDir(mResourceDir);
		
		mGUI.refreshModels();
		MM.add("pose", *new PoseModel(nav()));
		
		paramPanel().presetControl()
			.modelManager(MM)
			.loadFile()
		;
	}
}
示例#6
0
// ######################################################################
bool RobotBrainServiceService::start(int argc, char* argv[])
{
    MYLOGVERB = LOG_INFO;

    char adapterStr[255];

    //Create the adapter
    int port = RobotBrainObjects::RobotBrainPort;
    bool connected = false;

    // try to connect to ports until successful
    LDEBUG("Opening Connection");
    while(!connected)
    {
        try
        {
            LINFO("Trying Port:%d", port);
            sprintf(adapterStr, "default -p %i", port);
            itsAdapter = communicator()->createObjectAdapterWithEndpoints
                         ("RG_Lane", adapterStr);
            connected = true;
        }
        catch(Ice::SocketException)
        {
            port++;
        }
    }

    //Create the manager and its objects
    itsMgr = new ModelManager("RG_LaneService");

    LINFO("Starting RG_Lane System");
    nub::ref<RG_Lane>
    nav(new RG_Lane(*itsMgr, "RG_Lane", "RG_Lane"));
    LINFO("RG_Lane created");
    itsMgr->addSubComponent(nav);
    LINFO("RG_Lane Added As a subcomponent");
    nav->init(communicator(), itsAdapter);
    LINFO("RG_Lane initiated");

    // check command line inputs/options
    itsMgr->parseCommandLine(argc, argv, "", 0, 0);

    // activate manager and adapter
    itsAdapter->activate();
    itsMgr->start();

    return true;
}
inline OmniStereoGraphicsRenderer::OmniStereoGraphicsRenderer()
    : mNavControl(mNav), mOSCSend(12001) {

  bOmniEnable = true;
  mHostName = Socket::hostName();

  lens().near(0.01).far(40).eyeSep(0.03);
  nav().smooth(0.8);

  initWindow();
  initOmni();

  Window::append(mStdControls);
  Window::append(mNavControl);

  mOmniControls.o = this;
  Window::append(mOmniControls);
}
inline bool OmniStereoGraphicsRenderer::onFrame() {
  FPS::onFrame();

  // if running on a laptop?
  //
  nav().step();

  onAnimate(dt);

  Viewport vp(width(), height());

  if (bOmniEnable) {
    mOmni.onFrame(*this, lens(), pose, vp);
  } else {
    mOmni.onFrameFront(*this, lens(), pose, vp);
  }
  return true;
}
示例#9
0
Renderer::Renderer(CubemapSource* cubemapSource)
    :
    al::OmniApp("AlloPlayer", false, 2048), resizeCtx(nullptr), cubemapSource(cubemapSource),
    cubemap(nullptr), newCubemap(false)
{
    nav().smooth(0.8);
    
    // set up cube
    cube.color(1,1,1,1);
    cube.primitive(al::Graphics::TRIANGLES);
    addCube(cube);
    for (int i = 0; i < cube.vertices().size(); ++i) {
        float f = (float)i / cube.vertices().size();
        cube.color(al::Color(al::HSV(f, 1 - f, 1), 1));
    }
    cube.generateNormals();
    
    // set up sphere
    sphere.primitive(al::Graphics::TRIANGLES);
    addSphere(sphere, 1.0, 32, 32);
    for (int i = 0; i < sphere.vertices().size(); ++i) {
        float f = (float)i / sphere.vertices().size();
        sphere.color(al::Color(al::HSV(f, 1 - f, 1), 1));
    }
    sphere.generateNormals();
    
    // set up light
    light.ambient(al::Color(0.4, 0.4, 0.4, 1.0));
    light.pos(5, 5, 5);
    
    
    
    std::function<void (CubemapSource*, StereoCubemap*)> callback = boost::bind(&Renderer::onNextCubemap,
                                                                                this,
                                                                                _1,
                                                                                _2);
    cubemapSource->setOnNextCubemap(callback);
}
int main()
{
	Vectors3DSOA points, dirs, intermediatepoints, intermediatedirs;

	int np=1024;
	int NREPS = 1000;

	points.alloc(np);
	dirs.alloc(np);

	// generate benchmark cases
	TransformationMatrix const * identity = new TransformationMatrix(0,0,0,0,0,0);

	double L = 10.;
	double Lz = 10.;
	const double Sqrt2 = sqrt(2.);

	BoxParameters *	worldp =  new BoxParameters(L, L, Lz );
	PhysicalVolume * world = GeoManager::MakePlacedBox( worldp , identity );
	double volworld = worldp->GetVolume();

	BoxParameters * boxlevel2 = new BoxParameters( Sqrt2*L/2./2., Sqrt2*L/2./2., Lz );
	BoxParameters * boxlevel3 = new BoxParameters( L/2./2. ,L/2./2., Lz);
	BoxParameters * boxlevel1 = new BoxParameters( L/2., L/2., Lz );

	PhysicalVolume * box2 = GeoManager::MakePlacedBox(boxlevel2, new TransformationMatrix(0,0,0,0,0,45));
	PhysicalVolume * box3 = GeoManager::MakePlacedBox( boxlevel3, new TransformationMatrix(0,0,0,0,0,-45));
	box2->AddDaughter( box3 ); // rotated 45 degree around z axis

	PhysicalVolume * box1 = GeoManager::MakePlacedBox(boxlevel1, identity);
	box1->AddDaughter( box2 );

	PhysicalVolume const * box1left  = world->PlaceDaughter(GeoManager::MakePlacedBox(boxlevel1, new TransformationMatrix(-L/2.,0.,0.,0.,0.,0)), box1->GetDaughters());
	PhysicalVolume const * box1right = world->PlaceDaughter(GeoManager::MakePlacedBox(boxlevel1, new TransformationMatrix(+L/2.,0.,0.,0.,0.,0)), box1->GetDaughters());


    // perform basic tests
	SimpleVecNavigator nav(1, world);
	Vector3D result;
	VolumePath path(4);
	PhysicalVolume const * vol;

	{
	// point should be in world
	Vector3D p1(0, 9*L/10., 0); path.Clear();
	vol=nav.LocatePoint( world, p1, result, path );
	assert(vol==world);
	}

	{
	// outside world check
	Vector3D p2(-2*L, 9*L/10., 0); path.Clear();
	vol=nav.LocatePoint( world, p2, result, path );
	assert(vol==NULL);
	}

	{
		// inside box3 check
		Vector3D p3(-L/2., 0., 0.); path.Clear();
		vol=nav.LocatePoint( world, p3, result, path );
		assert(vol==box3);
		std::cerr << path.GetCurrentLevel() << std::endl;
		assert(path.GetCurrentLevel( ) == 4);
		assert(result == Vector3D(0.,0.,0));
		}

	{
		// inside box3 check iterative
		Vector3D p3(-L/2., 0., 0.); path.Clear();
		TransformationMatrix * m = new TransformationMatrix();
		vol=nav.LocatePoint_iterative( world, p3, result, path, m );
		path.Print();
		assert(vol==box3);
		std::cerr << path.GetCurrentLevel() << std::endl;
		assert(path.GetCurrentLevel( ) == 4);
		assert(result == Vector3D(0.,0.,0));
	}


	{
	// inside box3 check ( but second box )
	Vector3D p3(L/2., 0., 0.); path.Clear();
	TransformationMatrix * m1, * m2;
	m1=new TransformationMatrix();
	m2=new TransformationMatrix();

	vol=nav.LocatePoint( world, p3, result, path, m1 );
	assert(vol==box3);
	std::cerr << path.GetCurrentLevel() << std::endl;
	assert(path.GetCurrentLevel( ) == 4);
	assert(result == Vector3D(0.,0.,0));
	path.GetGlobalMatrixFromPath( m2 );
	assert( m1->Equals(m2) );
	delete m1; delete m2;
	}

	{
	// inside box2 check
	Vector3D p4(-L/2., 9*L/2./10., 0.); path.Clear();
	vol=nav.LocatePoint( world, p4, result, path );
	assert(vol==box2);
	}

	{
	// inside box2 check ( on other side )
	Vector3D p4(L/2., 9*L/2./10., 0.); path.Clear();
	vol=nav.LocatePoint( world, p4, result, path );
	assert(vol==box2);
	}

	{
	// inside box1 check
	Vector3D p5(-9.*L/10., 9*L/2./10., 0.); path.Clear();
	vol=nav.LocatePoint( world, p5, result, path );
	assert(vol == box1left );
	}

	{
	// inside box1 check
	Vector3D p6(9.*L/10., 9*L/2./10., 0.); path.Clear();
	vol=nav.LocatePoint( world, p6, result, path );
	assert(vol == box1right );
	assert(path.GetCurrentLevel( ) == 2); // this means actuall "next" free level
	}


	// now do location and transportation
	{
	  Vector3D p3(-L/2., 0., 0.); path.Clear();
	  Vector3D newpoint;
	  Vector3D d(9*L/2./10.,0,0);
	  TransformationMatrix * m=new TransformationMatrix();
	  TransformationMatrix * m2=new TransformationMatrix();

	  vol=nav.LocatePoint_iterative( world, p3, result, path, m );
	  assert(vol==box3);
	  // move point in local reference frame
	  Vector3D p = result+d;
	  vol=nav.LocateLocalPointFromPath_Relative_Iterative( p, newpoint, path, m );
	  // LocateLocalPointFromPath_Relative(Vector3D const & point, Vector3D & localpoint, VolumePath & path, TransformationMatrix * ) const;
	  assert( vol==box2 );
	  path.Print();
	  assert( path.GetCurrentLevel() == 3 );

	  // check the global transformation matrix
	  path.GetGlobalMatrixFromPath( m2 );
	  assert( m->Equals( m2 ) );

	  delete m;
	  delete m2;
	}



	// now do location and transportation
	{
		Vector3D p3(-L/2., 0., 0.); path.Clear();
		Vector3D newpoint;
		Vector3D d(0.1,0.,0.);
		TransformationMatrix * m=new TransformationMatrix();
		TransformationMatrix * m2=new TransformationMatrix();

		vol=nav.LocatePoint_iterative( world, p3, result, path, m );
		// move point in local reference frame
		Vector3D p = result+d;
		vol=nav.LocateLocalPointFromPath_Relative_Iterative( p, newpoint, path, m );
		// LocateLocalPointFromPath_Relative(Vector3D const & point, Vector3D & localpoint, VolumePath & path, TransformationMatrix * ) const;
		assert( vol==box3 );
		assert( path.GetCurrentLevel() == 4 );
		path.GetGlobalMatrixFromPath( m2 );
		assert(m2->Equals(m));
// testing new point also
		assert(newpoint == d);

		delete m;
		delete m2;
	}


	// now do location and transportation
	{
		Vector3D p3(-L/2., 0., 0.); path.Clear();
		Vector3D newpoint;
		Vector3D d(Sqrt2*L/4.+0.1,Sqrt2*L/4.+0.1,0);
		TransformationMatrix * m=new TransformationMatrix();
		vol=nav.LocatePoint_iterative( world, p3, result, path, m );
		// move point in local reference frame
		Vector3D p = result+d;
		vol=nav.LocateLocalPointFromPath_Relative_Iterative( p, newpoint, path, m );
		// LocateLocalPointFromPath_Relative(Vector3D const & point, Vector3D & localpoint, VolumePath & path, TransformationMatrix * ) const;
		assert( vol==box1left );
		assert( path.GetCurrentLevel() == 2 );

		delete m;
	}


	// now do location and transportation

	{
		Vector3D p3(-L/2., 0., 0.); path.Clear();
		Vector3D newpoint;
		Vector3D d(Sqrt2*L/2.+0.1,Sqrt2*L/2.+0.1,0);
		TransformationMatrix * m=new TransformationMatrix();
		TransformationMatrix * m2=new TransformationMatrix();

		vol=nav.LocatePoint_iterative( world, p3, result, path, m );
		// move point in local reference frame
		Vector3D p = result+d;
		vol=nav.LocateLocalPointFromPath_Relative_Iterative( p, newpoint, path, m );

		// LocateLocalPointFromPath_Relative(Vector3D const & point, Vector3D & localpoint, VolumePath & path, TransformationMatrix * ) const;
		path.Print();
		assert( vol==world );
		assert( path.GetCurrentLevel() == 1 );
		path.GetGlobalMatrixFromPath( m2 );
		assert( m2->Equals( m ) );

		delete m;
	}


	// now do location and transportation
	{
			Vector3D p3(-L/2., 0., 0.); path.Clear();
			Vector3D newpoint;
			Vector3D d(4*L,4*L,0);
			TransformationMatrix * m=new TransformationMatrix();
			vol=nav.LocatePoint_iterative( world, p3, result, path, m );
			// move point in local reference frame
			Vector3D p = result+d;
			vol=nav.LocateLocalPointFromPath_Relative_Iterative( p, newpoint, path, m );
			// LocateLocalPointFromPath_Relative(Vector3D const & point, Vector3D & localpoint, VolumePath & path, TransformationMatrix * ) const;
			assert( vol==NULL );

			delete m;
	}


	// now do location and transportation
	{
	  Vector3D p3(-L/2., 0., 0.); path.Clear();
	  Vector3D newpoint;
	  Vector3D d(L,0,0);
	  TransformationMatrix * m=new TransformationMatrix();
	  TransformationMatrix * m2=new TransformationMatrix();

	  vol=nav.LocatePoint_iterative( world, p3, result, path, m );
	  assert( vol==box3 );

	  // move point in local reference frame
	  Vector3D p = result+d;
	  vol=nav.LocateLocalPointFromPath_Relative_Iterative( p, newpoint, path, m );
	  // LocateLocalPointFromPath_Relative(Vector3D const & point, Vector3D & localpoint, VolumePath & path, TransformationMatrix * ) const;
	  assert( vol==box3 );
	  assert( path.GetCurrentLevel() == 4 );

	  path.GetGlobalMatrixFromPath( m2 );
	  assert( m2->Equals(m) );
	  assert(newpoint==Vector3D(0,0,0));

	  delete m;
	  delete m2;
	}

	// now do location and transportation
	{
	  Vector3D p3(-L/2., 0., 0.); path.Clear();
	  Vector3D newpoint;
	  Vector3D d(L+9*L/20.,0,0);
	  TransformationMatrix * m=new TransformationMatrix();

	  vol=nav.LocatePoint( world, p3, result, path );
	  assert( vol==box3 );

	  // move point in local reference frame
	  Vector3D p = result+d;
	  vol=nav.LocateLocalPointFromPath_Relative( p, newpoint, path, m );
	  // LocateLocalPointFromPath_Relative(Vector3D const & point, Vector3D & localpoint, VolumePath & path, TransformationMatrix * ) const;
	  assert( vol==box2 );
	  assert( path.GetCurrentLevel() == 3 );
	  delete m;
	}

	// now do location and transportation
	{
	  Vector3D p3(-9*L/10., -9*L/20., 0.); path.Clear();
	  Vector3D newpoint;
	  Vector3D d(L/2.,L/2.,0);
	  TransformationMatrix * m=new TransformationMatrix();

	  vol=nav.LocatePoint( world, p3, result, path );
	  assert( vol==box1left );

	  // move point in local reference frame
	  Vector3D p = result+d;
	  vol=nav.LocateLocalPointFromPath_Relative( p, newpoint, path, m );
	  // LocateLocalPointFromPath_Relative(Vector3D const & point, Vector3D & localpoint, VolumePath & path, TransformationMatrix * ) const;
	  assert( vol==box3 );
	  assert( path.GetCurrentLevel() == 4 );
	  delete m;
	}


	// testing the NavigationAndStepInterface
	{
		// setup point in world
		Vector3D p(-L/2, 9*L/10., 0 );
		Vector3D d(0,-1,0);
		Vector3D resultpoint;
		VolumePath path(4), newpath(4);
		TransformationMatrix *m = new TransformationMatrix();
		TransformationMatrix *m2 = new TransformationMatrix();
		vol = nav.LocatePoint_iterative( world, p, resultpoint, path, m );
		assert(vol==world);

		// do one step
		double step;
		nav.FindNextBoundaryAndStep_iterative(m, p, d, path, newpath, resultpoint, step);
		newpath.Print();
		resultpoint.print();
		std::cerr << " step "  << step << std::endl;
		std::cerr << " current global point " << resultpoint << std::endl;
		// at this moment we can do some tests
		assert( newpath.Top() == box2 );
		newpath.GetGlobalMatrixFromPath(m2);
		assert( m2->Equals(m) );

		// go on with navigation ( enter daughter here ( from box2 to box3 ) )
		p=resultpoint;
		path=newpath;
		nav.FindNextBoundaryAndStep_iterative(m, p, d, path, newpath, resultpoint, step);
		std::cerr << " step "  << step << std::endl;
		std::cerr << " current global point " << resultpoint << std::endl;
		newpath.Print();
		newpath.GetGlobalMatrixFromPath(m2);
		assert( m2->Equals(m) );
		assert( newpath.Top() == box3 );

		// go on with navigation
		p = resultpoint;
		path=newpath;
		nav.FindNextBoundaryAndStep(m, p, d, path, newpath, resultpoint, step);
		std::cerr << " step "  << step << std::endl;
		std::cerr << " current global point " << resultpoint << std::endl;
		assert( newpath.Top() == box2 );

		// go on with navigation
		p = resultpoint;
		path=newpath;
		nav.FindNextBoundaryAndStep(m, p, d, path, newpath, resultpoint, step);
		std::cerr << " step "  << step << std::endl;
		std::cerr << " current global point " << resultpoint << std::endl;
		assert( newpath.Top() == world );

		// go on with navigation ( particle should now leave the world )
		p = resultpoint;
		path=newpath;
		newpath.Clear();
		nav.FindNextBoundaryAndStep(m, p, d, path, newpath, resultpoint, step);
		std::cerr << " step "  << step << std::endl;
		std::cerr << " current global point " << resultpoint << std::endl;
		assert( newpath.Top() == NULL );
	}


	std::cout << " ALL tests passed " << std::endl;

}
  void doInteraction(float dt){
    Glove *l = &left;
    Glove *r = &right;

    Vec3f headPos = tracker->markerPositions[17]; // right(0-7) left(8-15) A B C (16 17 18)
    if(headPos.mag() == 0) return;

    Rayd rayS(headPos, r->centroid - headPos); // ray pointing in direction of head to right hand
    
    float t = rayS.intersectAllosphere(); // get t on surface of allosphere screen
    Vec3f pos = nav().quat().rotate( rayS(t) ); // rotate point on allosphere to match current nav orientation (check this)
    Rayd ray( nav().pos(), pos); // ray from sphere center (camera location) to intersected location

    // Use ray to intesect with plasma shell on pinch
    if( r->pinchOn[eIndex]){
      cout<<"right index finger pinched, create lightning!"<<endl; 
      //audio
      //cout << currentPlayer << endl;
      //cout << *currentPlayer << endl;
      samplePlayer[*currentPlayer].reset(); // reset the phase == start playing the sound

      *currentPlayer = *currentPlayer + 1;
      if (*currentPlayer == N_SAMPLE_PLAYER){
        *currentPlayer = 0;
        // currentPlayer = 0; // this was a horrible BUG! XXX
      }
      //visual
      Vec3f center = Vec3f(0, 0.6, -1);
      float t = ray.intersectSphere(Vec3f(0,0,0), R);
      Vec3f src = ray(t);
      Vec3f dest = 0.1f * (src - center).normalize() + center;
      Bolt* newPSBolt = new Bolt();
      newPSBolt->makeTexture();
      newPSBolt->start = src;
      newPSBolt->ending = dest;
      newPSBolt->makeBolt(src, dest, 2, 0.03);
      newPSBolt->createBulge(center);
      boltQ->push_back(newPSBolt); 
    }

    // state->cursor.set(nav().pos() + pos);

    // Navigation joystick mode
    // Translation done with the left index finger pinch gesture
    if( l->pinchOn[eIndex]){
    } else if( l->pinched[eIndex]){
      Vec3f translate = sensitivity * l->getPinchTranslate(eIndex);
      for(int i=0; i<3; i++){
        nav().pos()[i] = nav().pos()[i] * 0.9 + 
          (nav().pos()[i] + translate.dot(Vec3d(nav().ur()[i], nav().uu()[i], -nav().uf()[i]))) * 0.1;
      }
      // nav().pos().lerp( nav().pos() + translate, 0.01f);
    } else if( l->pinchOff[eIndex] ){
    } else {
    }
    //ePinky
    //eRing

    // change navigation sensitivity
    if( l->pinched[eMiddle]){
      Vec3f v = l->getPinchTranslate(eMiddle);
      sensitivity = abs(v.y*10);
    }

  }
示例#12
0
void Q3DataBrowser::prev()
{
    nav(&Q3SqlCursor::previous);
}
示例#13
0
void Q3DataBrowser::next()
{
    nav(&Q3SqlCursor::next);
}
示例#14
0
void Q3DataBrowser::last()
{
    nav(&Q3SqlCursor::last);
}
示例#15
0
int main()
{
   Vectors3DSOA points, dirs, intermediatepoints, intermediatedirs;
   StructOfCoord rpoints, rintermediatepoints, rdirs, rintermediatedirs;


   int np=1024;
   int NREPS = 1000;

   points.alloc(np);
   dirs.alloc(np);

    // generate benchmark cases
   TransformationMatrix const * identity = new TransformationMatrix(0,0,0,0,0,0);

   // the world volume is a tube
   double worlddx = 100.;
   double worlddy = 100;
   double worlddz = 10.;
   BoxParameters *   worldp =  new BoxParameters(worlddx, worlddy, worlddz);
   PhysicalVolume * world = GeoManager::MakePlacedBox( worldp , identity );
   double volworld = worldp->GetVolume();


   BoxParameters * cellparams = new BoxParameters( worlddx/20., worlddy/20., worlddz/4 );
   BoxParameters * waiverparams = new BoxParameters( worlddx/3., worlddy/3., worlddz/2 );
   double volcell = cellparams->GetVolume();
   double volwaiver = waiverparams->GetVolume();

   PhysicalVolume *waiver = GeoManager::MakePlacedBox( waiverparams, identity);

   // this just adds daughters which have been created in a placed way
   waiver->AddDaughter(GeoManager::MakePlacedBox( cellparams, new TransformationMatrix( -waiverparams->GetDX()/2., waiverparams->GetDY()/2., 0, 0, 0, 0) ));
   waiver->AddDaughter(GeoManager::MakePlacedBox( cellparams, new TransformationMatrix( waiverparams->GetDX()/2., waiverparams->GetDY()/2., 0, 0, 0, 45) ));
   waiver->AddDaughter(GeoManager::MakePlacedBox( cellparams, new TransformationMatrix( waiverparams->GetDX()/2., -waiverparams->GetDY()/2., 0, 0, 0, 0) ));
   waiver->AddDaughter(GeoManager::MakePlacedBox( cellparams, new TransformationMatrix( -waiverparams->GetDX()/2., -waiverparams->GetDY()/2., 0, 0, 0, 45)));

   // at this moment the waiver is not yet placed into the world; this will be done now with the new interface
   // we are basically replacing the waiver by using its existing parameters and daughterlist
   // TODO: the future interface will hide much of the details here
   world->PlaceDaughter(GeoManager::MakePlacedBox(waiverparams, new TransformationMatrix( worlddx/2., worlddy/2., 0, 0, 0, 45 )), waiver->GetDaughterList());
   world->PlaceDaughter(GeoManager::MakePlacedBox(waiverparams, new TransformationMatrix( -worlddx/2., worlddy/2., 0, 0, 0, 0  )), waiver->GetDaughterList());
   world->PlaceDaughter(GeoManager::MakePlacedBox(waiverparams, new TransformationMatrix( -worlddx/2., -worlddy/2., 0, 0, 0, 45 )), waiver->GetDaughterList());
   world->PlaceDaughter(GeoManager::MakePlacedBox(waiverparams, new TransformationMatrix( worlddx/2., -worlddy/2., 0, 0, 0, 0 )), waiver->GetDaughterList());


   world->fillWithRandomPoints(points,np);
   world->fillWithBiasedDirections(points, dirs, np, 9/10.);

   std::cerr << " Number of daughters " << world->GetNumberOfDaughters() << std::endl;

   // try to locate a global point

   StopWatch timer;
   timer.Start();
   VolumePath path(4), newpath(4);
   std::map<PhysicalVolume const *, int> volcounter;
   int total=0;
   TransformationMatrix * globalm=new TransformationMatrix();
   TransformationMatrix * globalm2 = new TransformationMatrix();
   SimpleVecNavigator nav(1, world);
   Vector3D displacementvector( worlddx/20, 0., 0. );
   int counter[2]={0,0};
   for(int i=0;i<1000000;i++)
   {
      globalm->SetToIdentity();
      globalm2->SetToIdentity();
      Vector3D point;
      Vector3D localpoint;
      Vector3D newlocalpoint;
      Vector3D cmppoint;
      PhysicalVolume::samplePoint( point, worlddx, worlddy, worlddz, 1 );
      //   PhysicalVolume const * deepestnode = nav.LocateGlobalPoint( world, point, localpoint, path, globalm2 );
      localpoint.x = point.x;
      localpoint.y = point.y;
      localpoint.z = point.z;
      PhysicalVolume const * deepestnode = nav.LocateGlobalPoint( world, point, localpoint, path );
      /*
      if(volcounter.find(deepestnode) == volcounter.end())
        {
          volcounter[deepestnode]=1;
        }
      else
        {
          volcounter[deepestnode]++;
        }
      */

      // do the cross check

//      Vector3D localpoint;

      // check one thing
      localpoint.x = localpoint.x + displacementvector.x;
      localpoint.y = localpoint.y + displacementvector.y;
      localpoint.z = localpoint.z + displacementvector.z;
      PhysicalVolume const * newnode = nav.LocateLocalPointFromPath( localpoint, path, newpath, globalm2 );
      if( newnode == deepestnode )
      {
         counter[0]++;
      }
      else
      {
         counter[1]++;
      }


   //   path.GetGlobalMatrixFromPath(globalm);
    //   globalm->LocalToMaster(localpoint, cmppoint);
   //  std::cerr << " ######################## " << std::endl;
   //   point.print();
   //   globalm->print();
   //   cmppoint.print();
   //   std::cerr << " ------------------------ " << std::endl;

      /*
      std::cerr << " ######################## " << std::endl;
      globalm->print();
      std::cerr << " ;;;;;;; " << std::endl;
      globalm2->print();
      std::cerr << " ------------------- " << std::endl;

      //globalm2->MasterToLocal<1,-1>( point, localpoint );
      PhysicalVolume const * cmpnode = nav.LocateLocalPointFromPath( localpoint, path, newpath );

      //assert( cmpnode == deepestnode );

*/
      // path.Print();
      path.Clear();
      newpath.Clear();
      //      deepestnode->printInfo();
   }
   timer.Stop();
   std::cerr << " step took " << timer.getDeltaSecs() << " seconds " << std::endl;
   std::cerr << counter[0] << std::endl;
   std::cerr << counter[1] << std::endl;
   
   for(auto k=volcounter.begin();k!=volcounter.end();k++)
     {
       total+=k->second;
     }
   
   for(auto k=volcounter.begin();k!=volcounter.end();k++)
     {
       std::cerr << k->first << " " << k->second << " " << k->second/(1.*total) << std::endl; 
     }
   std::cerr << 4*volcell/volworld << std::endl;
   std::cerr << volwaiver/volworld << std::endl;
   std::cerr << (volworld-4*volwaiver)/volworld << std::endl;
}
int main(int argc, char * argv[])
{
   bool iterative=true;
   if(argc>1) iterative=false;
   Vectors3DSOA points, dirs, intermediatepoints, intermediatedirs;

   int np=1024;
   int NREPS = 1000;

   points.alloc(np);
   dirs.alloc(np);

   // generate benchmark cases
   TransformationMatrix const * identity = new TransformationMatrix(0,0,0,0,0,0);

   double L = 10.;
   double Lz = 10.;
   const double Sqrt2 = sqrt(2.);

   BoxParameters *   worldp =  new BoxParameters(L, L, Lz );
   PhysicalVolume * world = GeoManager::MakePlacedBox( worldp , identity );
   double volworld = worldp->GetVolume();

   BoxParameters * boxlevel2 = new BoxParameters( Sqrt2*L/2./2., Sqrt2*L/2./2., Lz );
   BoxParameters * boxlevel3 = new BoxParameters( L/2./2. ,L/2./2., Lz);
   BoxParameters * boxlevel1 = new BoxParameters( L/2., L/2., Lz );

   PhysicalVolume * box2 = GeoManager::MakePlacedBox(boxlevel2, new TransformationMatrix(0,0,0,0,0,45));
   PhysicalVolume * box3 = GeoManager::MakePlacedBox( boxlevel3, new TransformationMatrix(0,0,0,0,0,-45));
   box2->AddDaughter( box3 ); // rotated 45 degree around z axis

   PhysicalVolume * box1 = GeoManager::MakePlacedBox(boxlevel1, identity);
   box1->AddDaughter( box2 );

   PhysicalVolume const * box1left  = world->PlaceDaughter(GeoManager::MakePlacedBox(boxlevel1, new TransformationMatrix(-L/2.,0.,0.,0.,0.,0)), box1->GetDaughters());
   PhysicalVolume const * box1right = world->PlaceDaughter(GeoManager::MakePlacedBox(boxlevel1, new TransformationMatrix(+L/2.,0.,0.,0.,0.,0)), box1->GetDaughters());


    // perform basic tests
   SimpleVecNavigator nav(1, world);

   StopWatch timer;
   // some object which are expensive to create
   FastTransformationMatrix * m = new FastTransformationMatrix();
   VolumePath path(4);
   VolumePath newpath(4);

   timer.Start();
   int stepsdone=0;
   for(int n=0;n<1000;n++)
     {
   for(int i=0;i<100000;i++)
   // testing the NavigationAndStepInterface
   {
      int localstepsdone=0;
      double distancetravelled=0.;
      Vector3DFast p;
      PhysicalVolume::samplePoint( p, worldp->GetDX(), worldp->GetDY(), worldp->GetDZ(), 1. );
#ifdef DEBUG
      std::cerr << p << " " << worldp->GetDX()-p.GetX() << " ";
#endif

      // setup point in world
      Vector3DFast d(1,0,0);
      Vector3DFast resultpoint;

      m->SetToIdentity();
      PhysicalVolume const * vol;
#ifdef ITERATIVE
         vol = nav.LocatePoint_iterative( world, p, resultpoint, path, m );
#else
         vol = nav.LocatePoint( world, p, resultpoint, path, m );
#endif
         while( vol!=NULL )
      {
         localstepsdone++;
         // do one step
         double step;
#ifdef ITERATIVE
         nav.FindNextBoundaryAndStep_iterative(m, p, d, path, newpath, resultpoint, step);
#else
         nav.FindNextBoundaryAndStep(m, p, d, path, newpath, resultpoint, step);
#endif
         distancetravelled+=step;
#ifdef DEBUG
         std::cerr << "  proposed step: " << step << std::endl;
         std::cerr << "  next point " << resultpoint << std::endl;
         std::cerr << "  in vol " << newpath.Top() << std::endl;
#endif

         // go on with navigation
         p = resultpoint;
         path=newpath;
         vol=path.Top();
      }
#ifdef DEBUG
         std::cerr << localstepsdone << " " << distancetravelled << std::endl;
#endif
         stepsdone+=localstepsdone;
   }
     }
   timer.Stop();
   std::cout << " time for 100000 particles " << timer.getDeltaSecs( ) << std::endl;
   std::cout << " average steps done " << stepsdone / 100000. << std::endl;
   std::cout << " time per step " << timer.getDeltaSecs()/stepsdone << std::endl;

   delete m;
}
示例#17
0
void Renderer::onAnimate(al_sec dt)
{
    pose = nav();
}
示例#18
0
void QDataBrowser::prev()
{
    nav( &QSqlCursor::prev );
}
示例#19
0
void QDataBrowser::next()
{
    nav( &QSqlCursor::next );
}
示例#20
0
void QDataBrowser::last()
{
    nav( &QSqlCursor::last );
}