Пример #1
0
FREObject KinectDevice::freGetPointCloudFrame(FREObject argv[])
{
	FREObject objectPointsByteArray = argv[1];
    
	const unsigned int numPointBytes = pointCloudGenerator->getByteArrayLength() * sizeof(short);
	if(numPointBytes == 0) return NULL;

    lockPointCloudMutex();
    
    FREByteArray pointsByteArray;			
    FREObject pointsLength;
    FRENewObjectFromUint32(numPointBytes, &pointsLength);
    FRESetObjectProperty(objectPointsByteArray, (const uint8_t*) "length", pointsLength, NULL);
    FREAcquireByteArray(objectPointsByteArray, &pointsByteArray);
	memcpy(pointsByteArray.bytes, pointCloudGenerator->getTargetBytes(), numPointBytes);
    FREReleaseByteArray(objectPointsByteArray);
    
    //set the region information?
    FREObject asPointCloudRegions = argv[2];
    if(asPointCloudRegions != NULL && &pointCloudRegions != 0)
    {
        //loop through these actionscript regions and get the native info back
        FREObject asPointCloudRegion, asRegionId;
        FREObject asNumPoints;
        unsigned int regionId;
        
        uint32_t freNumRegions;
        FREGetArrayLength(asPointCloudRegions, &freNumRegions);
        
        for(unsigned int i = 0; i < freNumRegions; i++)
        {
            FREGetArrayElementAt(asPointCloudRegions, i, &asPointCloudRegion);
            FREGetObjectProperty(asPointCloudRegion, (const uint8_t *) "regionId", &asRegionId, NULL);
            FREGetObjectAsUint32(asRegionId, &regionId);
            //get the region with this id from the device memory
            for(unsigned int j = 0; j < numRegions; j++)
            {
                PointCloudRegion *nativeRegion = &pointCloudRegions[j];
                if(nativeRegion->regionId == regionId)
                {
                    //update the actionscript properties
                    FRENewObjectFromUint32(nativeRegion->numPoints, &asNumPoints);
                    FRESetObjectProperty(asPointCloudRegion, (const uint8_t *) "numPoints", asNumPoints, NULL);
                    break;
                }
            }
        }
    }
    
    unlockPointCloudMutex();
    
    return NULL;
}
Пример #2
0
	FREObject getCameraFrameSize(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		int w = gGrabber.getWidth();
		int h = gGrabber.getHeight();

		FREObject fX,fY;

		FRENewObjectFromInt32(w,&fX);
		FRENewObjectFromInt32(h,&fY);

		FREObject value = argv[0];

		FRESetObjectProperty(value,(const uint8_t*)"w",fX,NULL);                
		FRESetObjectProperty(value,(const uint8_t*)"h",fY,NULL);
		return NULL;
	}
Пример #3
0
/**
 * Called by ActionScript after it receives an event when a contact has been updated.
 * This method returns an array of the properties that have been updated for each contact.
 */
FREObject getUpdatedContactProperties(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
	pthread_mutex_lock(&amutex);
	FREObject result = NULL;
	FRENewObject((const uint8_t*) "Array", 0, NULL, &result, NULL);

	trace( "getUpdatedContactProperties" );

	int i = 0;

	for( i = 0; i<update_size; i++ )
	{
		ContactUpdate contactUpdate = contact_updates[ i ];

		FREObject update;
		FRENewObject((const uint8_t*) "Object", 0, NULL, &update, NULL);

		if( contactUpdate.value != NULL )
		{
			FREObject value;
			FRENewObjectFromUTF8( (uint32_t)(strlen(contactUpdate.value) + 1), (const uint8_t*)contactUpdate.value, &value );
			FRESetObjectProperty( update, (const uint8_t*) "value", value, NULL );
		}

		FREObject ppid;
		FRENewObjectFromUTF8( (uint32_t)(strlen(contactUpdate.ppid) + 1), (const uint8_t*)contactUpdate.ppid, &ppid );
		FRESetObjectProperty( update, (const uint8_t*) "ppid", ppid, NULL );

		FREObject property;
		FRENewObjectFromInt32( (int32_t)contactUpdate.property, &property );
		FRESetObjectProperty( update, (const uint8_t*) "property", property, NULL );

		FREObject status;
		FRENewObjectFromInt32( (int32_t)contactUpdate.status, &status );
		FRESetObjectProperty( update, (const uint8_t*) "status", status, NULL );

		FRESetArrayElementAt( result, i, update );

		free( contactUpdate.value );
		free( contactUpdate.ppid );

	}

	update_size = 0;
	pthread_mutex_unlock(&amutex);
	return result;
}
 virtual void setWorldTransform(const btTransform &worldTrans) {
     printShit("Should set transform...");
     FREObject raw, trans;
     FRENewObject((uint8_t*)"Vector.<Number>", 0, NULL, &raw, NULL);
     FRESetArrayLength(raw, 16);
     
     btScalar data[16];
     worldTrans.getOpenGLMatrix(data);
     printShit("Data: ");
     print16scalars(data);
     for (int i=0; i < 16; i++) {
         FREObject val;
         printResult(FRENewObjectFromDouble(double(data[i]), &val), "Make double", false);
         printResult(FRESetArrayElementAt(raw, i, val), "Set arr elem", false);
     }
     printResult(FRENewObject((uint8_t*)"flash.geom.Matrix3D", 0, NULL, &trans, NULL), "New Mat3D", false);
     printResult(FRESetObjectProperty(trans, (uint8_t*)"rawData", raw, NULL), "Set rawData", false);
     printResult(FRESetObjectProperty(skin, (uint8_t*)"transform", trans, NULL), "Set transform", false);
 }
