- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I'm trying to control the orientation of a texture on a material based on the angle of a Vive tracker. The script below works well for that, but there is an unexpected behavior. When I turn my head while wearing the HMD, the texture rotates, even if the Vive tracker is not moving. In the attachments, img1 is looking straight-on, and img2 is with the HMD turned to the right. Any ideas?
Thanks,
CH
import math
tracker = vrDeviceService.getVRDevice('tracker-1')
tracker.enableRay('Z')
myDial = findNode('DialNode',True)
myMatl = myDial.getMaterial()
myTex = vrFieldAccess(myMatl.fields().getFieldContainer('colorComponentData'))
myComp = vrFieldAccess(myTex.getFieldContainer('diffuseComponent'))
def adjustDial():
myMatx = tracker.getTrackingMatrix()
rotXangle = math.atan2(-myMatx.row(1).z(), myMatx.row(2).z())
sinXangle = math.sin(rotXangle)
cosXangle = math.cos(rotXangle)
rotZangle = math.atan2(cosXangle * myMatx.row(1).x() + sinXangle * myMatx.row(2).x(), cosXangle * myMatx.row(1).y() + sinXangle * myMatx.row(2).y())
myComp.setReal32('rotate',math.degrees(rotZangle)+90)
tracker.signal().moved.connect(adjustDial)
Solved! Go to Solution.
