iWear VR920 module; Interested?

BlitzMax Forums/MiniB3D Module/iWear VR920 module; Interested?

JetFireDX(Posted 2009) [#1]
Hey everyone. I have a set of these VR920 and I have been in off again on again contact with the company about their support for the Mac. I have made a module for BlitzMax that wraps to their C based SDK except that the current version of the framework for MacOS doesn't support the function to flip the left / right eye view on a frame sync. Otherwise the 3 degrees of freedom rotation data is available as input for BlitzMax and it is usable but not in stereoscopic 3D.

What does this have to do with MiniB3D? I want to see MiniB3D projects be able to make use of commercial stereoscopic head mounted display hardware of course! And as a module, anything anybody is already working on could have it incorporated pretty easily.

I need to update my module to work in Windows as well so at least both platforms Vuzix supports are supported.

So what I would like to know is if anyone is interested at all in my module and supporting a product like the VR920 in their BMax/MiniB3D projects?

(Windows users have a much lower level version of the driver that is able to hijack the D3D / OpenGL information and do work on it before display allowing them to retroactively support almost anything. This is something they have not been able to bring to the Mac which is why I am looking to just code it into my apps and to provide others with tools to do the same.)


ima747(Posted 2009) [#2]
I'm curious about how you've implemented it. Wish I had a VR920 to play with, all my old 3d headgear was less sophisticated and based on CRT tech. Do you think your implementation could be made somewhat generic to support other devices or are the requirements of the vr920 too strict?


JetFireDX(Posted 2009) [#3]
It is just a straight one to one wrapper for the functions available via the framework / headers using extern. I dunno how hard it would be add other support to it as, as you can see in my comment in the code, I am crap for C/C++, but I suppose writing another one as long as there was documentation on your other hardware wouldn't be too difficult.

Here it is if you want to see it... It is too bad that Vuzix's current framework on the Mac doesn't support stereoscopic 3D... the IWEAR_Stereo function returns an error that the hardware is not supported.

'Okay here's how this works... and I am crap when it comes to C/C++

'I made a .m file that simply #include the iweardrv.h file since Blitz's compiler 
'pukes when you specify a .h file instead of a whole group with *.h

'Looking through the Mac specific Blitz sources I learned how to link against a 
'Framework... by telling it To with -Framework FRAMEWORKNAME ... kinda a "duh" moment.
Import "iweardrv.m"
Import "-framework IWear" 

Extern
	Function IWEAR_End:Int() 'Call at the end of your program to shut down any connection and handles to the iWear device(s)
	Function IWEAR_Start:Int() 'Must be called at the beginning to initialize the iWear
	Function IWEAR_Count:Int() 'Returns the number of iWear devices connection to the system.
	Function IWEAR_OpenIndexed:Int( c:Int ) 'Attempt to connect to the id of a specific iWear device. Returns pointer to device.
	Function IWEAR_Open:Int() 'Attemp to connect to the next available iWear. Returns errorcode or null.
	Function IWEAR_Close(handle:Int) 'Close the device at the handle.
	Function IWEAR_GetCapabilities:Int() 'Get what features the device supports.
	Function IWEAR_ZeroSet:Int(handle:Int) 'Set the current head position of the user as the calibrated ZERO point straight ahead and level.
	Function IWEAR_ZeroClear:Int(handle:Int)
	Function IWEAR_SetSmoothing:Int(handle:Int,smooth:Int) 'smooth can be 0 - 32 with 32 being max smoothing average.
	Function IWEAR_GetTracking:Int( handle:Int,yaw:Int Var, pitch:Int Var, roll:Int Var)
	Function IWEAR_GetTrackingNormalized:Int( handle:Int,yaw:Float Var, pitch:Float Var, roll:Float Var) 'Returns all values between -1.0 and 1.0
	Function IWEAR_GetHeading:Int(handle:Int,heading:Int Var) 'Returns the heading where 0 is north and -16000 is east (from 0) and 16000 is west
	Function IWEAR_GetHeadingNormalized:Int(handle:Int,heading:Float Var) 'returns the heading between -1.0 and 1.0, 0 = north, 1,-1 south, 0.5 = west, -0.5 = east.
	Function IWEAR_BeginCalibrate:Int(handle:Int) 'Begin the calibration process. See iWear docs for comments.
	Function IWEAR_EndCalibrate:Int(handle:Int, save:Int) 'save = 1 to save or 0 to not save the date to com.vuzix.VR920.plist.
	Function IWEAR_Stereo:Int(handle:Int, eye:Int)
		Rem
			Control how the iWear displays content
			eye = 0 then view is 2D, same for both eyes
			eye = 1 then the next frame should to go the left eye.
			eye = 2 the next frame goes to the right eye.
			eye = 3 AUTO starting left, so LRLR
			eye = 4 AUTO starting right, so RLRL
		EndRem

EndExtern

'Consts
Const IWEAR_2D:Int = 0
Const IWEAR_LEFT:Int = 1
Const IWEAR_RIGHT:Int = 2
Const IWEAR_AUTO_LR:Int = 3
Const IWEAR_AUTO_RL:Int = 4

Rem
ERROR CODES (From iweardrv.h for reference)
IWEAR_SUCCESS				(0)		/* the call was successful */
IWEAR_ERROR_NOT_FOUND		(-1)	/* the device was not found */
IWEAR_ERROR_UNABLE_TO_OPEN	(-2)	/* unable to open the device */
IWEAR_ERROR_OUT_OF_RANGE	(-3)	/* value was out of range */
IWEAR_ERROR_SAVING_PREFS	(-4)	/* unable to save the preferences */
IWEAR_ERROR_BAD_HANDLE		(-5)	/* handle passed in was bad */
IWEAR_ERROR_INCAPABLE		(-6)	/* device is incapable of that */
EndRem

'TESTING

testrResult:Int = 0

Print "TEST CASES: SANITY CHECK OF FUNCTIONALITY"
Print "-----------------------------------------"
Print "TEST 1:"
testResult = IWEAR_Start()
If testResult <> 0
	Print "	START() failed code:"+testResult
Else
	Print "	PASSED!"
EndIf

Print "TEST 2:"
testResult = IWEAR_Count()
Print "	COUNT() returned:"+testResult
Print "	Verify that "+testResult+" iWear devices are connected to the USB ports of the system."


Print "TEST 3:"
iwearhnd:Int = IWEAR_Open() 'we will need iwearhnd later to test close()
If iwearhnd > 0
	Print "	PASSED! Device handle:"+iwearhnd
EndIf

If iwearhnd < 0
	Print "	Open() failed code:"+iwearhnd
EndIf

Print "This concludes the sanity check to connect to a device."

Local headyaw:Int
Local headpitch:Int
Local headroll:Int

Graphics 800,600,32,0

While Not KeyDown(KEY_ESCAPE)
	Cls
	IWEAR_GetTracking(iwearhnd, headyaw,headpitch,headroll)
	DrawText "YAW:"+headyaw+" PITCH:"+headpitch+" ROLL:"+headroll,10,10
	Flip
Wend

Print "End() = "+IWEAR_End()
End

Type TiWear
	Field hmds:TiWearHMD[]
	
	'Init the iWear hardware and update the count of how many are attached and get all of their handles.
	Method init()
		IWEAR_Start()
		Local count = IWEAR_Count()
		Self.hmds = New TiWearHMD[count]
		
		For Local currHMD:TiWearHMD = EachIn hmds
			currHMD.handle = IWEAR_Open()
		Next
	EndMethod

	Method update()
		For Local currHMD:tiWearHMD = EachIn hmds
			currHMD.update()
		Next
	EndMethod
	
	Method cleanup()
		For Local currHMD:tiWearHMD = EachIn hmds
			currHMD.close()
		Next
		hmds = Null
		GCCollect
		IWEAR_End()
	EndMethod
	
	Method setDisplayMode(device:Int,mode:Int)
		If device <= hmds.length-1
			If mode > 0 And mode < 4
				hmds[device].display_mode = mode
			EndIf
		EndIf
	EndMethod

EndType

Type TiWearHMD
	Field handle:Int 				'pointer to the iWear headset
	Field display_mode:Int = 0 		'the current display mode of content on the device. See the consts.
	Field current_eye:Int = 0 		'0 = left, 1 = right
	Field status:Int				'last return code will be here
	Field yaw:Float				'I'll be using the normalized tracking.
	Field pitch:Float
	Field roll:Float
	
	Method update()
		'Get the latest head tracking data
		Self.status = IWEAR_GetTrackingNormalized(Self.handle, Self.yaw,Self.pitch,Self.roll)
		'update the stereo views if needed.
		If display_mode > 0
			update3D()
		EndIf
	EndMethod
	
	Method update3D()
		current_eye = Abs(current_eye - 1)
		IWEAR_Stereo(Self.handle,current_eye)
	EndMethod
	
	Method close()
		IWEAR_Close(Self.handle)
	EndMethod
EndType



jhocking(Posted 2009) [#4]
Very exciting stuff! I've had this HMD in the back of my head for a while to maybe experiment with, this work you've done will be a big help naturally.


JetFireDX(Posted 2009) [#5]
A friend of mine and I are looking into the possibilities of snooping the USB data while running my VR920 on Windows to see if we can catch the data that tells it to do stereo flipping and with the help of Brucey's libUSB module forcing it down its throat from my module under Mac OS X. It is that, or I finish the module to include Windows too and give up on stereoscopic views on the Mac version. (Not expecting much from Vuzix at this rate.)