Thanks Ilian, I found some resources further describing the methods. The color method seems to work pretty well from the demo source provided from the link below. It seems that frustum culling should only be done when zooming/panning(because thats the only time the viewing volume will change) and use the color picking method for mouse movements(for snap detection, looping through a 2D array of pixels surrounding the mouse cursor when in a CAD command) and clicking(the actual picking of an object).
http://www.lighthouse3d.com/opengl/picking/index.php?color1
http://www.lighthouse3d.com/opengl/viewfrustum/
I think I’ll stick with display lists for now. I’ll try to encapsulate that portion of code so that later on I can add VBO or other options. I’m planning to add some simple benchmarking features later on so I can test on different hardware.
_NK47, at the moment, I have one PushMatrix called before all and one PopMatrix after all drawing operations are executed. I did it because regardless of a display list, it just seems wasteful to have that in each objects display list…or did you mean something else?
I am using GL_COMPILE. Huge drawings/models are one of the main reasons I’d like to get performance as good as it can be. I use CAD at work and have to deal with this lag all the time.
A polyline for example is made up of many sub-parts and could possibly be shaped such that it stretches all throughout the drawing/model. For something as abstract shaped, are you suggesting to just use 1 large box for testing? Maybe anything fairly large in size is broken up into a few boxes?
I am wondering how well my zooming/panning method is performance wise though too. I haven’t made it into a display list as it constantly changes due to where the user wants to go. The performance isn’t bad at all imo so far, but I’m wondering if it could be somehow used as a display list or if a VBO is the best route, or something else. I came up with this method on my own after searching for a decent solution for “Zooming to mouse point” but not finding anything that remotely made sense. The way it works is it saves the last world coords of where the mouse is and then updates the projection and modelview matrices. Takes the difference between the two and then shifts the view accordingly. Right now it’s only set up for 2D, so you are looking at the 2D drawing plane. Suggestions? I’ve read a few things about a different ways to do zooming but some of them seemed like they are faking zooming by decreasing the size of things. I’m not sure how well my method will work when it comes to 3D zooming/rotation.
Here’s a snipplet of the zoom.cpp file for reference, zoomout and panning work similar in nature:
void CADGLObject::Coord2Dto3D(int x2d, int y2d, GLdouble* x3d, GLdouble* y3d, GLdouble* z3d)
{
glGetIntegerv (GL_VIEWPORT, viewport);
glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);
realY = WindowHeight - y2d - 1; //Invert Y for GL Screen coords
gluUnProject ((GLdouble) x2d, (GLdouble) realY, 1.0, mvmatrix, projmatrix, viewport, x3d, y3d, z3d);
}
//CAD Like Zooming
void CADGLObject::ZoomIn(int mx, int my)
{
printf("ZoomIn
");
MouseX = mx; MouseY = my;
Coord2Dto3D(mx, my, &DestX, &DestY, &DestZ); //Save the last mouse coords for zooming to point
//Do the Z zooming and update the matrices
CameraZ -= ZoomScaleIn;
if(CameraZ < 1.0f) CameraZ = 1.0f;
glMatrixMode(GL_PROJECTION); glLoadIdentity();
glOrtho (-CameraZ*((GLfloat)WindowWidth/(GLfloat)WindowHeight), CameraZ*((GLfloat)WindowWidth/(GLfloat)WindowHeight), -CameraZ, CameraZ, CameraZ/2, CameraZ);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
gluLookAt(CameraX, CameraY, CameraZ, TargetX, TargetY, TargetZ, 0.0f, 1.0f, 0.0f);
//Calculate the X/Y offset so that the destination coordinates are still located under the mouse.
Coord2Dto3D(mx, my, &WorldX, &WorldY, &WorldZ);
printf("DestX: %f DestY: %f DestZ: %f
", DestX, DestY, DestZ );
printf("WordX: %f WordY: %f WordZ: %f
", WorldX, WorldY, WorldZ );
CameraX += (DestX - WorldX); TargetX = CameraX;
CameraY += (DestY - WorldY); TargetY = CameraY;
// Update the matrices one last time and call SetMouseXY() so that the GLcrosscursor drawing will not be jittery
glMatrixMode(GL_PROJECTION); glLoadIdentity();
glOrtho (-CameraZ*((GLfloat)WindowWidth/(GLfloat)WindowHeight), CameraZ*((GLfloat)WindowWidth/(GLfloat)WindowHeight), -CameraZ, CameraZ, CameraZ/2, CameraZ);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
gluLookAt(CameraX, CameraY, CameraZ, TargetX, TargetY, TargetZ, 0.0f, 1.0f, 0.0f);
SetMouseXY(mx, my);
}