Page 2 of 2 FirstFirst 12
Results 21 to 31 of 31

Thread: 3 Dimensions using opengl

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 3 Dimensions using opengl

    Quote Originally Posted by vermarajeev View Post
    Actually I dont want to redraw the things again.
    It won't happen all by itself. It's much easier to simply draw that molecule again in 3D than convert a 2D image to 3D one. First you need some kind of a representation, for example a set of segments. Then you can draw it in whatever form you like.

  2. #22
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 3 Dimensions using opengl

    Well, you have to draw it again.

    QPainter when is using OpenGl is doing the similar thing like in my code example. It's just sends triangles to opengl using orthographic projection. But you cannot access QPainter OpenGL projection and modelview matrix (of course, you can change the source code if you want it), so you must redraw in 3D all that stuff. That's why I asked you what kind of 2D objects you want to represent in 3D.

    Qt Code:
    1. void paintGL()
    2. {
    3.  
    4. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    5.  
    6. static const QPoint points[6] = {
    7. QPointF(-3, -2),
    8. QPointF(-7, 3),
    9. QPointF(-3, 8),
    10. QPointF(3, 8),
    11. QPointF(7, 3),
    12. QPointF(3, -0) };
    13.  
    14. glMatrixMode(GL_MODELVIEW);
    15. glLoadIdentity();
    16.  
    17. glTranslatef(0.0, 0.0, -5.0);
    18.  
    19. glBegin(GL_LINE_LIST);
    20.  
    21. for(int i = 0 ; i < 6; i++){
    22. glVertex2f(points[i].x, points[i].y);
    23. }
    24.  
    25. glEnd();
    26. }
    To copy to clipboard, switch view to plain text mode 

    Maybe there are some errors...

  3. #23
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 3 Dimensions using opengl

    Quote Originally Posted by jacek View Post
    It won't happen all by itself. It's much easier to simply draw that molecule again in 3D than convert a 2D image to 3D one. First you need some kind of a representation, for example a set of segments. Then you can draw it in whatever form you like.
    Ok Here is the class representation of 2D objects drawn on QGraphicsView.

    Qt Code:
    1. class DrawMolecule : public ChemObject
    2. {}
    3. class DrawAtom : public ChemObject
    4. {}//
    5. class DrawBond : public ChemObject
    6. {}//
    To copy to clipboard, switch view to plain text mode 
    Here ChemObject is a pure Virtual class inherited from QObject which provides an interface to draw an atom, bonds. The combination of atoms and bonds forms a molecule.
    Jacek I think you were talking about this. Please suggest.

    minimoog--> Thanks for your sample program but there are some errors as you mentioned. M trying to rectify. Thanks again

    Jacek, you are a multitasking human being (really good at chemistry too). Fabulous!!!
    Last edited by vermarajeev; 19th April 2007 at 04:35.

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 3 Dimensions using opengl

    Quote Originally Posted by vermarajeev View Post
    Jacek I think you were talking about this.
    Yes, now you have to add routines that will draw each of those objects. Take a look at gluSphere() and gluCylinder() functions.

    You can add QGraphicsView and QGLWidget to QStackedWidget, so you can switch between the 2D and 3D view easily.

  5. The following user says thank you to jacek for this useful post:

    vermarajeev (20th April 2007)

  6. #25
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 3 Dimensions using opengl

    Quote Originally Posted by jacek View Post
    Yes, now you have to add routines that will draw each of those objects. Take a look at gluSphere() and gluCylinder() functions.

    You can add QGraphicsView and QGLWidget to QStackedWidget, so you can switch between the 2D and 3D view easily.
    Hi jackek,
    Thanks for your suggestions. I'll take a look at those examples and see how I can solve the problem. Thanks a lot. Will keep you updating.

    Thanks

  7. #26
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 3 Dimensions using opengl

    Hi Jacek,
    I did a sample program to convert 2D to 3D. I have not used any representation but just a sample. I'll make use of DrawAtom, DrawBond and DrawMolecule classes once I'm perfect with what I have to do. Anyway below is the code. Please tell me if I'm going anywhere wrong. Also when I draw two or more polygons, they are not displayed in exact positions as they appear in 2D.

    I have a zipped file.

    Steps to follow once the progrma is executed:
    1) Click on 'Draw Poly'.
    2) Release the mouse on GraphicsView. It will draw a polygon. If you want two or more
    polygon then again click 'Draw Poly' and then release mouse and so on.
    3) Once there are polygons on GraphicsView click 'opengl' to get the 3D View.

    Please help me to improve my code. Also the positions of polygons in 3D are not same as 2D
    Thanks
    Attached Files Attached Files

  8. #27
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 3 Dimensions using opengl

    I've put the QGraphicsView/Scene into a consistent coordinate system with OpenGL i.e.

    Y
    ^
    |
    +---> X

    I've switched you to a orthographic projection - always better for scientific stuff. The OpenGL viewport coordinates are mapped to the scenegraph, and I've changed the graphics object to use a 2:1 ratio triangle - much easier to see the mappings with this.

    Seems to work.

    Pete
    Attached Files Attached Files
    Last edited by pdolbey; 20th April 2007 at 19:55.

  9. The following user says thank you to pdolbey for this useful post:

    vermarajeev (21st April 2007)

  10. #28
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 3 Dimensions using opengl

    Hi Pete,
    Thanks a lot.

    Good one. Now since I have a orthigraphic projection view it is also possible to create actual 3D view from 2D. Wow!!!!

    Thanks
    Any more comments.

    But there is one flaw. When I move the triangle in 360 degrees, some portion is not displayed. What is it so?
    Last edited by vermarajeev; 21st April 2007 at 06:53.

  11. #29
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 3 Dimensions using opengl

    It'll be because I've set an arbitratry near and far plane of -100 to 100. The -100 should be behind the view point, its probably the far plane thats clipping try 1000.

    The near and far planes help OpenGL clamp the depth calcuations.

    But in terms of comments, have you considered using a scene graph component instead just using raw OpenGL - for instance VTK (http://www.kitware.com), Coin3D (http://www.coin3d.org), OpenSG, Open SceneGraph (no they're not the same) and so on. There a vid presetantion in Coin3d on the TrollTech site at http://www.trolltech.com/company/new...006/videolinks - its the "High-Level 3D Programming using Open Inventor API and Qt" link.

    One final thing - if you have lots of specific OpenGL questions, its worth joing the forum at http://www.opengl.org as well (if you haven't already).

    Pete
    Last edited by pdolbey; 21st April 2007 at 12:04.

  12. #30
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 3 Dimensions using opengl

    Hi pete,
    Thanks for your information.

  13. #31
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 3 Dimensions using opengl

    I took another look at my sample this morning and its still not quite right wrt coordinate systems. I'll have another play with it this evening.

    Pete

Similar Threads

  1. opengl help!!
    By rachana in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2007, 08:52
  2. Qt and OpenGL
    By ToddAtWSU in forum Qt Programming
    Replies: 8
    Last Post: 15th June 2006, 21:37
  3. Does OpenGL be supported in opensource of Qt-4.1.2?
    By showhand in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2006, 10:46
  4. Qt's optimized OpenGL context switching
    By sverhoff in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 16:40
  5. Example OpenGL project?
    By brcain in forum Qt Tools
    Replies: 9
    Last Post: 23rd February 2006, 21:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.