Выбор объектов возвращает слишком много объектов - OpenGL
#39634288
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
Делаю выбор объекта.
Рисую объекты:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26.
...
GL.InitNames()
...
Dim temp As Integer
temp = 1
For i As Integer = 1 To NM
GL.PushName(temp)
GL.Begin(BeginMode.Polygon)
GL.Vertex3(Xstart - r, Ystart + Rad / 2, Zstart + Depth)
GL.Vertex3(Xstart - r, Ystart - Rad / 2, Zstart + Depth)
GL.Vertex3(Xstart, Ystart - Rad, Zstart + Depth)
GL.Vertex3(Xstart + r, Ystart - Rad / 2, Zstart + Depth)
GL.Vertex3(Xstart + r, Ystart + Rad / 2, Zstart + Depth)
GL.Vertex3(Xstart, Ystart + Rad, Zstart + Depth)
GL.End()
GL.Begin(BeginMode.Quads)
GL.Vertex3(Xstart - r, Ystart + Rad / 2, Zstart)
GL.Vertex3(Xstart - r, Ystart - Rad / 2, Zstart)
GL.Vertex3(Xstart - r, Ystart - Rad / 2, Zstart + Depth)
GL.Vertex3(Xstart - r, Ystart + Rad / 2, Zstart + Depth)
GL.End()
GL.PopName()
temp = temp + 1
...
Next i
Есть функция, которая возникает при нажатии мышки:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43.
Public Function RetrieveObjectID(x As Integer, y As Integer) As Integer
Dim objectsFound As Integer = 0
Dim viewportCoords(4) As Integer
Dim selectBuffer(4 * CountHex) As Integer
GL.SelectBuffer(4 * CountHex, selectBuffer)
GL.GetInteger(GetPName.Viewport, viewportCoords)
GL.MatrixMode(MatrixMode.Projection)
GL.PushMatrix()
GL.RenderMode(RenderingMode.Select)
GL.LoadIdentity()
Glu.PickMatrix(x, viewportCoords(3) - y, 2, 2, viewportCoords)
Glu.Perspective(1, 3 / 1, 0.1, 10000)
GL.MatrixMode(MatrixMode.Modelview)
Call RenderScene()
objectsFound = GL.RenderMode(RenderingMode.Render)
GL.MatrixMode(MatrixMode.Projection)
GL.PopMatrix()
GL.MatrixMode(MatrixMode.Modelview)
'MsgBox("Найдено под курсором:" & objectsFound)
If objectsFound > 0 Then
Dim lowestDepth As Integer
lowestDepth = selectBuffer(1)
Dim selectedObject As Integer
selectedObject = selectBuffer(3)
For i As Integer = 1 To objectsFound - 1
If selectBuffer(i * 4 + 1) < lowestDepth Then
lowestDepth = selectBuffer(i * 4 + 1)
selectedObject = selectBuffer(i * 4 + 3)
End If
Next i
Return selectedObject
End If
Return 0
End Function
Но по не понятной мне причине возвращает что под курсором 50 объектов, хотя по задумке должен быть только 1. Подскажите что делаю не так?
|
|