3

i try to implement a coordinate picking function with OpenGL ES 2.0. I cannot implement the two versions i've implemented in my desktop version.

Version 1 is to render every triangle in a unique color, which represent the index of the triangle and than to calculate the coordinate with an raycast. This version doesn't work, because in the OpenGL ES GLSL Version 1.0 is no variable GL_PrimitiveID an bitwise shifting is also not possible.

Version 2 is to render the coordinate as the value of a floating-point texture, but floating-point texture is not available in OpenGL ES 2.0.

Has anybody another idea what I can implement? I don't want to raycast every triangle, because it's not so performant.

Thanks for help and any ideas.

user1844213
  • 47
  • 1
  • 6

2 Answers2

1

Another way to implement picking of coordinates is ray picking of objects. It is considered to be the best method to pick 3D objects from 2D screen coordinates. You won't have to render scene with unique colors of objects and pick colors to determine intersection.

I've implemented picking of 3D objects with the help of this great tutorial: http://android-raypick.blogspot.com/2012/04/first-i-want-to-state-this-is-my-first.html

After some optimizations of algorithm (I've made a comment in blog post) performance is not an issue in my case. To test performance I'm picking a 3D model with 3000+ triangles and it is fast. In real cases, for collision detection you can use models with very simplified geometry.

keaukraine
  • 5,315
  • 29
  • 54
  • I know this tutorial and I think ray picking is not fast enough. I have models with 300.000-1.000.000 triangles and I need the coordinate on the triangle. simple object picking is not the problem, but I have one huge model and with ray picking I have to check each triangle and this is realy slow. My goal is to move an object over the surface. – user1844213 Nov 22 '12 at 07:55
  • But as I stated, for object picking you can use model with simplified geometry. Of course, if you really need pixel-perfect and precise picking then you pick objects using not simplified mesh but full 1000000 triangles. – keaukraine Nov 22 '12 at 08:03
1

when using ray casting, testing each primitive against the ray is a bad idea anyway. you should build a hierarchical representation of your model, like a bounding volume tree and perform accelerated ray-casting tests. you have to update this tree every time your model changes of course.

returning to your original method of rendering a separate color for each triangle, it seems that you need to allocate another vertex attribute (color / index) and you have to repeat shared vertices for each triangle. the number of vertices will be 3*number of triangles, but this will solve your problem.