예제 #1
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 );
}
예제 #2
0
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 );
}
예제 #3
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 );
}
예제 #4
0
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 );
}
예제 #5
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);
}
예제 #6
0
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);

    
#if 0
    m1c.setIdentity();

    Matrix m2c, m3c;
    Quaternion q1c;

    tcamball.getRotation().getValue(m3c);

    q1c.setValue(m3c);

    m1c.setRotate(q1c);
    
    m2c.setTranslate( tcamball.getPosition() );
    
    m1c.mult( m2c );
#else
    m1c.setIdentity();

    float fLat  = xPoints[0][1] + (xPoints[1][1] - xPoints[0][1]) * t;
    float fLong = xPoints[0][0] + (xPoints[1][0] - xPoints[0][0]) * t;

//    fprintf(stderr, "%f %f\n", fLat, fLong);

    if(bAnimate == true)
    {
        t += tStep;
        
        if(t > 1)
        {
            tStep = -tStep;
            t     = 1;
        }
        else if(t < 0)
        {
            tStep = -tStep;
            t     = 0;
        }
    }

    Pnt3f p1;

    projectPnt(p1, fLat, fLong, 50);

    m1c[3][0] = p1[0];
    m1c[3][1] = p1[1];
    m1c[3][2] = p1[2];

#endif

    scene_trans->editSFMatrix()->setValue(m1c);

    Vec3f x1(m1c[3][0],
             m1c[3][1],
             m1c[3][2]);
    Vec3f x2;

    backProjectPnt(x2, x1);


/*
    fprintf(stderr, "%f %f %f\n", 
            osgRad2Degree(x2[0]), 
            x2[2],
            osgRad2Degree(x2[1]));
 */

/* -285.728333 -285.728333 | 494.500488 494.500488 */

    const BbqDataSourceInformation &tInfo = 
        pSource->getInformation();

    m4c.setIdentity();

    m4c[3][0] = osgRad2Degree(x2[0]);
    m4c[3][1] = 0; //x2[2];
//    m4c[3][2] = -45.f - (osgRad2Degree(x2[1]) + 40.f);
//    m4c[3][2] = -(osgRad2Degree(x2[1]) + 40.f);
    m4c[3][2] = osgRad2Degree(x2[1]);

//    fprintf(stderr, "%f %f\n", 
//            -(osgRad2Degree(x2[1]) + 40.f),
//           -45.f - (osgRad2Degree(x2[1]) + 40.f));
//    (571.45666/ 5.f)
//   (- 285.728333 - (170.f * fUnitScale))

//    m4c[3][0] = m4c[3][0] * fUnitScale + vUnitOffset[0]; 
    m4c[3][0] = m4c[3][0] * tInfo.vScale[0] + tInfo.vOffset[0]; 

//    m4c[3][2] = (-m4c[3][2] - 40.f) * fUnitScale - 285.728333; 
//    m4c[3][2] = m4c[3][2] * fUnitScale1 + vUnitOffset[1];
    m4c[3][2] = m4c[3][2] * tInfo.vScale[1] + tInfo.vOffset[1];

    ref_trans->editSFMatrix()->setValue(m4c);

    commitChanges();

//    win->render(rentravact);

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

    win->activate ();
    win->frameInit();    // query recently registered GL extensions
    
    win->renderAllViewports(rentravact);

    win->swap     ();
    win->frameExit();    // after frame cleanup: delete GL objects, if needed

}
예제 #7
0
void key(unsigned char key, int x, int y)
{
    switch(key)
    {
        case 27:    
            win = NULL;
            rentravact  = NULL;
            root        = NULL;
            file        = NULL;
            cam         = NULL;
            vp          = NULL;
            win         = NULL;
            cam_trans   = NULL;
            scene_trans = NULL;
            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;
            Line l;
            cam->calcViewRay( l, x, y, *vp );
            std::cerr << "From " << l.getPosition() << ", dir " 
                      << l.getDirection()
                      << std::endl;
        }
        break;
        case 'w':
            bWireframe = !bWireframe;
            break;

        case ' ':
        {
            Matrix     m;
            Quaternion q;
            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;
    }
}
예제 #8
0
void key(unsigned char key, int x, int y)
{
    switch ( key )
    {
    case 27:
        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 'z':
        glPolygonMode( GL_FRONT_AND_BACK, GL_POINT);
        std::cerr << "PolygonMode: Point." << std::endl;
        break;
    case 'x':
        glPolygonMode( GL_FRONT_AND_BACK, GL_LINE);
        std::cerr << "PolygonMode: Line." << std::endl;
        break;
    case 'c':
        glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
        std::cerr << "PolygonMode: Fill." << std::endl;
        break;
    case 'r':
    {
        std::cerr << "Sending ray through " << x << "," << y << std::endl;
        Line l;
        cam->calcViewRay( l, x, y, *vp );
        std::cerr << "From " << l.getPosition() << ", dir "
                  << l.getDirection()
                  << std::endl;
    }
    break;

    case ' ':
    {
        Matrix     m;
        Quaternion q;
        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;
    }
}