Esempio n. 1
0
int DAUDIO_Flush(void* id, int isSource) {
    SolPcmInfo* info = (SolPcmInfo*) id;
    int err = -1;
    int pos;

    TRACE0("DAUDIO_Flush\n");
    if (info) {
	if (isSource) {
	    err = ioctl(info->fd, I_FLUSH, FLUSHW);
	} else {
	    err = ioctl(info->fd, I_FLUSH, FLUSHR);
	}
	if (err >= 0) {
	    /* resets the transferedBytes parameter to
	     * the current samples count of the device
	     */
	    pos = getDevicePosition(info, isSource);
	    if (pos >= 0) {
		info->transferedBytes = pos;
	    }
	}
    }
    if (err < 0) {
	ERROR0("ERROR in DAUDIO_Flush\n");
    }
    return (err < 0)?FALSE:TRUE;
}
void SixDofWithScaleNavigationTool::frame(void)
	{
	/* Act depending on this tool's current state: */
	switch(navigationMode)
		{
		case IDLE:
			/* Do nothing */
			break;
		
		case MOVING:
			{
			/* Compose the new navigation transformation: */
			NavTrackerState navigation=getDeviceTransformation(0);
			navigation*=preScale;
			
			/* Update Vrui's navigation transformation: */
			setNavigationTransformation(navigation);
			break;
			}
		
		case SCALING:
			{
			/* Compose the new navigation transformation: */
			NavTrackerState navigation=preScale;
			Vector scaleDirection=getDeviceTransformation(1).transform(factory->deviceScaleDirection);
			Scalar currentScale=Math::exp((getDevicePosition(0)*scaleDirection-initialScale)/factory->scaleFactor);
			navigation*=NavTrackerState::scale(currentScale);
			navigation*=postScale;
			
			/* Update Vrui's navigation transformation: */
			setNavigationTransformation(navigation);
			break;
			}
		}
	}
Esempio n. 3
0
void ClutchTool::buttonCallback(int,int deviceButtonIndex,InputDevice::ButtonCallbackData* cbData)
	{
	if(deviceButtonIndex==0) // Clutch button
		{
		bool mustInit=false;
		if(factory->clutchButtonToggleFlag)
			{
			if(!cbData->newButtonState)
				{
				clutchButtonState=!clutchButtonState;
				mustInit=!clutchButtonState;
				}
			}
		else
			{
			clutchButtonState=cbData->newButtonState;
			mustInit=!clutchButtonState;
			}
		
		if(mustInit)
			{
			/* Calculate the new offset transformation: */
			Vector offsetT=transformedDevice->getPosition()-getDevicePosition(0);
			Rotation offsetR=transformedDevice->getTransformation().getRotation()*Geometry::invert(getDeviceTransformation(0).getRotation());
			offset=TrackerState(offsetT,offsetR);
			}
		}
	else // Pass-through button
		{
		if(setButtonState(deviceButtonIndex-1,cbData->newButtonState))
			transformedDevice->setButtonState(deviceButtonIndex-1,buttonStates[deviceButtonIndex-1]);
		}
	}
void SixDofWithScaleNavigationTool::buttonCallback(int,int,InputDevice::ButtonCallbackData* cbData)
	{
	if(cbData->newButtonState) // Button has just been pressed
		{
		if(navigationMode==IDLE&&activate())
			{
			/* Decide whether to go to moving or scaling mode: */
			if(Geometry::sqrDist(getDevicePosition(0),getDevicePosition(1))<=factory->scaleDeviceDistance2) // Want to scale
				{
				/* Determine the scaling center and initial scale: */
				scalingCenter=getDevicePosition(1);
				Vector scaleDirection=getDeviceTransformation(1).transform(factory->deviceScaleDirection);
				initialScale=getDevicePosition(0)*scaleDirection;
				
				/* Initialize the navigation transformations: */
				preScale=NavTrackerState::translateFromOriginTo(scalingCenter);
				postScale=NavTrackerState::translateToOriginFrom(scalingCenter);
				postScale*=getNavigationTransformation();
				
				/* Go from MOVING to SCALING mode: */
				navigationMode=SCALING;
				}
			else // Want to move
				{
				/* Initialize the navigation transformations: */
				preScale=Geometry::invert(getDeviceTransformation(0));
				preScale*=getNavigationTransformation();
				
				/* Go from IDLE to MOVING mode: */
				navigationMode=MOVING;
				}
			}
		}
	else // Button has just been released
		{
		/* Deactivate this tool: */
		deactivate();
		
		/* Go from MOVING or SCALING to IDLE mode: */
		navigationMode=IDLE;
		}
	}
