opengl+delphi 鼠标拾取(5)

2021-04-06 05:22

opengl+delphi 鼠标拾取

AME) shl 1), 2, 2, @viewportCoords);

// Next, we just call our normal gluPerspective() function, exactly as we did on startup.
// This is to multiply the perspective matrix by the pick matrix we created up above.

gluPerspective(45.0, viewportCoords[2]/viewportCoords[3], 0.5, 150.0);

glMatrixMode(GL_MODELVIEW);// Go back into our model view matrix

glDraw();// Now we render into our selective mode to pinpoint clicked objects

// If we return to our normal render mode from select mode, glRenderMode returns
// the number of objects that were found in our specified region (specified in gluPickMatrix())

objectsFound := glRenderMode(GL_RENDER);// Return to render mode and get the number of objects found

glMatrixMode(GL_PROJECTION);// Put our projection matrix back to normal.
glPopMatrix();// Stop effecting our projection matrix

glMatrixMode(GL_MODELVIEW);// Go back to our normal model view matrix

// PHEW! That was some stuff confusing stuff. Now we are out of the clear and should have
// an ID of the object we clicked on. objectsFound should be at least 1 if we found an object.

if (objectsFound > 0) then
begin
// If we found more than one object, we need to check the depth values
// of all the objects found. The object with the LEAST depth value is
// the closest object that we clicked on. Depending on what you are doing,
// you might want ALL the objects that you clicked on (if some objects were
// behind the closest one), but for this tutorial we just care about the one
// in front. So, how do we get the depth value? Well, The selectionBuffer
// holds it. For every object there is 4 values. The first value is
// "the number of names in the name stack at the time of the event, followed
// by the minimum and maximum depth values of all vertices that hit since the
// previous event, then followed by the name stack contents, bottom name first." - MSDN
// The only ones we care about are the minimum depth value (the second value) and
// the object ID that was passed into glLoadName() (This is the fourth value).
// So, [0 - 3] is the first object's data, [4 - 7] is the second object's data, etc...
// Be carefull though, because if you are displaying 2D text in front, it will
// always find that as the lowest object. So make sure you disable text when
// rendering the screen for the object test. I use a flag for RenderScene().
// So, lets get the object with the lowest depth!

// Set the lowest depth to the first object to start it off.
// 1 is the first object's minimum Z value.
// We use an unsigned int so we don't get a warning with selectBuffer below.
lowestDepth := selectBuffer[1];

// Set the selected object to the first object
to start it off.
// 3 is the first object's object ID we passed into glLoadName().
selectedObject := selectBuffer[3];

// Go through all of


opengl+delphi 鼠标拾取(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:神奇的滚筒

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: