LeapScene.h
Go to the documentation of this file.
00001 /******************************************************************************\
00002 * Copyright (C) Leap Motion, Inc. 2011-2013.                                   *
00003 * Leap Motion proprietary and  confidential.  Not for distribution.            *
00004 * Use subject to the terms of the Leap Motion SDK Agreement available at       *
00005 * https://developer.leapmotion.com/sdk_agreement, or another agreement between *
00006 * Leap Motion and you, your company or other organization.                     *
00007 \******************************************************************************/
00008 
00009 #if !defined(__LeapScene_h__)
00010 #define __LeapScene_h__
00011 
00012 #include "Leap.h"
00013 #include "LeapUtil.h"
00014 
00015 #if defined(LEAP_SCENE_USE_UTIL_GL)
00016   #include "LeapUtilGL.h"
00017 #endif
00018 
00019 // define this macro if you want SceneObject::GetAs<> to use
00020 // simple internally implemented typeid checks
00021 // instead of dynamic casting.
00022 // some code bases prohibit the use of dynamic_cast.
00023 // this provides a basic alternative.
00024 // see the comment at SceneObject::GetAs<> below
00025 #undef LEAP_SCENE_NO_DYNAMIC_CAST
00026 
00027 #undef LEAP_EXPORT
00028 #define LEAP_EXPORT
00029 #undef LEAP_EXPORT_CLASS
00030 #define LEAP_EXPORT_CLASS
00031 #undef LEAP_EXPORT_PLUGIN
00032 #define LEAP_EXPORT_PLUGIN
00033 
00034 namespace Leap {
00035 
00038 class Scene;
00039 
00041 class SceneObject;
00042 
00050 typedef LeapUtil::SmartPointer<SceneObject> SceneObjectPtr;
00051 
00053 struct SceneRay
00054 {
00055   SceneRay() {}
00056 
00057   SceneRay( const Vector& vOrigin, const Vector& vDirection ) : m_vOrigin( vOrigin ), m_vDirection( vDirection ) {}
00058 
00060   Vector CalcPointOn( float fDistFromOrigin ) const { return m_vOrigin + m_vDirection * fDistFromOrigin; }
00061 
00063   void Transform( const Matrix& mtxTransform )
00064   {
00065     m_vOrigin = mtxTransform.transformPoint( m_vOrigin );
00066     m_vDirection = mtxTransform.transformDirection( m_vDirection );
00067   }
00068 
00069   SceneRay Transformed( const Matrix& mtxTransform ) const
00070   {
00071     return SceneRay(  mtxTransform.transformPoint( m_vOrigin ),
00072                       mtxTransform.transformDirection( m_vDirection ) );
00073   }
00074 
00075   Vector  m_vOrigin;
00076   Vector  m_vDirection;
00077 };
00078 
00080 struct SceneRayHit
00081 {
00082 #if defined(LEAP_SCENE_USE_UTIL_GL)
00083   void DebugDrawGL( float fHitSphereSize ) const;
00084 #endif
00085 
00086   Vector          m_hitPoint;
00087   SceneRay        m_ray;
00088   int             m_iPointableID;
00089   float           m_fHitDistance;
00090   SceneObjectPtr  m_pHitObject;
00091 };
00092 
00094 enum eInteractionType
00095 {
00096   kIT_Rotation          = 1 << 0,
00097   kIT_Translation       = 1 << 1,
00098   kIT_Scale             = 1 << 2,
00099   kIT_SelectionChange   = 1 << 3,
00100   kIT_IsSelected        = 1 << 4
00101 };
00102 
00106 class SceneInteraction
00107 {
00108   friend class Scene;
00109 
00110 protected:
00111   SceneInteraction() : m_fScale(1), m_uiFlags(0) {}
00112 
00113 public:
00115   bool HasSelectionChange()   const { return (m_uiFlags & kIT_SelectionChange) != 0; }
00116   bool HasRotation()          const { return (m_uiFlags & kIT_Rotation) != 0; }
00117   bool HasTranslation()       const { return (m_uiFlags & kIT_Translation) != 0; }
00118   bool HasScale()             const { return (m_uiFlags & kIT_Scale) != 0; }
00119 
00120   bool HasInteraction( eInteractionType interactionType ) const
00121   {
00122     return ((m_uiFlags >> static_cast<uint32_t>(interactionType)) & 1) != 0;
00123   }
00124 
00125   void ClearSelectionChange() { m_uiFlags &= ~kIT_SelectionChange; }
00126   void ClearRotation()        { m_uiFlags &= ~kIT_Rotation; }
00127   void ClearTranslation()     { m_uiFlags &= ~kIT_Translation; }
00128   void ClearScale()           { m_uiFlags &= ~kIT_Scale; }
00129 
00130   void ClearInteraction( eInteractionType interactionType )
00131   {
00132     m_uiFlags &= ~(1 << static_cast<uint32_t>(interactionType));
00133   }
00134 
00135   bool HasAnyInteraction() const
00136   {
00137     static const uint32_t kInteractionMask =  kIT_SelectionChange  |
00138                                               kIT_Rotation         |
00139                                               kIT_Translation      |
00140                                               kIT_Scale;
00141     return (m_uiFlags & kInteractionMask) != 0;
00142   }
00143 
00145   bool                  IsSelected()      const { return (m_uiFlags & kIT_IsSelected) != 0; }
00146   Matrix                GetRotation()     const { return LeapUtil::ExtractRotation( m_mtxTransform ); }
00147   float                 GetScale()        const { return m_fScale; }
00148   Vector                GetTranslation()  const { return m_mtxTransform.origin; }
00149   Matrix                GetTransform()    const { return m_mtxTransform; }
00150 
00152   const SceneObjectPtr& GetObject()       const { return m_pObject; }
00153 
00154 private:
00155   Matrix          m_mtxTransform;
00156   SceneObjectPtr  m_pObject;
00157   float           m_fScale;
00158   uint32_t        m_uiFlags;
00159 };
00160 
00162 struct SceneContactPoint
00163 {
00164   SceneContactPoint() : m_iPointableID(-1) {}
00165   SceneContactPoint( const Vector& vPoint, int iPointableID ) : m_vPoint( vPoint ), m_iPointableID( iPointableID ) {}
00166   Vector  m_vPoint;
00167   int     m_iPointableID;
00168 };
00169 
00171 class LEAP_EXPORT_CLASS Scene
00172 {
00173 public:
00174   enum eFlag
00175   {
00176     kF_UpdateRayCast = 1 << 0,
00177     kF_UpdateContact = 1 << 1
00178   };
00179 
00180   enum
00181   {
00182     kMaxObjects             = 512,
00183     kMaxRayHits             = 32,
00184     kInteractionQueueLength = 32
00185   };
00186 
00187   LEAP_EXPORT Scene();
00188 
00189   LEAP_EXPORT virtual ~Scene()
00190   {
00191     Reset();
00192   }
00193 
00200   template<class ObjectClass>
00201   ObjectClass* AddObject()
00202   {
00203     return allocateObject<ObjectClass>();
00204   }
00205 
00211   LEAP_EXPORT void RemoveObject( SceneObject* pObject );
00212 
00216   LEAP_EXPORT void Reset();
00217 
00218 #if defined(LEAP_SCENE_USE_UTIL_GL)
00219   LEAP_EXPORT void RayHitsDebugDrawGL() const;
00220 #endif
00221 
00222   const SceneObjectPtr& GetObjectByIndex( int idx ) const
00223   {
00224     return (static_cast<uint32_t>(idx) < m_uiNumObjects) ? m_apObjects[idx] : SceneObjectPtr::Null();
00225   }
00226 
00227   uint32_t GetNumObjects() const { return m_uiNumObjects; }
00228 
00230   const SceneObjectPtr& TestRayHit( const SceneRay& ray ) const;
00231 
00239   LEAP_EXPORT void Update( const Frame& frame, float fDeltaTimeSeconds );
00240 
00242   LEAP_EXPORT void DeselectAll();
00243 
00251   void SetFrameTransform( const Matrix& mtxFrameTransform ) { m_mtxFrameTransform = mtxFrameTransform; }
00252 
00253   const Matrix& GetFrameTransform() const { return m_mtxFrameTransform; }
00254 
00255   void SetFrameScale( float fFrameScale ) { m_fFrameScale = fFrameScale; }
00256 
00257   float GetFrameScale() const { return m_fFrameScale; }
00258 
00261   void SetPointableRadius( float fRadius ) { m_fPointableRadius = fRadius; }
00262 
00263   float GetPointableRadius() const { return m_fPointableRadius; }
00264 
00266   void SetSelectHitTime( float fSelectHitTime ) { m_fSelectHitTime = fSelectHitTime; }
00267 
00268   float GetSelectHitTime() const { return m_fSelectHitTime; }
00269 
00272   void SetUserData( void* pUserData ) { m_pUserData = pUserData; }
00273 
00274   void* GetUserData() const { return m_pUserData; }
00275 
00277   float GetDeltaTime() const { return m_fDeltaTimeSeconds; }
00278 
00280   uint32_t GetNumRayHits() const { return m_uiNumRayHits; }
00281 
00283   const SceneRayHit* GetRayHit( uint32_t idx ) const
00284   {
00285     return idx < m_uiNumRayHits ? &(m_aRayHits[idx]) : NULL;
00286   }
00287 
00289   uint32_t GetNumQueuedInteractions() const { return m_uiNumQueuedInteractions; }
00290 
00292   const SceneInteraction* GetQueuedInteraction( uint32_t idx ) const
00293   {
00294     return idx < m_uiNumQueuedInteractions ? &(m_aInteractionQueue[idx]) : NULL;
00295   }
00296 
00298   Vector TransformFramePoint( const Vector& vFramePoint )
00299   {
00300     return m_mtxFrameTransform.transformPoint( vFramePoint * m_fFrameScale );
00301   }
00302 
00304   Vector TransformFrameDirection( const Vector& vFrameDirection )
00305   {
00306     return m_mtxFrameTransform.transformDirection( vFrameDirection );
00307   }
00308 
00309   uint32_t GetFlags() const { return m_uiFlags; }
00310 
00311   bool GetUpdateContact() const { return (m_uiFlags & kF_UpdateContact) != 0; }
00312 
00313   void SetUpdateContact( bool bUpdateContact )
00314   {
00315     m_uiFlags = bUpdateContact ? (m_uiFlags | kF_UpdateContact) : (m_uiFlags & ~kF_UpdateContact);
00316   }
00317 
00318   bool GetUpdateRayCast() const { return (m_uiFlags & kF_UpdateRayCast) != 0; }
00319 
00320   void SetUpdateRayCast( bool bUpdateRayCast )
00321   {
00322     m_uiFlags = bUpdateRayCast ? (m_uiFlags | kF_UpdateRayCast) : (m_uiFlags & ~kF_UpdateRayCast);
00323   }
00324 
00325   // internal methods for Scene
00326 private:
00327   void updateSelectionAndContact( const Frame& frame );
00328 
00329   void queueDeselectAll();
00330 
00331   bool queueInteraction( const SceneInteraction& interaction )
00332   {
00333     if ( m_uiNumQueuedInteractions < static_cast<uint32_t>(kInteractionQueueLength) )
00334     {
00335       m_aInteractionQueue[m_uiNumQueuedInteractions++] = interaction;
00336     }
00337 
00338     return false;
00339   }
00340 
00341   void clearInteractionQueue()
00342   {
00343     // release object references from the interaction queue
00344     for ( uint32_t i = 0; i < m_uiNumQueuedInteractions; m_aInteractionQueue[i++].m_pObject.Release() );
00345     m_uiNumQueuedInteractions = 0;
00346   }
00347 
00348   void clearRayHits()
00349   {
00350     // release object references from the ray hits
00351     for ( uint32_t i = 0; i < m_uiNumRayHits; m_aRayHits[i++].m_pHitObject.Release() );
00352     m_uiNumRayHits = 0;
00353   }
00354 
00355   void updateInteraction( const Frame& frame );
00356 
00357   void processPendingRemovals();
00358 
00359   bool testRayHitClosest( SceneRayHit& hitResult );
00360 
00361   void updateContact( const SceneContactPoint& testPoint );
00362 
00363   template<class T>
00364   T* allocateObject()
00365   {
00366     if ( m_uiNumObjects < static_cast<uint32_t>(kMaxObjects) )
00367     {
00368       if ( T* pObject = new T() )
00369       {
00370         pObject->m_pScene           = this;
00371         pObject->m_serial           = m_uiNextSerial++;
00372         pObject->m_index            = static_cast<uint16_t>(m_uiNumObjects);
00373         m_apObjects[m_uiNumObjects++] = SceneObjectPtr(pObject);
00374 
00375         return pObject;
00376       }
00377     }
00378 
00379     return NULL;
00380   }
00381 
00382   void deallocateObject( uint32_t idxToRemove );
00383 
00384 private:
00385   void*                   m_pUserData;
00386   float                   m_fDeltaTimeSeconds;
00387   float                   m_fPointableRadius;
00388   float                   m_fSelectHitTime;
00389 
00390   Matrix                  m_mtxFrameTransform;
00391   float                   m_fFrameScale;
00392 
00393   SceneObjectPtr          m_apObjects[kMaxObjects];
00394   SceneRayHit             m_aRayHits[kMaxRayHits];
00395   SceneInteraction        m_aInteractionQueue[kInteractionQueueLength];
00396 
00397   uint32_t                m_uiNumObjects;
00398   uint32_t                m_uiNumRayHits;
00399   uint32_t                m_uiNumQueuedInteractions;
00400   uint32_t                m_uiNumPendingRemovals;
00401   uint32_t                m_uiNextSerial;
00402   uint32_t                m_uiFlags;
00403 }; // Scene
00404 
00414 enum eSceneObjectType
00415 {
00416   kSOT_SceneObject = 0,
00417 
00418   // force 32 bit size
00419   kSOT_Invalid = 0x7fffffff
00420 };
00421 
00425 class LEAP_EXPORT_CLASS SceneObject
00426 {
00427   friend class Scene;
00428 
00429 public:
00430   static eSceneObjectType ObjectType() { return kSOT_SceneObject; }
00431 
00432   static eSceneObjectType NextObjectType()
00433   {
00434     static uint32_t s_nextID = kSOT_SceneObject + 1;
00435     return static_cast<eSceneObjectType>( s_nextID + 1 );
00436   }
00437 
00438   enum { kMaxContactPoints = 5 };
00439 
00440 public:
00441   SceneObject()
00442     : m_pUserData(NULL),
00443       m_paContactPoints( m_aContactPoints ),
00444       m_paLastContactPoints( m_aContactPoints + kMaxContactPoints ),
00445       m_fTotalHitTime(0.0f),
00446       m_fScale(1.0f),
00447       m_uiNumPointing(0),
00448       m_uiNumContacts(0),
00449       m_uiLastNumContacts(0),
00450       m_uiHasInitialContact(0),
00451       m_bSelected(false),
00452       m_bPendingRemoval(false),
00453       m_pScene(NULL)
00454   {}
00455 
00456   virtual ~SceneObject() {}
00457 
00458 public:
00460   LEAP_EXPORT virtual eSceneObjectType GetType() const = 0;
00461 
00462   LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const = 0;
00463 
00464   LEAP_EXPORT virtual bool TestSphereHit(const Vector& vTestPoint, float fTestRadius) const = 0;
00465 
00466 #if defined(LEAP_SCENE_USE_UTIL_GL)
00467   LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const = 0;
00468 #endif
00469 
00470   template<class T>
00471   T* GetAs()
00472   {
00473 #if defined(LEAP_SCENE_NO_DYNAMIC_CAST)
00474     // When relying on simple internal type ids GetAs() only works for exact type matches or up casts to the base type.
00475     // this mechanism is provided as a simple alternative for code bases that prohibit the use of dynamic_cast.
00476     // a complete, hierarchically correct type id system is beyond the scope of this code.
00477     return (this && (GetType() == T::ObjectType() || GetType() == SceneObject::ObjectType())) ? static_cast<T*>(this) : NULL;
00478 #else
00479     return dynamic_cast<T*>(this);
00480 #endif
00481   }
00482 
00483   template<class T>
00484   const T* GetAs() const
00485   {
00486     return const_cast<SceneObject*>(this)->GetAs<T>();
00487   }
00488 
00489   const SceneObjectPtr& GetSceneObjectPtr() const
00490   {
00491     return (this && m_pScene) ? m_pScene->GetObjectByIndex(m_index) : SceneObjectPtr::Null();
00492   }
00493 
00494   operator const SceneObjectPtr&() const
00495   {
00496     return GetSceneObjectPtr();
00497   }
00498 
00500   uint32_t GetSerial() const { return m_serial; }
00501 
00502   Scene* GetScene() const { return m_pScene; }
00503 
00504   void Translate(const Vector& translation) { m_mtxTransform.origin += translation; }
00505 
00506   void Rotate(const Vector& axis, float angleRadians)
00507   {
00508     m_mtxTransform =  m_mtxTransform * Matrix(axis, angleRadians);
00509   }
00510 
00511   void Rotate(const Matrix& rotationMatrix)
00512   {
00513     m_mtxTransform = m_mtxTransform * LeapUtil::ExtractRotation( rotationMatrix );
00514   }
00515 
00516   void Scale(float scaleMult)
00517   {
00518     m_fScale *= scaleMult;
00519   }
00520 
00521   void Transform( const Matrix& mtxTransform )
00522   {
00523     m_mtxTransform = m_mtxTransform * mtxTransform;
00524   }
00525 
00526   bool ApplyInteraction( const SceneInteraction& interaction )
00527   {
00528     if ( IsPendingRemoval() )
00529     {
00530       return false;
00531     }
00532 
00533     if ( interaction.HasRotation() )
00534     {
00535       Rotate( interaction.GetRotation() );
00536     }
00537 
00538     if ( interaction.HasTranslation() )
00539     {
00540       Translate( interaction.GetTranslation() );
00541     }
00542 
00543     if ( interaction.HasScale() )
00544     {
00545       Scale( interaction.GetScale() );
00546     }
00547 
00548     if ( interaction.HasSelectionChange() )
00549     {
00550       SetSelected( interaction.IsSelected() );
00551     }
00552 
00553     return true;
00554   }
00555 
00556   void SetCenter(const Vector& vCenter) { m_mtxTransform.origin = vCenter; }
00557 
00558   void SetRotation(const Vector& vAxis, float fAngleRadians)
00559   {
00560     m_mtxTransform.setRotation( vAxis, fAngleRadians );
00561   }
00562 
00563   void SetRotation(const Matrix& rotationMatrix)
00564   {
00565     m_mtxTransform = Matrix( rotationMatrix.xBasis, rotationMatrix.yBasis, rotationMatrix.zBasis, m_mtxTransform.origin );
00566   }
00567 
00568   void SetScale(float scale) { m_fScale = scale; }
00569 
00570   const Vector& GetCenter() const { return m_mtxTransform.origin; }
00571 
00572   const Matrix GetRotation() const { return Matrix( m_mtxTransform.xBasis, m_mtxTransform.yBasis, m_mtxTransform.zBasis ); }
00573 
00574   const Matrix& GetTransform() const { return m_mtxTransform; }
00575 
00576   float GetScale() const { return m_fScale; }
00577 
00578   bool IsSelected() const { return m_bSelected != false; }
00579 
00580   void SetSelected(bool selected)
00581   {
00582     m_bSelected = selected;
00583     if ( !m_bSelected )
00584     {
00585       ClearHitTime();
00586     }
00587   }
00588 
00589   uint32_t GetNumContacts() const { return m_uiNumContacts; }
00590 
00591   uint32_t GetNumPointing() const { return m_uiNumPointing; }
00592 
00593   uint32_t GetLastNumContacts() const { return m_uiLastNumContacts; }
00594 
00595   bool HasInitialContact() const { return m_uiHasInitialContact != 0; }
00596 
00597   void ClearNumContacts() { m_uiNumContacts = 0; }
00598 
00599   void ClearNumPointing() { m_uiNumPointing = 0; }
00600 
00601   void ClearHitTime() { m_fTotalHitTime = 0.0f; }
00602 
00603   void ClearInitialContact() { m_uiHasInitialContact = 0; }
00604 
00605   void IncNumPointing() { m_uiNumPointing++; }
00606 
00607   void IncNumContacts(const SceneContactPoint& contactPoint)
00608   {
00609     if (m_uiNumContacts < kMaxContactPoints)
00610     {
00611       m_paContactPoints[m_uiNumContacts++] = contactPoint;
00612     }
00613   }
00614 
00615   void ClearHits()
00616   {
00617     m_uiNumContacts       = 0;
00618     m_uiLastNumContacts   = 0;
00619     m_uiHasInitialContact = 0;
00620     m_uiNumPointing       = 0;
00621     m_fTotalHitTime       = 0.0f;
00622   }
00623 
00624   float GetTotalHitTime() const { return m_fTotalHitTime; }
00625 
00626   const SceneContactPoint* GetContactPoint(uint32_t uiIndex) const
00627   {
00628     return uiIndex < static_cast<uint32_t>(kMaxContactPoints) ? m_paContactPoints + uiIndex : NULL;
00629   }
00630 
00631   const SceneContactPoint* GetLastContactPoint(uint32_t uiIndex) const
00632   {
00633     return uiIndex < static_cast<uint32_t>(kMaxContactPoints) ? m_paLastContactPoints + uiIndex : NULL;
00634   }
00635 
00636   const SceneContactPoint* GetInitialContactPoint() const
00637   {
00638     return m_uiHasInitialContact ? &m_initialContactPoint : NULL;
00639   }
00640 
00641   const SceneContactPoint* GetContactPointByPointableID(int iPointableID) const
00642   {
00643     for ( uint32_t i = 0; i < m_uiNumContacts; i++ )
00644     {
00645       if ( m_paContactPoints[i].m_iPointableID == iPointableID )
00646       {
00647         return m_paContactPoints + i;
00648       }
00649     }
00650 
00651     return NULL;
00652   }
00653 
00654   const SceneContactPoint* GetLastContactPointByPointableID(int iPointableID) const
00655   {
00656     for ( uint32_t i = 0; i < m_uiLastNumContacts; i++ )
00657     {
00658       if ( m_paLastContactPoints[i].m_iPointableID == iPointableID )
00659       {
00660         return m_paContactPoints + i;
00661       }
00662     }
00663 
00664     return NULL;
00665   }
00666 
00667   void* GetUserData() const { return m_pUserData; }
00668 
00669   void SetUserData( void* pUserData ) { m_pUserData = pUserData; }
00670 
00671   bool IsPendingRemoval() const { return m_bPendingRemoval != false; }
00672 
00674   Matrix GetWorldToObjectTransform() const { return LeapUtil::RigidInverse(m_mtxTransform); }
00675 
00676   Vector WorldToObjectPoint( const Vector& vPoint ) const
00677   {
00678     return LeapUtil::RigidInverse(m_mtxTransform).transformPoint( vPoint );
00679   }
00680 
00681 protected:
00682   void rotateContactPoints()
00683   {
00684     m_uiLastNumContacts  = m_uiNumContacts;
00685     m_uiNumContacts      = 0;
00686 
00687     SceneContactPoint* pTemp  = m_paLastContactPoints;
00688     m_paLastContactPoints     = m_paContactPoints;
00689     m_paContactPoints         = pTemp;
00690   }
00691 
00692 protected:
00693   Matrix              m_mtxTransform;
00694   SceneContactPoint   m_initialContactPoint;
00695   SceneContactPoint   m_aContactPoints[kMaxContactPoints*2];
00696   void*               m_pUserData;
00697   SceneContactPoint*  m_paContactPoints;
00698   SceneContactPoint*  m_paLastContactPoints;
00699   float               m_fTotalHitTime;
00700   float               m_fScale;
00701 
00702   uint8_t             m_uiNumPointing;
00703   uint8_t             m_uiNumContacts;
00704   uint8_t             m_uiLastNumContacts;
00705   uint8_t             m_uiHasInitialContact;
00706 
00707   uint8_t             m_bSelected;
00708 
00709 private:
00710   uint8_t             m_bPendingRemoval;
00711   uint16_t            m_index;
00712   uint32_t            m_serial;
00713   Scene*              m_pScene;
00714 }; // SceneObject
00715 
00716 
00720 inline void DefaultProcessSceneInteractions( Scene& scene )
00721 {
00722   for ( uint32_t i = 0, n = scene.GetNumQueuedInteractions(); i < n; i++ )
00723   {
00724     const SceneInteraction& interaction = *scene.GetQueuedInteraction( i );
00725     interaction.GetObject()->ApplyInteraction( interaction );
00726   }
00727 }
00728 
00729 class LEAP_EXPORT_CLASS SceneBox : public SceneObject
00730 {
00731 public:
00735   static eSceneObjectType ObjectType() { static const eSceneObjectType s_type = NextObjectType(); return s_type; }
00736 
00737   LEAP_EXPORT virtual eSceneObjectType GetType() const { return ObjectType(); }
00738 
00739   SceneBox()
00740     : m_vSize( 1, 1, 1 )
00741   {}
00742 
00743   LEAP_EXPORT virtual ~SceneBox() {}
00744 
00745   const Vector& GetSize() const { return m_vSize; }
00746 
00747   void SetSize( const Vector& vSize ) { m_vSize = vSize; }
00748 
00749   LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const;
00750 
00751   LEAP_EXPORT virtual bool TestSphereHit(const Vector& vTestPoint, float fTestRadius) const;
00752 
00753 #if defined(LEAP_SCENE_USE_UTIL_GL)
00754   LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const;
00755 #endif
00756 
00757 private:
00758   Vector m_vSize;
00759 }; // SceneBox
00760 
00761 class LEAP_EXPORT_CLASS SceneCylinder : public SceneObject
00762 {
00763 public:
00767   static eSceneObjectType ObjectType() { static const eSceneObjectType s_type = NextObjectType(); return s_type; }
00768 
00769   LEAP_EXPORT virtual eSceneObjectType GetType() const { return ObjectType(); }
00770 
00771   SceneCylinder() : m_fRadius( 1.0f ), m_fHeight( 1.0f ) {}
00772 
00773   virtual ~SceneCylinder() {}
00774 
00775   void SetRadius(float radius) { m_fRadius = radius; }
00776 
00777   void SetHeight(float height) { m_fHeight = height; }
00778 
00779   const Vector& GetAxis() const { return m_mtxTransform.yBasis; }
00780 
00781   float GetRadius() const { return m_fRadius; }
00782 
00783   float GetHeight() const { return m_fHeight; }
00784 
00785   LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const;
00786 
00787   LEAP_EXPORT virtual bool TestSphereHit(const Vector& vTestPoint, float fTestRadius) const;
00788 
00789 #if defined(LEAP_SCENE_USE_UTIL_GL)
00790   LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const;
00791 #endif
00792 
00793 private:
00794   float    m_fRadius;
00795   float    m_fHeight;
00796 }; // SceneCylinder
00797 
00798 class LEAP_EXPORT_CLASS SceneDisk : public SceneObject
00799 {
00800 public:
00804   static eSceneObjectType ObjectType() { static const eSceneObjectType s_type = NextObjectType(); return s_type; }
00805 
00806   LEAP_EXPORT virtual eSceneObjectType GetType() const { return ObjectType(); }
00807 
00808   SceneDisk() : m_fRadius( 1.0f ) {}
00809 
00810   virtual ~SceneDisk() {}
00811 
00812   void SetRadius(float radius) { m_fRadius = radius; }
00813 
00814   const Vector& GetNormal() const { return m_mtxTransform.zBasis; }
00815 
00816   float GetRadius() const { return m_fRadius; }
00817 
00818   LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const;
00819 
00820   LEAP_EXPORT virtual bool TestSphereHit(const Vector& vTestPoint, float fTestRadius) const;
00821 
00822 #if defined(LEAP_SCENE_USE_UTIL_GL)
00823   LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const;
00824 #endif
00825 
00826 private:
00827   float    m_fRadius;
00828 }; // SceneDisk
00829 
00830 class LEAP_EXPORT_CLASS ScenePlane : public SceneObject
00831 {
00832 public:
00836   static eSceneObjectType ObjectType() { static const eSceneObjectType s_type = NextObjectType(); return s_type; }
00837 
00838   LEAP_EXPORT virtual eSceneObjectType GetType() const { return ObjectType(); }
00839 
00840   ScenePlane() {}
00841 
00842   virtual ~ScenePlane() {}
00843 
00844   const Vector& GetNormal() const { return m_mtxTransform.zBasis; }
00845 
00846   LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const;
00847 
00848   LEAP_EXPORT virtual bool TestSphereHit(const Vector& vPoint, float fRadius) const;
00849 
00850 #if defined(LEAP_SCENE_USE_UTIL_GL)
00851   LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const;
00852 #endif
00853 }; // ScenePlane
00854 
00855 class LEAP_EXPORT_CLASS SceneSphere : public SceneObject
00856 {
00857 public:
00861   static eSceneObjectType ObjectType() { static const eSceneObjectType s_type = NextObjectType(); return s_type; }
00862 
00863   LEAP_EXPORT virtual eSceneObjectType GetType() const { return ObjectType(); }
00864 
00865   SceneSphere() : m_fRadius(1.0f) { }
00866 
00867   virtual ~SceneSphere() {}
00868 
00869   void SetRadius(const float& radius) { m_fRadius = radius; }
00870 
00871   float GetRadius() const { return m_fRadius; }
00872 
00873   LEAP_EXPORT virtual bool TestRayHit(const SceneRay& testRay, float& fHitDistOut) const;
00874 
00875   LEAP_EXPORT virtual bool TestSphereHit(const Vector& vTestCenter, float fTestRadius) const;
00876 
00877 #if defined(LEAP_SCENE_USE_UTIL_GL)
00878   LEAP_EXPORT virtual void DebugDrawGL( LeapUtilGL::eStyle drawStyle=LeapUtilGL::kStyle_Solid ) const;
00879 #endif
00880 
00881 private:
00882   float      m_fRadius;
00883 }; // SceneSphere
00884 
00885 }; // namespace Leap
00886 
00887 #endif // __LeapScene_h__


leap_motion
Author(s): Florian Lier , Mirza Shah , Isaac IY Saito
autogenerated on Sat Jun 8 2019 18:47:25