Example #1
0
void Camera::updateCachedTransforms()
{
	m_worldToCamera = worldTransform().inverse();
	m_view = viewTransform();
	m_projection = projectionTransform();
	m_viewProjection = viewProjectionTransform();
}
Example #2
0
void MyGLWidget::mouseMoveEvent(QMouseEvent *e)
{
  makeCurrent();
  // Aqui cal que es calculi i s'apliqui la rotacio o el zoom com s'escaigui...
  if (DoingInteractive == ROTATE)
  {
    // Fem la rotació
   //angleY += (e->x() - xClick) * M_PI / 2;

    angleX += (e->y() - yClick) * M_PI / 180.0;
    angleY += (e->x() - xClick) * M_PI / 180.0;

    viewTransform ();

  }

  //NOU_______________________________________
  if (DoingInteractive == ZOOM) {

      zoom += (e->y() - yClick)*0.001;
      projectTransform();

  }
  //NOU_________________________________________

  xClick = e->x();
  yClick = e->y();

  update ();
}
Example #3
0
void MyGLWidget::keyPressEvent (QKeyEvent *e)
{
  switch (e->key())
  {
    case Qt::Key_K:
      posF[0] -= 0.5;
      Llum();
      updateGL();
      break;
    case Qt::Key_L:
      posF[0] += 0.5;
      Llum();
      updateGL();
      break;
    case Qt::Key_R:
        angleY += 0.5;
        viewTransform();
        updateGL();
        break;
    case Qt::Key_Escape:
        exit(0);

    default: e->ignore(); break;
  }
  updateGL();
}
Example #4
0
void MyGLWidget::mouseMoveEvent(QMouseEvent *e){
    if(first){
        oldPos = e->pos();
        first = false;
    }else{
        dx = e->x() - oldPos.x();
        dy = e->y() - oldPos.y();
        if(dx < 0) dx *= -1;
        if(dy < 0) dy *= -1;

        switch(e->buttons()){
            case Qt::RightButton :
                if(dx > dy){
                    if(e->x() > oldPos.x()){
                        ax += 0.02;
                        viewTransform();
                        updateGL();
                    }
                    else {
                        ax -= 0.02;
                        viewTransform();
                        updateGL();
                    }
                }else{
                    if(e->y() > oldPos.y()){//me muevo para arriba
                        ay += 0.02;
                        viewTransform();
                        updateGL();
                     }
                    else{
                        ay -= 0.02;
                        viewTransform();
                        updateGL();
                    }
               }
            default: e->ignore();
            oldPos = e->pos();
        }
    }
}
Example #5
0
void MyGLWidget::mouseMoveEvent(QMouseEvent *e){
  // Aqui cal que es calculi i s'apliqui la rotacio o el zoom com s'escaigui...
  if (DoingInteractive == ROTATE)   {
    // Fem la rotació
    angleY += (e->x() - xClick) * M_PI / 180.0;
    viewTransform ();
  }

  xClick = e->x();
  yClick = e->y();

  updateGL();
}
Example #6
0
void MyGLWidget::initializeGL () {
  // glew és necessari per cridar funcions de les darreres versions d'OpenGL
  glewExperimental = GL_TRUE;
  glewInit(); 
  glGetError();  // Reinicia la variable d'error d'OpenGL

  glClearColor (0.5, 0.7, 1.0, 1.0);  // defineix color de fons (d'esborrat)
  glEnable(GL_DEPTH_TEST);
  carregaShaders();
  createBuffers();
  projectTransform();
  viewTransform();
}
Example #7
0
void MyGLWidget::keyPressEvent (QKeyEvent *e)
{
  switch (e->key())
  {
    case Qt::Key_Escape:
        exit(0);
    case Qt::Key_R:
      gir += M_PI/6.0;
      break;
    case Qt::Key_L:
        posX += 1;
        viewTransform();
        updateGL();
        break;
    case Qt::Key_K:
        posX -= 1;
        viewTransform();
        updateGL();
        break;
    default: e->ignore(); break;
  }
  updateGL();
}
Example #8
0
void MyGLWidget::init_camera(){

    FOV = (float)M_PI/3.0f;
    ra = 1.0f;
    znear = 1.0;
    zfar = radiEsc*2+2;

    //Carreguem la projeccio del model
    projectTransform();

    OBS = glm::vec3(-1, 1,-1);
    VRP = glm::vec3(1, -0.5,0);
    UP = glm::vec3(0.,1.,0.);

    viewTransform();
}
Example #9
0
void ImageView::paint(QPainter &p, const QSizeF& sz, double zoom, const QPointF& origin) {
    if (!imageSize().isEmpty()) {
        QTransform tr = viewTransform(sz, zoom, origin);
        QTransform invTr = tr.inverted();
        QRectF wR = invTr.mapRect(QRectF(QPoint(0,0), sz));
        QRectF R = wR.intersected(QRectF(QPoint(0,0), imageSize()));
        if (!R.isEmpty()) {
            p.save();
            p.setTransform(tr, true);
            if (m_handler) {
                m_handler->draw(this, p, R, image());
            } else {
                draw(p, R, image());
            }
            p.restore();
        }
    }
}
Example #10
0
void MyGLWidget::initializeGL ()
{
  // Cal inicialitzar l'ús de les funcions d'OpenGL
  initializeOpenGLFunctions();  

  glClearColor(0.5, 0.7, 1.0, 1.0); // defineix color de fons (d'esborrat)
  glEnable(GL_DEPTH_TEST);
  carregaShaders();
  createBuffers();

  //FUNCIONS PROPIES______________
  distanciaMaximaEscena();
  init_camera();
  refreshColFocus();
  refreshPosFocus();

  projectTransform ();
  viewTransform ();
}
Example #11
0
void MyGLWidget::initializeGL ()
{
    // glew és necessari per cridar funcions de les darreres versions d'OpenGL
    glewExperimental = GL_TRUE;
    glEnable (GL_DEPTH_TEST);
    glewInit();
    glGetError();  // Reinicia la variable d'error d'OpenGL

    patricio.load("../models/Patricio.obj");
    scale = 1.0f;
    calcCapsaContenidora(patricio,patrMin,patrMax);
    ra=1;


    glClearColor(0.5, 0.7, 1.0, 1.0); // defineix color de fons (d'esborrat)
    carregaShaders();
    createBuffers();
    modelTransform ();
    projectTransform();
    viewTransform();
}
Example #12
0
void MyGLWidget::init_camera(){

    /**CONFIG PROJECCIO **/

    FOV = (float)M_PI/2.0f;
    angle = FOV/2;
    ra = 1.0f;
    znear = 0.4f;
    zfar = 3.0f;
    //Carreguem la projeccio del model
    projectTransform();

    /**CONFIG VIEW**/

    OBS = glm::vec3(0,0,1);
    VRP = glm::vec3(0,0,0);
    UP = glm::vec3(0,1,0);

    //Carreguem la view del model
    viewTransform();
}
Example #13
0
bool RCViewableTransform::screenSpaceFromWorldSpace(const Eks::Vector3D &worldPos, Eks::Vector3D &posOut)
  {
  auto eye = viewTransform() * worldPos;

  if(eye.z() > 0.0f)
    {
    return false;
    }

  Eks::Vector4D eyeH;
  eyeH.head<3>() = eye;
  eyeH(3) = 1.0f;

  Eks::Vector4D projected = projection() * eyeH;
  float w = projected.w();

  float x, y;
  screenViewportCoordinates(projected.x() / w, projected.y() / w, x, y);

  posOut = Eks::Vector3D(x, y, projected.z());
  return true;
  }
