Esempio n. 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;
}
 virtual void getWorldTransform(btTransform &worldTrans) const {
     FREObject trans, raw;
     FREGetObjectProperty(skin, (uint8_t*)"transform", &trans, NULL);
     FREGetObjectProperty(trans, (uint8_t*)"rawData", &raw, NULL);
     
     btScalar data[16];
     for (int i=0; i < 16; i++) {
         FREObject val;
         double dval;
         FREGetArrayElementAt(raw, i, &val);
         FREGetObjectAsDouble(val, &dval);
         data[i] = btScalar(dval);
     }
     worldTrans.setFromOpenGLMatrix(data);
 }
Esempio n. 3
0
std::vector<std::string> getStringVectorFromFREObject(FREObject arg, const uint8_t * propertyName) {
	uint32_t numItems = getFREObjectArrayLength(arg);
	std::vector<std::string> ret;
	for (unsigned int k = 0; k < numItems; ++k) {
		FREObject elemAS = NULL;
		FREGetArrayElementAt(arg, k, &elemAS);
		std::string elem;
		if (propertyName == NULL)
			elem = getStringFromFREObject(elemAS);
		else
			elem = getStringFromFREObject(getFREObjectProperty(elemAS, propertyName));
		ret.push_back(elem);
	}
	return ret;
}
Esempio n. 4
0
// converts a FREObject string-array to a std::vector
std::vector<std::string> extractStringArray(FREObject object) {
	std::vector<std::string> tags;

	uint32 arrayLength;
	if (FREGetArrayLength(object, &arrayLength) != FRE_OK)
		return tags;

	tags.reserve(arrayLength);
	for (uint32 i = 0; i < arrayLength; ++i) {
		FREObject value;
		if (FREGetArrayElementAt(object, i, &value) != FRE_OK)
			continue;

		std::string strval;
		if (!FREGetString(value, strval))
			continue;

		tags.push_back(strval);
	}

	return tags;
}
Esempio n. 5
0
FREObject KinectDevice::freSetPointCloudRegions(FREObject argv[])
{
	FREObject asPointCloudRegions = argv[1];
    FREObject asPointCloudRegion, asRegionId, asX, asY, asZ, asWidth, asHeight, asDepth;
    unsigned int regionId;
    double x, y, z, width, height, depth;
    
    uint32_t freNumRegions;
    FREGetArrayLength(asPointCloudRegions, &freNumRegions);
    
    PointCloudRegion *nativeRegions = new PointCloudRegion[freNumRegions];
    
    for(unsigned int i = 0; i < freNumRegions; i++)
    {
        FREGetArrayElementAt(asPointCloudRegions, i, &asPointCloudRegion);
        FREGetObjectProperty(asPointCloudRegion, (const uint8_t *) "regionId", &asRegionId, NULL);
        FREGetObjectProperty(asPointCloudRegion, (const uint8_t *) "x", &asX, NULL);
        FREGetObjectProperty(asPointCloudRegion, (const uint8_t *) "y", &asY, NULL);
        FREGetObjectProperty(asPointCloudRegion, (const uint8_t *) "z", &asZ, NULL);
        FREGetObjectProperty(asPointCloudRegion, (const uint8_t *) "width", &asWidth, NULL);
        FREGetObjectProperty(asPointCloudRegion, (const uint8_t *) "height", &asHeight, NULL);
        FREGetObjectProperty(asPointCloudRegion, (const uint8_t *) "depth", &asDepth, NULL);
        FREGetObjectAsUint32(asRegionId, &regionId);
        FREGetObjectAsDouble(asX, &x);
        FREGetObjectAsDouble(asY, &y);
        FREGetObjectAsDouble(asZ, &z);
        FREGetObjectAsDouble(asWidth, &width);
        FREGetObjectAsDouble(asHeight, &height);
        FREGetObjectAsDouble(asDepth, &depth);
        PointCloudRegion *nativeRegion = new PointCloudRegion();
        nativeRegion->setProperties(regionId, x, y, z, width, height, depth);
        nativeRegions[i] = *nativeRegion;
    }
    
    this->pointCloudRegions = nativeRegions;
    this->numRegions = freNumRegions;
    
    return NULL;
}
Esempio n. 6
0
FREObject KinectDevice::freChooseSkeletons(FREObject argv[])
{
	FREObject asSkeletonIds = argv[1];
	FREObject asSkeletonId;
	int skeletonId;
    
    uint32_t freNumChosenSkeletonIds;
    FREGetArrayLength(asSkeletonIds, &freNumChosenSkeletonIds);
    
	int *freChosenSkeletonIds = new int[freNumChosenSkeletonIds];
    
    for(unsigned int i = 0; i < freNumChosenSkeletonIds; i++)
    {
		FREGetArrayElementAt(asSkeletonIds, i, &asSkeletonId);
		FREGetObjectAsInt32(asSkeletonId, &skeletonId);
		freChosenSkeletonIds[i] = skeletonId;
    }

	this->chosenSkeletonIds = freChosenSkeletonIds;
	this->numChosenSkeletons = freNumChosenSkeletonIds;
    
	return NULL;
}
FREObject getScores(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
	SC_ScoreList_h score_list;
	SC_Score_h aScore;
    FREObject returnObject;
    int i,j;
    unsigned int contextArrayLength = 0;
	FREGetArrayLength(argv[0],&contextArrayLength);

	score_list = SC_ScoresController_GetScores(scores_controller);
	// arrayArgs has the Array arguments.
#if defined(BB10)
	unsigned int scoreListSize = SC_ScoreList_GetCount(score_list);
#else
	unsigned int scoreListSize = SC_ScoreList_GetScoresCount(score_list);
#endif

    FREObject* arrayArgs = (FREObject*)malloc(sizeof(FREObject)*scoreListSize);

	for(i = 0 ; i < scoreListSize ; i++)
	{
#if defined(BB10)
		aScore = SC_ScoreList_GetAt(score_list,i);
#else
		aScore = SC_ScoreList_GetScore(score_list,i);
#endif
	    FREObject* argV=(FREObject*)malloc(sizeof(FREObject)*6);
	    FRENewObjectFromInt32(SC_Score_GetMode(aScore), &argV[0]);
	    FRENewObjectFromInt32(SC_Score_GetLevel(aScore), &argV[1]);
	    FRENewObjectFromDouble(SC_Score_GetResult(aScore), &argV[2]);
	    FRENewObjectFromDouble(SC_Score_GetMinorResult(aScore), &argV[3]);

	    // Create the 5th argument(User)
	    SC_User_h aUser = SC_Score_GetUser(aScore);
	    SC_String_h scLogin = SC_User_GetLogin(aUser);
	    SC_String_h scEmail = SC_User_GetEmail(aUser);
	    const char * login = "";
	    const char * email = "";
	    if(scLogin != NULL)
	    	login= SC_String_GetData(scLogin);
	    if(scEmail != NULL)
	    	email = SC_String_GetData(scEmail);
	    FREObject* userArgV=(FREObject*)malloc(sizeof(FREObject)*2);
	    FRENewObjectFromUTF8(strlen(login)+1,(const uint8_t*)login, &userArgV[0]);
	    FRENewObjectFromUTF8(strlen(email)+1,(const uint8_t*)email, &userArgV[1]);
	    fprintf(stderr, "username: %s\n", login);

	    FRENewObject((const uint8_t*)"com.wallwizz.scoreloop.User",2,userArgV,&argV[4],NULL);

	    // Create the 6th argument(Context)
	    FREObject* contextArray = (FREObject*)malloc(sizeof(FREObject)*contextArrayLength);
	    for(j = 0; j < contextArrayLength; j++)
	    {
		    FREObject context;
			FREObject freContextKey;
			const char * aKey = "test";
			SC_String_h scValue = NULL;
			const char* aValue = NULL;
			unsigned int length;
			FREGetArrayElementAt(argv[0], j, &freContextKey);

			if(FREGetObjectAsUTF8(freContextKey,&length,(const uint8_t**)&aKey) != FRE_OK)
				fprintf(stderr, "FREGetArrayElementAt Error\n");

		    fprintf(stderr, "retrieved aKey: %s\n", aKey);
			SC_Context_h aContext = SC_Score_GetContext(aScore);
			SC_Context_Get(aContext, aKey, &scValue);
		    if(scValue != NULL)
		    {
		    	aValue= SC_String_GetData(scValue);
		    }else{
			    fprintf(stderr, "scValue NULL\n");
			    aValue = "not found";
		    }
		    fprintf(stderr, "retrieved aValue: %s\n", aValue);

		    FREObject* contextArgv=(FREObject*)malloc(sizeof(FREObject)*2);
		    FRENewObjectFromUTF8(strlen(aKey)+1,(const uint8_t*)aKey, &contextArgv[0]);
		    FRENewObjectFromUTF8(strlen(aValue)+1,(const uint8_t*)aValue, &contextArgv[1]);
		    FRENewObject((const uint8_t*)"com.wallwizz.scoreloop.Context",2,contextArgv,&contextArray[j],NULL);
		    free(contextArgv);
	    }
	    FRENewObject((const uint8_t*)"Array",contextArrayLength,contextArray,&argV[5],NULL);

	    FRENewObject((const uint8_t*)"com.wallwizz.scoreloop.Score",6,argV,&arrayArgs[i],NULL);
	    free(contextArray);
	}
    FRENewObject((const uint8_t*)"Array",scoreListSize,arrayArgs,&returnObject,NULL);
    free(arrayArgs);
    return returnObject;
}