示例#1
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 ();
}
示例#2
0
void MyGLWidget::keyPressEvent(QKeyEvent* event) 
{
  makeCurrent();
  switch (event->key()) {
    case Qt::Key_O: { // canvia òptica entre perspectiva i axonomètrica
      perspectiva = !perspectiva;
      projectTransform ();
      break;
    }
    case Qt::Key_R: {
        rotate += (float)M_PI/6.0;
        break;
    }
  case Qt::Key_X: {
      franges_bool = !franges_bool;

        int ff = 0;
        if(franges_bool) ff = 1;
        glUniform1i (franges,ff);
      break;
  }
    default: event->ignore(); break;
  }
  update();
}
示例#3
0
void MyGLWidget:: wheelEvent(QWheelEvent *e)
{
    int numDegrees = e->delta() / 8;
    int numSteps = numDegrees / 15;

    if (e->orientation() == Qt::Vertical) {
        fov += 0.08 * numSteps;
        projectTransform();
    }
    updateGL();
}
示例#4
0
文件: MyGLWidget.cpp 项目: ealch/IDI
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();
}
示例#5
0
文件: MyGLWidget.cpp 项目: ealch/IDI
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 ();
  } else if (DoingInteractive == ZOOM ) {
    zoom += (e->y() - yClick) * 0.005;
    projectTransform(); 
  }

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

  updateGL();
}
示例#6
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();
}
示例#7
0
void MyGLWidget::resizeGL (int w, int h)
{
    ra = (double)w/(double)h;

    if(w>h) {
        FOV = 2*(M_PI/6.0);
    }
    else if(h>w){
        FOV=2*atan(tan(M_PI/6.0)/ra);
        if(FOV <= 0) FOV = 0.001745329252;
        if(FOV > M_PI) FOV = M_PI;
    }
    projectTransform();


  glViewport (0, 0, w, h);
}
示例#8
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 ();
}
示例#9
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();
}
示例#10
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();
}
示例#11
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();
}
示例#12
0
// Calculate cameraHomography -- go from current position to camera position
CvMat* modelViewMatrix(int baseIndex, struct pData* poses)
{
  // Initial Homography
  CvMat* initHomography = create3DIdentity();

  // Find Forward and Up Vector
  CvScalar forward = cvScalarAll(0);
  createForwardVector(&forward, myScene->pose, poses[baseIndex]);
  CvScalar up = poses[baseIndex].up;
  //printf("forward vector: [%.2lf %.2lf %.2lf]\n", forward.val[0], forward.val[1], forward.val[2]);
  //printf("up vector: [%.2lf %.2lf %.2lf]\n", up.val[0], up.val[1], up.val[2]);

  // the z-axis
  double forwardAngle = atan2(forward.val[1], forward.val[0]);
  if (forwardAngle < 0)
    forwardAngle += PI;
  //printf("forwardAngle: %.2lf\n", forwardAngle * 180 / PI);

  // the y-axis
  double upAngleY = atan2(up.val[0], up.val[2]);
  //  if (upAngleY < 0)
  //  upAngleY += PI;
  //printf("upAngleY: %.2lf\n", upAngleY * 180 / PI);

  // the x-axis
  double upAngleX = atan2(up.val[1], up.val[2]);
  //if (upAngleX < 0)
  //  upAngleX += PI;
  //printf("upAngleX: %.2lf\n", upAngleX * 180 / PI);

  CvMat* rotateXHomography = cvCreateMat(3, 3, CV_64F);
  makeXAxisRotation(rotateXHomography, upAngleX);

  //printf("X: \n");
  //printMatrix(rotateXHomography);

  CvMat* rotateYHomography = cvCreateMat(3, 3, CV_64F);
  makeYAxisRotation(rotateYHomography, upAngleY);

  //printf("Y: \n");
  //printMatrix(rotateYHomography);

  CvMat* rotateZHomography = cvCreateMat(3, 3, CV_64F);
  makeZAxisRotation(rotateZHomography, forwardAngle);
  

  //printf("Z: \n");
  //printMatrix(rotateZHomography);

  // Apply all transformations
  cvMatMulAdd(rotateXHomography, initHomography, 0, initHomography);
  //cvMatMulAdd(rotateYHomography, initHomography, 0, initHomography);  
  //cvMatMulAdd(rotateZHomography, initHomography, 0, initHomography);
  projectTransform(initHomography);

  //printf("final: \n");
  //printMatrix(initHomography);

  cvReleaseMat(&rotateXHomography);
  cvReleaseMat(&rotateYHomography);
  cvReleaseMat(&rotateZHomography);

  return initHomography;

}
示例#13
0
void MyGLWidget::resizeGL (int w, int h)
{
  glViewport(0, 0, w, h);
  projectTransform();
}
示例#14
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();
}