Example #14
0
void MyGLWidget::initializeGL ()
{

  FOV = M_PI/2; // NEW 5.1
  FOVIni = M_PI/4; // NEW 5.1

  // glew és necessari per cridar funcions de les darreres versions d'OpenGL
  glewExperimental = GL_TRUE;
  glewInit();
  glGetError();  // Reinicia la variable d'error d'OpenGL

  glEnable(GL_DEPTH_TEST);

  glClearColor(0.5, 0.7, 1.0, 1.0); // defineix color de fons (d'esborrat)
  carregaShaders();
  m.load("../models/Patricio.obj");
  calculaCapsaModel();
  createBuffers();
  //modelTransform ();
  projectTransform();
  viewTransform();
}
Example #15
0
void MyGLWidget::keyPressEvent (QKeyEvent *e)
{
  switch (e->key())
  {
    case Qt::Key_C:
      {
        if(isCameraModified){
            posObs = glm::vec3(0, 0, -2*radiAux);
            vrp = glm::vec3(0 ,0, 0);
            up = glm::vec3(0,1,0);
            zNear = double(radiAux);
            zFar = 3. * double(radiAux);
            angleY = M_PI*7/4.;
            angleX = -M_PI/8.;
            //aqui es podria afegir angleXaux i angleYaux per recuperar la càmera
        } else {
            posObs = glm::vec3(-10 , 4, -10);
            vrp = glm::vec3(-10 ,0, 10);
            up = glm::vec3(0,1,0);
            zNear = 1;
            zFar = sqrt(16 + 4000);
            angleX = 0.;
            angleY = 0.;
        }
        isCameraModified = !isCameraModified;
        projectTransform();
        viewTransform();
        break;
      }

    case Qt::Key_L:
      {
        if (isFocusRed){
            colFocus = glm::vec3(0.8, 0.8, 0.8);
        } else {
            colFocus = glm::vec3(0.8, 0., 0.);
        }
        isFocusRed = !isFocusRed;
        break;
      }

    //camera axonomètrica vista en planta
    case Qt::Key_A:
    {
        isOrthoPlantCamera = !isOrthoPlantCamera;
        projectTransform();
        viewTransform();
        break;
    }

    case Qt::Key_R:
    {
        angleModelsRotation += M_PI/8.0;
        break;
    }

    case Qt::Key_Escape:
        exit(0);
    default: e->ignore(); break;
  }
  updateGL();
}