Beispiel #1
0
void MyOSGQGLWidget::mouseMoveEvent ( QMouseEvent *me )
{               
    Real32 w = _osgWin->getWidth();     // force the calc to Real32
    Real32 h = _osgWin->getHeight();
    
    Real32 a = -2. * ( _lastx / w - .5 );
    Real32 b = -2. * ( .5 - _lasty / h );
    Real32 c = -2. * ( me->pos().x() / w - .5 );
    Real32 d = -2. * ( .5 - me->pos().y() / h );
                    
    if ( _mouseb & LeftButton )
    {
        tball.updateRotation( a, b, c, d );
    }
    else if ( _mouseb & MidButton )
    {
        tball.updatePosition( a, b, c, d );
    }
    else if ( _mouseb & RightButton )
    {
        tball.updatePositionNeg( a, b, c, d );
    }
    _lastx = me->pos().x();
    _lasty = me->pos().y();
    
    doCamTrans();
    paintGL();
}
Beispiel #2
0
void keyboardEvent(unsigned char key, int x, int y) {
  switch (key) {
    case 'x':
    case 27 : {
      exit(0);
      break;
    }
    case 'w': {
      // move forward //
      trackball.updateOffset(Trackball::MOVE_FORWARD);
      break;
    }
    case 's': {
      // move backward //
      trackball.updateOffset(Trackball::MOVE_BACKWARD);
      break;
    }
    case 'a': {
      // move left //
      trackball.updateOffset(Trackball::MOVE_LEFT);
      break;
    }
    case 'd': {
      // move right //
      trackball.updateOffset(Trackball::MOVE_RIGHT);
      break;
    }
    default : {
      break;
    }
  }
  glutPostRedisplay();
}
Beispiel #3
0
void
display(void)
{
    Matrix m1, m2, m3;
    Quaternion q1;

    tball.getRotation().getValue(m3);

    q1.setValue(m3);

    m1.setRotate(q1);

//    std::cout << "TBROT" << std::endl << tball.getRotation() << std::endl;
//    std::cout << "M3" << std::endl << m3 << std::endl;
//    std::cout << "Q1" << std::endl << q1 << std::endl;
//    std::cout << "M1" << std::endl << m1 << std::endl;

//  m1.setRotate( tball.getRotation() );
    m2.setTranslate( tball.getPosition() );

//std::cout << "Pos: " << tball.getPosition() << ", Rot: " << tball.getRotation() << std::endl;

//    std::cout << tball.getRotation() << std::endl;

    m1.mult( m2 );
    cam_trans->editSFMatrix()->setValue( m1 );

    win->draw( ract );
}
void 
display(void)
{
	Matrix m1, m2;

	m1.setRotate( tball.getRotation() );
	m2.setTranslate( tball.getPosition() );
	
	m1.mult( m2 );
	cam_trans->editSFMatrix()->setValue( m1 );


    // move the object
    
    float t = glutGet(GLUT_ELAPSED_TIME);
    Quaternion q;
    
    q.setValueAsAxisDeg(0, 1, 0, t / 5000);
    
    m1.setTransform(Vec3f(osgsin(t / 500.), 0, osgcos(t / 500)), q);
                    
    tr->setMatrix(m1);
    
	if ( doRender )
		win->render( ract );
	else
		win->draw( dact );
}
Beispiel #5
0
void
mouse(int button, int state, int x, int y)
{
    if ( state == 0 )
    {
        switch ( button )
        {
        case GLUT_LEFT_BUTTON:  break;
        case GLUT_MIDDLE_BUTTON:tball.setAutoPosition(true);
                                break;
        case GLUT_RIGHT_BUTTON: tball.setAutoPositionNeg(true);
                                break;
        }
        mouseb |= 1 << button;
    }
    else if ( state == 1 )
    {
        switch ( button )
        {
        case GLUT_LEFT_BUTTON:  break;
        case GLUT_MIDDLE_BUTTON:tball.setAutoPosition(false);
                                break;
        case GLUT_RIGHT_BUTTON: tball.setAutoPositionNeg(false);
                                break;
        }
        mouseb &= ~(1 << button);
    }
    lastx = x;
    lasty = y;
}
Beispiel #6
0
void
motion(int x, int y)
{
    Real32 w = win->getWidth(), h = win->getHeight();


    Real32  a = -2. * ( lastx / w - .5 ),
            b = -2. * ( .5 - lasty / h ),
            c = -2. * ( x / w - .5 ),
            d = -2. * ( .5 - y / h );

    if ( mouseb & ( 1 << GLUT_LEFT_BUTTON ) )
    {
        tball.updateRotation( a, b, c, d );
    }
    else if ( mouseb & ( 1 << GLUT_MIDDLE_BUTTON ) )
    {
        tball.updatePosition( a, b, c, d );
    }
    else if ( mouseb & ( 1 << GLUT_RIGHT_BUTTON ) )
    {
        tball.updatePositionNeg( a, b, c, d );
    }
    lastx = x;
    lasty = y;
}
Beispiel #7
0
/** This method is automatically called by GLFW everytime the mouse moves */
static void cursorPos_callback(GLFWwindow* window, double x, double y)
{
    if(mButton == GLFW_MOUSE_BUTTON_LEFT) 
    {
        mCamera.dragRotate(Vector2f(x,y));
    }
    else if(mButton == GLFW_MOUSE_BUTTON_MIDDLE) 
    {
        mCamera.dragTranslate(Vector2f(x,y));
    }
    mLastMousePos = Vector2f(x,y);
}
Beispiel #8
0
void doCamTrans ( void )
{
    Matrix m1, m2, m3;
    Quaternion q1;

    tball.getRotation().getValue(m3);
    q1.setValue(m3);
    m1.setRotate(q1);
    m2.setTranslate( tball.getPosition() );
    m1.mult( m2 );
    cam_trans->getSFMatrix()->setValue( m1 );
}
void display(void)
{
  Matrix m1, m2, m3;
  Quaternion q1;
  
  tball.getRotation().getValue(m3);
  q1.setValue(m3);
  m1.setRotate(q1);
  m2.setTranslate( tball.getPosition() );
  m1.mult( m2 );
  cam_trans->editSFMatrix()->setValue( m1 );
  window->draw( drAct );
}
Beispiel #10
0
void display(void)
{
    Matrix  m1, m2;

    m1.setRotate(tball.getRotation());
    m2.setTranslate(tball.getPosition());

    m1.mult(m2);
    cam_trans->editSFMatrix()->setValue(m1);

    if(doRender)
        win->render(ract);
    else
        win->draw(dact);
}
Beispiel #11
0
void 
mouse ( int button, int state, int x, int y )
{
  if ( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
    trackball.startMouse ( x, y );
  }
}
Beispiel #12
0
void display()
{
  static GLdouble m[4][4];
  
  if ( white_background )
    glClearColor(1.0, 1.0, 1.0, 1.0);
  else
    glClearColor(0.0, 0.0, 0.0, 1.0);
  
  glClear(GL_COLOR_BUFFER_BIT);
  
  tb.writeOpenGLTransfMatrix(m);
  
  glPushMatrix();
    glMultMatrixd( &m[0][0] );
    
    // Draw display lists
    if ( white_background )
      glColor3f(0.0, 0.0, 0.0);
    else
      glColor3f(1.0, 1.0, 1.0);
    
    if ( show_ball )
      glutWireSphere(1.0, 10, 10);
    
    if ( show_axes )
      glCallList(axes_list);
  glPopMatrix();
  
  glutSwapBuffers();
  glFlush();
}
Beispiel #13
0
void MyOSGQGLWidget::mouseReleaseEvent ( QMouseEvent *me )
{
    switch ( me->button() )
    {
        case MidButton:
            tball.setAutoPosition(false);
            break;
        case RightButton:
            tball.setAutoPositionNeg(false);
            break;
        default:
            break;
    }
    _mouseb &= me->button();
    _lastx = me->x();
    _lasty = me->y();   
}
Beispiel #14
0
/** This method is automatically called by GLFW everytime the OpenGL windows is resized.
      * \param width the new width of the windows (in pixels)
      * \param height the new height of the windows (in pixels)
      */
