/******************************************************
   Handle mouse events
*******************************************************/
void HandleMouse(int button,int state,int x,int y)
{
   int i,maxselect = 100,nhits = 0;
   GLuint selectlist[100];

   if (state == GLUT_DOWN) {
      glSelectBuffer(maxselect,selectlist);
      glRenderMode(GL_SELECT);
      glInitNames();
      glPushName(-1);

      glPushMatrix();
      MakeCamera(TRUE,x,y);
      MakeGeometry();
      glPopMatrix();
      nhits = glRenderMode(GL_RENDER);

      if (button == GLUT_LEFT_BUTTON) {

      } else if (button == GLUT_MIDDLE_BUTTON) {

      } /* Right button events are passed to menu handlers */

      if (nhits == -1)
         fprintf(stderr,"Select buffer overflow\n");

      if (nhits > 0) {
         fprintf(stderr,"\tPicked %d objects: ",nhits);
         for (i=0;i<nhits;i++)
            fprintf(stderr,"%d ",selectlist[4*i+3]);
         fprintf(stderr,"\n");
      }

   }
}
/**************************************************************
   This is the basic display callback routine
   It creates the geometry, lighting, and viewing position
   In this case it rotates the camera around the scene
***************************************************************/
void Display(void)
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glPushMatrix();
   MakeCamera(FALSE,0,0);
   MakeLighting();
   MakeGeometry();
   glPopMatrix();
    //glFlush(); This isn't necessary for double buffers
   glutSwapBuffers();
}
Exemplo n.º 3
0
/*
   This is the basic display callback routine
   It creates the geometry, lighting, and viewing position
   In this case it rotates the camera around the scene
*/
void Display(void)
{
   XYZ r,eyepos;
   double dist,ratio,radians,scale,wd2,ndfl;
   double left,right,top,bottom;

   /* Do we need to recreate the list ? */
   if (geometrydirty != NOTDIRTY) {
      MakeGeometry();
      geometrydirty = NOTDIRTY;
   }

   /* Clip to avoid extreme stereo */
   near = 0.1;
   far = 1000;
   if (stereo)
      near = camera.focallength / 5;

   /* Misc stuff */
   ratio  = camera.screenwidth / (double)camera.screenheight;
   radians = DTOR * camera.aperture / 2;
   wd2     = near * tan(radians);
   ndfl    = near / camera.focallength;

   /* Clear the buffers */
   glDrawBuffer(GL_BACK_LEFT);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   if (stereo) {
      glDrawBuffer(GL_BACK_RIGHT);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   }

   if (stereo) {

      /* Derive the two eye positions */
      CROSSPROD(camera.vd,camera.vu,r);
      Normalise(&r);
      r.x *= camera.eyesep / 2.0;
      r.y *= camera.eyesep / 2.0;
      r.z *= camera.eyesep / 2.0;
      eyepos = VectorAdd(camera.vp,r);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      left  = - ratio * wd2 - 0.5 * camera.eyesep * ndfl;
      right =   ratio * wd2 - 0.5 * camera.eyesep * ndfl;
      top    =   wd2;
      bottom = - wd2;
      glFrustum(left,right,bottom,top,near,far);

      glMatrixMode(GL_MODELVIEW);
      glDrawBuffer(GL_BACK_RIGHT);
      glLoadIdentity();
      gluLookAt(eyepos.x,eyepos.y,eyepos.z,
                eyepos.x + camera.vd.x,
                eyepos.y + camera.vd.y,
                eyepos.z + camera.vd.z,
                camera.vu.x,camera.vu.y,camera.vu.z);
      MakeLighting();
      glCallList(1);

      eyepos = VectorSub(r,camera.vp);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      left  = - ratio * wd2 + 0.5 * camera.eyesep * ndfl;
      right =   ratio * wd2 + 0.5 * camera.eyesep * ndfl;
      top    =   wd2;
      bottom = - wd2;
      glFrustum(left,right,bottom,top,near,far);

      glMatrixMode(GL_MODELVIEW);
      glDrawBuffer(GL_BACK_LEFT);
      glLoadIdentity();
      gluLookAt(eyepos.x,eyepos.y,eyepos.z,
                eyepos.x + camera.vd.x,
                eyepos.y + camera.vd.y,
                eyepos.z + camera.vd.z,
                camera.vu.x,camera.vu.y,camera.vu.z);
      MakeLighting();
      glCallList(1);

   } else {

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      left  = - ratio * wd2;
      right =   ratio * wd2;
      top    =   wd2;
      bottom = - wd2;
      glFrustum(left,right,bottom,top,near,far);

      glMatrixMode(GL_MODELVIEW);
      glDrawBuffer(GL_BACK_LEFT);
      glLoadIdentity();
      gluLookAt(camera.vp.x,camera.vp.y,camera.vp.z,
                camera.vp.x + camera.vd.x,
                camera.vp.y + camera.vd.y,
                camera.vp.z + camera.vd.z,
                camera.vu.x,camera.vu.y,camera.vu.z);
      MakeLighting();
      glCallList(1);
   }

   /* glFlush(); This isn't necessary for double buffers */
   glutSwapBuffers();

   if (record || windowdump) {
      WindowDump(camera.screenwidth,camera.screenheight,stereo);
      windowdump = FALSE;
   }

   if (demomode && iterationdepth < 1000) {
      iterationdepth++;
      geometrydirty = ADDONE;
      if (debug)
         fprintf(stderr,"Iteration: %d\n",iterationdepth);
   }
}
    util::json::Object MakeRoute(const std::vector<PhantomNodes> &segment_end_coordinates,
                                 const std::vector<std::vector<PathData>> &unpacked_path_segments,
                                 const std::vector<bool> &source_traversed_in_reverse,
                                 const std::vector<bool> &target_traversed_in_reverse) const
    {
        std::vector<guidance::RouteLeg> legs;
        std::vector<guidance::LegGeometry> leg_geometries;
        auto number_of_legs = segment_end_coordinates.size();
        legs.reserve(number_of_legs);
        leg_geometries.reserve(number_of_legs);

        for (auto idx : util::irange<std::size_t>(0UL, number_of_legs))
        {
            const auto &phantoms = segment_end_coordinates[idx];
            const auto &path_data = unpacked_path_segments[idx];

            const bool reversed_source = source_traversed_in_reverse[idx];
            const bool reversed_target = target_traversed_in_reverse[idx];

            auto leg_geometry = guidance::assembleGeometry(
                BaseAPI::facade, path_data, phantoms.source_phantom, phantoms.target_phantom);
            auto leg = guidance::assembleLeg(facade, path_data, leg_geometry, phantoms.source_phantom,
                                             phantoms.target_phantom, reversed_target, parameters.steps);

            if (parameters.steps)
            {
                auto steps = guidance::assembleSteps(
                    BaseAPI::facade, path_data, leg_geometry, phantoms.source_phantom,
                    phantoms.target_phantom, reversed_source, reversed_target);

                /* Perform step-based post-processing.
                 *
                 * Using post-processing on basis of route-steps for a single leg at a time
                 * comes at the cost that we cannot count the correct exit for roundabouts.
                 * We can only emit the exit nr/intersections up to/starting at a part of the leg.
                 * If a roundabout is not terminated in a leg, we will end up with a
                 *enter-roundabout
                 * and exit-roundabout-nr where the exit nr is out of sync with the previous enter.
                 *
                 *         | S |
                 *         *   *
                 *  ----*        * ----
                 *                  T
                 *  ----*        * ----
                 *       V *   *
                 *         |   |
                 *         |   |
                 *
                 * Coming from S via V to T, we end up with the legs S->V and V->T. V-T will say to
                 *take
                 * the second exit, even though counting from S it would be the third.
                 * For S, we only emit `roundabout` without an exit number, showing that we enter a
                 *roundabout
                 * to find a via point.
                 * The same exit will be emitted, though, if we should start routing at S, making
                 * the overall response consistent.
                 */

                guidance::trimShortSegments(steps, leg_geometry);
                leg.steps = guidance::postProcess(std::move(steps));
                leg.steps = guidance::collapseTurns(std::move(leg.steps));
                leg.steps = guidance::assignRelativeLocations(std::move(leg.steps), leg_geometry,
                                                              phantoms.source_phantom,
                                                              phantoms.target_phantom);
                leg_geometry = guidance::resyncGeometry(std::move(leg_geometry), leg.steps);
            }

            leg_geometries.push_back(std::move(leg_geometry));
            legs.push_back(std::move(leg));
        }

        auto route = guidance::assembleRoute(legs);
        boost::optional<util::json::Value> json_overview;
        if (parameters.overview != RouteParameters::OverviewType::False)
        {
            const auto use_simplification =
                parameters.overview == RouteParameters::OverviewType::Simplified;
            BOOST_ASSERT(use_simplification ||
                         parameters.overview == RouteParameters::OverviewType::Full);

            auto overview = guidance::assembleOverview(leg_geometries, use_simplification);
            json_overview = MakeGeometry(overview.begin(), overview.end());
        }

        std::vector<util::json::Value> step_geometries;
        for (const auto idx : util::irange<std::size_t>(0UL, legs.size()))
        {
            auto &leg_geometry = leg_geometries[idx];
            std::transform(
                legs[idx].steps.begin(), legs[idx].steps.end(), std::back_inserter(step_geometries),
                [this, &leg_geometry](const guidance::RouteStep &step) {
                    if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
                    {
                        return static_cast<util::json::Value>(
                            json::makePolyline(leg_geometry.locations.begin() + step.geometry_begin,
                                               leg_geometry.locations.begin() + step.geometry_end));
                    }
                    BOOST_ASSERT(parameters.geometries == RouteParameters::GeometriesType::GeoJSON);
                    return static_cast<util::json::Value>(json::makeGeoJSONGeometry(
                        leg_geometry.locations.begin() + step.geometry_begin,
                        leg_geometry.locations.begin() + step.geometry_end));
                });
        }

        return json::makeRoute(route,
                               json::makeRouteLegs(std::move(legs), std::move(step_geometries)),
                               std::move(json_overview));
    }
