Clicking into a 3D world

BlitzMax Forums/BlitzMax OpenGL Programming/Clicking into a 3D world

Here's the gluUnProject code translated into BlitzMax:

*****

Method selectPiece(x, y)
Print "selectPiece(" + x + "," + y + ")"

Local viewport:Int[4]
Local modelview:Double[16]
Local projection:Double[16]
Local winX:Float, winY:Float, winZ:Float
Local posX:Double, posY:Double, posZ:Double

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

winX = Float( MouseX() )
winY = Float( viewport[3] - MouseY() )

glReadPixels( x, Int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, Varptr winZ )

gluUnProject( winX, winY, winZ, modelview, projection, viewport, Varptr posX, Varptr posY, Varptr posZ )

Print "You clicked on " + posX +","+ posY +","+ posZ

End Method

*****



I think I like the Selection Mode method better, though. This method requires you to figure out what model is located at that 3D point, while using Selection Mode can tell you what model (or group of polys, or whatever) was rendered at the location the user clicked on.