Talking to the controllers

The module vrOpenVRController is the only way you can program the HTC vive controllers at this moment. It takes a while to understand and you might be able to reverse engineer my code, but to write it from scratch and understand it took me a very long time. This was well after I took those code academy classes.

What I am hoping is that as you learn you can use my code and change it around to sort of start understanding what is going on. 

So let's break down my code a little bit. 

First we define our tool

The top of of our code is just us telling VRED what actions we want to take. The first line looks for the node that has our light. The second line called AttachLight(): We define a tool that attaches our light into the htc vive controller. PowerLight() toggles the light on and off. ChangeColor() changes the color of the sphere and prints Color changed on the terminal. So now we need to attach these tools to the controller. 

Main_Hand = findNode('Main_Hand')

def AttachLight():
    Main_Hand.setTransformMatrix(Maincontroller.getWorldMatrix(), false)

def PowerLight():

def ChangeColor():
    print "Color Changed"

Connecting signals

So here is the point in the code that connects all our tools to the htc Vive controller. In the first line I am telling VRED that when I type Maincontroller, what I'm saying is the Controller0 in the htc Vive. 

Maincontroller.connectSignal("controllerMoved", AttachLight)

Here I am telling VRED that I want to connect the signal of the controller moving with the light node. This attaches the light to the controller

Maincontroller.connectSignal("triggerPressed", ChangeColor)

Here I am telling VRED that I want to connect the trigger to my variant set that changes the color

Maincontroller.connectSignal("touchpadPressed", PowerLight)

Here I am telling VRED that I want to connect the main trackpad button to power on my light. 


Maincontroller = vrOpenVRController("Controller0")
Maincontroller.connectSignal("controllerMoved", AttachLight)
Maincontroller.connectSignal("triggerPressed", ChangeColor)
Maincontroller.connectSignal("touchpadPressed", PowerLight)

print "VR Loaded"

Do you feel very confused

I know I did when I was barely learning how to write python code. This tutorial was not meant to teach you how to read and write python perfectly. It was made to help you start understanding the basic concepts behind them. It took me about 6 months before I really started to understand coding. I have been doing this off and on for two years and I still get confused sometimes. It takes a while but after some practice, you will have full control of your VR experiences. I hope this tutorial helped and feel free to contact me for any questions or maybe even to say thank you :P