Exemplo n.º 1
0
void MotionSystem::noiseShiftWithOdo(Particle* particle, float dX, float dY, float dH) {
    // How x,y,h factors when deciding ranges
    float xF = 5.f;
    float yF = 5.f;
    float hF = 5.f;

    float xL, xU, yL, yU, hL, hU;

    if ((std::fabs(dX * xF) - .2f) < 0.001f) {
        xL = -.2f;
        xU =  .2f;
    }
    else if (dX >0) {
        xL = -1.f * dX * xF;
        xU = dX * xF;
    }
    else {//dX <0
        xL = dX * xF;
        xU = -1.f * dX * xF;
    }

    if ((std::fabs(dY * yF) - .2f) < 0.001f) {
        yL = -.2f;
        yU =  .2f;
    }
    else if (dY >0) {
        yL = -1.f * dY * yF;
        yU = dY * yF;
    }
    else { //dY <0
        yL = dY * yF;
        yU = -1.f * dY * yF;
    }

    if ((std::fabs(dH * hF) - .025f) < 0.001f) {
        hL = -.025f;
        hU =  .025f;
    }
    else if (dH >0) {
        hL = -1.f * dH * hF;
        hU = dH * hF;
    }
    else { //dH <0
        hL = dH * hF;
        hU = -1.f * dH * hF;
    }

    boost::uniform_real<float> xRange(xL, xU);
    boost::uniform_real<float> yRange(yL, yU);
    boost::uniform_real<float> hRange(hL, hU);

    boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > xShift(rng, xRange);
    boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > yShift(rng, yRange);
    boost::variate_generator<boost::mt19937&, boost::uniform_real<float> > hShift(rng, hRange);

    particle->shift(xShift(), yShift(), hShift());
}
Exemplo n.º 2
0
    void ViewingArea::update_projection_matrices()
    {
      // if the inset is asymmetric, shift the viewing volume accordingly
      GLfloat xShift((insetCenter_[X_INDEX]-centerAndRelative_[X_INDEX])/centerAndRelative_[X_INDEX]);
      GLfloat yShift((insetCenter_[Y_INDEX]-centerAndRelative_[Y_INDEX])/centerAndRelative_[Y_INDEX]);
	  
      // if the inset is smaller than the window, rescale the viewing volume accordingly;
      GLfloat xScale((insetRelative_[X_INDEX]/centerAndRelative_[X_INDEX]));
      GLfloat yScale((insetRelative_[Y_INDEX]/centerAndRelative_[Y_INDEX]));
      
      // correct for the aspect ratio of the inset; 
      GLfloat r(insetRelative_[X_INDEX]/insetRelative_[Y_INDEX]);
      if(r>1)
	xScale/=r;
      else
	yScale*=r;

      // check if we have orthogonal projection
      if(!(angle_>0))
	{
	  projectionMatrix_[X_INDEX+N_ROWS*X_INDEX]=xScale;inverseProjectionMatrix_[X_INDEX+N_ROWS*X_INDEX]=1/xScale;
	  projectionMatrix_[Y_INDEX+N_ROWS*Y_INDEX]=yScale;inverseProjectionMatrix_[Y_INDEX+N_ROWS*Y_INDEX]=1/yScale;
	  projectionMatrix_[Z_INDEX+N_ROWS*Z_INDEX]=-zScaleOrtho_;inverseProjectionMatrix_[Z_INDEX+N_ROWS*Z_INDEX]=-1/zScaleOrtho_;
	  
	  projectionMatrix_[X_INDEX+N_ROWS*N_SPATIAL_DIMENSIONS]=xShift;inverseProjectionMatrix_[X_INDEX+N_ROWS*N_SPATIAL_DIMENSIONS]=-xShift/xScale;
	  projectionMatrix_[Y_INDEX+N_ROWS*N_SPATIAL_DIMENSIONS]=yShift;inverseProjectionMatrix_[Y_INDEX+N_ROWS*N_SPATIAL_DIMENSIONS]=-yShift/yScale;
	}
      else // perspective projection
	{
	  /* The original (-1,-1,-1) - (1,1,1) viewing volume must be rescaled to fit into
	     the window depending on its distance from the camera. 
	  */
	  xScale*=(zShift_+zCamera_);
	  yScale*=(zShift_+zCamera_);

	  // set near and far clipping planes (magic numbers right now -> find better way)
	  GLfloat n(zShift_/10);
	  GLfloat f(zShift_*10);

	  /* put together the perspective projection everything together in this order:
	     scale x, y and z in camera space,
	     shift z in camera space,
	     apply perspective transformation (as in gluPerspective, aspect ratio is
	     already built into xScale and yScale)
	     shift x and y in screen space (shifting in camera space would decenter the frustum)
	     the projection matrix below is the product of all these transformations
	  */
	  
	  /* note that zShift_ is positive, with larger values equivalent to a larger distance 
	     from the viewer. In camera space, however, negative values are further away from 
	     the viewer. zShift_ enters the projection matrix below such that a large positive
	     value of zShift_ will create a large negative shift in the z coordinate of the input
	     vector.
	  */
	  
	  a_=(-(f+n)/(f-n));
	  b_=(-2.0f*(f*n)/(f-n));
	  
	  // first column
	  projectionMatrix_[X_INDEX+N_ROWS*X_INDEX]=xScale;inverseProjectionMatrix_[X_INDEX+N_ROWS*X_INDEX]=1/xScale;

	  // second column
	  projectionMatrix_[Y_INDEX+N_ROWS*Y_INDEX]=yScale;inverseProjectionMatrix_[Y_INDEX+N_ROWS*Y_INDEX]=1/yScale;
	  
	  // third column
	  projectionMatrix_[N_ROWS*Z_INDEX+X_INDEX]=-xShift;
	  projectionMatrix_[N_ROWS*Z_INDEX+Y_INDEX]=-yShift;
	  projectionMatrix_[N_ROWS*Z_INDEX+Z_INDEX]=a_;inverseProjectionMatrix_[N_ROWS*Z_INDEX+Z_INDEX]=zShift_/b_;
	  projectionMatrix_[N_ROWS*Z_INDEX+N_SPATIAL_DIMENSIONS]=-1;inverseProjectionMatrix_[N_ROWS*Z_INDEX+N_SPATIAL_DIMENSIONS]=1/b_;
	  
	  // fourth column
	  projectionMatrix_[N_ROWS*N_SPATIAL_DIMENSIONS+X_INDEX]=zShift_*xShift;inverseProjectionMatrix_[N_ROWS*N_SPATIAL_DIMENSIONS+X_INDEX]=-xShift/xScale;
	  projectionMatrix_[N_ROWS*N_SPATIAL_DIMENSIONS+Y_INDEX]=zShift_*yShift;inverseProjectionMatrix_[N_ROWS*N_SPATIAL_DIMENSIONS+Y_INDEX]=-yShift/yScale;
	  projectionMatrix_[N_ROWS*N_SPATIAL_DIMENSIONS+Z_INDEX]=-a_*zShift_+b_;inverseProjectionMatrix_[N_ROWS*N_SPATIAL_DIMENSIONS+Z_INDEX]=a_*zShift_/b_-1;
	  projectionMatrix_[N_ROWS*N_SPATIAL_DIMENSIONS+N_SPATIAL_DIMENSIONS]=zShift_;inverseProjectionMatrix_[N_ROWS*N_SPATIAL_DIMENSIONS+N_SPATIAL_DIMENSIONS]=a_/b_;
	
	}

      glContext_->update_global_uniform_4x4(GLContext::PROJECTION_MATRIX,projectionMatrix_);
      glContext_->update_global_uniform_4x4(GLContext::INVERSE_PROJECTION_MATRIX,inverseProjectionMatrix_);

      glContext_->request_redraw();
    }