Toss the pick operation for two days ...

Source: Internet
Author: User

Aha, it's been a couple of days. OpenGL on the pick operation, finally found a problem.

Can be picked up at the beginning, but the record in the Selectbuffer is always wrong, began to think it was just picking up the function problem, and then carefully read the red book, follow the steps in red Book to go through, or error ... And then began to consider whether it was before using the Glulookat view transformation problem, simply do not use this function, that is, the view transformation by default, or error ... Then constantly change the code, constantly debug ... Finally found a problem, ya, in

Glupickmatrix (Point.x,viewport[3]-point.y,5.0,5.0,viewport);
Gluperspective (Double) m_wide/(double) m_heigth,0.1,2000);

These two functions cannot have any matrix operations before the Drawpoint function. = =, this sentence seems to be a bit confusing, in detail what does it mean?

My render function is renderscene, there are some drawpoint, drawaxes and so on, if I have a translation, rotation and other operations before the Drawpoint, Gluperspective after the Drawpoint pickup, pick the ray will not go through the mouse click on the pixel location, why, because the rendering when I translate ah, and pick up when there is no such translation, of course, the problem.

It is necessary to realize the software rasterization Ah, suddenly feel the foundation is not shake ... It's hard to say that OpenGL's fixed pipeline is difficult to use T T

1Gluint Selectbuf [ +];2 glint hits;3Glint Viewport [4];4 Glgetintegerv (gl_viewport,viewport);5Glselectbuffer ( +, selectbuf);6(void) Glrendermode (gl_select);7 glinitnames ();8Glpushname (0);9 Glmatrixmode (gl_projection);Ten Glpushmatrix (); One glloadidentity (); AGlupickmatrix (point.x,viewport[3]-point.y,5.0,5.0, viewport); -Gluperspective (45.0f, (Double) m_wide/(Double) M_heigth,0.1, -);  - Drawpoint (gl_select); the Glmatrixmode (gl_projection); - Glpopmatrix (); - Glflush (); -hits =Glrendermode (gl_render); + Processselect (HITS,SELECTBUF); -Glmatrixmode (Gl_modelview);

Then add Glulookat, do not change the words no problem, if the rotation problem, directly without glulookat, the problem is in Drawpoint before, Renderscene can not have the translation of things like ....

Toss the pick operation for two days ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.