LeapScene.h
Go to the documentation of this file.
1 /******************************************************************************\
2 * Copyright (C) Leap Motion, Inc. 2011-2013. *
3 * Leap Motion proprietary and confidential. Not for distribution. *
4 * Use subject to the terms of the Leap Motion SDK Agreement available at *
5 * https://developer.leapmotion.com/sdk_agreement, or another agreement between *
6 * Leap Motion and you, your company or other organization. *
7 \******************************************************************************/
8 
9 #if !defined(__LeapScene_h__)
10 #define __LeapScene_h__
11 
12 #include "Leap.h"
13 #include "LeapUtil.h"
14 
15 #if defined(LEAP_SCENE_USE_UTIL_GL)
16  #include "LeapUtilGL.h"
17 #endif
18 
19 // define this macro if you want SceneObject::GetAs<> to use
20 // simple internally implemented typeid checks
21 // instead of dynamic casting.
22 // some code bases prohibit the use of dynamic_cast.
23 // this provides a basic alternative.
24 // see the comment at SceneObject::GetAs<> below
25 #undef LEAP_SCENE_NO_DYNAMIC_CAST
26 
27 #undef LEAP_EXPORT
28 #define LEAP_EXPORT
29 #undef LEAP_EXPORT_CLASS
30 #define LEAP_EXPORT_CLASS
31 #undef LEAP_EXPORT_PLUGIN
32 #define LEAP_EXPORT_PLUGIN
33 
34 namespace Leap {
35 
38 class Scene;
39 
42 
51 
53 struct SceneRay
54 {
55  SceneRay() {}
56 
57  SceneRay( const Vector& vOrigin, const Vector& vDirection ) : m_vOrigin( vOrigin ), m_vDirection( vDirection ) {}
58 
60  Vector CalcPointOn( float fDistFromOrigin ) const { return m_vOrigin + m_vDirection * fDistFromOrigin; }
61 
63  void Transform( const Matrix& mtxTransform )
64  {
65  m_vOrigin = mtxTransform.transformPoint( m_vOrigin );
67  }
68 
69  SceneRay Transformed( const Matrix& mtxTransform ) const
70  {
71  return SceneRay( mtxTransform.transformPoint( m_vOrigin ),
72  mtxTransform.transformDirection( m_vDirection ) );
73  }
74 
77 };
78 
81 {
82 #if defined(LEAP_SCENE_USE_UTIL_GL)
83  void DebugDrawGL( float fHitSphereSize ) const;
84 #endif
85 
90  SceneObjectPtr m_pHitObject;
91 };
92 
95 {
96  kIT_Rotation = 1 << 0,
97  kIT_Translation = 1 << 1,
98  kIT_Scale = 1 << 2,
100  kIT_IsSelected = 1 << 4
101 };
102 
107 {
108  friend class Scene;
109 
110 protected:
111  SceneInteraction() : m_fScale(1), m_uiFlags(0) {}
112 
113 public:
115  bool HasSelectionChange() const { return (m_uiFlags & kIT_SelectionChange) != 0; }
116  bool HasRotation() const { return (m_uiFlags & kIT_Rotation) != 0; }
117  bool HasTranslation() const { return (m_uiFlags & kIT_Translation) != 0; }
118  bool HasScale() const { return (m_uiFlags & kIT_Scale) != 0; }
119 
120  bool HasInteraction( eInteractionType interactionType ) const
121  {
122  return ((m_uiFlags >> static_cast<uint32_t>(interactionType)) & 1) != 0;
123  }
124 
125  void ClearSelectionChange() { m_uiFlags &= ~kIT_SelectionChange; }
126  void ClearRotation() { m_uiFlags &= ~kIT_Rotation; }
127  void ClearTranslation() { m_uiFlags &= ~kIT_Translation; }
128  void ClearScale() { m_uiFlags &= ~kIT_Scale; }
129 
130  void ClearInteraction( eInteractionType interactionType )
131  {
132  m_uiFlags &= ~(1 << static_cast<uint32_t>(interactionType));
133  }
134 
135  bool HasAnyInteraction() const
136  {
137  static const uint32_t kInteractionMask = kIT_SelectionChange |
138  kIT_Rotation |
140  kIT_Scale;
141  return (m_uiFlags & kInteractionMask) != 0;
142  }
143 
145  bool IsSelected() const { return (m_uiFlags & kIT_IsSelected) != 0; }
146  Matrix GetRotation() const { return LeapUtil::ExtractRotation( m_mtxTransform ); }
147  float GetScale() const { return m_fScale; }
148  Vector GetTranslation() const { return m_mtxTransform.origin; }
149  Matrix GetTransform() const { return m_mtxTransform; }
150 
152  const SceneObjectPtr& GetObject() const { return m_pObject; }
153 
154 private:
156  SceneObjectPtr m_pObject;
157  float m_fScale;
158  uint32_t m_uiFlags;
159 };
160 
163 {
164  SceneContactPoint() : m_iPointableID(-1) {}
165  SceneContactPoint( const Vector& vPoint, int iPointableID ) : m_vPoint( vPoint ), m_iPointableID( iPointableID ) {}
168 };
169 
172 {
173 public:
174  enum eFlag
175  {
176  kF_UpdateRayCast = 1 << 0,
177  kF_UpdateContact = 1 << 1
178  };
179 
180  enum
181  {
182  kMaxObjects = 512,
183  kMaxRayHits = 32,
184  kInteractionQueueLength = 32
185  };
186 
187  LEAP_EXPORT Scene();
188 
189  LEAP_EXPORT virtual ~Scene()
190  {
191  Reset();
192  }
193 
200  template<class ObjectClass>
201  ObjectClass* AddObject()
202  {
203  return allocateObject<ObjectClass>();
204  }
205 
211  LEAP_EXPORT void RemoveObject( SceneObject* pObject );
212 
216  LEAP_EXPORT void Reset();
217 
218 #if defined(LEAP_SCENE_USE_UTIL_GL)
219  LEAP_EXPORT void RayHitsDebugDrawGL() const;
220 #endif
221 
222  const SceneObjectPtr& GetObjectByIndex( int idx ) const
223  {
224  return (static_cast<uint32_t>(idx) < m_uiNumObjects) ? m_apObjects[idx] : SceneObjectPtr::Null();
225  }
226 
227  uint32_t GetNumObjects() const { return m_uiNumObjects; }
228 
230  const SceneObjectPtr& TestRayHit( const SceneRay& ray ) const;
231 
239  LEAP_EXPORT void Update( const Frame& frame, float fDeltaTimeSeconds );
240 
242  LEAP_EXPORT void DeselectAll();
243 
251  void SetFrameTransform( const Matrix& mtxFrameTransform ) { m_mtxFrameTransform = mtxFrameTransform; }
252 
253  const Matrix& GetFrameTransform() const { return m_mtxFrameTransform; }
254 
255  void SetFrameScale( float fFrameScale ) { m_fFrameScale = fFrameScale; }
256 
257  float GetFrameScale() const { return m_fFrameScale; }
258 
261  void SetPointableRadius( float fRadius ) { m_fPointableRadius = fRadius; }
262 
263  float GetPointableRadius() const { return m_fPointableRadius; }
264 
266  void SetSelectHitTime( float fSelectHitTime ) { m_fSelectHitTime = fSelectHitTime; }
267 
268  float GetSelectHitTime() const { return m_fSelectHitTime; }
269 
272  void SetUserData( void* pUserData ) { m_pUserData = pUserData; }
273 
274  void* GetUserData() const { return m_pUserData; }
275 
277  float GetDeltaTime() const { return m_fDeltaTimeSeconds; }
278 
280  uint32_t GetNumRayHits() const { return m_uiNumRayHits; }
281 
283  const SceneRayHit* GetRayHit( uint32_t idx ) const
284  {
285  return idx < m_uiNumRayHits ? &(m_aRayHits[idx]) : NULL;
286  }
287 
289  uint32_t GetNumQueuedInteractions() const { return m_uiNumQueuedInteractions; }
290 
292  const SceneInteraction* GetQueuedInteraction( uint32_t idx ) const
293  {
294  return idx < m_uiNumQueuedInteractions ? &(m_aInteractionQueue[idx]) : NULL;
295  }
296 
298  Vector TransformFramePoint( const Vector& vFramePoint )
299  {
300  return m_mtxFrameTransform.transformPoint( vFramePoint * m_fFrameScale );
301  }
302 
304  Vector TransformFrameDirection( const Vector& vFrameDirection )
305  {
306  return m_mtxFrameTransform.transformDirection( vFrameDirection );
307  }
308 
309  uint32_t GetFlags() const { return m_uiFlags; }
310 
311  bool GetUpdateContact() const { return (m_uiFlags & kF_UpdateContact) != 0; }
312 
313  void SetUpdateContact( bool bUpdateContact )
314  {
315  m_uiFlags = bUpdateContact ? (m_uiFlags | kF_UpdateContact) : (m_uiFlags & ~kF_UpdateContact);
316  }
317 
318  bool GetUpdateRayCast() const { return (m_uiFlags & kF_UpdateRayCast) != 0; }
319 
320  void SetUpdateRayCast( bool bUpdateRayCast )
321  {
322  m_uiFlags = bUpdateRayCast ? (m_uiFlags | kF_UpdateRayCast) : (m_uiFlags & ~kF_UpdateRayCast);
323  }
324 
325  // internal methods for Scene
326 private:
327  void updateSelectionAndContact( const Frame& frame );
328 
329  void queueDeselectAll();
330 
331  bool queueInteraction( const SceneInteraction& interaction )
332  {
333  if ( m_uiNumQueuedInteractions < static_cast<uint32_t>(kInteractionQueueLength) )
334  {
335  m_aInteractionQueue[m_uiNumQueuedInteractions++] = interaction;
336  }
337 
338  return false;
339  }
340 
342  {
343  // release object references from the interaction queue
344  for ( uint32_t i = 0; i < m_uiNumQueuedInteractions; m_aInteractionQueue[i++].m_pObject.Release() );
345  m_uiNumQueuedInteractions = 0;
346  }
347 
349  {
350  // release object references from the ray hits
351  for ( uint32_t i = 0; i < m_uiNumRayHits; m_aRayHits[i++].m_pHitObject.Release() );
352  m_uiNumRayHits = 0;
353  }
354 
355  void updateInteraction( const Frame& frame );
356 
357  void processPendingRemovals();
358 
359  bool testRayHitClosest( SceneRayHit& hitResult );
360 
361  void updateContact( const SceneContactPoint& testPoint );
362 
363  template<class T>
365  {
366  if ( m_uiNumObjects < static_cast<uint32_t>(kMaxObjects) )
367  {
368  if ( T* pObject = new T() )
369  {
370  pObject->m_pScene = this;
371  pObject->m_serial = m_uiNextSerial++;
372  pObject->m_index = static_cast<uint16_t>(m_uiNumObjects);
373  m_apObjects[m_uiNumObjects++] = SceneObjectPtr(pObject);
374 
375  return pObject;
376  }
377  }
378 
379  return NULL;
380  }
381 
382  void deallocateObject( uint32_t idxToRemove );
383 
384 private:
385  void* m_pUserData;
389 
392 
393  SceneObjectPtr m_apObjects[kMaxObjects];
394  SceneRayHit m_aRayHits[kMaxRayHits];
395  SceneInteraction m_aInteractionQueue[kInteractionQueueLength];
396 
397  uint32_t m_uiNumObjects;
398  uint32_t m_uiNumRayHits;
401  uint32_t m_uiNextSerial;
402  uint32_t m_uiFlags;
403 }; // Scene
404 
415 {
417 
418  // force 32 bit size
419  kSOT_Invalid = 0x7fffffff
420 };
421 
426 {
427  friend class Scene;
428 
429 public:
431 
433  {
434  static uint32_t s_nextID = kSOT_SceneObject + 1;
435  return static_cast<eSceneObjectType>( s_nextID + 1 );
436  }
437 
438  enum { kMaxContactPoints = 5 };
439 
440 public:
442  : m_pUserData(NULL),
443  m_paContactPoints( m_aContactPoints ),
444  m_paLastContactPoints( m_aContactPoints + kMaxContactPoints ),
445  m_fTotalHitTime(0.0f),
446  m_fScale(1.0f),
447  m_uiNumPointing(0),
448  m_uiNumContacts(0),
449  m_uiLastNumContacts(0),
450  m_uiHasInitialContact(0),
451  m_bSelected(false),
452  m_bPendingRemoval(false),
453  m_pScene(NULL)
454  {}
455 
456  virtual ~SceneObject() {}
457 
458 public:
460  LEAP_EXPORT virtual eSceneObjectType GetType() const = 0;
461 
462  LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const = 0;
463 
464  LEAP_EXPORT virtual bool TestSphereHit(const Vector& vTestPoint, float fTestRadius) const = 0;
465 
466 #if defined(LEAP_SCENE_USE_UTIL_GL)
467  LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const = 0;
468 #endif
469 
470  template<class T>
471  T* GetAs()
472  {
473 #if defined(LEAP_SCENE_NO_DYNAMIC_CAST)
474  // When relying on simple internal type ids GetAs() only works for exact type matches or up casts to the base type.
475  // this mechanism is provided as a simple alternative for code bases that prohibit the use of dynamic_cast.
476  // a complete, hierarchically correct type id system is beyond the scope of this code.
477  return (this && (GetType() == T::ObjectType() || GetType() == SceneObject::ObjectType())) ? static_cast<T*>(this) : NULL;
478 #else
479  return dynamic_cast<T*>(this);
480 #endif
481  }
482 
483  template<class T>
484  const T* GetAs() const
485  {
486  return const_cast<SceneObject*>(this)->GetAs<T>();
487  }
488 
489  const SceneObjectPtr& GetSceneObjectPtr() const
490  {
491  return (this && m_pScene) ? m_pScene->GetObjectByIndex(m_index) : SceneObjectPtr::Null();
492  }
493 
494  operator const SceneObjectPtr&() const
495  {
496  return GetSceneObjectPtr();
497  }
498 
500  uint32_t GetSerial() const { return m_serial; }
501 
502  Scene* GetScene() const { return m_pScene; }
503 
504  void Translate(const Vector& translation) { m_mtxTransform.origin += translation; }
505 
506  void Rotate(const Vector& axis, float angleRadians)
507  {
508  m_mtxTransform = m_mtxTransform * Matrix(axis, angleRadians);
509  }
510 
511  void Rotate(const Matrix& rotationMatrix)
512  {
513  m_mtxTransform = m_mtxTransform * LeapUtil::ExtractRotation( rotationMatrix );
514  }
515 
516  void Scale(float scaleMult)
517  {
518  m_fScale *= scaleMult;
519  }
520 
521  void Transform( const Matrix& mtxTransform )
522  {
523  m_mtxTransform = m_mtxTransform * mtxTransform;
524  }
525 
526  bool ApplyInteraction( const SceneInteraction& interaction )
527  {
528  if ( IsPendingRemoval() )
529  {
530  return false;
531  }
532 
533  if ( interaction.HasRotation() )
534  {
535  Rotate( interaction.GetRotation() );
536  }
537 
538  if ( interaction.HasTranslation() )
539  {
540  Translate( interaction.GetTranslation() );
541  }
542 
543  if ( interaction.HasScale() )
544  {
545  Scale( interaction.GetScale() );
546  }
547 
548  if ( interaction.HasSelectionChange() )
549  {
550  SetSelected( interaction.IsSelected() );
551  }
552 
553  return true;
554  }
555 
556  void SetCenter(const Vector& vCenter) { m_mtxTransform.origin = vCenter; }
557 
558  void SetRotation(const Vector& vAxis, float fAngleRadians)
559  {
560  m_mtxTransform.setRotation( vAxis, fAngleRadians );
561  }
562 
563  void SetRotation(const Matrix& rotationMatrix)
564  {
565  m_mtxTransform = Matrix( rotationMatrix.xBasis, rotationMatrix.yBasis, rotationMatrix.zBasis, m_mtxTransform.origin );
566  }
567 
568  void SetScale(float scale) { m_fScale = scale; }
569 
570  const Vector& GetCenter() const { return m_mtxTransform.origin; }
571 
572  const Matrix GetRotation() const { return Matrix( m_mtxTransform.xBasis, m_mtxTransform.yBasis, m_mtxTransform.zBasis ); }
573 
574  const Matrix& GetTransform() const { return m_mtxTransform; }
575 
576  float GetScale() const { return m_fScale; }
577 
578  bool IsSelected() const { return m_bSelected != false; }
579 
580  void SetSelected(bool selected)
581  {
582  m_bSelected = selected;
583  if ( !m_bSelected )
584  {
585  ClearHitTime();
586  }
587  }
588 
589  uint32_t GetNumContacts() const { return m_uiNumContacts; }
590 
591  uint32_t GetNumPointing() const { return m_uiNumPointing; }
592 
593  uint32_t GetLastNumContacts() const { return m_uiLastNumContacts; }
594 
595  bool HasInitialContact() const { return m_uiHasInitialContact != 0; }
596 
597  void ClearNumContacts() { m_uiNumContacts = 0; }
598 
599  void ClearNumPointing() { m_uiNumPointing = 0; }
600 
601  void ClearHitTime() { m_fTotalHitTime = 0.0f; }
602 
603  void ClearInitialContact() { m_uiHasInitialContact = 0; }
604 
605  void IncNumPointing() { m_uiNumPointing++; }
606 
607  void IncNumContacts(const SceneContactPoint& contactPoint)
608  {
609  if (m_uiNumContacts < kMaxContactPoints)
610  {
611  m_paContactPoints[m_uiNumContacts++] = contactPoint;
612  }
613  }
614 
615  void ClearHits()
616  {
617  m_uiNumContacts = 0;
618  m_uiLastNumContacts = 0;
619  m_uiHasInitialContact = 0;
620  m_uiNumPointing = 0;
621  m_fTotalHitTime = 0.0f;
622  }
623 
624  float GetTotalHitTime() const { return m_fTotalHitTime; }
625 
626  const SceneContactPoint* GetContactPoint(uint32_t uiIndex) const
627  {
628  return uiIndex < static_cast<uint32_t>(kMaxContactPoints) ? m_paContactPoints + uiIndex : NULL;
629  }
630 
631  const SceneContactPoint* GetLastContactPoint(uint32_t uiIndex) const
632  {
633  return uiIndex < static_cast<uint32_t>(kMaxContactPoints) ? m_paLastContactPoints + uiIndex : NULL;
634  }
635 
637  {
638  return m_uiHasInitialContact ? &m_initialContactPoint : NULL;
639  }
640 
641  const SceneContactPoint* GetContactPointByPointableID(int iPointableID) const
642  {
643  for ( uint32_t i = 0; i < m_uiNumContacts; i++ )
644  {
645  if ( m_paContactPoints[i].m_iPointableID == iPointableID )
646  {
647  return m_paContactPoints + i;
648  }
649  }
650 
651  return NULL;
652  }
653 
655  {
656  for ( uint32_t i = 0; i < m_uiLastNumContacts; i++ )
657  {
658  if ( m_paLastContactPoints[i].m_iPointableID == iPointableID )
659  {
660  return m_paContactPoints + i;
661  }
662  }
663 
664  return NULL;
665  }
666 
667  void* GetUserData() const { return m_pUserData; }
668 
669  void SetUserData( void* pUserData ) { m_pUserData = pUserData; }
670 
671  bool IsPendingRemoval() const { return m_bPendingRemoval != false; }
672 
674  Matrix GetWorldToObjectTransform() const { return LeapUtil::RigidInverse(m_mtxTransform); }
675 
676  Vector WorldToObjectPoint( const Vector& vPoint ) const
677  {
678  return LeapUtil::RigidInverse(m_mtxTransform).transformPoint( vPoint );
679  }
680 
681 protected:
683  {
684  m_uiLastNumContacts = m_uiNumContacts;
685  m_uiNumContacts = 0;
686 
687  SceneContactPoint* pTemp = m_paLastContactPoints;
688  m_paLastContactPoints = m_paContactPoints;
689  m_paContactPoints = pTemp;
690  }
691 
692 protected:
695  SceneContactPoint m_aContactPoints[kMaxContactPoints*2];
696  void* m_pUserData;
700  float m_fScale;
701 
706 
707  uint8_t m_bSelected;
708 
709 private:
711  uint16_t m_index;
712  uint32_t m_serial;
714 }; // SceneObject
715 
716 
721 {
722  for ( uint32_t i = 0, n = scene.GetNumQueuedInteractions(); i < n; i++ )
723  {
724  const SceneInteraction& interaction = *scene.GetQueuedInteraction( i );
725  interaction.GetObject()->ApplyInteraction( interaction );
726  }
727 }
728 
730 {
731 public:
735  static eSceneObjectType ObjectType() { static const eSceneObjectType s_type = NextObjectType(); return s_type; }
736 
737  LEAP_EXPORT virtual eSceneObjectType GetType() const { return ObjectType(); }
738 
740  : m_vSize( 1, 1, 1 )
741  {}
742 
743  LEAP_EXPORT virtual ~SceneBox() {}
744 
745  const Vector& GetSize() const { return m_vSize; }
746 
747  void SetSize( const Vector& vSize ) { m_vSize = vSize; }
748 
749  LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const;
750 
751  LEAP_EXPORT virtual bool TestSphereHit(const Vector& vTestPoint, float fTestRadius) const;
752 
753 #if defined(LEAP_SCENE_USE_UTIL_GL)
754  LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const;
755 #endif
756 
757 private:
759 }; // SceneBox
760 
762 {
763 public:
767  static eSceneObjectType ObjectType() { static const eSceneObjectType s_type = NextObjectType(); return s_type; }
768 
769  LEAP_EXPORT virtual eSceneObjectType GetType() const { return ObjectType(); }
770 
771  SceneCylinder() : m_fRadius( 1.0f ), m_fHeight( 1.0f ) {}
772 
773  virtual ~SceneCylinder() {}
774 
775  void SetRadius(float radius) { m_fRadius = radius; }
776 
777  void SetHeight(float height) { m_fHeight = height; }
778 
779  const Vector& GetAxis() const { return m_mtxTransform.yBasis; }
780 
781  float GetRadius() const { return m_fRadius; }
782 
783  float GetHeight() const { return m_fHeight; }
784 
785  LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const;
786 
787  LEAP_EXPORT virtual bool TestSphereHit(const Vector& vTestPoint, float fTestRadius) const;
788 
789 #if defined(LEAP_SCENE_USE_UTIL_GL)
790  LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const;
791 #endif
792 
793 private:
794  float m_fRadius;
795  float m_fHeight;
796 }; // SceneCylinder
797 
799 {
800 public:
804  static eSceneObjectType ObjectType() { static const eSceneObjectType s_type = NextObjectType(); return s_type; }
805 
806  LEAP_EXPORT virtual eSceneObjectType GetType() const { return ObjectType(); }
807 
808  SceneDisk() : m_fRadius( 1.0f ) {}
809 
810  virtual ~SceneDisk() {}
811 
812  void SetRadius(float radius) { m_fRadius = radius; }
813 
814  const Vector& GetNormal() const { return m_mtxTransform.zBasis; }
815 
816  float GetRadius() const { return m_fRadius; }
817 
818  LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const;
819 
820  LEAP_EXPORT virtual bool TestSphereHit(const Vector& vTestPoint, float fTestRadius) const;
821 
822 #if defined(LEAP_SCENE_USE_UTIL_GL)
823  LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const;
824 #endif
825 
826 private:
827  float m_fRadius;
828 }; // SceneDisk
829 
831 {
832 public:
836  static eSceneObjectType ObjectType() { static const eSceneObjectType s_type = NextObjectType(); return s_type; }
837 
838  LEAP_EXPORT virtual eSceneObjectType GetType() const { return ObjectType(); }
839 
841 
842  virtual ~ScenePlane() {}
843 
844  const Vector& GetNormal() const { return m_mtxTransform.zBasis; }
845 
846  LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const;
847 
848  LEAP_EXPORT virtual bool TestSphereHit(const Vector& vPoint, float fRadius) const;
849 
850 #if defined(LEAP_SCENE_USE_UTIL_GL)
851  LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const;
852 #endif
853 }; // ScenePlane
854 
856 {
857 public:
861  static eSceneObjectType ObjectType() { static const eSceneObjectType s_type = NextObjectType(); return s_type; }
862 
863  LEAP_EXPORT virtual eSceneObjectType GetType() const { return ObjectType(); }
864 
865  SceneSphere() : m_fRadius(1.0f) { }
866 
867  virtual ~SceneSphere() {}
868 
869  void SetRadius(const float& radius) { m_fRadius = radius; }
870 
871  float GetRadius() const { return m_fRadius; }
872 
873  LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const;
874 
875  LEAP_EXPORT virtual bool TestSphereHit(const Vector& vTestCenter, float fTestRadius) const;
876 
877 #if defined(LEAP_SCENE_USE_UTIL_GL)
878  LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const;
879 #endif
880 
881 private:
882  float m_fRadius;
883 }; // SceneSphere
884 
885 }; // namespace Leap
886 
887 #endif // __LeapScene_h__
const SceneRayHit * GetRayHit(uint32_t idx) const
access to a ray test hit that happened during the last update
Definition: LeapScene.h:283
uint8_t m_uiHasInitialContact
Definition: LeapScene.h:705
void ClearInteraction(eInteractionType interactionType)
Definition: LeapScene.h:130
uint32_t m_uiNumQueuedInteractions
Definition: LeapScene.h:399
Vector xBasis
Definition: LeapMath.h:1021
const Matrix GetRotation() const
Definition: LeapScene.h:572
Vector CalcPointOn(float fDistFromOrigin) const
returns a point that is the specified distance down the ray.
Definition: LeapScene.h:60
const Vector & GetAxis() const
Definition: LeapScene.h:779
Matrix GetWorldToObjectTransform() const
returns a transform for converting world space coordinates and direction to object space...
Definition: LeapScene.h:674
uint8_t m_uiLastNumContacts
Definition: LeapScene.h:704
static const SmartPointer & Null()
convenient static method for returning in cases where a null return value is needed.
Definition: LeapUtil.h:882
float GetHeight() const
Definition: LeapScene.h:783
bool HasScale() const
Definition: LeapScene.h:118
Vector m_vSize
Definition: LeapScene.h:758
LeapUtil::SmartPointer< SceneObject > SceneObjectPtr
Definition: LeapScene.h:41
void Rotate(const Matrix &rotationMatrix)
Definition: LeapScene.h:511
bool GetUpdateRayCast() const
Definition: LeapScene.h:318
uint32_t m_uiNumRayHits
Definition: LeapScene.h:398
void SetRadius(float radius)
Definition: LeapScene.h:775
void SetUserData(void *pUserData)
Definition: LeapScene.h:669
float GetDeltaTime() const
the last value of the fDeltatTimeSeconds argument passed to Update()
Definition: LeapScene.h:277
Vector GetTranslation() const
Definition: LeapScene.h:148
f
static eSceneObjectType ObjectType()
Definition: LeapScene.h:861
uint32_t GetFlags() const
Definition: LeapScene.h:309
Leap::Matrix RigidInverse(const Leap::Matrix &mtxTransform)
Definition: LeapUtil.h:117
virtual LEAP_EXPORT eSceneObjectType GetType() const
pure virtual methods requiring implementation in inheriting classes.
Definition: LeapScene.h:838
Vector transformDirection(const Vector &in) const
Definition: LeapMath.h:817
static eSceneObjectType ObjectType()
Definition: LeapScene.h:767
const SceneObjectPtr & GetSceneObjectPtr() const
Definition: LeapScene.h:489
uint32_t GetLastNumContacts() const
Definition: LeapScene.h:593
virtual ~ScenePlane()
Definition: LeapScene.h:842
const SceneObjectPtr & GetObject() const
scene object this interaction is associated with
Definition: LeapScene.h:152
uint16_t m_index
Definition: LeapScene.h:711
void Translate(const Vector &translation)
Definition: LeapScene.h:504
void SetRotation(const Vector &vAxis, float fAngleRadians)
Definition: LeapScene.h:558
Vector m_vDirection
Definition: LeapScene.h:76
void SetSize(const Vector &vSize)
Definition: LeapScene.h:747
contact point between a pointable (finger or tool) and a scene object.
Definition: LeapScene.h:162
virtual LEAP_EXPORT ~SceneBox()
Definition: LeapScene.h:743
void SetFrameScale(float fFrameScale)
Definition: LeapScene.h:255
void rotateContactPoints()
Definition: LeapScene.h:682
bool HasSelectionChange() const
convenient predicates for represented interaction types
Definition: LeapScene.h:115
uint32_t m_uiNumPendingRemovals
Definition: LeapScene.h:400
#define LEAP_EXPORT
Definition: LeapScene.h:28
void IncNumPointing()
Definition: LeapScene.h:605
uint32_t GetNumRayHits() const
the number of ray tests that resulted in hits from the last update
Definition: LeapScene.h:280
static eSceneObjectType ObjectType()
Definition: LeapScene.h:430
bool HasAnyInteraction() const
Definition: LeapScene.h:135
void SetRotation(const Matrix &rotationMatrix)
Definition: LeapScene.h:563
void DefaultProcessSceneInteractions(Scene &scene)
Definition: LeapScene.h:720
void SetPointableRadius(float fRadius)
Definition: LeapScene.h:261
Vector m_hitPoint
Definition: LeapScene.h:86
float m_fSelectHitTime
Definition: LeapScene.h:388
float m_fFrameScale
Definition: LeapScene.h:391
float GetRadius() const
Definition: LeapScene.h:781
void SetSelectHitTime(float fSelectHitTime)
the amount of time an object must be pointed at or touched before it is selected
Definition: LeapScene.h:266
static eSceneObjectType NextObjectType()
Definition: LeapScene.h:432
virtual ~SceneDisk()
Definition: LeapScene.h:810
void SetRadius(float radius)
Definition: LeapScene.h:812
const SceneContactPoint * GetContactPointByPointableID(int iPointableID) const
Definition: LeapScene.h:641
float GetPointableRadius() const
Definition: LeapScene.h:263
Vector TransformFrameDirection(const Vector &vFrameDirection)
transform a direction from the LeapAPI (e.g. Pointable::direction()) into scene space ...
Definition: LeapScene.h:304
uint32_t m_uiNextSerial
Definition: LeapScene.h:401
void Rotate(const Vector &axis, float angleRadians)
Definition: LeapScene.h:506
Definition: Leap.h:48
virtual LEAP_EXPORT eSceneObjectType GetType() const
pure virtual methods requiring implementation in inheriting classes.
Definition: LeapScene.h:806
bool queueInteraction(const SceneInteraction &interaction)
Definition: LeapScene.h:331
virtual LEAP_EXPORT eSceneObjectType GetType() const
pure virtual methods requiring implementation in inheriting classes.
Definition: LeapScene.h:863
const Vector & GetSize() const
Definition: LeapScene.h:745
Matrix GetRotation() const
Definition: LeapScene.h:146
float m_fDeltaTimeSeconds
Definition: LeapScene.h:386
SceneRay m_ray
Definition: LeapScene.h:87
const Vector & GetCenter() const
Definition: LeapScene.h:570
void SetCenter(const Vector &vCenter)
Definition: LeapScene.h:556
const Vector & GetNormal() const
Definition: LeapScene.h:844
void ClearNumContacts()
Definition: LeapScene.h:597
const SceneContactPoint * GetLastContactPoint(uint32_t uiIndex) const
Definition: LeapScene.h:631
uint32_t GetNumContacts() const
Definition: LeapScene.h:589
virtual LEAP_EXPORT ~Scene()
Definition: LeapScene.h:189
bool IsPendingRemoval() const
Definition: LeapScene.h:671
uint32_t m_uiFlags
Definition: LeapScene.h:402
void clearInteractionQueue()
Definition: LeapScene.h:341
virtual LEAP_EXPORT eSceneObjectType GetType() const
pure virtual methods requiring implementation in inheriting classes.
Definition: LeapScene.h:769
void SetScale(float scale)
Definition: LeapScene.h:568
void ClearNumPointing()
Definition: LeapScene.h:599
uint8_t m_uiNumPointing
Definition: LeapScene.h:702
virtual ~SceneCylinder()
Definition: LeapScene.h:773
SceneObjectPtr m_pObject
Definition: LeapScene.h:156
virtual ~SceneSphere()
Definition: LeapScene.h:867
void ClearHitTime()
Definition: LeapScene.h:601
Matrix m_mtxFrameTransform
Definition: LeapScene.h:390
uint8_t m_bPendingRemoval
Definition: LeapScene.h:710
void SetUpdateRayCast(bool bUpdateRayCast)
Definition: LeapScene.h:320
float GetScale() const
Definition: LeapScene.h:576
Vector yBasis
Definition: LeapMath.h:1029
float m_fHitDistance
Definition: LeapScene.h:89
void * m_pUserData
Definition: LeapScene.h:696
void ClearInitialContact()
Definition: LeapScene.h:603
T * allocateObject()
Definition: LeapScene.h:364
ray used for ray hit tests
Definition: LeapScene.h:53
float GetScale() const
Definition: LeapScene.h:147
float m_fPointableRadius
Definition: LeapScene.h:387
float GetRadius() const
Definition: LeapScene.h:871
scene manages scene objects - handles selection and movement
Definition: LeapScene.h:171
void SetSelected(bool selected)
Definition: LeapScene.h:580
bool HasInteraction(eInteractionType interactionType) const
Definition: LeapScene.h:120
const Vector & GetNormal() const
Definition: LeapScene.h:814
void Transform(const Matrix &mtxTransform)
change the orientation and position of this ray by the given transform
Definition: LeapScene.h:63
Scene * m_pScene
Definition: LeapScene.h:713
ObjectClass * AddObject()
Definition: LeapScene.h:201
void * GetUserData() const
Definition: LeapScene.h:274
SceneRay(const Vector &vOrigin, const Vector &vDirection)
Definition: LeapScene.h:57
Vector zBasis
Definition: LeapMath.h:1037
uint32_t GetSerial() const
a unique serial number assigned to each object at creation time.
Definition: LeapScene.h:500
uint32_t GetNumObjects() const
Definition: LeapScene.h:227
void SetHeight(float height)
Definition: LeapScene.h:777
void * m_pUserData
Definition: LeapScene.h:385
uint32_t m_uiNumObjects
Definition: LeapScene.h:397
const T * GetAs() const
Definition: LeapScene.h:484
void clearRayHits()
Definition: LeapScene.h:348
const Matrix & GetFrameTransform() const
Definition: LeapScene.h:253
Vector TransformFramePoint(const Vector &vFramePoint)
transforms a point from the Leap API (e.g. Pointable::tipPosition()) into scene space ...
Definition: LeapScene.h:298
uint8_t m_uiNumContacts
Definition: LeapScene.h:703
Vector m_vOrigin
Definition: LeapScene.h:75
const SceneInteraction * GetQueuedInteraction(uint32_t idx) const
access to a potential interaction queued up during the last update
Definition: LeapScene.h:292
stores the result of a ray test that hit something
Definition: LeapScene.h:80
#define LEAP_EXPORT_CLASS
Definition: LeapScene.h:30
float GetRadius() const
Definition: LeapScene.h:816
void * GetUserData() const
Definition: LeapScene.h:667
bool HasTranslation() const
Definition: LeapScene.h:117
SceneRay Transformed(const Matrix &mtxTransform) const
Definition: LeapScene.h:69
bool ApplyInteraction(const SceneInteraction &interaction)
Definition: LeapScene.h:526
Leap::Matrix ExtractRotation(const Leap::Matrix &mtxTransform)
create a new matrix with just the rotation block from the argument matrix
Definition: LeapUtil.h:102
float GetSelectHitTime() const
Definition: LeapScene.h:268
void SetUpdateContact(bool bUpdateContact)
Definition: LeapScene.h:313
bool HasInitialContact() const
Definition: LeapScene.h:595
bool GetUpdateContact() const
Definition: LeapScene.h:311
void SetFrameTransform(const Matrix &mtxFrameTransform)
Definition: LeapScene.h:251
SceneContactPoint * m_paLastContactPoints
Definition: LeapScene.h:698
float GetFrameScale() const
Definition: LeapScene.h:257
static eSceneObjectType ObjectType()
Definition: LeapScene.h:836
void Scale(float scaleMult)
Definition: LeapScene.h:516
eSceneObjectType
Definition: LeapScene.h:414
const SceneObjectPtr & GetObjectByIndex(int idx) const
Definition: LeapScene.h:222
float m_fTotalHitTime
Definition: LeapScene.h:699
void SetUserData(void *pUserData)
Definition: LeapScene.h:272
virtual LEAP_EXPORT eSceneObjectType GetType() const
pure virtual methods requiring implementation in inheriting classes.
Definition: LeapScene.h:737
static eSceneObjectType ObjectType()
Definition: LeapScene.h:735
SceneContactPoint m_initialContactPoint
Definition: LeapScene.h:694
bool IsSelected() const
accessors to interaction values - validity depends on what types of interactions are in the flags...
Definition: LeapScene.h:145
SceneObjectPtr m_pHitObject
Definition: LeapScene.h:90
uint8_t m_bSelected
Definition: LeapScene.h:707
const SceneContactPoint * GetContactPoint(uint32_t uiIndex) const
Definition: LeapScene.h:626
Matrix m_mtxTransform
Definition: LeapScene.h:693
void IncNumContacts(const SceneContactPoint &contactPoint)
Definition: LeapScene.h:607
const SceneContactPoint * GetLastContactPointByPointableID(int iPointableID) const
Definition: LeapScene.h:654
SceneContactPoint * m_paContactPoints
Definition: LeapScene.h:697
uint32_t GetNumQueuedInteractions() const
number of potential interactions that were queued up during the last update
Definition: LeapScene.h:289
bool HasRotation() const
Definition: LeapScene.h:116
Matrix GetTransform() const
Definition: LeapScene.h:149
static eSceneObjectType ObjectType()
Definition: LeapScene.h:804
eInteractionType
types of interactions that may be performed on a scene object
Definition: LeapScene.h:94
Vector transformPoint(const Vector &in) const
Definition: LeapMath.h:803
bool IsSelected() const
Definition: LeapScene.h:578
virtual ~SceneObject()
Definition: LeapScene.h:456
uint32_t GetNumPointing() const
Definition: LeapScene.h:591
SceneContactPoint(const Vector &vPoint, int iPointableID)
Definition: LeapScene.h:165
Vector WorldToObjectPoint(const Vector &vPoint) const
Definition: LeapScene.h:676
Scene * GetScene() const
Definition: LeapScene.h:502
void Transform(const Matrix &mtxTransform)
Definition: LeapScene.h:521
const SceneContactPoint * GetInitialContactPoint() const
Definition: LeapScene.h:636
void SetRadius(const float &radius)
Definition: LeapScene.h:869
float GetTotalHitTime() const
Definition: LeapScene.h:624
const Matrix & GetTransform() const
Definition: LeapScene.h:574
uint32_t m_serial
Definition: LeapScene.h:712


leap_motion
Author(s): Florian Lier , Mirza Shah , Isaac IY Saito
autogenerated on Tue Jun 2 2020 03:58:01