static void reshape_callback(GLFWwindow* window, int width, int height)
{
    // configure the rendering target size (viewport)
    WIDTH = width;
    HEIGHT = height;
    glViewport(0, 0, width, height);
    mCamera.setScreenViewport(AlignedBox2f(Vector2f(0.0,0.0), Vector2f(width,height)));
    render(window);
}
Beispiel #15
0
void 
display(void)
{
    Matrix m1, m2, m3;
    Quaternion q1;

#ifdef PAR_SCHEDULER
    if(pVSCThread == NULL)
    {
        pVSCThread = ExternalThread::find("VSCScheduler");
    }

    VSC::VSCScheduler::the()->enterSyncBarrier(2);

    pVSCThread->getChangeList()->applyToCurrent();
    pVSCThread->getChangeList()->clearAll();

//    VSC::vsc_sleep(100);

    VSC::VSCScheduler::the()->enterSyncBarrier(2);
#endif

//    tball.getRotation().getValue(m3);

//    q1.setValue(m3);

//    m1.setRotate(q1);
    
//    cout << "TBROT" << endl << tball.getRotation() << endl;
//    cout << "M3" << endl << m3 << endl;
//    cout << "Q1" << endl << q1 << endl;
//    cout << "M1" << endl << m1 << endl;

//  m1.setRotate( tball.getRotation() );
//    m2.setTranslate( tball.getPosition() );
    
//cout << "Pos: " << tball.getPosition() << ", Rot: " << tball.getRotation() << endl;

//    cout << tball.getRotation() << endl;

//    m1.mult( m2 );

    cam_trans->getSFMatrix()->setValue(tball.getFullTrackballMatrix());

/*
    fprintf(stderr, "%d %d %d %d | %d | %d\r",
            glutGet(GLUT_WINDOW_RED_SIZE),
            glutGet(GLUT_WINDOW_GREEN_SIZE),
            glutGet(GLUT_WINDOW_BLUE_SIZE),
            glutGet(GLUT_WINDOW_ALPHA_SIZE),
            glutGet(GLUT_WINDOW_DEPTH_SIZE),
            glutGet(GLUT_WINDOW_STENCIL_SIZE));
*/

    win->draw( ract );
}
Beispiel #16
0
/** This method needs to be called once the GL context has been created by GLFW.
  * It is called only once per execution */
