예제 #1
0
void GLWidget::setBottomView()
{
    makeCurrent();
    setXRotation(0);
    setYRotation(180*16);
    setZRotation(0);
}
예제 #2
0
void GLWidget::setTopView()
{
    makeCurrent();
    setXRotation(0);
    setYRotation(0);
    setZRotation(0);
}
예제 #3
0
void GLWidget::setRightView()
{
    makeCurrent();
    setXRotation(270*16);
    setYRotation(0);
    setZRotation(270*16);
}
예제 #4
0
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();

    if (event->buttons() & Qt::LeftButton)
    {
        if (isRotate)
        {
            setXRotation(xRot + 8 * dy);
            setYRotation(yRot + 8 * dx);
        }
        else if (isScale)
            setupScale(dx, dy);
        else if (isTranslate)
            setupTranslate(dx, dy);
    }
    else if (event->buttons() & Qt::RightButton)
    {
        if (isRotate)
        {
            setXRotation(xRot + 8 * dy);
            setZRotation(zRot + 8 * dx);
        }
        /*else if (isScale)
        {
            scale /= 1.05;
            updateGL();
        }*/
    }
    lastPos = event->pos();
}
예제 #5
0
void CompassWidget::setAllRotations(float xAngle, float yAngle, float zAngle)
{
// 	setXRotation( (int) (xAngle*16) );
// 	setYRotation( (int) (yAngle*16) );
// 	setZRotation( (int) (zAngle*16) );
	setXRotation( xAngle );
	setYRotation( yAngle );
	setZRotation( zAngle );
}
예제 #6
0
void CompasWidget::mouseMoveEvent(QMouseEvent *event){
	int dx = event->x() - m_lastPos.x();
	int dy = event->y() - m_lastPos.y();

	if (event->buttons() & Qt::LeftButton) {
		setXRotation(m_xRot + 8 * dy);
		setYRotation(m_yRot + 8 * dx);
	} else if (event->buttons() & Qt::RightButton) {
		setXRotation(m_xRot + 8 * dy);
		setZRotation(m_zRot + 8 * dx);
	}
	m_lastPos = event->pos();
}
//! [10]
void Visualizer::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();

    if (event->buttons() & Qt::LeftButton) {
        setXRotation(xRot + 8 * dy);
        setYRotation(yRot + 8 * dx);
    } else if (event->buttons() & Qt::RightButton) {
        setXRotation(xRot + 8 * dy);
        setZRotation(zRot + 8 * dx);
    }
    lastPos = event->pos();
}
예제 #8
0
void PainelOpenGL::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();

    if (event->buttons() & Qt::LeftButton) {
        setXRotation(xRot + 8 * dy);
        setYRotation(yRot + 8 * dx);
    } else if (event->buttons() & Qt::RightButton) {
        setXRotation(xRot + 8 * dy);
        setZRotation(zRot + 8 * dx);
    }
    //glFrustum();
    lastPos = event->pos();
}
예제 #9
0
//! [10]
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();

    if (event->buttons() & Qt::LeftButton) {
        setXRotation(xRot +  dy);
        setYRotation(yRot +  dx);
    } else if (event->buttons() & Qt::RightButton) {
        setXRotation(xRot + 8 * dy);
        setZRotation(zRot + 8 * dx);
    }
    lastPos = event->pos();

    rotation = QQuaternion::fromAxisAndAngle(0,0,1, 8*dx) * rotation;
    rotation = QQuaternion::fromAxisAndAngle(0,1,0, 8*dy) *rotation;
}
예제 #10
0
void QCastViewGL::mouseMoveEvent(QMouseEvent *event)
{
   double trans_scale = 0.01, rot_scale = 1.0;
   double dx = (double)(event->x() - m_lastPos.x());
   double dy = (double)(event->y() - m_lastPos.y());

   if (event->buttons() & Qt::LeftButton) {
      setCameraEye(m_camera.eye + (m_camera.up*dy + m_camera.normal()*dx)*trans_scale);
   }
   else if(event->buttons() & Qt::MidButton) {
      setCameraEye(m_camera.eye - m_camera.view*dy*trans_scale);
   }
   else if(event->buttons() & Qt::RightButton) {
      // Rotate the scene (not the camera)
      // TODO: directions (signs) may change depending on m_camera position
      if (event->modifiers() & Qt::ControlModifier) {
         setXRotation(xRot - dy*rot_scale);
         setZRotation(zRot + dx*rot_scale);
      }
      else {
         // orbit around current pivot
#if 0 // TODO ENABLE
         const double dang = -M_PI / 36;
         m_camera.orbit(m_pivot, m_camera.up, dx * dang);
         m_camera.orbit(m_pivot, m_camera.normal(), dy * dang);
         emit cameraEyeChanged(m_camera.eye);
         updateGL();
#else
         la::Vector3 dir = m_camera.normal()*dx + m_camera.up*dy;
         //std::cout << dir.x << " " << dir.y << " " << dir.z << std::endl;

         // very simple approach: keep the radius
         double R = (m_camera.eye - m_pivot).length();
         la::Vector3 neweye = m_camera.eye + dir * (R/36);
         dir = neweye - m_pivot;
         dir.normalize();
         m_camera.view = dir * -1;
         m_camera.normalize();
         setCameraEye(dir * R);
#endif
      }
   }
   //printf("dx: %lf, dy: %lf, xRot: %f, yRot: %f, zRot: %f\n", dx, dy, xRot, yRot, zRot);
   m_lastPos = event->pos();
}
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();

    // 鼠标拖动的旋转速率
    //默认为8
    double rotateRate = 8;

    if (event->buttons() & Qt::LeftButton) {
        setXRotation(xRot + rotateRate * dy);
        setYRotation(yRot + rotateRate * dx);
    } else if (event->buttons() & Qt::RightButton) {
        setXRotation(xRot + rotateRate * dy);
        setZRotation(zRot + rotateRate * dx);
    }
    lastPos = event->pos();
}
예제 #12
0
/*
 * Mouse displacement handler (within the framebuffer)
 *
 * Mouse rotation is modified X/Y on left-click, X/Z on right-click
 * (user must hold down the button to acheive this behavior)
 */
