View Full Version : picking

giuseppe500

11-12-2012, 09:18 AM

hello.

I have a qt gui interface with an opengl widget.

I can draw disks(2d circular mesh) and lines, my problem is the picking.

1)how i can create a ray with a direction from the mouse for the picking?

2)How i can test the intersection of a ray with a disks and with a lines?

3)how i can transform the ray from the 2d view to model view?(is sufficent multiply for the inverse(in my case the transposed ) of the modelview matrix?

thanks.

Carmine

11-12-2012, 09:52 AM

Why not use the built-in picking capabilities of OpenGL?

That way you don't have to do any of the math yourself.

Google 'OpenGL Picking' to see examples.

giuseppe500

11-12-2012, 10:37 AM

no , i would implement my own picking , for many reason.

thanks

praetorian

11-12-2012, 12:58 PM

How have you implemented the drawing of lines? Do you have a geometry/vector math class to generate lines created from two points with an x,y coordinate. That's where you want start.

So your project will have a several line objects stored in a container such as std::vector. Each line is made up of two points. Iterate thru the container to determine if a selection is made using an intersection algorithm between the two points of each line and a selection point with some x,y distance. Use gluUnProject to convert the mouse selection point from local coordinates to project coordinates.

giuseppe500

11-12-2012, 02:54 PM

very thanks Praetorian.

Is properly as you described.

But my goal is to create a 2d camera for zooming and translating.

For this in another post i asked if glortho returns a matrix.

How i can get a matrix from an eye point that i can translate or go ahead(zoom in) or go far(zoom out)

I wish use only opengl function, not glut or other.

and I wish using matrixes,shader and vbo , is a project "like" acrobat reader , i use it for text drawing and other (lines and points)in opengl.

Use gluUnProject to convert the mouse selection point from local coordinates to project coordinates

isn't the same to multiply the points for the inverse of the modelview matrix (in this case the transpose of modelviewmatrix )

Thanks.

praetorian

11-12-2012, 03:17 PM

very thanks Praetorian.

Is properly as you described.

But my goal is to create a 2d camera for zooming and translating.

For this in another post i asked if glortho returns a matrix.

How i can get a matrix from an eye point that i can translate or go ahead(zoom in) or go far(zoom out)

I wish use only opengl function, not glut or other.

and I wish using matrixes,shader and vbo , is a project "like" acrobat reader , i use it for text drawing and other (lines and points)in opengl.

isn't the same to multiply the points for the inverse of the modelview matrix (in this case the transpose of modelviewmatrix )

Thanks.

It sounds like you're trying to do too many things at once. First focus on zooming.

I don't see any problem using glOrtho to implement zooming/panning for 2d as it works fine for me.

glViewport( 0, 0, cx, cy);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho( xMin, xMax, yMin, yMax, -1.0, 1.0);

glMatrixMode( GL_MODELVIEW );

glLoadIdentity();

Just change the xmin,xMax,yMin,yMax to zoom in, zoom out and pan the view space. cx,cy are your window dimensions.

At any point call gluUnProject to convert local to project coordinates. I don't use Qt but it should be same as Windows

// Given local coordinate return project coordinate

CPoint3D COGLView::CoordinateUnProject(CPoint3D *point)

{

CPoint3D result;

GLdouble modelMatrix[16];

GLdouble projMatrix[16];

GLint viewport[4];

GLdouble objx, objy, objz;

glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);

glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);

glGetIntegerv(GL_VIEWPORT, viewport);

gluUnProject(point->x, point->y, point->z, modelMatrix, projMatrix, viewport, &objx, &objy, &objz);

result.x = (double)objx;

result.y = (double)objy;

result.z = (double)objz;

return result;

}

Where CPoint3D is a point class defined by my vector math library. Now use the returned point to implement picking. No glut needed by I'm not familiar with vbo/shaders.

giuseppe500

11-13-2012, 12:39 AM

but

gluUnProject(point->x, point->y, point->z, modelMatrix, projMatrix, viewport, &objx, &objy, &objz);

is not the same as MVP->transpose() * point?

in this case i can use the transpose, because is a square matrix, else i must use the inverse.

is correct?

thanks.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.