void initGL()
{ 
    // set the background color, i.e., the color used
    // to fill the screen when calling glClear(GL_COLOR_BUFFER_BIT)
    glClearColor(0.3f,0.3f,0.3f,0.);

    glEnable(GL_DEPTH_TEST);

    // load the default shaders 
    mBlinn.loadFromFiles(PGHP_DIR"/shaders/blinn.vert", PGHP_DIR"/shaders/blinn.frag");
    mSimple.loadFromFiles(PGHP_DIR"/shaders/simple.vert", PGHP_DIR"/shaders/simple.frag");
    mHole.loadFromFiles(PGHP_DIR"/shaders/hole.vert", PGHP_DIR"/shaders/hole.frag");
    mMesh.loadFromFiles(PGHP_DIR"/shaders/mesh.vert", PGHP_DIR"/shaders/mesh.frag");

    //PointCloud
    pc = new PointCloud();
    pc->load(PGHP_DIR"/data/decimate.asc");
    pc->makeUnitary();
    pc->init(&mBlinn);

    //Mesh
    mesh = new Mesh();
    //mesh->load(PGHP_DIR"/data/PhantomUgly.obj");
    //mesh->load(PGHP_DIR"/data/PhantomLite.obj");
    //mesh->load(PGHP_DIR"/data/bunny.obj");
    mesh->load(PGHP_DIR"/data/sphere.obj");
    //mesh->load(PGHP_DIR"/data/sphere2.obj");
    mesh->makeUnitary();
    mesh->init(&mBlinn);

    //Octree
    octree = new Octree(pc,15,10);
    wirecube = new WireCube();
    wirecube->init(&mSimple);

    mCamera.setSceneCenter(Vector3f(0.0,0.0,0.0));
    mCamera.setSceneDistance(4);
    mCamera.setMinNear(0.1f);
    mCamera.setNearFarOffsets(-200.f,200.0f);
    mCamera.setScreenViewport(AlignedBox2f(Vector2f(0.0,0.0), Vector2f(WIDTH,HEIGHT)));

    GL_TEST_ERR;
}
Beispiel #17
0
void mouse(int button, int state, int x, int y)
{
        long s=0x00000000;
    s |= (button == GLUT_LEFT_BUTTON)   ? ((state == GLUT_DOWN) ? Trackball::LBUTTON_DOWN : Trackball::LBUTTON_UP) : 0;
    s |= (button == GLUT_MIDDLE_BUTTON) ? ((state == GLUT_DOWN) ? Trackball::MBUTTON_DOWN : Trackball::MBUTTON_UP) : 0;
    s |= (button == GLUT_RIGHT_BUTTON)  ? ((state == GLUT_DOWN) ? Trackball::RBUTTON_DOWN : Trackball::RBUTTON_UP) : 0;

    int key_state = glutGetModifiers();
    s |= (key_state & GLUT_ACTIVE_CTRL)  ? Trackball::CTRL_DOWN  : 0;
    s |= (key_state & GLUT_ACTIVE_ALT)   ? Trackball::ALT_DOWN   : 0;
    s |= (key_state & GLUT_ACTIVE_SHIFT) ? Trackball::SHIFT_DOWN : 0;

        if (s & Trackball::BUTTON_DOWN){
        trackball.mouseDown(s, x, y);
        }

        if (s & Trackball::BUTTON_UP){
        trackball.mouseUp(s, x, y);
        }
}
Beispiel #18
0
void init(char *infname)
{
// CMSC: init your geometry if any

  svVector3 center = svVector3(0, 0, 0);
  center.getValue(view_info.coi);

  // CMSC: please replace the numbers with the real geometry boundary 
  GLfloat x,y,z;
  myVectorField = new svVectorField(infname);
  myVectorField->Generate();
  myVectorField->GetPhysicalDimension(&x,&y, &z);

  view_info.eye[0] = x/2.0;
  view_info.eye[1] = y/2.0;
  view_info.eye[2] = z*2.0;

  trackball.setEye(view_info.eye);
  trackball.setFocus(center);
  trackball.setWindowSize(IMAGE_WIDTH, IMAGE_HEIGHT);
}
Beispiel #19
0
/* Trackball Handler */
void trackball_handler(int event,int xx,int yy) {
    float matrix[4][4];
    if ( event == FL_PUSH ) {
        x_ang = xx ;
        y_ang = yy ;
        trackball.rotate( 0,0,0,0 ) ;
    }
    else if (( event == FL_DRAG ) ) {
        trackball.rotate((2.0 * x_ang - screen_width) / float(screen_width),
                         (screen_height - 2.0 * y_ang) / float(screen_height),
                         (2.0 * xx - screen_width) / float(screen_width),
                         (screen_height - 2.0 * yy) / float(screen_height));
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        trackball.rotationMatrix(matrix);
        glMultMatrixf((float *)matrix);
        x_ang = xx ;
        y_ang = yy ;
        glutPostRedisplay() ;
    }
}
Beispiel #20
0
/** This method needs to be called once the GL context has been created by GLFW.
  * It is called only once per execution */
