/* * 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(); }
void view::mousePressEvent(QMouseEvent *event) { m_lastPos = event->pos(); if (event->buttons() & Qt::LeftButton) { //setXRotation(m_xRot + 8 * 100); setXRotation(0); } }
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(); }
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); }
void TorusGLWidget::initializeGL() { GLWidget::initializeGL(); setXRotation(90); torusList = glGenLists(1); glNewList(torusList, GL_COMPILE); renderTorus(); glEndList(); }
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); } lastPos = event->pos(); }
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(); }
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(); }
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(); }
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 ) ); }
//metodo que responde al movimiento del raton void graficos::mouseMoveEvent(QMouseEvent *event){ int dx = event->x() - lastPos.x(); int dy = event->y() - lastPos.y(); if (event->buttons() & Qt::LeftButton) { setXRotation(xRot + 8 * dx); setYRotation(yRot + 8 * dy); } /*else if (event->buttons() & Qt::RightButton) { pcamara[1] = 10*sin(dy*PI/360); pcamara[2] = 10*cos(dx*PI/360); }*/ lastPos = event->pos(); }
//! [10] void GLWidget::mouseMoveEvent(QMouseEvent *event) { if (event->buttons() & Qt::LeftButton) { int dx = event->x() - lastPos.x(); int dy = event->y() - lastPos.y(); setXRotation(xRot + 8 * dy); setYRotation(yRot + 8 * dx); } else if (event->buttons() & Qt::RightButton) { float ratio = 2.0/scale; xMove += ratio * (float)(event->x() - lastPos.x())/this->size().width(); yMove -= ratio * (float)(event->y() - lastPos.y())/this->size().height(); updateGL(); } lastPos = event->pos(); }
void Camera::OnMouseMove(int x, int y) { // The movement int dx = x - m_lastPosX; int dy = y - m_lastPosY; float divAngle = 5000.0f; m_xMov = (float)dx / divAngle; m_yMov = (float)dy / divAngle; setYRotation(m_yMov); setXRotation(m_xMov); m_lastPosX = x; m_lastPosY = y; }
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(); }
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; }
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; }
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); cam->OnMouseMove(event->x(),event->y()); updateGL(); } else if (event->buttons() & Qt::RightButton) { //setXRotation(xRot + 8 * dy); //setZRotation(zRot + 8 * dx); cam->OnMouseMove(event->x(),event->y()); updateGL(); } lastPos = event->pos(); }
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(); }
/* * 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 ); }
/* * 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 ); }
//! [10] //! [11] void GLWidget::rotateLeft(int angle) { setXRotation(xRot + angle); }
//------------------------------------------------------------------------------ // onXRotate() -- updates the X rotation value (rad) //------------------------------------------------------------------------------ bool Rotators::onXRotate(const Basic::Angle* const rotation) { if (rotation != 0) return setXRotation( (LCreal)Basic::Radians::convertStatic( *rotation ) ); return false; }
void GLControlWidget::setRotationImpulse(double x, double y, double z) { setXRotation(xRot + 180*x); setYRotation(yRot + 180*y); setZRotation(zRot - 180*z); }
//------------------------------------------------------------------------------ // onXRotate() -- updates the X rotation value (rad) //------------------------------------------------------------------------------ bool Rotators::onXRotate(const Basic::Number* const rotation) { if (rotation != 0) return setXRotation( rotation->getReal() ); return false; }
//------------------------------------------------------------------------------ // onXRotate() -- updates the X rotation value (rad) //------------------------------------------------------------------------------ bool Rotators::onXRotate(const Basic::Angle* const rotation) { if (rotation != nullptr) return setXRotation(static_cast<LCreal>(Basic::Radians::convertStatic(*rotation))); return false; }