Example #1
0
/*
 * Returns true if the given point is visible from the given viewpoint.
 *
 * A point is visible if it will be on screen, and if it is not occluded by
 * other objects.
 *
 * Input:
 *   point: The point whose visibility we want to check.
 *   viewpoint: The viewpoint to check from.
 *
 * Returns: True if the point is visible from the viewpoint.
 */
bool VisibilityChecker::IsVisible(const Ogre::Vector3& point,
                                  const Viewpoint& viewpoint) {
  float screen_x;
  float screen_y;
  auto old_position = camera_->getPosition();
  auto old_direction = camera_->getDirection();
  camera_->setPosition(viewpoint.position());
  camera_->lookAt(viewpoint.focus());
  GetScreenPosition(point, &screen_x, &screen_y);
  bool result = false;
  if (IsOnScreen(screen_x, screen_y)) {
    Ogre::Ray ray;
    camera_->getCameraToViewportRay(screen_x, screen_y, &ray);
    Ogre::Vector3 hit;
    if (RaycastAABB(ray, &hit)) {
      auto dist = point.distance(hit);
      if (dist < kOcclusionThreshold) {
        result = true;
      } else { // Hit something, but too far away from the target.
        result = false;
      }
    } else {
      // No hits. The ray should hit the target, but if it doesn't, that usually
      // indicates visibility. This is because if the target is occluded, the
      // ray is likely to have hit the occluding object.
      result = true;
    }
  } else { // Not on screen
    result= false;
  }
  camera_->setPosition(old_position);
  camera_->setDirection(old_direction);
  return result;
}
Example #2
0
void RGLView::setScale(double* src)
{
    Viewpoint* viewpoint = scene->getViewpoint();

    viewpoint->setScale(src);

    View::update();
}
Example #3
0
void RGLView::setUserMatrix(double* src)
{
    Viewpoint* viewpoint = scene->getViewpoint();

    viewpoint->setUserMatrix(src);

    View::update();
}
Example #4
0
void RGLView::polarBegin(int mouseX, int mouseY)
{
    Viewpoint* viewpoint = scene->getViewpoint();

    camBase = viewpoint->getPosition();

    dragBase = screenToPolar(width,height,mouseX,height-mouseY);

}
Example #5
0
SDL_Rect find_map_rect(Idevice& input, Viewpoint& camera)
{
    SDL_Rect tilerect;
    int tilex, tiley;
    tilex = (input.get_x() + camera.get_x()) / TILEW;
    tiley = (input.get_y() + camera.get_y()) / TILEH;
    tilerect.x = tilex * TILEW; tilerect.y = tiley * TILEH;
    tilerect.w = TILEW; tilerect.h = TILEH;
    return tilerect;
}
Example #6
0
void RGLView::buttonPress(int button, int mouseX, int mouseY)
{
    Viewpoint* viewpoint = scene->getViewpoint();
    if ( viewpoint->isInteractive() ) {
        if (!drag) {
            drag = button;
            windowImpl->captureMouse(this);
            (this->*ButtonBeginFunc[button-1])(mouseX,mouseY);
        }
    }
}
Example #7
0
void RGLView::oneAxisUpdate(int mouseX, int mouseY)
{
	Viewpoint* viewpoint = scene->getViewpoint();

  	rotCurrent = screenToVector(width,height,mouseX,height/2);

	windowImpl->beginGL();
	viewpoint->mouseOneAxis(rotBase,rotCurrent,axis[drag-1]);
	windowImpl->endGL();

	View::update();
}
Example #8
0
void RGLView::trackballUpdate(int mouseX, int mouseY)
{
	Viewpoint* viewpoint = scene->getViewpoint();

  	rotCurrent = screenToVector(width,height,mouseX,height-mouseY);

	windowImpl->beginGL();
	viewpoint->updateMouseMatrix(rotBase,rotCurrent);
	windowImpl->endGL();

	View::update();
}
Example #9
0
void
KML_Feature::build( xml_node<>* node, KMLContext& cx, osg::Node* working )
{
    KML_Object::build(node, cx, working);

    // subclass feature is built; now add feature level data if available
    if ( working )
    {
        // parse the visibility to show/hide the item by default:
		std::string visibility = getValue(node, "visibility");
        if ( !visibility.empty() )
            working->setNodeMask( as<int>(visibility, 1) == 1 ? ~0 : 0 );

        // parse a "LookAt" element (stores a viewpoint)
        AnnotationData* anno = getOrCreateAnnotationData(working);
        
        anno->setName( getValue(node, "name") );
        anno->setDescription( getValue(node, "description") );

        xml_node<>* lookat = node->first_node("lookat", 0, false);
        if ( lookat )
        {
            Viewpoint vp;

            vp.focalPoint() = GeoPoint(
                cx._srs.get(),
				as<double>(getValue(lookat, "longitude"), 0.0),
				as<double>(getValue(lookat, "latitude"), 0.0),
				as<double>(getValue(lookat, "altitude"), 0.0),
                ALTMODE_ABSOLUTE );

            vp.heading() =  as<double>(getValue(lookat, "heading"), 0.0);
            vp.pitch()   = -as<double>(getValue(lookat, "tilt"), 45.0),
            vp.range()   =  as<double>(getValue(lookat, "range"), 10000.0);

            anno->setViewpoint( vp );
        }

        xml_node<>* extdata = node->first_node("extendeddata", 0, false);
        if ( extdata )
        {
            xml_node<>* data = extdata->first_node("data", 0, false);
            if ( data )
            {
			    for (xml_node<>* n = data->first_node(); n; n = n->next_sibling())
			    {
    				working->setUserValue(getValue(n, "name"), getValue(n, "value"));
			    }
            }
        }
    }
}
Example #10
0
void RGLView::polarUpdate(int mouseX, int mouseY)
{
    Viewpoint* viewpoint = scene->getViewpoint();

    dragCurrent = screenToPolar(width,height,mouseX,height-mouseY);

    PolarCoord newpos = camBase - ( dragCurrent - dragBase );

    newpos.phi = clamp( newpos.phi, -90.0f, 90.0f );

    viewpoint->setPosition( newpos );
    View::update();
}
Example #11
0
void RGLView::adjustZoomUpdate(int mouseX, int mouseY)
{
    Viewpoint* viewpoint = scene->getViewpoint();

    int dy = mouseY - zoomBaseY;

    float zoom = clamp ( viewpoint->getZoom() * exp(-dy*ZOOM_PIXELLOGSTEP), ZOOM_MIN, ZOOM_MAX);
    viewpoint->setZoom(zoom);

    View::update();

    zoomBaseY = mouseY;
}
Example #12
0
void RGLView::adjustFOVUpdate(int mouseX, int mouseY)
{
    Viewpoint* viewpoint = scene->getViewpoint();

    int dy = mouseY - fovBaseY;

    float py = ((float)dy/(float)height) * 180.0f;

    viewpoint->setFOV( viewpoint->getFOV() + py );

    View::update();

    fovBaseY = mouseY;
}
Example #13
0
void ViewpointProvider::flyTo()
{
	if ( m_refManipulator == NULL )
	{
		return;
	}

	Viewpoint currentVP = m_refManipulator->getViewpoint();
	osgEarth::GeoPoint vp0( currentVP.getSRS(), currentVP.getFocalPoint(), osgEarth::ALTMODE_ABSOLUTE );
	osgEarth::GeoPoint vp1( this->getSRS(), this->getFocalPoint(), osgEarth::ALTMODE_ABSOLUTE );
	double distance = vp0.distanceTo( vp1 );
	double duration = osg::clampBetween( distance / VP_METERS_PER_SECOND, VP_MIN_DURATION, VP_MAX_DURATION );
	m_refManipulator->setViewpoint( *this, duration );
}
Example #14
0
File: api.cpp Project: jefferis/rgl
void rgl_getFOV(int* successptr, double* fov)
{
  int success = RGL_FAIL;
  Device* device = deviceManager->getAnyDevice();

  if ( device ) {
    RGLView* rglview = device->getRGLView();
    Scene* scene = rglview->getScene();
    Viewpoint* viewpoint = scene->getViewpoint();
    *fov = viewpoint->getFOV();
    success = RGL_SUCCESS;
  }
  *successptr = success;
}
Example #15
0
File: api.cpp Project: jefferis/rgl
void rgl_getZoom(int* successptr, double* zoom)
{
  int success = RGL_FAIL;
  Device* device;

  if (deviceManager && (device = deviceManager->getAnyDevice())) {

    RGLView* rglview = device->getRGLView();
    Scene* scene = rglview->getScene();
    Viewpoint* viewpoint = scene->getViewpoint();
    *zoom = viewpoint->getZoom();
    success = RGL_SUCCESS;
  }
  *successptr = success;
}
Example #16
0
File: api.cpp Project: jefferis/rgl
void rgl_setZoom(int* successptr, double* zoom)
{
  int success = RGL_FAIL;
  Device* device = deviceManager->getAnyDevice();

  if ( device ) {
    RGLView* rglview = device->getRGLView();
    Scene* scene = rglview->getScene();
    Viewpoint* viewpoint = scene->getViewpoint();
    viewpoint->setZoom((*zoom - 1.0f)/((float)(VIEWPOINT_MAX_ZOOM-1)));
    rglview->update();
    success = RGL_SUCCESS;
  }
  *successptr = success;
}
Example #17
0
void Mesh::Render(const Viewpoint &viewpoint) {
  static float m[16];
  glPushMatrix();
  viewpoint.FillTransformationMatrix(m);
  glMultMatrixf(m);
  Render();
  glPopMatrix();
}
Example #18
0
File: api.cpp Project: jefferis/rgl
void rgl_setFOV(int* successptr, double* fov)
{
  int success = RGL_FAIL;
  Device* device;

  if (deviceManager && (device = deviceManager->getAnyDevice())) {

    RGLView* rglview = device->getRGLView();
    Scene* scene = rglview->getScene();
    Viewpoint* viewpoint = scene->getViewpoint();
    viewpoint->setFOV(*fov);
    rglview->update();
    success = RGL_SUCCESS;
  }
  CHECKGLERROR;
  *successptr = success;
}
/*!
  \brief Zooms the current \l Esri::ArcGISRuntime::GeoView to the current input position.
 */