void initGL()
{ 
    // set the background color, i.e., the color used
    // to fill the screen when calling glClear(GL_COLOR_BUFFER_BIT)
    glClearColor(0.3f,0.3f,0.3f,0.);

    glEnable(GL_DEPTH_TEST);

    // load the default shaders 
    mBlinn.loadFromFiles(PGHP_DIR"/shaders/blinn.vert", PGHP_DIR"/shaders/blinn.frag");
    mSimple.loadFromFiles(PGHP_DIR"/shaders/simple.vert", PGHP_DIR"/shaders/simple.frag");

    //PointCloud
    pc = new PointCloud();
    //pc->load(PGHP_DIR"/data/decimate.asc");
    //pc->load(PGHP_DIR"/data/decimateRed.asc");
    pc->load(PGHP_DIR"/data/sunglasses_lens.asc");
    pc->makeUnitary();
    pc->init(&mBlinn);

    //Ball
    ball = new Ball(pc);
    ball->init(&mBlinn);

    surface = new Surface();
    surface->init(&mSimple);

    //Octree
    octree = new Octree(pc,15,10);
    wirecube = new WireCube();
    wirecube->init(&mSimple);

    mCamera.setSceneCenter(Vector3f(0.0,0.0,0.0));
    mCamera.setSceneDistance(4);
    mCamera.setMinNear(0.1f);
    mCamera.setNearFarOffsets(-200.f,200.0f);
    mCamera.setScreenViewport(AlignedBox2f(Vector2f(0.0,0.0), Vector2f(WIDTH,HEIGHT)));

    GL_TEST_ERR;
}
Beispiel #21
0
void mouse(int button, int state, int x, int y)
{
  switch ( button ) {
    
  case GLUT_LEFT_BUTTON:
    if ( state == GLUT_DOWN )
      tb.startRotation(x,y);
    else
      tb.stopRotation();
    break;
    
  case GLUT_MIDDLE_BUTTON:
    if ( state == GLUT_DOWN )
      tb.startTranslationZ(x,y);
    else
      tb.stopTranslationZ();
    break;
    
  case GLUT_RIGHT_BUTTON:
    if ( state == GLUT_DOWN )
      tb.startTranslationXY(x,y);
    else
      tb.stopTranslationXY();
    break;
  }
}
Beispiel #22
0
void reshape(int w, int h)
{
  glViewport( 0, 0, static_cast<GLsizei>(w), static_cast<GLsizei>(h) );
  aspect = static_cast<GLfloat>(w) / static_cast<GLfloat>(h);
  
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0, aspect, 1.0e-2, 1.0e+2);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  
  tb.reshape(w,h);
}
Beispiel #23
0
	void start(){
		//resource
		String rspath = Application::instance()->appResourcesDirectory();
		//init renders
		Vec4 viewport(0, 0, 1280, 720);
		getRender().setViewportState(viewport);
        getRender().setClearColorState({64,64,64,255});
		getRender().setZBufferState(true);
		getRender().setBlendState(BlendState(BLEND::ONE, BLEND::ZERO));
		getRender().setCullFaceState(CullFace::DISABLE);
		//materials
		matTrackball.init();
		matPoints.init();
		matGeometry.init();
		matGeometry.setColor({1.0,1.0,1.0,1.0});
		//init trackball
		trackball.init(&matTrackball);
        //init track area
        //left
        trackAreaLeft.init(&matGeometry, &matPoints);
        trackAreaLeft.setTrackball(trackball);
        //right
        trackAreaRight.init(&matGeometry, &matPoints);
        trackAreaRight.setTrackball(trackball);
        //init ui
        ui.setSizeLeft(UI_SIZE);
        ui.setCallBackLoad([this](const String& path)
                           {
                               loadModel(path);
                           });
        ui.setCallBackSave([this](const String& path)
                           {
                               saveModels(path);
                           });
        ui.setCallBackSVD([this]()
                         {
                             mergeMesh();
                         });
		#if 0
		Mesh m1;
		m1.addMeshOFF(modelRight, {
			1, 0, 0, 0,
			0, 0.5, 0, 0,
			0, 0, 1, 0,
			0, 0, 0, 1
		});
		m1.saveOFF(rspath + "/meshs/faccia045.off");
		#endif
		
	}
