Example #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;
}
extern "C" FREObject createRigidBody(FREContext ctx, void *funcData, uint32_t argc, FREObject argv[])
{
    FREObject as3_shape = argv[0];
    FREObject as3_mass = argv[1];
    FREObject as3_inertia = argv[2];
    btCollisionShape* shape;
    double mass;
    
    FREGetObjectAsUint32(as3_shape, (uint32_t*)&shape);
    FREGetObjectAsDouble(as3_mass, &mass);
    
    bool isDynamic = (mass != 0.0f);
    
    btVector3 localInertia(0,0,0);
    if (as3_inertia)
        localInertia = vec3DToBtVector(as3_inertia);
    else if (isDynamic)
        shape->calculateLocalInertia((btScalar)mass, localInertia);
    
//    btMotionState* a3dMotionState = new Away3DMotionState(as3_skin);
    btMotionState* defaultMS = new btDefaultMotionState();
    btRigidBody::btRigidBodyConstructionInfo rbInfo((btScalar)mass, defaultMS, shape, localInertia);
    btRigidBody* body = new btRigidBody(rbInfo);
    
    FREObject ptr;
    FRENewObjectFromUint32((uint32_t)body, &ptr);
    return ptr;
}
Example #3
0
 FREObject LNLeapDevice::getPolicyFlags() {
     FREObject freFlags;
     
     uint32_t flags = controller->policyFlags();
     FRENewObjectFromUint32(flags, &freFlags);
     
     return freFlags;
 }
extern "C" FREObject RigidBodygetNumConstraintRefs(FREContext ctx, void *funcData, uint32_t argc, FREObject argv[])
{
    FREObject as3_body = argv[0];
    btRigidBody* body;
    
    FREGetObjectAsUint32(as3_body, (uint32_t*)&body);
    uint32_t num = body->getNumConstraintRefs();
    
    FREObject as3num;
    FRENewObjectFromUint32(num, &as3num);
    return as3num;
}
extern "C" FREObject createConeShape(FREContext ctx, void *funcData, uint32_t argc, FREObject argv[])
{
    FREObject as3_rad = argv[0];
    FREObject as3_height = argv[1];
    double rad, height;
    
    FREGetObjectAsDouble(as3_rad, &rad);
    FREGetObjectAsDouble(as3_height, &height);
    
    btCollisionShape* shape = new btConeShape(btScalar(rad), btScalar(height));
    
    FREObject ptr;
    FRENewObjectFromUint32((uint32_t)shape, &ptr);
    return ptr;
}
extern "C" FREObject RigidBodygetConstraintRef(FREContext ctx, void *funcData, uint32_t argc, FREObject argv[])
{
    FREObject as3_body = argv[0];
    FREObject as3_index = argv[1];
    btRigidBody* body;
    uint32_t index;
    
    FREGetObjectAsUint32(as3_body, (uint32_t*)&body);
    FREGetObjectAsUint32(as3_index, &index);
    btTypedConstraint* ref = body->getConstraintRef(index);
    
    FREObject as3ref;
    FRENewObjectFromUint32((uint32_t)ref, &as3ref);
    return as3ref;
}
FREObject getByte(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
	FREObject result;

	pthread_mutex_lock(&safety);
	FRENewObjectFromUint32(buffer[0], &result);
	memcpy(buffer, buffer + 1, bufferSize - 1);
	bufferSize--;
	if (bufferSize == 0)
	{
		sentEvent = 0;
	}
	pthread_mutex_unlock(&safety);

	return result;
}
Example #8
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;
}
Example #9
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;
}
Example #10
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;
}
Example #11
0
FREObject getFREObjectFromUint32(uint32_t arg) {
	FREObject result;
	FRENewObjectFromUint32(arg, &result);
	return result;
}
FREObject FREUint(uint32 value) {
	FREObject result;
	FRENewObjectFromUint32(value, &result);
	return result;
}