0

I'm developing a medical app that involves android OpenGL for some data visualization. In my app, I have a complex brain object (with some 80000 vertices) and a small sphere. I'm trying to figure out a way where I can move the centroid of that sphere to one of the vertices on the brain.

The way I see it, this can be broken down into two problems (both of which I don't have great solutions to). The first problem is determining which vertex I want to move the sphere to. Ideally, it would be great if I could simply touch a location on the brain and select the closest vertex that way. I've tried converting window coordinates to world coordinates using glUnProject unsuccessfully. Another idea I had was to simply take my camera's location, and find the closest vertex to the camera.

The 2nd problem is determining how to move the sphere to that vertex. This is the part that I thought I had sound logic, but it isn't working correctly. I have the sphere's initial position. When the user touches the brain (for my first attempt described earlier) or moves the camera (for my second attempt described earlier), I basically iterated through all the vertices of the brain, and using the distance formula, found the vertex with the minimum distance from my either my touch location or my camera. I saved this vertex and then proceeded to translate the sphere. Basically, my translation involved taking the new vertex, subtracting the sphere's current position, and translating the sphere by that amount. I'd then save the new current position of the sphere as the new vertex's position.

For me, the biggest headscratcher from this all is that my sphere doesn't translate to any points on the brain. It moves when I tell it to, and generally in the right direction, but it's centroid doesn't sit on any of the vertices

So all in all, these are my 2 big questions:

  1. For my 1st problem, does anyone have any opinions on which might be a better way of picking a vertex (which one is easier or more efficient?). If someone thinks the 1st way is better, are there in depth tutorials on the parameters of glUnProject? I'm having trouble understanding the "view" parameter.
  2. For my 2nd problem, is there anything wrong with my logic? Once I find a vertex, i just perform a linear translation on the sphere and it should move to that new vertex, correct?
genpfault
  • 51,148
  • 11
  • 85
  • 139
brohan322
  • 358
  • 1
  • 12

1 Answers1

0

Never mind, turns out scale factors were lost in my code and I didn't apply them, now the points are sitting in the right places.

brohan322
  • 358
  • 1
  • 12
  • Still, if anyone can give a good Android walkthrough of how to convert world coordinates to opengl coordinates, including an explanation of glUnProject, it would be greatly appreciated – brohan322 Jul 07 '15 at 20:30