Beispiel #24
0
void 
display ()
{
  glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

  root->update(0.033); // assumes called at 30Hz

  // mouse control 
  mat4 tball = trackball.getMat4();
  mat4 mv = modelviewMatrix * tball;

  root->draw(mv, projectionMatrix );

  glutSwapBuffers();
}
Beispiel #25
0
/** This method is automatically called by GLFW everytime a mouse button is pressed */
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) 
{
    if(action == GLFW_PRESS) {
        if(button == GLFW_MOUSE_BUTTON_LEFT)
        {
            mCamera.startRotation(mLastMousePos);
        }
        else if(button == GLFW_MOUSE_BUTTON_MIDDLE)
        {
            mCamera.startTranslation(mLastMousePos);
        }
        mButton = button;       
    }else if(action == GLFW_RELEASE) {
        if(mButton == GLFW_MOUSE_BUTTON_LEFT)
        {
            mCamera.endRotation();
        }
        else if(mButton == GLFW_MOUSE_BUTTON_MIDDLE)
        {
            mCamera.endTranslation();
        }
        mButton = -1;
    }
}
void display(void)
{
    m1c = tball.getFullTrackballMatrix();

    if(move_obj == true)
    {
        scene_trans->editSFMatrix()->setValue( m1c );
    }
    else
    {
        cam_trans->editSFMatrix()->setValue( m1c );
    }

    commitChanges();

    win->render(rentravact);
}
Beispiel #27
0
void mouseEvent(int button, int state, int x, int y) {
 Trackball::MouseState mouseState;
  if (state == GLUT_DOWN) {
    switch (button) {
      case GLUT_LEFT_BUTTON : {
        mouseState = Trackball::LEFT_BTN;
        break;
      }
      case GLUT_RIGHT_BUTTON : {
        mouseState = Trackball::RIGHT_BTN;
        break;
      }
      default : break;
    }
  } else {
    mouseState = Trackball::NO_BTN;
  }
  trackball.updateMouseBtn(mouseState, x, y);
}
Beispiel #28
0
void updateGL() {
  GLfloat aspectRatio = (GLfloat)windowWidth / windowHeight;
  
  glViewport(0, 0, windowWidth, windowHeight);
  
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(fov, aspectRatio, zNear, zFar);
  
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  
  trackball.rotateView();
  
  // render  //
  renderScene();
  
  // swap render and screen buffer //
  glutSwapBuffers();
}
Beispiel #29
0
void display ()
{
  glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

  root->update(0.033); // assumes called at 30Hz

  mat4 tball = trackball.getMat4();
  mat4 mv = modelviewMatrix * tball;

  if (currentFrame == endFrame) {
    currentFrame = startFrame;
  } else {
    currentFrame++;
  }

  Ptr<Material> mat;
  //  dynamic_cast<Instance*>(root)->getChild ( currentFrame-startFrame )->draw(mv,projectionMatrix,mat);
  root->getChild ( currentFrame-startFrame )->draw(mv,projectionMatrix,mat);

  glutSwapBuffers();
}
Beispiel #30
0
void display(void)
{
        // set new model view and projection matrix
        glClearColor(0.3, 0.3, 0.3, 1);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glEnable(GL_DEPTH_TEST);

        glEnable(GL_COLOR_MATERIAL);
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

        GLfloat m[16];
        trackball.getMatrix().getValue(m);

        glPushMatrix();
        glMultMatrixf(m);

        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glEnable(GL_TEXTURE_2D);
    
    // CMSC:  rendering your geometry here...

    myVectorField->Render();
    
    
    drawAxis(0., 0., 0., 1.);
    
    
    
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);

    glPopMatrix();
    glFlush();
    glutSwapBuffers();
}