question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how do you use mDeviceToAbsoluteTracking to find the tracking data for a controller

See original GitHub issue

heres my code

import sys
import time
import openvr
import math
def from_matrix_to_pose_dict(matrix):
    pose = {}
    # From http://steamcommunity.com/app/358720/discussions/0/358417008714224220/#c359543542244499836
    position = {}
    position['x'] = matrix[0][3]
    position['y'] = matrix[1][3]
    position['z'] = matrix[2][3]
    q = {}
    q['w'] = math.sqrt(max(0, 1 + matrix[0][0] + matrix[1][1] + matrix[2][2])) / 2.0
    q['x'] = math.sqrt(max(0, 1 + matrix[0][0] - matrix[1][1] - matrix[2][2])) / 2.0
    q['y'] = math.sqrt(max(0, 1 - matrix[0][0] + matrix[1][1] - matrix[2][2])) / 2.0
    q['z'] = math.sqrt(max(0, 1 - matrix[0][0] - matrix[1][1] + matrix[2][2])) / 2.0
    q['x'] = math.copysign(q['x'], matrix[2][1] - matrix[1][2])
    q['y'] = math.copysign(q['y'], matrix[0][2] - matrix[2][0])
    q['z'] = math.copysign(q['z'], matrix[1][0] - matrix[0][1])
    pose['position'] = position
    pose['orientation'] = q
    return pose
openvr.init(openvr.VRApplication_Scene)
poses = []  # will be populated with proper type after first call
for i in range(100):
    poses, _ = openvr.VRCompositor().waitGetPoses(poses, None)
    hmd_pose = poses[openvr.k_unTrackedDeviceIndex_Hmd]
    matrix = (hmd_pose.mDeviceToAbsoluteTracking)
    d = from_matrix_to_pose_dict(matrix)
    print(d)       
    sys.stdout.flush()
    time.sleep(0.2)
openvr.shutdown()

its doing what i want it to except that its getting data from the head mount display and i want it to get data from a controller instead how would i do so?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Simontho001commented, Apr 7, 2020

fixed it sorry not very familiar with this website

0reactions
risa2000commented, Apr 7, 2020

You will get the pose exactly the same way as you did for the HMD:

controller_pose = poses[controller_index]

and then do whatever you want with it.

There is not much documentation for the Python code, as it basically mimics the native API. So for example, for how to use WaitGetPoses you might want to read the official doc (https://github.com/ValveSoftware/openvr/wiki/IVRCompositor::WaitGetPoses), or even read the source code (https://github.com/ValveSoftware/openvr/blob/master/headers/openvr.h).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Get Raw (Positional) Data from HTC Vive? - CodeProject
2) Open samples/samples_vs2010.sln solution file by visual studio. Then, run it to make sure everyting works. You should see a window like the ......
Read more >
Week Three: Tracking - David Weis
Simple code for getting tracking data from OpenVR using the C# bindings: ... mDeviceToAbsoluteTracking; Position pos = new ...
Read more >
Using HTC Vive to Control Dynamixel Servo
Get into your tracking area with the Vive controller and click any button on them and move around the left controller. You should...
Read more >
What is OpenVR and how to get started with its APIs
So let's start coding our Hello World application using OpenVR, while we describe which are the most relevant operations needed to obtain data...
Read more >
Solved: Is there a way to know if the controllers are bein...
Is there a way to know if the controllers are being tracked using the ... using Unity's Legacy XR Input this should provide...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found