Using the 3D Connexion SDK/Introducing the 3D Connexion SDK

Introducing the 3D Connexion SDK edit

An SDK is a Software Development Kit, a load of code to allow you to make programs which do things with companies' products.

Let's unzip the VB.ZIP file which 3D connexion provides as part of the SDK, and drag the monitor.sln file into Visual Basic Express. You will need to run it through the converter to upgrade to your version of Visual Basic, so just keep pressing Ignore, Yes or Next until it finishes. Hit F5 to try it out. You should see a live readout of the data that the device is feeding back; which button is being pressed, what its rotation is, all sorts of nice, useful stuff.

Double click Form1.vb to look at the code. What this is a mixture of massively complex code which the 3D connexion team has written to connect your mouse to your computer, and stuff which we don't actually need. What we're going to do is make a template file from this project. First, go into design view and select all. Delete and go into code view. Delete all code and paste the following in:

(Reproduced by kind permission of Logitech)

 Public Class Form1
   Delegate Sub SetMotionTextCallback()
   Delegate Sub SetKeyTextCallback(ByVal keyCode As Integer)
 
Private WithEvents Sensor As TDxInput.Sensor Private WithEvents Keyboard As TDxInput.Keyboard Private WithEvents Device As TDxInput.Device
Public Sub New() Device = New TDxInput.Device Sensor = Device.Sensor Keyboard = Device.Keyboard
SetMotionTexts()
Device.Connect()
End Sub
Private Sub Sensor_SensorInput() Handles Sensor.SensorInput
Me.SetMotionTexts()
End Sub
Private Sub SetMotionTexts()
Dim Style1 As String = "f" Dim translation As TDxInput.Vector3D translation = Sensor.Translation
Dim rotation As TDxInput.AngleAxis rotation = Sensor.Rotation
End Sub

Protected Overrides Sub Finalize() Device.Disconnect() MyBase.Finalize() End Sub
End Class

You need to save all of this, by pressing Save All. Now close Visual Basic. To create a new program, create a copy of the template folder and open the Monitor.sln file in Visual Basic. There are ways to create your own from scratch, however, it gets complicated.

So, let's have a look at the code:

First they start Form1:

 Public Class Form1

Don't worry about this bit

   Delegate Sub SetMotionTextCallback()
   Delegate Sub SetKeyTextCallback(ByVal keyCode As Integer)
 

Here, they add in the TDx Sensor objects. The TDx sensor is the data which the 3D Connexion mouse sends back.

   Private WithEvents Sensor As TDxInput.Sensor
   Private WithEvents Keyboard As TDxInput.Keyboard
   Private WithEvents Device As TDxInput.Device
 

This starts the feed of information

   Public Sub New()
       Device = New TDxInput.Device
       Sensor = Device.Sensor
       Keyboard = Device.Keyboard
 
SetMotionTexts()
Device.Connect()
End Sub

This is a "listener" for changes in the sensor's state:

   Private Sub Sensor_SensorInput() Handles Sensor.SensorInput
 
Me.SetMotionTexts()
End Sub

This is an example procedure using inputs from the mouse:

   Private Sub SetMotionTexts()
 
Dim Style1 As String = "f" Dim translation As TDxInput.Vector3D translation = Sensor.Translation
Dim rotation As TDxInput.AngleAxis rotation = Sensor.Rotation
End Sub

This 'signs out' from the mouse when you finish with it

   Protected Overrides Sub Finalize()
       Device.Disconnect()
       MyBase.Finalize()
   End Sub
 
End Class

Don't worry about the exact details of this. All you need to know is that it created 7 variables:

Rotation.x: The rotation in the x axis as an accurate decimal

Rotation.y: Rotation in the y axis given as 0, -1 or 1. Rotation.y * rotation.Angle must be used for this.

Rotation.z: rotation in the z axis

rotation.angle: The total angle that the device has moved from its rest position

translation.x: The total translation in the x axis

translation.y: guess

translation.z: guess

translation.length: The distance the node of the device has moved from rest.