Exemplo n.º 5
0
void display() {
	
	double nearp = 0.1;
	double farp = 10000;
	XYZ r;
	double dist, ratio, radians, scale, wd2, ndfl;
	double left, right, top, bottom;
	
	/* Clip to avoid extreme stereo */
#ifdef STEREO_3D
	nearp = camera.focallength / 5;
#endif

	/* Misc stuff */
	ratio  = camera.screenwidth / (double)camera.screenheight;
	radians = DTOR * camera.aperture / 2;
	wd2     = nearp * tan(radians);
	ndfl    = nearp / camera.focallength;

	glDrawBuffer(GL_BACK);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

#ifdef STEREO_3D

		update();

		/* Derive the two eye positions */
		CROSSPROD(camera.vd,camera.vu,r);
		Normalise(&r);
		r.x *= camera.eyesep / 2.0;
		r.y *= camera.eyesep / 2.0;
		r.z *= camera.eyesep / 2.0;

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		left  = - ratio * wd2 - 0.5 * camera.eyesep * ndfl;
		right =   ratio * wd2 - 0.5 * camera.eyesep * ndfl;
		top    =   wd2;
		bottom = - wd2;
		glFrustum(left,right,bottom,top,nearp,farp);

		glMatrixMode(GL_MODELVIEW);
		glDrawBuffer(GL_BACK);

#ifdef INVERT_STEREO
		glViewport (
			camera.screenwidth / 2, 0, 
			camera.screenwidth / 2, camera.screenheight);
#else
		glViewport (
			0, 0, 
			camera.screenwidth / 2, camera.screenheight);
#endif


		glLoadIdentity();
		gluLookAt(camera.vp.x + r.x,camera.vp.y + r.y,camera.vp.z + r.z,
			camera.vp.x + r.x + camera.vd.x,
			camera.vp.y + r.y + camera.vd.y,
			camera.vp.z + r.z + camera.vd.z,
			camera.vu.x,camera.vu.y,camera.vu.z);

		glTranslatef(-0.5f, -0.5f, -2.0f);

		MakeLighting();
		MakeGeometry();

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		left  = - ratio * wd2 + 0.5 * camera.eyesep * ndfl;
		right =   ratio * wd2 + 0.5 * camera.eyesep * ndfl;
		top    =   wd2;
		bottom = - wd2;
		glFrustum(left,right,bottom,top,nearp,farp);

		glMatrixMode(GL_MODELVIEW);
		glDrawBuffer(GL_BACK);

#ifdef INVERT_STEREO
		glViewport (
			0, 0, 
			camera.screenwidth / 2, camera.screenheight);
#else
		glViewport (
			camera.screenwidth / 2, 0, 
			camera.screenwidth / 2, camera.screenheight);
#endif


//		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glLoadIdentity();
		gluLookAt(camera.vp.x - r.x,camera.vp.y - r.y,camera.vp.z - r.z,
			camera.vp.x - r.x + camera.vd.x,
			camera.vp.y - r.y + camera.vd.y,
			camera.vp.z - r.z + camera.vd.z,
			camera.vu.x,camera.vu.y,camera.vu.z);

		glTranslatef(-0.5f, -0.5f, -2.0f);

		MakeLighting();
		MakeGeometry();

		glutSwapBuffers();
		glutPostRedisplay();

#else

		update();

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		left  = - ratio * wd2;
		right =   ratio * wd2;
		top    =   wd2;
		bottom = - wd2;
		glFrustum(left,right,bottom,top,nearp,farp);
		
		glMatrixMode(GL_MODELVIEW);

		glLoadIdentity();
		gluLookAt(camera.vp.x,camera.vp.y,camera.vp.z,
			camera.vp.x + camera.vd.x,
			camera.vp.y + camera.vd.y,
			camera.vp.z + camera.vd.z,
			camera.vu.x,camera.vu.y,camera.vu.z);

		glTranslatef(-0.5f, -0.5f, -2.0f);

		MakeLighting();
		MakeGeometry();

		glutSwapBuffers();
		glutPostRedisplay();

#endif // STEREO_3D
}
Exemplo n.º 6
0
static void LoadThemeFrame(Magick::Image& img, const std::string& path, Rect& plc)
{
    img.read(path.c_str());
    Point sz = plc.Size();
    img.zoom( MakeGeometry(sz.x, sz.y) );
}
Exemplo n.º 7
0
void draw_s2fishdome(CAMERA cam) {
  
  // draw a fisheye / warped projection of the geometry
  double r, near, far;
  XYZ vp, vd, vr, vl;
  XYZ vright, vleft, vup;

  // Calculate various view vectors 
  vp = cam.vp;
  vd = cam.vd;
  vr = CrossProduct(vd,cam.vu);
  vl = CrossProduct(cam.vu,vd);
  vd = ArbitraryRotate(vd,cam.fishrotate,vr);
  vup = CrossProduct(vr,vd);
  vright = VectorAdd(vr,vd);
  vleft = VectorAdd(vl,vd);
  near = VectorLength(_s2priv_pmin(),_s2priv_pmax()) / 100;
  far  = MAX(cam.focallength,VectorLength(_s2priv_pmin(),
					     _s2priv_pmax())) * 20;
  
  // Left
  glDrawBuffer(GL_BACK);
  glReadBuffer(GL_BACK);
  glViewport(0,0,TEXTURESIZE,TEXTURESIZE);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  s2Perspective(90.0,1.0,near,far);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  s2LookAt(vp.x,vp.y,vp.z,vp.x+vleft.x,vp.y+vleft.y,vp.z+vleft.z,vup.x,vup.y,vup.z);
  MakeLighting();
  MakeMaterial();
  MakeGeometry(FALSE, FALSE);
  glBindTexture(GL_TEXTURE_2D,walltextureid[2]);
  glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE);
    
  // Right
  glDrawBuffer(GL_BACK);
  glReadBuffer(GL_BACK);
  glViewport(0,0,TEXTURESIZE,TEXTURESIZE);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  s2Perspective(90.0,1.0,near,far);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  s2LookAt(vp.x,vp.y,vp.z,vp.x+vright.x,vp.y+vright.y,vp.z+vright.z,vup.x,vup.y,vup.z);
  MakeLighting();
  MakeMaterial();
  MakeGeometry(FALSE, FALSE);
  glBindTexture(GL_TEXTURE_2D,walltextureid[3]);
  glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE);
  
  // Top 
  glDrawBuffer(GL_BACK);
  glReadBuffer(GL_BACK);
  glViewport(0,0,TEXTURESIZE,TEXTURESIZE);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  s2Perspective(90.0,1.0,near,far);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  s2LookAt(vp.x,vp.y,vp.z,vp.x+vup.x,vp.y+vup.y,vp.z+vup.z,-vright.x,-vright.y,-vright.z);
  MakeLighting();
  MakeMaterial();
  MakeGeometry(FALSE, FALSE);
  glBindTexture(GL_TEXTURE_2D,walltextureid[0]);
  glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE);
  
  // Bottom 
  glDrawBuffer(GL_BACK);
  glReadBuffer(GL_BACK);
  glViewport(0,0,TEXTURESIZE,TEXTURESIZE);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  s2Perspective(90.0,1.0,near,far);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  s2LookAt(vp.x,vp.y,vp.z,vp.x-vup.x,vp.y-vup.y,vp.z-vup.z,-vleft.x,-vleft.y,-vleft.z);
  MakeLighting();
  MakeMaterial();
  MakeGeometry(FALSE, FALSE);
  glBindTexture(GL_TEXTURE_2D,walltextureid[1]);
  glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,TEXTURESIZE,TEXTURESIZE);
  
  // Remember the graphics state and return it at the end
  glPushAttrib(GL_ALL_ATTRIB_BITS);
  glDisable(GL_LIGHTING);
  glDisable(GL_ALPHA_TEST);
  glDisable(GL_COLOR_MATERIAL);
  glDisable(GL_DITHER);
  //glDisable(GL_FOG);
  glDisable(GL_LINE_SMOOTH);
  glDisable(GL_LINE_STIPPLE);
  glDisable(GL_SCISSOR_TEST);
  glDisable(GL_STENCIL_TEST);
  
  // Setup projections for the dome
  glDrawBuffer(GL_BACK);
  if (_s2fd_options->dometype == WARPMAP)
    glClearColor(0.0,0.0,0.0,0.0);
  else
    glClearColor(0.05,0.05,0.05,0.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glViewport(0,0,_s2fd_options->screenwidth,_s2fd_options->screenheight);
  r = _s2fd_options->screenwidth / (double)_s2fd_options->screenheight;
  switch (_s2fd_options->dometype) {
  case TRUNCTOP:
  case TRUNCBOTTOM:
    glOrtho(-r*0.75,r*0.75,-0.75,0.75,0.1,10.0);
    break;
  case HSPHERICAL:
    glOrtho(-r*0.75,r*0.75,-0.75,0.75,0.1,10.0);
    break;
  case VSPHERICAL:
  case WARPMAP:
  default:
    glOrtho(-r,r,-1.0,1.0,0.1,10.0);
    break;
  }
    
  // Create camera projection for dome
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  switch (_s2fd_options->dometype) {
  case TRUNCBOTTOM:
    s2LookAt(0.0,-1.0,0.25,0.0,0.0,0.25,0.0,0.0,1.0);
    break;
  case TRUNCTOP:
    s2LookAt(0.0,-1.0,-0.25,0.0,0.0,-0.25,0.0,0.0,1.0);
    break;
  case HSPHERICAL:
  case VSPHERICAL:
  case WARPMAP:
  default:
    s2LookAt(0.0,-1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0);
    break;
  }
    
  // Finally draw the dome geometry
  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  glColor3f(1.0,1.0,1.0);
  DrawDome(TRUE,FALSE);

  _s2_fadeinout();
  
  DrawExtras();
  glPopAttrib();
  
}