void CoordinateConversionController::zoomTo()
{
  if (m_sceneView)
  {
    const Camera currentCam = m_sceneView->currentViewpointCamera();
    constexpr double targetDistance = 1500.0;
    const Camera newCam(m_pointToConvert, targetDistance, currentCam.heading(), currentCam.pitch(), currentCam.roll());

    m_sceneView->setViewpointCamera(newCam, 1.0);
  }
  else if (m_mapView)
  {
    const Viewpoint currVP = m_mapView->currentViewpoint(ViewpointType::CenterAndScale);
    const Viewpoint newViewPoint(m_pointToConvert, currVP.targetScale());

    m_mapView->setViewpoint(newViewPoint, 1.0);
  }
}
Example #20
0
void Light::applyOnlyRotation(int projection_nb)
{
	if(m_type == OMNI)
		return;
	if(m_type == SUN)
	{
#ifdef MERGEFORSUN
		return;
#endif
		Viewpoint* targetVp = RENDER_MANAGER.getRenderPassInfo()->lod_viewpoint;
		targetVp->applyOnlyRotation(projection_nb);
		return;
	}

	Transformf trans(node()->getGlobalTransform());
	Matrix3d rotation = trans.getRotation();
	Transformf transform(rotation.getInverse(),Vector3f(),Vector3f(1,1,1));
	transform.glMultd();
}
Example #21
0
void Light::computePSSM(Matrix4d& mat, int split_nb) const
{
	// Get viewprojection matrix
	Viewpoint* targetVp = RENDER_MANAGER.getRenderPassInfo()->lod_viewpoint;
#ifdef MERGEFORSUN
	Matrix4d VpMat = targetVp->getViewProjection(1,0);
	debug("MATRIX_STACK", "compute PSSM" << QMatrix4x4(VpMat.values));
#else
	Matrix4d VpMat = targetVp->getProjection(1,0);
#endif
	// Compute subfrustum
	mat = VpMat;
	// Compute matrix targetting subfrustum

	/*
	const float w = 0.001;
	const float h = 0.001;
	const float d = 0.0026;

	mat[0] = 0;
	mat[1] = 0;
	mat[2] = -d;
	mat[3] = 0;

	mat[4] = 0;
	mat[5] = h;
	mat[6] = 0;
	mat[7] = 0;

	mat[8] = w;
	mat[9] = 0;
	mat[10] = 0;
	mat[11] = 0;

	mat[12] = 0;
	mat[13] = 0;
	mat[14] = -1;
	mat[15] = 1;
	*/
}
Example #22
0
	virtual void onDraw(Graphics& g, const Viewpoint& v){		
		Frustumd fr;
		v.lens().frustum(fr, v.worldTransform(), v.viewport().aspect());

//		printf("ntl: %g %g %g\n", fr.ntl[0], fr.ntl[1], fr.ntl[2]);
//		printf("ftl: %g %g %g\n", fr.ftl[0], fr.ftl[1], fr.ftl[2]);

		Mesh& m = g.mesh();
		
		m.reset();
		m.primitive(g.LINES);
		m.vertex(-1,-1, -11);
		m.vertex( 1, 1, -12);

		for(int i=0; i<m.vertices().size(); ++i){
			int r = fr.testPoint(m.vertices()[i]);
			
			m.color(HSV(r ? 0.3 : 0));
		}

		g.lineWidth(10);
		g.antialiasing(g.NICEST);
		g.draw();

		{
//			int r = fr.testPoint(Vec3d(0,0,15));
//			printf("%d\n", r);
		}

		// draw rectangle across frustum diagonal
		m.reset();
		m.color(Color(0.5));
		m.vertex(fr.nbl);
		m.vertex(fr.fbr);
		m.vertex(fr.ntr);
		m.vertex(fr.ftl);
		m.primitive(g.LINE_LOOP);
		g.draw();
	}