Пример #5
0
	FREObject getMouseXY(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		POINT cursorPos;
		GetCursorPos(&cursorPos);

		FREObject value = argv[0];

		int x = (int) cursorPos.x;
		int y = (int) cursorPos.y;


		FREObject fX,fY;


		FRENewObjectFromInt32(x,&fX);
		FRENewObjectFromInt32(y,&fY);

		FRESetObjectProperty(value,(const uint8_t*)"x",fX,NULL);                
		FRESetObjectProperty(value,(const uint8_t*)"y",fY,NULL);        

		return NULL;
	}
Пример #6
0
FREObject getMouseInfo(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
	FREObject result = argv[0];

	POINT mouse;

	GetCursorPos(&mouse);

	int32_t x = (int32_t) mouse.x;
	int32_t y = (int32_t) mouse.y;

	FREObject mouseX;
	FREObject mouseY;

	FRENewObjectFromInt32(x, &mouseX);
	FRENewObjectFromInt32(y, &mouseY);

	FRESetObjectProperty(result, (const uint8_t*) "mouseX", mouseX, NULL);
	FRESetObjectProperty(result, (const uint8_t*) "mouseY", mouseY, NULL);

	return NULL;
}
Пример #7
0
FREObject KinectDevice::freGetInfraredFrame(FREObject argv[])
{
    const unsigned int numInfraredBytes = infraredImageBytesGenerator->getTargetPixelCount() * 4;
    
    FREObject objectByteArray = argv[1];
    FREByteArray byteArray;			
    FREObject length;
    FRENewObjectFromUint32(numInfraredBytes, &length);
    FRESetObjectProperty(objectByteArray, (const uint8_t*) "length", length, NULL);
    FREAcquireByteArray(objectByteArray, &byteArray);
    lockInfraredMutex();
	memcpy(byteArray.bytes, infraredImageBytesGenerator->getTargetBytes(), numInfraredBytes);
    unlockInfraredMutex();
    FREReleaseByteArray(objectByteArray);

	return NULL;
}
Пример #8
0
FREObject KinectDevice::freGetUserMaskFrame(FREObject argv[])
{
	unsigned int trackingID; FREGetObjectAsUint32(argv[1], &trackingID);
    
    if(trackingID > 0) trackingID--;
    
    const unsigned int numUserMaskBytes = userMasksGenerator->getTargetPixelCount() * 4;
    
    FREObject objectByteArray = argv[2];
    FREByteArray byteArray;			
    FREObject length;
    FRENewObjectFromUint32(numUserMaskBytes, &length);
    FRESetObjectProperty(objectByteArray, (const uint8_t*) "length", length, NULL);
    FREAcquireByteArray(objectByteArray, &byteArray);
    lockUserMaskMutex();
	memcpy(byteArray.bytes, userMasksGenerator->getTargetBytes()[trackingID], numUserMaskBytes);
    unlockUserMaskMutex();
    FREReleaseByteArray(objectByteArray);
    
    return NULL;
}
Пример #9
0
FREObject grabCamShot(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    if(_cam_shot_data)
    {
        FREObject length = NULL;
        FRENewObjectFromUint32(_cam_shot_size, &length);
        FRESetObjectProperty(argv[0], (const uint8_t*) "length", length, NULL);
    
        FREObject objectBA = argv[0];
        FREByteArray baData;
        FREAcquireByteArray(objectBA, &baData);
        uint8_t *ba = baData.bytes;
        
        memcpy(ba, _cam_shot_data, _cam_shot_size);
    
        FREReleaseByteArray(objectBA);
        
        free(_cam_shot_data);
        _cam_shot_size = 0;
        _cam_shot_data = NULL;
    }
    
    return NULL;
}
Пример #10
0
FREObject AKOpenNIUserFrameGenerator::getFREObject()
{
	FREObject freUserFrame, freUsers;

	FRENewObject( (const uint8_t*) _asUserFrameClass, 0, NULL, &freUserFrame, NULL);

	FRESetObjectProperty(freUserFrame, (const uint8_t*) "frameNumber", createFREObjectForUnsignedInt(_userFrame->frameNumber), NULL);
	FRESetObjectProperty(freUserFrame, (const uint8_t*) "timeStamp", createFREObjectForUnsignedInt(_userFrame->timeStamp), NULL);
    
	FRENewObject( (const uint8_t*) "Vector.<com.as3nui.nativeExtensions.air.kinect.data.User>", 0, NULL, &freUsers, NULL);

	int trackedSkeletons = 0;
	for(int i = 0; i < _userFrame->maxSkeletons; i++)
	{
		AKOpenNIUser* user = &_openNIUserFrame->openNIUsers[i];
		if(user->user->isTracking)
		{
			FREObject freUser, freJoints, freBones;

			FRENewObject( (const uint8_t*) _asUserClass, 0, NULL, &freUser, NULL);

			FRESetObjectProperty(freUser, (const uint8_t*) "framework", createFREObjectForUTF8(_framework), NULL);
			FRESetObjectProperty(freUser, (const uint8_t*) "userID", createFREObjectForUnsignedInt(user->user->userID), NULL);
			FRESetObjectProperty(freUser, (const uint8_t*) "trackingID", createFREObjectForUnsignedInt(user->user->trackingID), NULL);
			FRESetObjectProperty(freUser, (const uint8_t*) "position", user->user->position.asFREObject(), NULL);
			FRESetObjectProperty(freUser, (const uint8_t*) "hasSkeleton", createFREObjectForBool(user->user->hasSkeleton), NULL);

			FRENewObject( (const uint8_t*) "Vector.<com.as3nui.nativeExtensions.air.kinect.data.SkeletonJoint>", 0, NULL, &freJoints, NULL);

			for(int j = 0; j < user->user->numJoints; j++)
			{
				AKOpenNISkeletonJoint* skeletonJoint = &user->openNISkeletonJoints[j];

				FREObject freJoint;
				FRENewObject( (const uint8_t*) _asJointClass, 0, NULL, &freJoint, NULL);

				FRESetObjectProperty(freJoint, (const uint8_t*) "name", createFREObjectForUTF8(_jointNames[skeletonJoint->skeletonJoint->jointNameIndex]), NULL);
				FRESetObjectProperty(freJoint, (const uint8_t*) "position", skeletonJoint->skeletonJoint->position.asFREObject(), NULL);
				FRESetObjectProperty(freJoint, (const uint8_t*) "positionConfidence", createFREObjectForDouble(skeletonJoint->skeletonJoint->positionConfidence), NULL);
				
				FRESetObjectProperty(freJoint, (const uint8_t*) "nativeOrientationConfidence", createFREObjectForDouble(skeletonJoint->orientationConfidence), NULL);
				FRESetObjectProperty(freJoint, (const uint8_t*) "nativeOrientation", skeletonJoint->orientation.asFREObject(), NULL);
				
				FRESetArrayElementAt(freJoints, j, freJoint);
			}

			FRESetObjectProperty(freUser, (const uint8_t*) "skeletonJoints", freJoints, NULL);

			FRENewObject( (const uint8_t*) "Vector.<com.as3nui.nativeExtensions.air.kinect.data.SkeletonBone>", 0, NULL, &freBones, NULL);

			for(int j = 0; j < user->user->numBones; j++)
			{
				AKOpenNISkeletonBone* skeletonBone = &user->openNISkeletonBones[j];
				FREObject freBone;
				FRENewObject( (const uint8_t*) _asBoneClass, 0, NULL, &freBone, NULL);

				FRESetObjectProperty(freBone, (const uint8_t*) "name", createFREObjectForUTF8(_boneNames[skeletonBone->skeletonBone->boneNameIndex]), NULL);
				FRESetObjectProperty(freBone, (const uint8_t*) "orientation", skeletonBone->skeletonBone->orientation.asFREObject(), NULL);
				
				if(skeletonBone->skeletonBone->startJointNameIndex > -1) 
					FRESetObjectProperty(freBone, (const uint8_t*) "startJointName", createFREObjectForUTF8(_jointNames[skeletonBone->skeletonBone->startJointNameIndex]), NULL);
				
				if(skeletonBone->skeletonBone->endJointNameIndex > -1) 
					FRESetObjectProperty(freBone, (const uint8_t*) "endJointName", createFREObjectForUTF8(_jointNames[skeletonBone->skeletonBone->endJointNameIndex]), NULL);
				
				if(skeletonBone->skeletonBone->parentBoneNameIndex > -1) 
					FRESetObjectProperty(freBone, (const uint8_t*) "parentBoneName", createFREObjectForUTF8(_boneNames[skeletonBone->skeletonBone->parentBoneNameIndex]), NULL);

				FRESetArrayElementAt(freBones, j, freBone);
			}

			FRESetObjectProperty(freUser, (const uint8_t*) "skeletonBones", freBones, NULL);

			FRESetObjectProperty(freUser, (const uint8_t*) "skeletonJointNameIndices", freGetSkeletonJointNameIndices(), NULL);
			FRESetObjectProperty(freUser, (const uint8_t*) "skeletonJointNames", freGetSkeletonJointNames(), NULL);

			FRESetObjectProperty(freUser, (const uint8_t*) "skeletonBoneNameIndices", freGetSkeletonBoneNameIndices(), NULL);
			FRESetObjectProperty(freUser, (const uint8_t*) "skeletonBoneNames", freGetSkeletonBoneNames(), NULL);

			FRESetArrayElementAt(freUsers, trackedSkeletons, freUser);
			trackedSkeletons++;
		}
	}

	FRESetObjectProperty(freUserFrame, (const uint8_t*) "users", freUsers, NULL);

	return freUserFrame;
}
Пример #11
0
    FREObject LNLeapDevice::getFrame() {
        
        Frame frame = controller->frame();
        
        // TODO: Only continue with valid Frame?
        
        FREObject freCurrentFrame;
        FRENewObject( (const uint8_t*) "com.leapmotion.leap.Frame", 0, NULL, &freCurrentFrame, NULL);
        
        FREObject freFrameId;
        FRENewObjectFromInt32((int32_t) frame.id(), &freFrameId);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "id", freFrameId, NULL);
        
        const Vector frameTranslation = frame.translation(lastFrame);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "translationVector", createVector3(frameTranslation.x, frameTranslation.y, frameTranslation.z), NULL);
        
        const Matrix frameRotation = frame.rotationMatrix(lastFrame);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "rotation", createMatrix(
                     createVector3(frameRotation.xBasis[0], frameRotation.xBasis[1], frameRotation.xBasis[2]),
                     createVector3(frameRotation.yBasis[0], frameRotation.yBasis[1], frameRotation.yBasis[2]),
                     createVector3(frameRotation.zBasis[0], frameRotation.zBasis[1], frameRotation.zBasis[2]),
                     createVector3(frameRotation.origin[0], frameRotation.origin[1], frameRotation.origin[2])
        ), NULL);
        
        FREObject freFrameScaleFactor;
        FRENewObjectFromDouble(frame.scaleFactor(lastFrame), &freFrameScaleFactor);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "scaleFactorNumber", freFrameScaleFactor, NULL);
        
        FREObject freTimestamp;
        FRENewObjectFromInt32((int32_t) frame.timestamp(), &freTimestamp);
        FRESetObjectProperty(freCurrentFrame, (const uint8_t*) "timestamp", freTimestamp, NULL);
        
        std::map<int, FREObject> freHandsMap;
        if (!frame.hands().empty()) {
            
            FREObject freHands;
            FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "hands", &freHands, NULL);
            
            for(int i = 0; i < frame.hands().count(); i++) {
                const Hand hand = frame.hands()[i];
                
                FREObject freHand;
                FRENewObject( (const uint8_t*) "com.leapmotion.leap.Hand", 0, NULL, &freHand, NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "frame", freCurrentFrame, NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "direction", createVector3(hand.direction()[0], hand.direction()[1], hand.direction()[2]), NULL);
                
                FREObject freHandId;
                FRENewObjectFromInt32(hand.id(), &freHandId);
                FRESetObjectProperty(freHand, (const uint8_t*) "id", freHandId, NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "palmNormal", createVector3(hand.palmNormal()[0], hand.palmNormal()[1], hand.palmNormal()[2]), NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "palmPosition", createVector3(hand.palmPosition()[0], hand.palmPosition()[1], hand.palmPosition()[2]), NULL);
                FRESetObjectProperty(freHand, (const uint8_t*) "palmVelocity", createVector3(hand.palmVelocity()[0], hand.palmVelocity()[1], hand.palmVelocity()[2]), NULL);
                
                const Matrix rotation = hand.rotationMatrix(lastFrame);
                FRESetObjectProperty(freHand, (const uint8_t*) "rotation", createMatrix(
                                     createVector3(rotation.xBasis[0], rotation.xBasis[1], rotation.xBasis[2]),
                                     createVector3(rotation.yBasis[0], rotation.yBasis[1], rotation.yBasis[2]),
                                     createVector3(rotation.zBasis[0], rotation.zBasis[1], rotation.zBasis[2]),
                                     createVector3(rotation.origin[0], rotation.origin[1], rotation.origin[2])
                ), NULL);
                
                FREObject freScaleFactor;
                FRENewObjectFromDouble(hand.scaleFactor(lastFrame), &freScaleFactor);
                FRESetObjectProperty(freHand, (const uint8_t*) "scaleFactorNumber", freScaleFactor, NULL);
                
                FRESetObjectProperty(freHand, (const uint8_t*) "sphereCenter", createVector3(hand.sphereCenter()[0], hand.sphereCenter()[1], hand.sphereCenter()[2]), NULL);
                
                FREObject freSphereRadius;
                FRENewObjectFromDouble(hand.sphereRadius(), &freSphereRadius);
                FRESetObjectProperty(freHand, (const uint8_t*) "sphereRadius", freSphereRadius, NULL);
                
                const Vector translation = hand.translation(lastFrame);
                FRESetObjectProperty(freHand, (const uint8_t*) "translationVector", createVector3(translation.x, translation.y, translation.z), NULL);
                
                FRESetArrayElementAt(freHands, i, freHand);
                
                freHandsMap[hand.id()] = freHand;
            }
        }
        
        std::map<int, FREObject> frePointablesMap;
        if(!frame.pointables().empty()) {
            
            FREObject frePointables;
            FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "pointables", &frePointables, NULL);
            
            for(int i = 0; i < frame.pointables().count(); i++) {
                const Pointable pointable = frame.pointables()[i];
                
                FREObject frePointable;
                if(pointable.isTool()) {
                    FRENewObject( (const uint8_t*) "com.leapmotion.leap.Tool", 0, NULL, &frePointable, NULL);
                } else {
                    FRENewObject( (const uint8_t*) "com.leapmotion.leap.Finger", 0, NULL, &frePointable, NULL);
                }
                
                FRESetObjectProperty(frePointable, (const uint8_t*) "frame", freCurrentFrame, NULL);
                
                FREObject frePointableId;
                FRENewObjectFromInt32(pointable.id(), &frePointableId);
                FRESetObjectProperty(frePointable, (const uint8_t*) "id", frePointableId, NULL);
                
                FREObject frePointableLength;
                FRENewObjectFromDouble(pointable.length(), &frePointableLength);
                FRESetObjectProperty(frePointable, (const uint8_t*) "length", frePointableLength, NULL);

                FREObject frePointableWidth;
                FRENewObjectFromDouble(pointable.width(), &frePointableWidth);
                FRESetObjectProperty(frePointable, (const uint8_t*) "width", frePointableWidth, NULL);

                FRESetObjectProperty(frePointable, (const uint8_t*) "direction", createVector3(pointable.direction().x, pointable.direction().y, pointable.direction().z), NULL);
                FRESetObjectProperty(frePointable, (const uint8_t*) "tipPosition", createVector3(pointable.tipPosition().x, pointable.tipPosition().y, pointable.tipPosition().z), NULL);
                FRESetObjectProperty(frePointable, (const uint8_t*) "tipVelocity", createVector3(pointable.tipVelocity().x, pointable.tipVelocity().y, pointable.tipVelocity().z), NULL);
                
                //map to hand & back
                if(pointable.hand().isValid()) {
                    FREObject freHand = freHandsMap[pointable.hand().id()];
                    FRESetObjectProperty(frePointable, (const uint8_t*) "hand", freHand, NULL);
                    
                    FREObject frePointables;
                    FREGetObjectProperty(freHand, (const uint8_t*) "pointables", &frePointables, NULL);
                    
                    uint32_t numPointables;
                    FREGetArrayLength(frePointables, &numPointables);
                    FRESetArrayElementAt(frePointables, numPointables, frePointable);
                    
                    FREObject freSpecificHandPointables;
                    if(pointable.isTool()) {
                        FREGetObjectProperty(freHand, (const uint8_t*) "tools", &freSpecificHandPointables, NULL);
                    } else {
                        FREGetObjectProperty(freHand, (const uint8_t*) "fingers", &freSpecificHandPointables, NULL);
                    }
                    uint32_t numSpecificHandTools;
                    FREGetArrayLength(freSpecificHandPointables, &numSpecificHandTools);
                    FRESetArrayElementAt(freSpecificHandPointables, numSpecificHandTools, frePointable);
                }
                
                //push it in current frame
                FRESetArrayElementAt(frePointables, i, frePointable);
                
                //specific
                FREObject freSpecificPointables;
                if(pointable.isTool()) {
                    FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "tools", &freSpecificPointables, NULL);
                } else {
                    FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "fingers", &freSpecificPointables, NULL);
                }
                uint32_t numSpecificTools;
                FREGetArrayLength(freSpecificPointables, &numSpecificTools);
                FRESetArrayElementAt(freSpecificPointables, numSpecificTools, frePointable);
                frePointablesMap[pointable.id()] = frePointable;
            }
        }
        
        if(!frame.gestures().empty()) {
            
            FREObject freGestures;
            FREGetObjectProperty(freCurrentFrame, (const uint8_t*) "gesturesVector", &freGestures, NULL);
            
            for(int i = 0; i < frame.gestures().count(); i++) {
                const Gesture gesture = frame.gestures()[i];
                
                int state;
                switch (gesture.state()) {
                    case Gesture::STATE_INVALID:
                        state = 0;
                        break;
                    case Gesture::STATE_START:
                        state = 1;
                        break;
                    case Gesture::STATE_UPDATE:
                        state = 2;
                        break;
                    case Gesture::STATE_STOP:
                        state = 3;
                        break;
                        
                    default:
                        break;
                }
                
                int type;
                FREObject freGesture;
                switch (gesture.type()) {
                    case Gesture::TYPE_SWIPE:
                    {
                        type = 5;
                        SwipeGesture swipe = gesture;
                        
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.SwipeGesture", 0, NULL, &freGesture, NULL);
                        
                        FRESetObjectProperty(freGesture, (const uint8_t*) "direction", createVector3(swipe.direction().x, swipe.direction().y, swipe.direction().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "position", createVector3(swipe.position().x, swipe.position().y, swipe.position().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "startPosition", createVector3(swipe.startPosition().x, swipe.startPosition().y, swipe.startPosition().z), NULL);
                        
                        FREObject freSwipeGestureSpeed;
                        FRENewObjectFromDouble(swipe.speed(), &freSwipeGestureSpeed);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "speed", freSwipeGestureSpeed, NULL);

                        break;
                    }
                    case Gesture::TYPE_CIRCLE:
                    {
                        type = 6;
                        CircleGesture circle = gesture;

                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.CircleGesture", 0, NULL, &freGesture, NULL);
                        
                        FRESetObjectProperty(freGesture, (const uint8_t*) "center", createVector3(circle.center().x, circle.center().y, circle.center().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "normal", createVector3(circle.normal().x, circle.normal().y, circle.normal().z), NULL);
                        
                        FREObject freCircleGestureProgress;
                        FRENewObjectFromDouble(circle.progress(), &freCircleGestureProgress);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "progress", freCircleGestureProgress, NULL);
                        
                        FREObject freCircleGestureRadius;
                        FRENewObjectFromDouble(circle.radius(), &freCircleGestureRadius);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "radius", freCircleGestureRadius, NULL);
                    
                        FREObject frePointable = frePointablesMap[circle.pointable().id()];
                        if(frePointable != NULL)
                        {
                            FRESetObjectProperty(freGesture, (const uint8_t*) "pointable", frePointable, NULL);
                        }

                        break;
                    }
                    case Gesture::TYPE_SCREEN_TAP:
                    {
                        type = 7;
                        ScreenTapGesture screentap = gesture;
                        
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.ScreenTapGesture", 0, NULL, &freGesture, NULL);

                        FRESetObjectProperty(freGesture, (const uint8_t*) "direction", createVector3(screentap.direction().x, screentap.direction().y, screentap.direction().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "position", createVector3(screentap.position().x, screentap.position().y, screentap.position().z), NULL);

                        break;
                    }
                    case Gesture::TYPE_KEY_TAP:
                    {
                        type = 8;
                        KeyTapGesture tap = gesture;
                        
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.KeyTapGesture", 0, NULL, &freGesture, NULL);

                        FRESetObjectProperty(freGesture, (const uint8_t*) "direction", createVector3(tap.direction().x, tap.direction().y, tap.direction().z), NULL);
                        FRESetObjectProperty(freGesture, (const uint8_t*) "position", createVector3(tap.position().x, tap.position().y, tap.position().z), NULL);
                        
                        break;
                    }
                    default:
                    {
                        type = 4;
                        FRENewObject( (const uint8_t*) "com.leapmotion.leap.Gesture", 0, NULL, &freGesture, NULL);
                        break;
                    }
                }
                
                FREObject freGestureState;
                FRENewObjectFromInt32(state, &freGestureState);
                FRESetObjectProperty(freGesture, (const uint8_t*) "state", freGestureState, NULL);
                
                FREObject freGestureType;
                FRENewObjectFromInt32(type, &freGestureType);
                FRESetObjectProperty(freGesture, (const uint8_t*) "type", freGestureType, NULL);

                FREObject freGestureDuration;
                FRENewObjectFromInt32((int32_t) gesture.duration(), &freGestureDuration);
                FRESetObjectProperty(freGesture, (const uint8_t*) "duration", freGestureDuration, NULL);
                
                FREObject freGestureDurationSeconds;
                FRENewObjectFromDouble(gesture.durationSeconds(), &freGestureDurationSeconds);
                FRESetObjectProperty(freGesture, (const uint8_t*) "durationSeconds", freGestureDurationSeconds, NULL);
                
                FRESetObjectProperty(freGesture, (const uint8_t*) "frame", freCurrentFrame, NULL);
                
                FREObject freGestureId;
                FRENewObjectFromInt32(gesture.id(), &freGestureId);
                FRESetObjectProperty(freGesture, (const uint8_t*) "id", freGestureId, NULL);
                
                if (!gesture.hands().empty()) {
                    
                    FREObject freGestureHands;
                    FREGetObjectProperty(freGesture, (const uint8_t*) "hands", &freGestureHands, NULL);
                    
                    for(int i = 0; i < gesture.hands().count(); i++) {
                        const Hand hand = gesture.hands()[i];
                        
                        FREObject freHand = freHandsMap[hand.id()];
                        FRESetArrayElementAt(freGestureHands, i, freHand);
                    }
                }
                
                if (!gesture.pointables().empty()) {
                    
                    FREObject freGesturePointables;
                    FREGetObjectProperty(freGesture, (const uint8_t*) "pointables", &freGesturePointables, NULL);
                    
                    for(int i = 0; i < gesture.pointables().count(); i++) {
                        const Pointable pointable = gesture.pointables()[i];
                        
                        FREObject frePointable = frePointablesMap[pointable.id()];
                        FRESetArrayElementAt(freGesturePointables, i, frePointable);
                    }
                }
                
                //push it in current gesture vector
                FRESetArrayElementAt(freGestures, i, freGesture);
            }
        }
        
        lastFrame = frame;
        
        return freCurrentFrame;
    }