Esempio n. 5
0
void ClipPlaneTool::frame(void)
	{
	if(active)
		{
		/* Get the new normal vector and plane center point: */
		Vector normal=getDeviceTransformation(0).transform(factory->normal);
		Point center=getDevicePosition(0);
		
		/* Set the clipping plane's plane equation: */
		clipPlane->getPlane()=Plane(normal,center);
		}
	}
Esempio n. 6
0
void DAUDIO_SetBytePosition(void* id, int isSource, INT64 javaBytePos) {
    SolPcmInfo* info = (SolPcmInfo*) id;
    int ret;
    int pos;

    if (info) {
	pos = getDevicePosition(info, isSource);
	if (pos >= 0) {
	    info->positionOffset = javaBytePos - pos;
	}
    }
}
Esempio n. 7
0
void ClutchTool::frame(void)
	{
	if(!clutchButtonState)
		{
		/* Update the transformation of the transformed device: */
		TrackerState clutch=getDeviceTransformation(0);
		clutch.leftMultiply(TrackerState::rotateAround(getDevicePosition(0),offset.getRotation()));
		clutch.leftMultiply(TrackerState::translate(offset.getTranslation()));
		clutch.renormalize();
		transformedDevice->setTransformation(clutch);
		}
	}
Esempio n. 8
0
INT64 DAUDIO_GetBytePosition(void* id, int isSource, INT64 javaBytePos) {
    SolPcmInfo* info = (SolPcmInfo*) id;
    int ret;
    int pos;
    INT64 result = javaBytePos;

    if (info) {
	pos = getDevicePosition(info, isSource);
	if (pos >= 0) {
	    result = info->positionOffset + pos;
	}
    }

    //printf("getbyteposition: javaBytePos=%d , return=%d\n", (int) javaBytePos, (int) result);
    return result;
}
Esempio n. 9
0
int DAUDIO_GetAvailable(void* id, int isSource) {
    SolPcmInfo* info = (SolPcmInfo*) id;
    int ret = 0;
    int pos;

    if (info) {
	/* unfortunately, the STREAMS architecture 
	 * seems to not have a method for querying
	 * the available bytes to read/write!
	 * estimate it...
	 */
	pos = getDevicePosition(info, isSource);
	if (pos >= 0) {
	    if (isSource) {
		/* we usually have written more bytes
		 * to the queue than the device position should be
		 */
		ret = (info->bufferSizeInBytes) - (info->transferedBytes - pos);
	    } else {
		/* for record, the device stream should
		 * be usually ahead of our read actions
		 */
		ret = pos - info->transferedBytes;
	    }
	    if (ret > info->bufferSizeInBytes) {
		ERROR2("DAUDIO_GetAvailable: available=%d, too big at bufferSize=%d!\n",
		       (int) ret, (int) info->bufferSizeInBytes);
		ERROR2("                     devicePos=%d, transferedBytes=%d\n",
		       (int) pos, (int) info->transferedBytes);
		ret = info->bufferSizeInBytes;
	    }
	    else if (ret < 0) {
		ERROR1("DAUDIO_GetAvailable: available=%d, in theory not possible!\n",
		       (int) ret);
		ERROR2("                     devicePos=%d, transferedBytes=%d\n",
		       (int) pos, (int) info->transferedBytes);
		ret = 0;
	    }
	}
    }

    TRACE1("DAUDIO_GetAvailable returns %d bytes\n", ret);
    return ret;
}
void ValuatorScalingNavigationTool::valuatorCallback(int,int,InputDevice::ValuatorCallbackData* cbData)
	{
	currentValue=Scalar(cbData->newValuatorValue);
	if(Math::abs(currentValue)>factory->valuatorThreshold)
		{
		/* Try activating this tool: */
		if(!isActive()&&activate())
			{
			/* Initialize the navigation transformations: */
			scalingCenter=getDevicePosition(0);
			preScale=NavTrackerState::translateFromOriginTo(scalingCenter);
			postScale=NavTrackerState::translateToOriginFrom(scalingCenter);
			postScale*=getNavigationTransformation();
			currentScale=Scalar(1);
			}
		}
	else
		{
		/* Deactivate this tool: */
		deactivate();
		}
	}