2
votes

I know how to test intersection between a point and a triangle.

...But i dont get it, how i can move the starting position of the point onto the screen plane precisely by using my mouse coordinates, so the point angle should change depending on where mouse cursor is on the screen, also this should work perfectly no matter which perspective angle i am using in my OpenGL application, so the point angle would be different on different perspective angles... gluPerspective() is the function im talking about.

3
What do you mean "move the starting position of the point"? A point is a point. Get my point? ;)ralphtheninja
Can you clarify what your question is? You're asking how you can move a point precisely?Drew Dormann

3 Answers

2
votes

Well, gonna take a shot and guess what you mean. The guess is that you would like to pick objects with your mouse. Check out:

glUnProject.

This transforms the screen coordinates back into 3d world coordinates.

Google has more information if you run into problems.

Cheers !

1
votes

yes, i want to move the point on the screen plane, so for example i could render a cube on that point where my mouse is currently, by using 3d coordinates, and then i shoot a line from that position to the place where my mouse is pointing, so it would hit the triangle in my 3d world, and that how i could select that object with mouse.

sorry for being unclear :/

--

Edit: yay i got it working with that nehe tutorial! thanks, i didnt know it would be that easy!

This is the code im using now and it works great:

void GetOGLPos(int x, int y, GLdouble &posX, GLdouble &posY, GLdouble &posZ){
    GLint viewport[4];
    GLdouble modelview[16];
    GLdouble projection[16];
    GLfloat winX, winY, winZ;

    glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    glGetDoublev(GL_PROJECTION_MATRIX, projection);
    glGetIntegerv(GL_VIEWPORT, viewport);

    winX = (float)x;
    winY = (float)viewport[3]-(float)y;
    glReadPixels(x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);

    gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
}
0
votes

You need to generate a ray (line) passing through the mouse location perpendicular to the screen.

I would recommend getting some basic information on 3d geometry and 2d projections before you go much further.

Check out Wikipedia

A book search on Google has come up with quite a few titles.

Foley & Van Dam though is the definitive book - here on Amazon.co.uk or here on Amazon.com