Reputation: 540
I need to get a slightly 3D representation of a two-dimensional layer of plant cells in OpenGL 2.1 (actually Compatibility profile). It's looking pretty good so far with no transformations:
What you see in the center is a small 3D cube I drew for comparison purposes. It uses the same transformation matrix as all other models. Every cell consists of an extruded plateau (lighter parts) and sloped walls (the shadowy bits). There's a diffuse white light source pointed at the cell from somewhere about the eye.
Now comes the part where I'm stuck. Scaling and translations work just fine, but I can't get 3D rotations of the cell to work. The cube, defined around (0, 0, 0) rotates exactly as expected but the cells show a strange behaviour I haven't managed to explain.
Here's the same model slightly rotated.
First of all, the shadows are different (as expected I'd say). The light source doesn't move. I've tried moving it but it didn't really change much, so that's another problem altogether. What's especially peculiar to me is the way the cells get cut off. The lower left corner has missing pieces. One could say we're looking under that part of the cell, but then the other part of that cell doesn't look quite like expected. Or is the lighting just bad?
I'm looking for a rotation of this only slightly 3D model that would look more pleasing to the user. Would I go about changing the lighting? Mind you there is no way I can use Glu so there's no gluLookAt
to instead view my camera around. Would there be another way around though? Creative answers are encouraged. In short, I need a way for a user to navigate around this slightly 3D model, knowing it's mostly 2D, that feels intuitive.
Some more images for context. The application supports rotation by dragging around the screen with the mouse so playing around is easy.
Rotated 90 degrees about the y axis (OK)
Ever so slightly rotated
Transformations:
glLoadIdentity();
glScalef(m_preferences->m_mesh_magnification, m_preferences->m_mesh_magnification, 1.0);
glRotatef(m_totalRotation.x() / 5., 0, 1, 0); // user rotation
glRotatef(m_totalRotation.y() / 5., -1, 0, 0); // user rotation
Body of resizeGL(w, h)
, responsible for the projection view:
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho(-((GLdouble) w) / 2, ((GLdouble) w) / 2, ((GLdouble) h) / 2, -((GLdouble) h) / 2, -1.0, 1.0);
//glFrustum(...) if we want a realistic projection
glMatrixMode (GL_MODELVIEW);
Basically I make y point down and have (0, 0) in the middle. The y direction I believe mimicks Qt's default, while the origin's location was a project decision.
EDIT: final result after rotating
Upvotes: 1
Views: 676
Reputation: 181715
glOrtho(-((GLdouble) w) / 2, ((GLdouble) w) / 2, ((GLdouble) h) / 2, -((GLdouble) h) / 2, -1.0, 1.0);
The -1.0, 1.0
are your near and far clipping planes. Anything in front of the near plane or behind the far plane will not be drawn. You'll need to increase those values -- but not much more than you need to, because you'll lose Z-buffer precision.
Upvotes: 1