void GLWidget::mouseMoveEvent( QMouseEvent *event )
{
        int dx = event->x() - lastPos.x();
        int dy = event->y() - lastPos.y();

        if (event->buttons() & Qt::LeftButton) {
                setXRotation( xRot + 8 * dy );
                setYRotation( yRot + 8 * dx );
        }
        else {
                setXRotation( xRot + 8 * dy );
                setZRotation( zRot + 8 * dx );
        }

        // Update lastPos with the new position so subsequent moves
        // will be handled based off of the present location.
        lastPos = event->pos();
}
예제 #13
0
int InputView::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QGLWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: xRotationChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 1: yRotationChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 2: zRotationChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 3: setXRotation((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 4: setYRotation((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 5: setZRotation((*reinterpret_cast< int(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 6;
    }
    return _id;
}
예제 #14
0
void OpenGLContainer::mouseMoveEvent(QMouseEvent *event) {
  // Size of dx and dy represent the speed of movement along the respective axis
  int dx = event->x() - lastPos.x();
  int dy = event->y() - lastPos.y();

  if(event->buttons() & Qt::LeftButton) {
    setXRotation(xRot + 8. * dy);
    setYRotation(yRot + 8. * dx);
  }
  else if (event->buttons() & Qt::RightButton) {
    setXRotation(xRot + 8. * dy);
    setZRotation(zRot + 8. * dx);
  }

  lastPos = event->pos();

  // Translate camera horizontally and vertically
  if(toggleTranslation) setXYTranslation(dx, dy);
}
예제 #15
0
void GLWidget::mouseMoveEvent(QMouseEvent *event) {

    int dx = event->x() - lastPos_.x();
    int dy = event->y() - lastPos_.y();

    if (event->buttons() & Qt::LeftButton) {
        setXRotation(xRot_ + 8 * dy);
        setYRotation(yRot_ + 8 * dx);
    } else if (event->buttons() & Qt::RightButton) {
        setXRotation(xRot_ + 8 * dy);
        setZRotation(zRot_ + 8 * dx);
    }
    else if (event -> buttons() & Qt::MiddleButton) {
        //std::cerr<<"tup\n";
        setXTranslate(xTranslate_ + 0.002*dx/scale_);
        setYTranslate(yTranslate_ - 0.002*dy/scale_);
    }

    lastPos_ = event->pos();
}
예제 #16
0
void mouseEvent(int x, int y)
{
	int dx = x - lastx;
	int dy = y - lasty;

	if(rigthButtonPressed == 1)
	{

			

		setXRotation(xRot + 8 * dy);
		setZRotation(zRot + 8 * dx);


		glutPostRedisplay();
	}
 	lastx = x;
	lasty = y;

}
예제 #17
0
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();

    if (event->buttons() & Qt::LeftButton) {
        setXRotation(rotation[0] + 8 * dy);
        setYRotation(rotation[1] + 8 * dx);

        theta += dx/2;
        phi += dy/2;

        theta %= 360;
        phi %=360;

    } else if (event->buttons() & Qt::RightButton) {
        setXRotation(rotation[0] + 8 * dy);
        setZRotation(rotation[2] + 8 * dx);
    }
    lastPos = event->pos();
}
예제 #18
0
void Simulator::mouseMoveEvent(QMouseEvent* event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();

    if (event->buttons() && Qt::LeftButton)
    {
        setXRotation(xRot + 8*dy);
        setYRotation(yRot + 8*dx);
    }
    else if (event->buttons() && Qt::RightButton)
    {
        setXRotation(xRot + 8*dy);
        setZRotation(zRot + 8*dx);
    }

    lastPos = event->pos();

    if (!timerID)
        updateGL();
}
예제 #19
0
void FLGLWidget::mouseMoveEvent(QMouseEvent *event)
{
   int dx = event->x() - lastPos.x();
   int dy = event->y() - lastPos.y();

   if (event->buttons() & Qt::LeftButton) {
      setXRotation(xRot + 8 * dy);
      setYRotation(yRot + 8 * dx);
   } else if (event->buttons() & Qt::RightButton) {
      setXRotation(xRot + 8 * dy);
      setZRotation(zRot + 8 * dx);
   }
   lastPos = event->pos();
    
    QMatrix4x4 a,b;
    a.perspective(60.f, 1., .1f, 10.f);
    b.rotate(zRot / 16., QVector3D(0,0,1));
    b.rotate(yRot / 16., QVector3D(0,1,0));
    b.rotate(xRot / 16., QVector3D(1,0,0));
    for(size_t v = 0; v < 3; v++)
        pts_[v] = a * b * points_[v];
    m_vertexBuffer.allocate( pts_, 3 * 4 * sizeof( float ) );
}
예제 #20
0
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
    int dx = event->x() - lastPos.x();
    int dy = event->y() - lastPos.y();

    // Reverse Y-Axis if needed
    if(GLWidget::yAxisReversed)
    {
        dy = -dy;
    }

    if  (
        (event->buttons() & Qt::LeftButton && leftMouseButtonMode == PANNING) ||
        event->buttons() & Qt::MidButton
        )
    {
        if(width <= height)
        {
            setXTranslation(xTrans - dx*2*zoomFactor/width);
            setYTranslation(yTrans + dy*2*zoomFactor/width);
        }
        else
        {
            setXTranslation(xTrans - dx*2*zoomFactor/height);
            setYTranslation(yTrans + dy*2*zoomFactor/height);
        }
    }
    else if (
            (event->buttons() & Qt::LeftButton && leftMouseButtonMode == ROTATE) ||
            event->buttons() & Qt::RightButton
            )
    {
        setXRotation(xRot + 8 * dy);
        setZRotation(zRot - 8 * dx);
    }
    lastPos = event->pos();
}
예제 #21
0
//------------------------------------------------------------------------------
// onZRotate() -- updates the Z rotation value (rad)
//------------------------------------------------------------------------------
bool Rotators::onZRotate(const Basic::Number* const rotation)
{
    if (rotation != 0) return setZRotation( rotation->getReal() );
    return false;
}
예제 #22
0
/*
 * Constructor to setup the scene
 */
GLWidget::GLWidget( QWidget *parent ) :
                QGLWidget( QGLFormat( QGL::SampleBuffers ), parent )
{
        // We'll start WITHOUT a logo first because it's put in by 
        // GLWidget::initializeGL() anyway.
        logo = 0;

        ///////////////////////////////////////
        // Attempt to load whatever asset
        ///////////////////////////////////////
        asset = new Asset3ds("models/elecloco/Locomotive chs4 072.3DS");


        std::cerr << "Loaded a new asset" << std::endl ;

        // Look dead-on at the scene to start (no initial rotations)
        setXRotation( 0 );
        setYRotation( 0 );
        setZRotation( 0 );

        // Position Offset Initializer
        xPos = yPos = 0;

        // Push model BACK a bit to start. This is important because
        // some are ungodly huge and need to be visible at least in some
        // fashion right away, less the user thinks something failed.
        zPos = -20.0;

        // Initialize motion state bools
        moveUp_ = moveDn_ = moveRight_ = moveLeft_ = false;

        // These colors must be generated via CMYK values otherwise
        // it seems lighting will simply NOT WORK.
        qtGreen = QColor::fromCmykF( 0.2, 0.1, 0.9, 0.3 );
        qtPurple = QColor::fromCmykF( 0.4, 0.4, 0.0, 0.1 );
        qtGray = QColor::fromCmykF( 0.0, 0.0, 0.0, 0.75 );
        qtRed = QColor::fromCmykF( 0.1, 0.7, 0.9, 0.2 );
        qtDark = QColor::fromCmykF( 0.0, 0.0, 0.0, 0.85 );

        // Initially going to say the ambient light is on
        // (as is the movable light)
        ambientLight = true;
        flashlightOn = true;
        oppositeOn   = true;

        // The starting values for the variable color light
        auxRed(10);
        auxGreen(10);
        auxBlue(10);
        
        // Make the default on instantiation be perspective projection
        p_Perspective();

        // Default size of orthographic projection mode
        // (These are changed with the mouse wheel when in PROJECTION).
        ortho_left = ortho_top = -3.0;
        ortho_bottom = ortho_right = 3.0;

        // Begin the updating of the GLwidget using the QTimerEvent here
        startTimer( 20 );
}
예제 #23
0
/*
 * Constructor to setup the scene
 */
GLWidget::GLWidget( QWidget *parent ) :
                QGLWidget( QGLFormat( QGL::SampleBuffers ), parent )
{
        // We'll start WITHOUT a logo first because it's put in by 
        // GLWidget::initializeGL() anyway.
        logo = 0;

        ///////////////////////////////////////
        // Attempt to load whatever asset
        ///////////////////////////////////////
        QStringList args = QCoreApplication::arguments();

        // Pure AWESOME cascading member function calls! WHeeeeeeeeee
        char *assetName = args.at(1).toLocal8Bit().data();

        asset = new Asset3ds(assetName);

        // Look dead-on at the scene to start (no initial rotations)
        // WARNING: This is overruled by the slider settings in window.cpp!!
        setXRotation( 0 );
        setYRotation( 0 );
        setZRotation( 0 );

        // Position Offset Initializer
        xPos = yPos = 0;

        // Push model BACK a bit to start. This is important because
        // some are ungodly huge and need to be visible at least in some
        // fashion right away, less the user thinks something failed.
        zPos = -20.0;

        // Initialize scaling factor to 1, no scale change
        scaleFactor = 1.0;

        // Initialize motion state bools
        moveUp_ = moveDn_ = moveRight_ = moveLeft_ = false;

        // These colors must be generated via CMYK values otherwise
        // it seems lighting will simply NOT WORK.
        qtGreen = QColor::fromCmykF( 0.2, 0.1, 0.9, 0.3 );
        qtPurple = QColor::fromCmykF( 0.4, 0.4, 0.0, 0.1 );
        qtGray = QColor::fromCmykF( 0.0, 0.0, 0.0, 0.75 );
        qtRed = QColor::fromCmykF( 0.1, 0.7, 0.9, 0.2 );
        qtDark = QColor::fromCmykF( 0.0, 0.0, 0.0, 0.85 );

        // Initially going to say the ambient light is on
        // (as is the movable light)
        ambientLight = true;
        flashlightOn = true;
        oppositeOn   = true;

        // The starting values for the variable color light
        auxRed(10);
        auxGreen(10);
        auxBlue(10);
        
        // Make the default on instantiation be perspective projection
        p_Perspective();

        // Default size of orthographic projection mode
        // (These are changed with the mouse wheel when in PROJECTION).
        ortho_left = ortho_top = -3.0;
        ortho_bottom = ortho_right = 3.0;

        // Begin the updating of the GLwidget using the QTimerEvent here
        startTimer( 20 );
}
예제 #24
0
void GLControlWidget::setRotationImpulse(double x, double y, double z)
{
	setXRotation(xRot + 180*x);
	setYRotation(yRot + 180*y);
	setZRotation(zRot - 180*z);
}
예제 #25
0
//------------------------------------------------------------------------------
// onZRotate() -- updates the Z rotation value (rad)
//------------------------------------------------------------------------------
bool Rotators::onZRotate(const Basic::Angle* const rotation)
{
    if (rotation != nullptr)
        return setZRotation(static_cast<LCreal>(Basic::Radians::convertStatic(*rotation)));
    return false;
}
예제 #26
0
//------------------------------------------------------------------------------
// onZRotate() -- updates the Z rotation value (rad)
//------------------------------------------------------------------------------
bool Rotators::onZRotate(const Basic::Angle* const rotation)
{
    if (rotation != 0) return setZRotation( (LCreal)Basic::Radians::convertStatic( *rotation ) );
    return false;
}