def _position_vr_overlay(self):        # initialize overlay & setup transform to fix overlay to display viewport
     Transform_Type= (ctypes.c_float * 4) * 3
     transform = Transform_Type()
     transform[0][0]  = 1
     transform[0][1]  = 0
     transform[0][2]  = 0
     transform[0][3]  = 0
     
     transform[1][0] = 0
     transform[1][1] = 1
     transform[1][2] = 0
     transform[1][3] = 0
     
     transform[2][0] = 0
     transform[2][1] = 0
     transform[2][2] = 1
     transform[2][3] = -1
     self._hmd_transform = openvr.HmdMatrix34_t()
     self._hmd_transform.m = transform
     
 #set overlay to be fixed to hmd viewport
     openvr.IVROverlay().setOverlayTransformTrackedDeviceRelative(
           self._overlay,
           0,
           self._hmd_transform)
Example #2
0
def matMul33(a, b, result=None):
    if result is None:
        result = openvr.HmdMatrix34_t()
    for i in range(3):
        for j in range(3):
            result.m[i][j] = 0.0
            for k in range(3):
                result.m[i][j] += a.m[i][k] * b.m[k][j]
    result[0][3] = b[0][3]
    result[1][3] = b[1][3]
    result[2][3] = b[2][3]
    return result
Example #3
0
    def __init__(self):
        super().__init__()

        vr_sys = openvr.init(openvr.VRApplication_Scene)
        poses_t = openvr.TrackedDevicePose_t * openvr.k_unMaxTrackedDeviceCount
        poses = poses_t()

        print("Recommended W H:", vr_sys.getRecommendedRenderTargetSize())

        ctrls = []

        for i in range(5):
            c = vr_sys.getTrackedDeviceClass(i)
            if c == openvr.TrackedDeviceClass_HMD:
                HMD_id = i
            elif c == openvr.TrackedDeviceClass_Controller:
                print("Controller:", i)
                ctrls.append(i)

        self.ov = openvr.VROverlay()
        self.cmp = openvr.VRCompositor()
        self.vrsys = openvr.VRSystem()

        self.CONTROLLERS = ctrls

        self.VRposes = poses

        k = random.randint(0, 1000)
        self.vrBuf1 = self.ov.createOverlay("Buffer 1 " + str(k), "A")
        self.vrBuf2 = self.ov.createOverlay("Buffer 2 " + str(k), "B")

        # FOV 80 size 0.2
        # FOV 120 size 0.6
        self.ov.setOverlayWidthInMeters(self.vrBuf1, 0.6)
        self.ov.setOverlayWidthInMeters(self.vrBuf2, 0.6)

        self.ov.setOverlayFromFile(self.vrBuf1, PATH + "lib/Combat.png")
        self.ov.setOverlayFromFile(self.vrBuf2, PATH + "lib/Combat.png")
        self.ov.showOverlay(self.vrBuf1)
        self.ov.showOverlay(self.vrBuf2)

        mt = [(ctypes.c_float * 4)(1, 0, 0, 0.02), (ctypes.c_float * 4)(0, 1,
                                                                        0, 0),
              (ctypes.c_float * 4)(0, 0, 1, -0.2)]

        y = openvr.HmdMatrix34_t(*mt)

        self.ov.setOverlayTransformTrackedDeviceRelative(
            self.vrBuf1, HMD_id, y)
        self.ov.setOverlayTransformTrackedDeviceRelative(
            self.vrBuf2, HMD_id, y)

        self.VRMode = True
Example #4
0
    def rotate(self, angles, axis=[2,]):
        try:
            self.rotation_matrix
        except AttributeError:
            self.rotation_matrix = openvr.HmdMatrix34_t()
        if not isinstance(angles, list):
            angles = [angles, ]

        if not isinstance(axis, list):
            axis = [axis, ]

        result = copy.copy(self.transform)
        for angle, ax in zip(angles, axis):
            initRotationMatrix(ax, -angle, self.rotation_matrix)
            result = matMul33(self.rotation_matrix, result)

        fn = self.vroverlay.function_table.setOverlayTransformAbsolute
        fn(self.wheel, openvr.TrackingUniverseSeated, openvr.byref(result))
Example #5
0
def initRotationMatrix(axis, angle, matrix=None):
    # angle in radians
    if matrix is None:
        matrix = openvr.HmdMatrix34_t()
    if axis == 0:
        matrix.m[0][0] = 1.0
        matrix.m[0][1] = 0.0
        matrix.m[0][2] = 0.0
        matrix.m[0][3] = 0.0
        matrix.m[1][0] = 0.0
        matrix.m[1][1] = cos(angle)
        matrix.m[1][2] = -sin(angle)
        matrix.m[1][3] = 0.0
        matrix.m[2][0] = 0.0
        matrix.m[2][1] = sin(angle)
        matrix.m[2][2] = cos(angle)
        matrix.m[2][3] = 0.0
    elif axis == 1:
        matrix.m[0][0] = cos(angle)
        matrix.m[0][1] = 0.0
        matrix.m[0][2] = sin(angle)
        matrix.m[0][3] = 0.0
        matrix.m[1][0] = 0.0
        matrix.m[1][1] = 1.0
        matrix.m[1][2] = 0.0
        matrix.m[1][3] = 0.0
        matrix.m[2][0] = -sin(angle)
        matrix.m[2][1] = 0.0
        matrix.m[2][2] = cos(angle)
        matrix.m[2][3] = 0.0
    elif axis == 2:
        matrix.m[0][0] = cos(angle)
        matrix.m[0][1] = -sin(angle)
        matrix.m[0][2] = 0.0
        matrix.m[0][3] = 0.0
        matrix.m[1][0] = sin(angle)
        matrix.m[1][1] = cos(angle)
        matrix.m[1][2] = 0.0
        matrix.m[1][3] = 0.0
        matrix.m[2][0] = 0.0
        matrix.m[2][1] = 0.0
        matrix.m[2][2] = 1.0
        matrix.m[2][3] = 0.0
    return matrix
Example #6
0
 def __init__(self, openvr_id):
     self._id = openvr_id
     self._x = 0
     self._y = 0
     self._z = 0
     self._pose = openvr.HmdMatrix34_t()