👍️[Update] Model : overlay 左手周りの処理を追加

- HMD,左手の初期値を追加
- 初期値からの変化量をUIから調整できるように変更
- quaternionは不要なため、削除
This commit is contained in:
misyaguziya
2024-05-15 12:58:58 +09:00
parent 212a3e62d1
commit 095eaac420
5 changed files with 183 additions and 51 deletions

View File

@@ -1,19 +1,56 @@
import os
import ctypes
from psutil import process_iter
import time
import openvr
from PIL import Image
from psutil import process_iter
from threading import Thread
import openvr
import numpy as np
import quaternion
from PIL import Image
try:
from . import overlay_utils as utils
except ImportError:
import overlay_utils as utils
def mat34Id():
def mat34Id(array):
arr = openvr.HmdMatrix34_t()
# arr[0][0] = 1
# arr[1][1] = 1
# arr[2][2] = 1
# print(arr)
for i in range(3):
for j in range(4):
arr[i][j] = array[i][j]
return arr
def getBaseMatrix(x_pos, y_pos, depth, x_rotation, y_rotation, z_rotation):
arr = np.zeros((3, 4))
rot = utils.euler_to_rotation_matrix((x_rotation, y_rotation, z_rotation))
for i in range(3):
for j in range(3):
arr[i][j] = rot[i][j]
arr[0][3] = x_pos * depth
arr[1][3] = y_pos * depth
arr[2][3] = - depth
return arr
def getHMDBaseMatrix():
x_pos = 0.0
y_pos = -0.4
depth = 1.0
x_rotation = 0.0
y_rotation = 0.0
z_rotation = 0.0
arr = getBaseMatrix(x_pos, y_pos, depth, x_rotation, y_rotation, z_rotation)
return arr
def getLeftHandBaseMatrix():
x_pos = 0.0
y_pos = -0.06
depth = -0.14
x_rotation = -62.0
y_rotation = 154.0
z_rotation = 71.0
arr = getBaseMatrix(x_pos, y_pos, depth, x_rotation, y_rotation, z_rotation)
return arr
class Overlay:
@@ -108,6 +145,7 @@ class Overlay:
depth is a float representing the depth of the icon plane
x_rotation, y_rotation, z_rotation are floats representing the rotation of the icon plane
"""
self.settings["x_pos"] = pos[0]
self.settings["y_pos"] = pos[1]
self.settings["depth"] = depth
@@ -115,26 +153,20 @@ class Overlay:
self.settings["y_rotation"] = y_rotation
self.settings["z_rotation"] = z_rotation
self.transform = mat34Id() # no rotation required for HMD attachment
base_matrix = getHMDBaseMatrix()
# base_matrix = getLeftHandBaseMatrix()
translation = (self.settings["x_pos"], self.settings["y_pos"], - self.settings['depth'])
rotation = (self.settings["x_rotation"], self.settings["y_rotation"], self.settings["z_rotation"])
transform = utils.transform_matrix(base_matrix, translation, rotation)
self.transform = mat34Id(transform)
# assign rotation
rot = np.quaternion(1, self.settings["x_rotation"], self.settings["y_rotation"], self.settings["z_rotation"])
rot = quaternion.as_rotation_matrix(rot)
# self.transform[:3, :3] = rot
for i in range(3):
for j in range(3):
self.transform[i][j] = rot[i][j]
# assign position
self.transform[0][3] = self.settings["x_pos"] * self.settings['depth']
self.transform[1][3] = self.settings["y_pos"] * self.settings['depth']
self.transform[2][3] = - self.settings['depth']
leftControllerIndex = self.overlay_system.getTrackedDeviceIndexForControllerRole(openvr.TrackedControllerRole_LeftHand)
hmdIndex = openvr.k_unTrackedDeviceIndex_Hmd
# leftControllerIndex = self.overlay_system.getTrackedDeviceIndexForControllerRole(openvr.TrackedControllerRole_LeftHand)
# rightControllerIndex = self.overlay_system.getTrackedDeviceIndexForControllerRole(openvr.TrackedControllerRole_RightHand)
if self.initialized is True:
self.overlay.setOverlayTransformTrackedDeviceRelative(
self.handle,
leftControllerIndex, #openvr.k_unTrackedDeviceIndex_Hmd,
hmdIndex,
self.transform
)
@@ -210,17 +242,17 @@ class Overlay:
return _proc_name in (p.name() for p in process_iter())
if __name__ == '__main__':
from overlay_image import OverlayImage
overlay_image = OverlayImage()
# from overlay_image import OverlayImage
# overlay_image = OverlayImage()
overlay = Overlay(0, 0, 1, 1, 0, 1, 1)
overlay.startOverlay()
time.sleep(1)
# overlay = Overlay(0, 0, 1, 1, 0, 1, 1)
# overlay.startOverlay()
# time.sleep(1)
# Example usage
img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese")
overlay.updateImage(img)
time.sleep(100000)
# # Example usage
# img = overlay_image.createOverlayImageShort("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese")
# overlay.updateImage(img)
# time.sleep(100000)
# for i in range(100):
# print(i)
@@ -238,3 +270,17 @@ if __name__ == '__main__':
# time.sleep(0.5)
# overlay.shutdownOverlay()
x_pos = 0
y_pos = 0
depth = 0
x_rotation = 0
y_rotation = 0
z_rotation = 0
base_matrix = getLeftHandBaseMatrix()
translation = (x_pos * depth, y_pos * depth, depth)
rotation = (x_rotation, y_rotation, z_rotation)
transform = utils.transform_matrix(base_matrix, translation, rotation)
transform = mat34Id(transform)
print(transform)