Breakdown of Leap Motion classes
This blog post isn't really for reading, it's more about me trying to understand what everything in the classes do so that it will be easier to write my own classes when it comes to decoupling them. It's mainly a break down, line by line of how the bottom two classes, which deal with the actual frames/data work.
Leap Service Provider
Order of method calls in Unity. |
Start()
- checkShouldEnableHeadMounted()
- This checks to see if VR is enabled and whether or not head mounted is enabled and logs an error if both are true. This is because by default they enforce that you use head mount when in virtual reality. This is an important thing to note for when I go to implement a table mounted version of the system. Would have to disable this check.
- Returns true if we should enable head mount, false if not necessary
- createController()
- "Create an instance of a Controller, initialize its policy flags and subscribe to connection event" - Leap Motion
- Create the instance of the controller and then if its connected we call the initializeFlags
- initializeFlags()
- "Initializes the Leap Motion policy flags. The POLICY_OPTIMIZE_HMD flag improves tracking for head-mounted devices."
- If head mounted then set policy flag for optimizing HMD otherwise clear it.
- I wasn't really sure what policies were so after some googling I think they are to do with C++, someone on SO defined it as: Policies are classes (or class templates) to inject behavior into a parent class, typically through inheritance. It sounds like it's kind of like dependency injection in Java i think?
- The above screenshot is from the Leap motion website and explains a bit about the ones that they use in Leap. The initialiseFlags is only referring to the optimize HMD flag in this case though.
- Start() ends by creating 4 new frame objects called respectively:
- _transformedUpdateFrame
- _transformedFixedFrame
- _untransformedUpdateFrame
- _untransformedFizedFrame
Update()
- Update the fixed offset which is a "smoothed float" class created by Unity which is made to make the movements between states more fluid (i think)
- DispatchUpdateFrameEvent(transforedfixedframe)
- If the updateFrame event is not null fire the current frame to unity
- If using interpolation:
- GetInterpolatedFrameFromTime
- Takes a frame to fill, a time and a source time. (untransformedUpdateFrame). Is this where we get the data from the controller and put in frame?
- Else:
- Similar to previous method but doesn't take any time values. Just a frame to fill.
- We get the timeStamp
- Not really sure what this is/what it does.
- if (_untransformedUpdateFrame != null)
- transformFrame(_untransform, _transform)
- Takes a source frame and a destination frame and if we are using temporalWarping apply a bunch of transforms to the LeapTransform.
- This is the method where we are currently mirroring the frame by mirroring the LeapTransform
- At the end we copy the data from the source frame into the destination frame with the transform applied. I assume this is because frames are mutable so we should save a copy of it.
- DispatchUpdateFrameEvent
- Again fire the frame into Unity
FixedUpdate()
Occurs before Update and the method calls are almost exactly the same as Update.
IHandModel/Rigged Hands
"Methods that drive transform based on data"
UpdateHand()
- First iterate through fingers and update them
- if(palm!= null)
- get the center and rotation using the skeletahand implementation of the abstract ihandmodel and if there is a rigid body use the movePosition/moveRotation methods otherwise directly set the transform of the palm.
- Potential for mirroring/translating could occur in this method and would be interesting to try out.
- if(forearm!=null)
- Get the collider
- Initialise the capsule
- Update radius and height using methods from skeletal hand
- Move like palm depending on whether or not there is a rigid body attached.
This method plus Skeletal Hands etc seems to be what I will need for doing this myself.
\
Comments
Post a Comment