9 #if !defined(__LeapScene_h__) 10 #define __LeapScene_h__ 15 #if defined(LEAP_SCENE_USE_UTIL_GL) 25 #undef LEAP_SCENE_NO_DYNAMIC_CAST 29 #undef LEAP_EXPORT_CLASS 30 #define LEAP_EXPORT_CLASS 31 #undef LEAP_EXPORT_PLUGIN 32 #define LEAP_EXPORT_PLUGIN 82 #if defined(LEAP_SCENE_USE_UTIL_GL) 83 void DebugDrawGL(
float fHitSphereSize )
const;
122 return ((m_uiFlags >> static_cast<uint32_t>(interactionType)) & 1) != 0;
132 m_uiFlags &= ~(1 <<
static_cast<uint32_t
>(interactionType));
141 return (m_uiFlags & kInteractionMask) != 0;
152 const SceneObjectPtr&
GetObject()
const {
return m_pObject; }
176 kF_UpdateRayCast = 1 << 0,
177 kF_UpdateContact = 1 << 1
184 kInteractionQueueLength = 32
200 template<
class ObjectClass>
203 return allocateObject<ObjectClass>();
218 #if defined(LEAP_SCENE_USE_UTIL_GL) 224 return (static_cast<uint32_t>(idx) < m_uiNumObjects) ? m_apObjects[idx] :
SceneObjectPtr::Null();
230 const SceneObjectPtr& TestRayHit(
const SceneRay& ray )
const;
285 return idx < m_uiNumRayHits ? &(m_aRayHits[idx]) : NULL;
294 return idx < m_uiNumQueuedInteractions ? &(m_aInteractionQueue[idx]) : NULL;
300 return m_mtxFrameTransform.transformPoint( vFramePoint * m_fFrameScale );
306 return m_mtxFrameTransform.transformDirection( vFrameDirection );
315 m_uiFlags = bUpdateContact ? (m_uiFlags | kF_UpdateContact) : (m_uiFlags & ~kF_UpdateContact);
322 m_uiFlags = bUpdateRayCast ? (m_uiFlags | kF_UpdateRayCast) : (m_uiFlags & ~kF_UpdateRayCast);
327 void updateSelectionAndContact(
const Frame& frame );
329 void queueDeselectAll();
333 if ( m_uiNumQueuedInteractions < static_cast<uint32_t>(kInteractionQueueLength) )
335 m_aInteractionQueue[m_uiNumQueuedInteractions++] = interaction;
344 for ( uint32_t i = 0; i < m_uiNumQueuedInteractions; m_aInteractionQueue[i++].m_pObject.Release() );
345 m_uiNumQueuedInteractions = 0;
351 for ( uint32_t i = 0; i < m_uiNumRayHits; m_aRayHits[i++].m_pHitObject.Release() );
355 void updateInteraction(
const Frame& frame );
357 void processPendingRemovals();
366 if ( m_uiNumObjects < static_cast<uint32_t>(kMaxObjects) )
368 if ( T* pObject =
new T() )
371 pObject->
m_serial = m_uiNextSerial++;
372 pObject->
m_index =
static_cast<uint16_t
>(m_uiNumObjects);
382 void deallocateObject( uint32_t idxToRemove );
393 SceneObjectPtr m_apObjects[kMaxObjects];
438 enum { kMaxContactPoints = 5 };
443 m_paContactPoints( m_aContactPoints ),
444 m_paLastContactPoints( m_aContactPoints + kMaxContactPoints ),
445 m_fTotalHitTime(0.0
f),
449 m_uiLastNumContacts(0),
450 m_uiHasInitialContact(0),
452 m_bPendingRemoval(false),
462 LEAP_EXPORT virtual bool TestRayHit(
const SceneRay& testRay,
float& fHitDistOut)
const = 0;
464 LEAP_EXPORT virtual bool TestSphereHit(
const Vector& vTestPoint,
float fTestRadius)
const = 0;
466 #if defined(LEAP_SCENE_USE_UTIL_GL) 473 #if defined(LEAP_SCENE_NO_DYNAMIC_CAST) 477 return (
this && (GetType() == T::ObjectType() || GetType() ==
SceneObject::ObjectType())) ?
static_cast<T*
>(
this) : NULL;
479 return dynamic_cast<T*
>(
this);
494 operator const SceneObjectPtr&()
const 496 return GetSceneObjectPtr();
508 m_mtxTransform = m_mtxTransform *
Matrix(axis, angleRadians);
518 m_fScale *= scaleMult;
523 m_mtxTransform = m_mtxTransform * mtxTransform;
528 if ( IsPendingRemoval() )
560 m_mtxTransform.setRotation( vAxis, fAngleRadians );
565 m_mtxTransform =
Matrix( rotationMatrix.
xBasis, rotationMatrix.
yBasis, rotationMatrix.
zBasis, m_mtxTransform.origin );
582 m_bSelected = selected;
609 if (m_uiNumContacts < kMaxContactPoints)
611 m_paContactPoints[m_uiNumContacts++] = contactPoint;
618 m_uiLastNumContacts = 0;
619 m_uiHasInitialContact = 0;
621 m_fTotalHitTime = 0.0f;
628 return uiIndex < static_cast<uint32_t>(kMaxContactPoints) ? m_paContactPoints + uiIndex : NULL;
633 return uiIndex < static_cast<uint32_t>(kMaxContactPoints) ? m_paLastContactPoints + uiIndex : NULL;
638 return m_uiHasInitialContact ? &m_initialContactPoint : NULL;
643 for ( uint32_t i = 0; i < m_uiNumContacts; i++ )
645 if ( m_paContactPoints[i].m_iPointableID == iPointableID )
647 return m_paContactPoints + i;
656 for ( uint32_t i = 0; i < m_uiLastNumContacts; i++ )
658 if ( m_paLastContactPoints[i].m_iPointableID == iPointableID )
660 return m_paContactPoints + i;
684 m_uiLastNumContacts = m_uiNumContacts;
688 m_paLastContactPoints = m_paContactPoints;
689 m_paContactPoints = pTemp;
751 LEAP_EXPORT virtual bool TestSphereHit(
const Vector& vTestPoint,
float fTestRadius)
const;
753 #if defined(LEAP_SCENE_USE_UTIL_GL) 787 LEAP_EXPORT virtual bool TestSphereHit(
const Vector& vTestPoint,
float fTestRadius)
const;
789 #if defined(LEAP_SCENE_USE_UTIL_GL) 820 LEAP_EXPORT virtual bool TestSphereHit(
const Vector& vTestPoint,
float fTestRadius)
const;
822 #if defined(LEAP_SCENE_USE_UTIL_GL) 848 LEAP_EXPORT virtual bool TestSphereHit(
const Vector& vPoint,
float fRadius)
const;
850 #if defined(LEAP_SCENE_USE_UTIL_GL) 869 void SetRadius(
const float& radius) { m_fRadius = radius; }
875 LEAP_EXPORT virtual bool TestSphereHit(
const Vector& vTestCenter,
float fTestRadius)
const;
877 #if defined(LEAP_SCENE_USE_UTIL_GL) 887 #endif // __LeapScene_h__ const SceneRayHit * GetRayHit(uint32_t idx) const
access to a ray test hit that happened during the last update
uint8_t m_uiHasInitialContact
void ClearInteraction(eInteractionType interactionType)
uint32_t m_uiNumQueuedInteractions
const Matrix GetRotation() const
Vector CalcPointOn(float fDistFromOrigin) const
returns a point that is the specified distance down the ray.
const Vector & GetAxis() const
Matrix GetWorldToObjectTransform() const
returns a transform for converting world space coordinates and direction to object space...
uint8_t m_uiLastNumContacts
static const SmartPointer & Null()
convenient static method for returning in cases where a null return value is needed.
LeapUtil::SmartPointer< SceneObject > SceneObjectPtr
void Rotate(const Matrix &rotationMatrix)
bool GetUpdateRayCast() const
void SetRadius(float radius)
void SetUserData(void *pUserData)
float GetDeltaTime() const
the last value of the fDeltatTimeSeconds argument passed to Update()
Vector GetTranslation() const
static eSceneObjectType ObjectType()
uint32_t GetFlags() const
Leap::Matrix RigidInverse(const Leap::Matrix &mtxTransform)
virtual LEAP_EXPORT eSceneObjectType GetType() const
pure virtual methods requiring implementation in inheriting classes.
Vector transformDirection(const Vector &in) const
static eSceneObjectType ObjectType()
const SceneObjectPtr & GetSceneObjectPtr() const
uint32_t GetLastNumContacts() const
const SceneObjectPtr & GetObject() const
scene object this interaction is associated with
void Translate(const Vector &translation)
void SetRotation(const Vector &vAxis, float fAngleRadians)
void SetSize(const Vector &vSize)
virtual LEAP_EXPORT ~SceneBox()
void SetFrameScale(float fFrameScale)
void rotateContactPoints()
bool HasSelectionChange() const
convenient predicates for represented interaction types
uint32_t m_uiNumPendingRemovals
uint32_t GetNumRayHits() const
the number of ray tests that resulted in hits from the last update
static eSceneObjectType ObjectType()
bool HasAnyInteraction() const
void SetRotation(const Matrix &rotationMatrix)
void DefaultProcessSceneInteractions(Scene &scene)
void SetPointableRadius(float fRadius)
void SetSelectHitTime(float fSelectHitTime)
the amount of time an object must be pointed at or touched before it is selected
static eSceneObjectType NextObjectType()
void SetRadius(float radius)
const SceneContactPoint * GetContactPointByPointableID(int iPointableID) const
float GetPointableRadius() const
Vector TransformFrameDirection(const Vector &vFrameDirection)
transform a direction from the LeapAPI (e.g. Pointable::direction()) into scene space ...
void Rotate(const Vector &axis, float angleRadians)
virtual LEAP_EXPORT eSceneObjectType GetType() const
pure virtual methods requiring implementation in inheriting classes.
bool queueInteraction(const SceneInteraction &interaction)
virtual LEAP_EXPORT eSceneObjectType GetType() const
pure virtual methods requiring implementation in inheriting classes.
const Vector & GetSize() const
Matrix GetRotation() const
float m_fDeltaTimeSeconds
const Vector & GetCenter() const
void SetCenter(const Vector &vCenter)
const Vector & GetNormal() const
const SceneContactPoint * GetLastContactPoint(uint32_t uiIndex) const
uint32_t GetNumContacts() const
virtual LEAP_EXPORT ~Scene()
bool IsPendingRemoval() const
void clearInteractionQueue()
virtual LEAP_EXPORT eSceneObjectType GetType() const
pure virtual methods requiring implementation in inheriting classes.
void SetScale(float scale)
Matrix m_mtxFrameTransform
uint8_t m_bPendingRemoval
void SetUpdateRayCast(bool bUpdateRayCast)
void ClearInitialContact()
ray used for ray hit tests
scene manages scene objects - handles selection and movement
void SetSelected(bool selected)
bool HasInteraction(eInteractionType interactionType) const
const Vector & GetNormal() const
void Transform(const Matrix &mtxTransform)
change the orientation and position of this ray by the given transform
ObjectClass * AddObject()
void * GetUserData() const
SceneRay(const Vector &vOrigin, const Vector &vDirection)
uint32_t GetSerial() const
a unique serial number assigned to each object at creation time.
uint32_t GetNumObjects() const
void SetHeight(float height)
const Matrix & GetFrameTransform() const
Vector TransformFramePoint(const Vector &vFramePoint)
transforms a point from the Leap API (e.g. Pointable::tipPosition()) into scene space ...
void ClearSelectionChange()
const SceneInteraction * GetQueuedInteraction(uint32_t idx) const
access to a potential interaction queued up during the last update
stores the result of a ray test that hit something
#define LEAP_EXPORT_CLASS
void * GetUserData() const
bool HasTranslation() const
SceneRay Transformed(const Matrix &mtxTransform) const
bool ApplyInteraction(const SceneInteraction &interaction)
Leap::Matrix ExtractRotation(const Leap::Matrix &mtxTransform)
create a new matrix with just the rotation block from the argument matrix
float GetSelectHitTime() const
void SetUpdateContact(bool bUpdateContact)
bool HasInitialContact() const
bool GetUpdateContact() const
void SetFrameTransform(const Matrix &mtxFrameTransform)
SceneContactPoint * m_paLastContactPoints
float GetFrameScale() const
static eSceneObjectType ObjectType()
void Scale(float scaleMult)
const SceneObjectPtr & GetObjectByIndex(int idx) const
void SetUserData(void *pUserData)
virtual LEAP_EXPORT eSceneObjectType GetType() const
pure virtual methods requiring implementation in inheriting classes.
static eSceneObjectType ObjectType()
SceneContactPoint m_initialContactPoint
bool IsSelected() const
accessors to interaction values - validity depends on what types of interactions are in the flags...
SceneObjectPtr m_pHitObject
const SceneContactPoint * GetContactPoint(uint32_t uiIndex) const
void IncNumContacts(const SceneContactPoint &contactPoint)
const SceneContactPoint * GetLastContactPointByPointableID(int iPointableID) const
SceneContactPoint * m_paContactPoints
uint32_t GetNumQueuedInteractions() const
number of potential interactions that were queued up during the last update
Matrix GetTransform() const
static eSceneObjectType ObjectType()
eInteractionType
types of interactions that may be performed on a scene object
Vector transformPoint(const Vector &in) const
uint32_t GetNumPointing() const
Vector WorldToObjectPoint(const Vector &vPoint) const
void Transform(const Matrix &mtxTransform)
const SceneContactPoint * GetInitialContactPoint() const
void SetRadius(const float &radius)
float GetTotalHitTime() const
const Matrix & GetTransform() const