16 #if defined(LEAP_SCENE_USE_UTIL_GL) 27 : m_pUserData( NULL ),
28 m_fDeltaTimeSeconds( 0.0
f ),
29 m_fPointableRadius( 1.0
f ),
30 m_fSelectHitTime( 1.0
f ),
33 m_uiNumQueuedInteractions( 0 ),
34 m_uiNumPendingRemovals( 0 ),
36 m_uiFlags( kF_UpdateRayCast | kF_UpdateContact )
56 pObj->m_pScene = NULL;
98 float fClosestHitDist = FLT_MAX;
99 int closestHitIndex = -1;
103 float fHitDist = FLT_MAX;
106 closestHitIndex =
static_cast<int>(i);
107 fClosestHitDist = fHitDist;
111 if (closestHitIndex >= 0)
119 #if defined(LEAP_SCENE_USE_UTIL_GL) 120 void Scene::RayHitsDebugDrawGL()
const 122 GLAttribScope attribScope( GL_CURRENT_BIT | GL_LIGHTING_BIT );
124 glDisable( GL_LIGHTING );
132 rayHit.DebugDrawGL( fHitSphereSize );
135 #endif // LEAP_SCENE_USE_UTIL_GL 150 pObjToRemove->m_pScene = NULL;
153 pObjToRemove->m_index =
static_cast<uint32_t
>(
kMaxObjects);
179 float fClosestHitDist = FLT_MAX;
180 int closestHitIndex = -1;
184 float fHitDist = FLT_MAX;
187 closestHitIndex =
static_cast<int>(i);
188 fClosestHitDist = fHitDist;
192 if (closestHitIndex >= 0)
229 for ( uint32_t j = 0, numPointables = pointables.
count(); j < numPointables; j++ )
231 const Pointable& pointable = pointables[j];
233 const int iPointableID = pointable.
id();
257 static const uint8_t kMaxContactMissedFrames = 64;
286 if ( contactPointable.
isValid() )
334 if ( pCurContact0 && pCurContact1 )
341 const float fLastDist = lastVec.
magnitude();
342 const float fNewDist = newVec.
magnitude();
344 const float fScale = fNewDist/fLastDist;
347 const Vector vLastDir = lastVec * 1.0f/fLastDist;
348 const Vector vNewDir = newVec * 1.0f/fNewDist;
351 const float fAngle = acosf( vNewDir.
dot(vLastDir) );
428 #if defined(LEAP_SCENE_USE_UTIL_GL) 429 void SceneRayHit::DebugDrawGL(
float fHitSphereSize )
const 431 const Vector& pos = m_ray.m_vOrigin;
432 const Vector& pt = m_hitPoint;
435 glVertex3fv( &(pos.
x) );
436 glVertex3fv( &(pt.
x) );
442 glTranslatef(pt.
x, pt.
y, pt.
z);
443 glScalef( fHitSphereSize, fHitSphereSize, fHitSphereSize );
448 #endif // LEAP_SCENE_USE_UTIL_GL 462 Vector vMax = GetSize() * m_fScale * 0.5f;
493 Vector vPos = WorldToObjectPoint(vTestPoint);
494 Vector vMax = GetSize() * m_fScale * 0.5f;
501 #if defined(LEAP_SCENE_USE_UTIL_GL) 502 void SceneBox::DebugDrawGL(
eStyle drawStyle )
const 505 const Vector vSize = GetSize() * GetScale();
507 glMultMatrixf( GetTransform().toArray4x4() );
509 glScalef( vSize.
x, vSize.
y, vSize.
z );
515 GLAttribScope attribScope( GL_CURRENT_BIT|GL_DEPTH_BUFFER_BIT );
519 glColor3f(1.0
f, 1.0
f, 1.0
f);
523 glDisable(GL_DEPTH_TEST);
525 glScalef( vScale.
x, vScale.
y, vScale.
z );
530 #endif // LEAP_SCENE_USE_UTIL_GL 537 float radius = m_fScale * m_fRadius;
538 float height = m_fScale * m_fHeight;
552 float tin = temp - s;
553 float tout = temp + s;
555 if (tin > 0 && fabs(testRayObj.
CalcPointOn(tin).
y) <= height/2.0)
561 if (tout > 0 && fabs(testRayObj.
CalcPointOn(tout).
y) <= height/2.0)
576 const Vector vTestPosObj = WorldToObjectPoint(vTestPoint);
578 const float fCylRadius = m_fRadius * m_fScale;
579 const float fHalfCylHeight = m_fHeight * m_fScale * 0.5f;
581 const Vector vAxisToPoint =
Vector(vTestPosObj.
x, 0, vTestPosObj.
z);
587 if (fAxisToPointDistSq < (fTestRadius + fCylRadius)*(fTestRadius + fCylRadius))
590 const float fAbsDistAlongAxis = fabs(vTestPosObj.
y);
595 if (fAbsDistAlongAxis < fHalfCylHeight)
604 if (fAxisToPointDistSq < (fCylRadius*fCylRadius) && fAbsDistAlongAxis < (fHalfCylHeight + fTestRadius) )
613 Vector( 0, fHalfCylHeight * ((vTestPosObj.
y < 0.0f) ? -1.0f : 1.0f), 0 );
617 if ((vTestPosObj-vClosest).magnitudeSquared() < fTestRadius*fTestRadius)
626 #if defined(LEAP_SCENE_USE_UTIL_GL) 627 void SceneCylinder::DebugDrawGL(
eStyle drawStyle )
const 630 const float fHeight = GetHeight() * GetScale();
631 const float fRadius = GetRadius() * GetScale();
633 glMultMatrixf( GetTransform().toArray4x4() );
635 glScalef( fRadius * 2, fHeight, fRadius * 2 );
641 GLAttribScope attribScope( GL_CURRENT_BIT|GL_DEPTH_BUFFER_BIT );
645 glColor3f(1.0
f, 1.0
f, 1.0
f);
649 glDisable(GL_DEPTH_TEST);
650 const float fScaleXZ = 1.0f/(fRadius + fRadius) * 0.125
f;
651 glScalef( fScaleXZ, 1.0
f/fHeight * 0.125
f, fScaleXZ );
655 #endif // LEAP_SCENE_USE_UTIL_GL 663 float fRadius = m_fScale * m_fRadius;
679 if ( fPlaneHitDist > 0 )
687 fHitDistOut = fPlaneHitDist;
700 const Vector vPos = WorldToObjectPoint(vTestPoint);
701 const float fDiskRadius = (m_fScale*m_fRadius);
704 if (fabs(vPos.
z) < fTestRadius)
707 const Vector vOnPlane( vPos.
x, vPos.
y, 0 );
708 const float fSin = vPos.
z/fTestRadius;
709 const float fCos = sqrtf(1 - fSin*fSin);
714 fTestRadius = fCos * fTestRadius + fDiskRadius;
725 #if defined(LEAP_SCENE_USE_UTIL_GL) 726 void SceneDisk::DebugDrawGL(
eStyle drawStyle )
const 729 const float fRadius = GetRadius() * GetScale();
731 glMultMatrixf( GetTransform().toArray4x4() );
733 glScalef( fRadius + fRadius, fRadius + fRadius, fRadius + fRadius );
739 GLAttribScope attribScope( GL_CURRENT_BIT|GL_DEPTH_BUFFER_BIT );
743 glColor3f(1.0
f, 1.0
f, 1.0
f);
747 glDisable(GL_DEPTH_TEST);
748 const float fScale = 1.0f/(fRadius + fRadius) * 0.125
f;
749 glScalef( fScale, fScale, fScale );
753 #endif // LEAP_SCENE_USE_UTIL_GL 757 const float fRayAngleCos = GetNormal().dot( testRay.
m_vDirection );
765 const float fRayOriginPlaneDist = GetNormal().dot(GetCenter() - testRay.
m_vOrigin);
768 const float fPlaneHitDist = fRayOriginPlaneDist/fRayAngleCos;
770 if (fPlaneHitDist > 0)
772 fHitDistOut = fPlaneHitDist;
781 return fabs((vTestPoint - GetCenter()).
dot(GetNormal())) < fTestRadius;
784 #if defined(LEAP_SCENE_USE_UTIL_GL) 785 void ScenePlane::DebugDrawGL(
eStyle drawStyle )
const 789 #endif // LEAP_SCENE_USE_UTIL_GL 793 const float fRadius = m_fScale * m_fRadius;
796 const float c = O.
dot(O) - fRadius*fRadius;
797 const float disc = b*b - c;
801 float sdisc = sqrtf(disc);
802 float root = (-b - sdisc);
824 const float fMaxDist = (m_fScale*m_fRadius + fTestRadius);
825 return (GetCenter() - vTestPoint).magnitudeSquared() < (fMaxDist * fMaxDist);
828 #if defined(LEAP_SCENE_USE_UTIL_GL) 829 void SceneSphere::DebugDrawGL(
eStyle drawStyle )
const 833 const float fRadius = GetRadius() * GetScale();
835 glMultMatrixf( GetTransform().toArray4x4() );
837 glScalef( fRadius+fRadius, fRadius+fRadius, fRadius+fRadius );
843 GLAttribScope attribScope( GL_CURRENT_BIT|GL_DEPTH_BUFFER_BIT );
847 glColor3f(1.0
f, 1.0
f, 1.0
f);
851 glDisable(GL_DEPTH_TEST);
853 const float fScale = 1.0f/(fRadius + fRadius) * 0.125
f;
854 glScalef( fScale, fScale, fScale );
859 #endif // LEAP_SCENE_USE_UTIL_GL void drawCylinder(eStyle style, eAxis axis)
uint8_t m_uiHasInitialContact
Vector CalcPointOn(float fDistFromOrigin) const
returns a point that is the specified distance down the ray.
uint8_t m_uiLastNumContacts
virtual LEAP_EXPORT bool TestRayHit(const SceneRay &testRay, float &fHitDistOut) const
LEAP_EXPORT bool isValid() const
virtual LEAP_EXPORT bool TestSphereHit(const Vector &vTestPoint, float fTestRadius) const
static const SmartPointer & Null()
convenient static method for returning in cases where a null return value is needed.
void updateInteraction(const Frame &frame)
bool GetUpdateRayCast() const
bool IsNearEqual(const T &a, const T &b)
works with Vectors as well as floats
virtual LEAP_EXPORT bool TestRayHit(const SceneRay &testRay, float &fHitDistOut) const
TFSIMD_FORCE_INLINE Vector3 cross(const Vector3 &v) const
Vector cross(const Vector &other) const
uint32_t GetLastNumContacts() const
bool IsNearZero(float fVal)
void drawSphere(eStyle style)
SceneObjectPtr m_apObjects[kMaxObjects]
float MinComponent(const Leap::Vector &vVec)
void deallocateObject(uint32_t idxToRemove)
void rotateContactPoints()
uint32_t m_uiNumPendingRemovals
LEAP_EXPORT Vector tipPosition() const
uint32_t GetNumRayHits() const
the number of ray tests that resulted in hits from the last update
const SceneContactPoint * GetContactPointByPointableID(int iPointableID) const
void drawBox(eStyle style)
Vector TransformFrameDirection(const Vector &vFrameDirection)
transform a direction from the LeapAPI (e.g. Pointable::direction()) into scene space ...
LEAP_EXPORT bool isEmpty() const
bool queueInteraction(const SceneInteraction &interaction)
SceneRayHit m_aRayHits[kMaxRayHits]
float m_fDeltaTimeSeconds
const Vector & GetCenter() const
virtual LEAP_EXPORT bool TestRayHit(const SceneRay &testRay, float &fHitDistOut) const
utility class for caching and restoring GL attributes via the glPushAttrib/glPopAttrib calls...
const SceneContactPoint * GetLastContactPoint(uint32_t uiIndex) const
uint32_t GetNumContacts() const
float MaxComponent(const Leap::Vector &vVec)
void clearInteractionQueue()
void processPendingRemovals()
uint8_t m_bPendingRemoval
const SceneObjectPtr & TestRayHit(const SceneRay &ray) const
allows for casting an arbitrary ray and finding out what it hits (if anything)
virtual LEAP_EXPORT bool TestSphereHit(const Vector &vTestPoint, float fTestRadius) const
float magnitudeSquared() const
LEAP_EXPORT void Update(const Frame &frame, float fDeltaTimeSeconds)
Leap::Vector ComponentWiseReciprocal(const Leap::Vector &vVec)
ray used for ray hit tests
void drawDisk(eStyle style, ePlane plane)
disk is double-side
virtual LEAP_EXPORT bool TestSphereHit(const Vector &vTestPoint, float fTestRadius) const
void SetSelected(bool selected)
static const Vector & yAxis()
float dot(const Vector &other) const
virtual LEAP_EXPORT bool TestSphereHit(const Vector &vPoint, float fRadius) const
TFSIMD_FORCE_INLINE tfScalar dot(const Quaternion &q1, const Quaternion &q2)
Leap::Vector ComponentWiseMax(const Leap::Vector &vLHS, const Leap::Vector &vRHS)
virtual LEAP_EXPORT bool TestRayHit(const SceneRay &testRay, float &fHitDistOut) const
virtual LEAP_EXPORT bool TestRayHit(const SceneRay &testRay, float &fHitDistOut) const
LEAP_EXPORT void RemoveObject(SceneObject *pObject)
bool testRayHitClosest(SceneRayHit &hitResult)
Vector TransformFramePoint(const Vector &vFramePoint)
transforms a point from the Leap API (e.g. Pointable::tipPosition()) into scene space ...
void setRotation(const Vector &axis, float angleRadians)
stores the result of a ray test that hit something
SceneRay Transformed(const Matrix &mtxTransform) const
LEAP_EXPORT int count() const
static const Vector & zero()
virtual LEAP_EXPORT bool TestSphereHit(const Vector &vTestCenter, float fTestRadius) const
bool HasInitialContact() const
bool GetUpdateContact() const
LEAP_EXPORT void DeselectAll()
does not queue interactions, sets all objects to deselected state immediately.
static const float kfEpsilon
SceneContactPoint m_initialContactPoint
SceneObjectPtr m_pHitObject
const SceneContactPoint * GetContactPoint(uint32_t uiIndex) const
Leap::Vector ComponentWiseMin(const Leap::Vector &vLHS, const Leap::Vector &vRHS)
void IncNumContacts(const SceneContactPoint &contactPoint)
void updateContact(const SceneContactPoint &testPoint)
void updateSelectionAndContact(const Frame &frame)
utility class for keeping the gl matrix stack push/pop operations paired up correctly.
uint32_t GetNumPointing() const
Leap::Vector ComponentWiseScale(const Leap::Vector &vLHS, const Leap::Vector &vRHS)
LEAP_EXPORT Pointable pointable(int32_t id) const