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:
void paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -5.0); glBegin(GL_LINE_LIST); for(int i = 0 ; i < 6; i++){ glVertex2f(points[i].x, points[i].y); } glEnd(); }To copy to clipboard, switch view to plain text mode
Maybe there are some errors...
Ok Here is the class representation of 2D objects drawn on QGraphicsView.
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.Qt Code:
class DrawMolecule : public ChemObject {} class DrawAtom : public ChemObject {}// class DrawBond : public ChemObject {}//To copy to clipboard, switch view to plain text mode
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.
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.
vermarajeev (20th April 2007)
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
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
Last edited by pdolbey; 20th April 2007 at 19:55.
vermarajeev (21st April 2007)
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.
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.
Hi pete,
Thanks for your information.
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
Bookmarks