Example #23
0
void Light::applyTransform(int projection_nb)
{
	if(m_type == OMNI)
	{
		Transformf trans(node()->getGlobalTransform());
		float transx = -trans.getPosition().x;
		float transy = -trans.getPosition().y;
		float transz = -trans.getPosition().z;
		glTranslatef(transx, transy, transz);
	}
	else if(m_type == SPOT)
	{
		node()->getGlobalTransform().getInverse().glMultd();
	}
	else if(m_type == SUN)
	{
#ifdef MERGEFORSUN
		return;
#endif
		Viewpoint* targetVp = RENDER_MANAGER.getRenderPassInfo()->lod_viewpoint;
		targetVp->applyTransform(projection_nb);
	}
}
Example #24
0
void RGLView::wheelRotate(int dir)
{
    Viewpoint* viewpoint = scene->getViewpoint();

    float zoom = viewpoint->getZoom();

#define ZOOM_STEP  1.05f
#define ZOOM_PIXELLOGSTEP 0.02f

    switch(dir)
    {
    case GUI_WheelForward:
        zoom *= ZOOM_STEP;
        break;
    case GUI_WheelBackward:
        zoom /= ZOOM_STEP;
        break;
    }

    zoom = clamp( zoom , ZOOM_MIN, ZOOM_MAX);
    viewpoint->setZoom(zoom);

    View::update();
}
Example #25
0
void move_camera(Map& level, Player& player1, Viewpoint& camera)
{
    int camx, camy;
    int llimit, rlimit;
    int tlimit, blimit;
    camx = player1.get_x() - SCRWIDTH / 2;
    camy = player1.get_y() - SCRHEIGHT / 2;    
    
    llimit = SCRWIDTH /2;
    tlimit = SCRHEIGHT / 2;
    llimit = 0;
    tlimit = 0;
    rlimit = level.get_w() * TILEW - SCRWIDTH;
    blimit = level.get_h() * TILEH - SCRHEIGHT;
    if(camx < 0) camx = llimit;
    if(camx > rlimit) camx = rlimit;
    if(camy < 0) camy = tlimit;
    if(camy > blimit) camy = blimit;
    
    camera.put_xy(camx,camy);    
}
	void onDraw(Graphics& g, const Viewpoint& v){

		// Get the viewport dimensions, in pixels, for positioning the text
		float W = v.viewport().w;
		float H = v.viewport().h;

		// Setup our matrices for 2D pixel space
		g.pushMatrix(Graphics::PROJECTION);
		g.loadMatrix(Matrix4f::ortho2D(0, W, 0, H));
		g.pushMatrix(Graphics::MODELVIEW);

		// Before rendering text, we must turn on blending
		g.blendAdd();

		// Render text in the top-left corner
		g.loadIdentity();
		g.translate(8, H - (font1.size() + 8));
		g.currentColor(1,1,0,1);
		font1.render(g, "Top-left text");

		// Render text in the bottom-left corner
		g.loadIdentity();
		g.translate(8, 8);
		g.currentColor(1,0,1,1);
		font3.render(g, "Bottom-left text");

		// Render text centered on the screen
		g.loadIdentity();
		std::string str = "Centered text";
		// Note that dimensions must be integers to avoid blurred text
		g.translate(int(W/2 - font2.width(str)/2), int(H/2 - font2.size()/2));
		g.currentColor(0,1,1,1);
		font2.render(g, str);

		// Turn off blending
		g.blendOff();

		g.popMatrix();
		g.popMatrix(Graphics::PROJECTION);
	}
	void onDraw(Graphics& g, const Viewpoint& vp){

		// Switch to the projection matrix
		g.pushMatrix(Graphics::PROJECTION);

		// Set up 2D orthographic projection coordinates
		// The args to Matrix4::ortho2D are left, right, bottom, top
		float aspect = vp.viewport().aspect(); // width divided by height
		g.loadMatrix(Matrix4f::ortho2D(-aspect,aspect, -1,1));

		// If you want units of pixels, use this instead:
		//g.loadMatrix(Matrix4f::ortho2D(0,vp.viewport().w, vp.viewport().h, 0));

		// Switch to the modelview matrix
		g.pushMatrix(Graphics::MODELVIEW);
		g.loadIdentity();

			g.draw(verts);

		g.popMatrix();

		// Don't forget to restore original projection matrix
		g.popMatrix(Graphics::PROJECTION);
	}
Example #28
0
void RGLView::setPosition(double* src)
{
    Viewpoint* viewpoint = scene->getViewpoint();

    viewpoint->setPosition(src);
}
Example #29
0
void RGLView::getPosition(double* dest)
{
    Viewpoint* viewpoint = scene->getViewpoint();
    viewpoint->getPosition(dest);
}
Example #30
0
void RGLView::getScale(double* dest)
{
    Viewpoint* viewpoint = scene->getViewpoint();

    viewpoint->getScale(dest);
}