Leap points to Unity space
Post Holger & Tobi meeting:
- Work on leap to unity conversions
- Visualize the interaction box/sensor frustum/ even potentially rift viewing space??
- Move on to the decoupling hands from data
- Step 1 have hands just in front of you
- Step 2 mimic movement for chris
Leap Point to Unity
So what I now know is that when leap returns a position vector, the point is relative to the origin of the leap controller rather than an absolute point. To convert this I followed the following steps:
- Divide the vector by 1000 to convert from mm to m
- Negate the Z value to change from rh to lf coordinate system
- Find the unity position of the leap controller's origin
- Add the origin to the vector
Drawing Bounds
This proved to be more of a challenge for me then I expected. I was struggling to work out how to draw these straight lines at run time using the GL library. GL is a basic graphics tool which can be used to draw lines and triangles (potentially more I'm not sure).
I started with the interaction box as it had the most information readily available. The IB class had fields for the center vector aswell as the height, width and depth of the box. The way GL works is it draws lines between pairs of vectors so I needed to work out the position vectors of each of the 8 corners so that I could draw each edge of the box. This was easy to work out because I had all the information necessary given to me. For example the Top back left point would equal (origin.x-.5 width, origin.y + .5height, origin.z-.5depth). After this I was still having issues with any of the graphics actually showing up so I changed two things.
- The first was that I nicked the bounds shader from Sam's demo. I did a little tiny bit of reading into what a shader is but I still don't really understand why it was necessary to use a Shader in his demo and why I need a shader at all to draw a line but for now it seems like a good bandaid fix.
- The second and main reason it wasn't rendering was because I'd put my code in the OnPostRender() method because I'd read that if the graphics were done before rendering the camera might wipe it out so it's best to do it after the rendering has done. What I hadn't realised was that this method would only be called if the script was attached to an enabled camera object. Once I realized this I moved the script and managed to have my Interaction box working. (Although right now it's not fully centered over the leap controller model, I think this must be a problem with the model placing rather than the interaction box coordinates)
- Vertical angle in degrees
- Horizontal angle in degrees
- Top/Origin point
- Depth
Diagram of frustum shape |
I still have to add the near Z plane to the frustum bounds and the leap motion frustum but I think these both will be relatively trivial now that I have the basics down.
Comments
Post a Comment