Results 1 to 7 of 7

Thread: Dragging rotated object

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    3

    Dragging rotated object

    Hello,

    I am not sure if I am just thinking wrong or where exactly to start with solving the problem:

    I have a graph with nodes (spheres) and edges which the user can rotate around the middle point of the system (QT + glu OpenGL library). Now I implemented the dragging itself (using glUnProject), so the user can drag an object (a node) normally as long as the graph has not been rotated, as the x and y axes for the graph and the mouse are the same. However, when the graph is rotated, the 3 axes of the graph and the 2 axes of the window obviously differ. I am not sure what I should do to make the dragging work, thus, how to translate the 2 window axes into the 3D system and taking into account how much the graph was already rotated. Any hint?

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Dragging rotated object

    So translation must be node after rotating. Due to how matrix multiplication works, I am pretty sure it means that you have to place the translate instructions before the rotations. But maybe I am wrong and it it the other way round .

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    3

    Re: Dragging rotated object

    But when I translate after rotating, then I just change the position of the graph or the distance to the rotation point, or am I wrong?

    Actually I do not translate the rotation, I just use glTranslate in the resize function:

    Code :
    void GLWidget::resizeGL(int width, int height) {
    	GLfloat aspect = (GLfloat)width/height;
        glViewport(0,0,(GLint)width,(GLint)height);
     
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(20.0, aspect, 0.1, 200.0);
        glMatrixMode(GL_MODELVIEW);
        //glLoadIdentity();
        glTranslated(0.0, 0.0, -10.0);
    }

    What I want is, that when the user for example turns the graph 180 degrees around the y-axis, a node is going to the right when the user moves the mouse to the right. At the moment the node would go left when the user drags right, as I do not know how to translate the movement of the mouse to the graph which does not use the same system any more as the user window after the rotation.

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Dragging rotated object

    You have to consider 2 spaces:

    - a world space with coordinates system (Xw, Yw, Zw).
    - an object space with coordinates system (Xo, Yo, Zo).

    The object space is attached to you graph and you can consider that the center of this space is its middle point. So the object space rotates and translates like your grapth related to the world space.

    You will need to build a matrix Mwo that transforms a point in world space to object space. So Mwo contains inverse of all object space transformations.


    the problem is that all your graph objects (spheres and edges) coordinates are given in object space, so you will need to move the world transformations Tw in object space to obtain a transformation matrix To.

    With a little math you have :

    To = Mwo * Tw * inverse(Mwo)

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    3

    Re: Dragging rotated object

    Ok, I expected a matrix transformation problem. Is it a complete manual thing, or does OpenGL provide any help here, or a code snippet at least somewhere?

  6. #6
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Dragging rotated object

    Opengl api doesn't provide any function to inverse matrices but you should easily find a code to do 4x4 matrix inverse.

  7. #7
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Dragging rotated object

    In your case, if you do just rotations and translations, this would be useful:
    http://gpwiki.org/index.php/MathGem:...trix_Inversion

Similar Threads

  1. dragging a 2d object
    By rohit_static in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-20-2010, 09:07 AM
  2. Dragging a 2D object with mouse help pls!!
    By bod2na in forum OpenGL: Basic Coding
    Replies: 18
    Last Post: 12-03-2009, 09:15 AM
  3. Dragging a 2D object with mouse
    By kram87 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-26-2009, 05:53 AM
  4. Clicking and dragging to translate an object
    By Infil in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-10-2008, 02:45 PM
  5. dragging an object in 3d - I got it!!!!
    By DalTXColtsFan in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-02-2003, 10:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean