void display(void)
{
#if 0
    Matrix m1, m2, m3;
    Quaternion q1;

    tball.getRotation().getValue(m3);

    q1.setValue(m3);

    m1.setRotate(q1);
    
    m2.setTranslate( tball.getPosition() );
    
    m1.mult( m2 );

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

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

#if 0
    fprintf(stderr, "%f %f %f\n", 
            cam_trans->getMatrix()[3][0],
            cam_trans->getMatrix()[3][1],
            cam_trans->getMatrix()[3][2]);
#endif

    OSG::Real32 t = glutGet(GLUT_ELAPSED_TIME);

    for(OSG::UInt32 i = 0; i < 6; ++i)
    {
        if(pAnimTrs[i] != NULL)
        {
            pAnimTrs[i]->editRotation().setValueAsAxisDeg(
                0.f, 1.f, 0.f, 
                t / 50.f);
        }
    }

    OSG::commitChanges();

//    fprintf(stderr, "Frame start\n");
//    fprintf(stderr, "============================================\n");
    

    win->render(rentravact);
}
Ejemplo n.º 2
0
void display(void)
{
	osg::Matrix m1, m2;
	osg::Quaternion q1;

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

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

	//move_and_check();

	win->draw( render_action );
}
void MyOSGQGLWidget::paintGL(void)
{
    OSG::Matrix m1, m2, m3;
    OSG::Quaternion q1;

    tball.getRotation().getValue(m3);
    q1.setValue(m3);
    m1.setRotate(q1);
    m2.setTranslate( tball.getPosition() );
    m1.mult( m2 );
    cam_trans->setMatrix( m1 );

    OSG::commitChanges();

    osgWin->render(ract);   // draw the viewports     
}
void redraw ( void )
{
    OSG::Matrix m1, m2, m3;
    OSG::Quaternion q1;

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

    OSG::Thread::getCurrentChangeList()->commitChanges();

    win->render(ract);
}
void display(void)
{
    OSG::Matrix m1, m2, m3;
    OSG::Quaternion q1;

    tball.getRotation().getValue(m3);

    q1.setValue(m3);

    m1.setRotate(q1);
    
//    std::cout << "TBROT" << std::endl << tball.getRotation() << 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 );

//    std::cerr << m1 << std::endl;
    
    m1 = tball.getFullTrackballMatrix();

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

    OSG::commitChangesAndClear();

    win->render(rentravact);

    if(dumpImg == true)
    {
        vpFBO->setTravMask(oldTravMask);

        pTexBuffer                   ->setReadBack               (false);
        vpFBO->getFrameBufferObject()->setPostProcessOnDeactivate(false);

        pImg->write("/tmp/test.png");

        dumpImg = false;
    }

    if(dumpImg_RB == true)
    {
        pRenBuffer->getImage()->write("/tmp/test1.png");

        dumpImg_RB = false;

        win->subPortByObj(vpFBO_RB);

        vpFBO_RB   = NULL;
        pRenBuffer = NULL;

        win->runFrameExit();

//        OSG::FieldContainerFactory::the()->dump();
    }


//    win->render(renact);

//    std::cerr << "------------- AR START --------------" << std::endl;

//    Thread::getCurrentChangeList()->dump();
}
void key(unsigned char key, int x, int y)
{
    switch ( key )
    {
        case 27:    
            root        = NULL;
            file        = NULL;
            cam         = NULL;
            vp          = NULL;
            win         = NULL;
            cam_trans   = NULL;
            scene_trans = NULL;
            pPoly       = NULL;
            pCOver      = NULL;
            gwin        = NULL;

            tx1o        = NULL;
            tx1e        = NULL;

            vpFBO       = NULL;
            vpFBO_RB    = NULL;
            pTexBuffer  = NULL;
            pRenBuffer  = NULL;
            pImg        = NULL;

            delete rentravact;

            OSG::osgExit(); 

            exit(0);
        case 'f':
            vpFBO->setTravMask(~vpFBO->getTravMask());
            break;
        case 'd':
            oldTravMask = vpFBO->getTravMask();

            if(oldTravMask == 0x0000)
            {
                vpFBO->setTravMask(~vpFBO->getTravMask());
            }

            dumpImg = true;

            pTexBuffer                   ->setReadBack               (true);
            vpFBO->getFrameBufferObject()->setPostProcessOnDeactivate(true);

            break;

        case 'r':
        {
//            OSG::FieldContainerFactory::the()->dump();
            //RenderBuffer Readback
            // Background
            OSG::SolidBackgroundUnrecPtr bkgndFBO_RB = 
                OSG::SolidBackground::create();

            bkgndFBO_RB->setColor(OSG::Color3f(0.5,1.0,0.5));
    
            // Viewport

            vpFBO_RB = OSG::FBOViewport::create();

            vpFBO_RB->setCamera    (cam        );
            vpFBO_RB->setBackground(bkgndFBO_RB);
            vpFBO_RB->setRoot      (root       );
            vpFBO_RB->setSize      (0, 0, 1, 1 );
            
            OSG::FrameBufferObjectUnrecPtr pFBO_RB = 
                OSG::FrameBufferObject::create();
            
            pRenBuffer = OSG::RenderBuffer::create();

            OSG::RenderBufferUnrecPtr  pDepthBuffer_RB = 
                OSG::RenderBuffer::create();

            pDepthBuffer_RB->setInternalFormat(GL_DEPTH_COMPONENT24   );
            pRenBuffer->setInternalFormat(GL_RGBA);
            
            OSG::ImageUnrecPtr pImg_RB = OSG::Image::create();
    
            OSG::UInt32 uiImgSize = 4096;

            pImg_RB->set(OSG::Image::OSG_RGB_PF, uiImgSize, uiImgSize);

            fprintf(stderr, "Image data : %p\n", pImg_RB->getData());

            pRenBuffer->setImage(pImg_RB);

            pFBO_RB->setSize(uiImgSize, uiImgSize);
    
            pFBO_RB->setColorAttachment(pRenBuffer,     0);
            pFBO_RB->setDepthAttachment(pDepthBuffer_RB  );

            pFBO_RB->editMFDrawBuffers()->clear();
            pFBO_RB->editMFDrawBuffers()->push_back(GL_COLOR_ATTACHMENT0_EXT);

            vpFBO_RB->setFrameBufferObject(pFBO_RB);

            pRenBuffer                      ->setReadBack               (true);
            vpFBO_RB->getFrameBufferObject()->setPostProcessOnDeactivate(true);

            win->addPort(vpFBO_RB);

            dumpImg_RB = true;
        }
        break;

        case 'v':
            rentravact->setVolumeDrawing(!rentravact->getVolumeDrawing());
            break;
        case 'a':   
            glDisable( GL_LIGHTING );
            std::cerr << "Lighting disabled." << std::endl;
            break;
        case 's':   
            glEnable( GL_LIGHTING );
            std::cerr << "Lighting enabled." << std::endl;
            break;
        case 'z':   
            pPoly->setFrontMode(GL_POINT);
            pPoly->setBackMode(GL_POINT);
            std::cerr << "PolygonMode: Point." << std::endl;
            break;
        case 'x':   
            pPoly->setFrontMode(GL_LINE);
            pPoly->setBackMode(GL_LINE);
            std::cerr << "PolygonMode: Line." << std::endl;
            break;
        case 'c':   
            pPoly->setFrontMode(GL_FILL);
            pPoly->setBackMode(GL_FILL);
            std::cerr << "PolygonMode: Fill." << std::endl;
            break;
        case 'p':
        {
            if(bPolyActive == true)
            {
                OSG_ASSERT(pCOver->subChunk(pPoly) == true);
                bPolyActive = false;
            }
            else
            {
                OSG_ASSERT(pCOver->addChunk(pPoly) == true);
                bPolyActive = true;
            }
            break;
        }

        case ' ':
        {
            OSG::Matrix     m;
            OSG::Quaternion q;
            OSG::Vec3f      v;

            q = oldq;
            v = oldv;

            oldq = tball.getRotation();
            oldv = tball.getPosition();

            move_obj = ! move_obj;
            if ( move_obj )
            {
                puts("moving object");
//                m = scene_trans->getSFMatrix()->getValue();
                tball.setMode( OSG::Trackball::OSGCamera );

            }
            else
            {
                puts("moving camera");
//                m = cam_trans->getSFMatrix()->getValue();
                tball.setMode( OSG::Trackball::OSGObject );
            }
            
//            q.setValue(m);
            tball.setStartPosition( v, true );
            tball.setStartRotation( q, true );

//            std::cout << q << std::endl;
//            std::cout << v << std::endl;

//            std::cout << " " << m[3][0] << " " << m[3][1] << " " << m[3][2] << std::endl;
            
        }
        break;
    }
}
void key(unsigned char key, int x, int y)
{
    switch ( key )
    {
        case 27:    

            fprintf(stderr, "Start Destruction\n\n");

            rentravact = NULL;

            hdrroot = NULL;
            root    = NULL;
            file    = NULL;

            cam = NULL;
            vp  = NULL;
            win = NULL;

            cam_trans   = NULL;
            scene_trans = NULL;

            pAnimTrs[0] = NULL;
            pAnimTrs[1] = NULL;
            pAnimTrs[2] = NULL;
            pAnimTrs[3] = NULL;
            pAnimTrs[4] = NULL;
            pAnimTrs[5] = NULL;
            

            OSG::osgExit(); 
            exit(0);
        case 'a':   
            glDisable( GL_LIGHTING );
            std::cerr << "Lighting disabled." << std::endl;
            break;
        case 's':   
            glEnable( GL_LIGHTING );
            std::cerr << "Lighting enabled." << std::endl;
            break;
        case 'r':   
        {
            std::cerr << "Sending ray through " << x << "," << y << std::endl;
            OSG::Line l;
            cam->calcViewRay( l, x, y, *vp );
            std::cerr << "From " << l.getPosition() << ", dir " 
                      << l.getDirection()
                      << std::endl;
        }
        break;

        case 'd':
            OSG::ActionDataSlotPool::the()->dumpState();
            OSG::StageIdPool       ::the()->dumpState();
            rentravact->dumpStore();
            break;
        case ' ':
        {
            OSG::Matrix     m;
            OSG::Quaternion q;
            OSG::Vec3f      v;

            q = oldq;
            v = oldv;

            oldq = tball.getRotation();
            oldv = tball.getPosition();

            move_obj = ! move_obj;
            if ( move_obj )
            {
                puts("moving object");
                tball.setMode( OSG::Trackball::OSGCamera );

            }
            else
            {
                puts("moving camera");
                tball.setMode( OSG::Trackball::OSGObject );
            }
            
            tball.setStartPosition( v, true );
            tball.setStartRotation( q, true );
        }
        break;
    }
}
Ejemplo n.º 8
0
void key(unsigned char key, int x, int y)
{
    switch ( key )
    {
        case 27:    

            fprintf(stderr, "Start Destruction\n\n");

            rentravact = NULL;

            hdrroot = NULL;
            root    = NULL;
//            file    = NULL;

            cam = NULL;
            vp  = NULL;
            win = NULL;

            cam_trans   = NULL;
            scene_trans = NULL;

            pAnimTrs[0] = NULL;
            pAnimTrs[1] = NULL;
            pAnimTrs[2] = NULL;
            pAnimTrs[3] = NULL;
            pAnimTrs[4] = NULL;
            pAnimTrs[5] = NULL;
            

            OSG::osgExit(); 
            exit(0);
        case 'a':   
            glDisable( GL_LIGHTING );
            std::cerr << "Lighting disabled." << std::endl;
            break;
        case 's':   
            glEnable( GL_LIGHTING );
            std::cerr << "Lighting enabled." << std::endl;
            break;
        case 'r':   
        {
            std::cerr << "Sending ray through " << x << "," << y << std::endl;
            OSG::Line l;
            cam->calcViewRay( l, x, y, *vp );
            std::cerr << "From " << l.getPosition() << ", dir " 
                      << l.getDirection()
                      << std::endl;
        }
        break;

        case 'g':
            hdrroot->setCore(OSG::Group::create());
            break;
        case 'h':
            createHDRCore(hdrroot);
            break;
        case 'd':
            OSG::ActionDataSlotPool::the()->dumpState();
            OSG::StageIdPool       ::the()->dumpState();
            rentravact->dumpStore();
            break;
        case ' ':
        {
            OSG::Matrix     m;
            OSG::Quaternion q;
            OSG::Vec3f      v;

            q = oldq;
            v = oldv;

            oldq = tball.getRotation();
            oldv = tball.getPosition();

            move_obj = ! move_obj;
            if ( move_obj )
            {
                puts("moving object");
                tball.setMode( OSG::Trackball::OSGCamera );

            }
            else
            {
                puts("moving camera");
                tball.setMode( OSG::Trackball::OSGObject );
            }
            
            tball.setStartPosition( v, true );
            tball.setStartRotation( q, true );
        }
        break;

        case '1':
        {
            OSG::HDR2Stage* pHDR = dynamic_cast<OSG::HDR2Stage*>(hdrroot->getCore());
            if (pHDR) pHDR->setTarget(OSG::HDR2Stage::SCENE_TEXTURE);
        }
        break;
        case '2':
        {
            OSG::HDR2Stage* pHDR = dynamic_cast<OSG::HDR2Stage*>(hdrroot->getCore());
            if (pHDR) pHDR->setTarget(OSG::HDR2Stage::LUMINANCE_TEXTURE);
        }
        break;
        case '3':
        {
            OSG::HDR2Stage* pHDR = dynamic_cast<OSG::HDR2Stage*>(hdrroot->getCore());
            if (pHDR) pHDR->setTarget(OSG::HDR2Stage::ADAPTED_LUMINANCE_TEXTURE);
        }
        break;
        case '4':
        {
            OSG::HDR2Stage* pHDR = dynamic_cast<OSG::HDR2Stage*>(hdrroot->getCore());
            if (pHDR) pHDR->setTarget(OSG::HDR2Stage::THRESHOLD_TEXTURE);
        }
        break;
        case '5':
        {
            OSG::HDR2Stage* pHDR = dynamic_cast<OSG::HDR2Stage*>(hdrroot->getCore());
            if (pHDR) pHDR->setTarget(OSG::HDR2Stage::BLURRED_TEXTURE);
        }
        break;
        case '6':
        {
            OSG::HDR2Stage* pHDR = dynamic_cast<OSG::HDR2Stage*>(hdrroot->getCore());
            if (pHDR) pHDR->setTarget(OSG::HDR2Stage::COMPOSITE_TEXTURE);
        }
        break;
        case '7':
        {
            OSG::HDR2Stage* pHDR = dynamic_cast<OSG::HDR2Stage*>(hdrroot->getCore());
            if (pHDR) pHDR->setTarget(OSG::HDR2Stage::EXPOSURE_TEXTURE);
        }
        break;

    }
}