Commit a1afffb1 authored by Dalai Felinto's avatar Dalai Felinto
Browse files

Projection Matrix

parent f5131b34
...@@ -75,11 +75,19 @@ class HMD_Base: ...@@ -75,11 +75,19 @@ class HMD_Base:
@property @property
def width(self): def width(self):
return self._width return self._width[self._current_eye]
@width.setter
def width(self, value):
self._width[self._current_eye] = value
@property @property
def height(self): def height(self):
return self._height return self._height[self._current_eye]
@height.setter
def height(self, value):
self._height[self._current_eye] = value
@property @property
def offscreen_object(self): def offscreen_object(self):
...@@ -97,6 +105,18 @@ class HMD_Base: ...@@ -97,6 +105,18 @@ class HMD_Base:
def projection_matrix(self): def projection_matrix(self):
return self._projection_matrix[self._current_eye] return self._projection_matrix[self._current_eye]
@projection_matrix.setter
def projection_matrix(self, value):
print("projection_matrix", value)
matrix = Matrix()
matrix[0] = value[0:4]
matrix[1] = value[4:8]
matrix[2] = value[8:12]
matrix[3] = value[12:16]
self._projection_matrix[self._current_eye] = matrix
@property @property
def modelview_matrix(self): def modelview_matrix(self):
return self._modelview_matrix[self._current_eye] return self._modelview_matrix[self._current_eye]
...@@ -104,15 +124,6 @@ class HMD_Base: ...@@ -104,15 +124,6 @@ class HMD_Base:
def setEye(self, eye): def setEye(self, eye):
self._current_eye = int(bool(eye)) self._current_eye = int(bool(eye))
def isConnected(self):
"""
Check if device is connected
:return: return True if the device is connected
:rtype: bool
"""
assert False, "isConnected() not implemented for the \"{0}\" device".format(self._name)
def init(self): def init(self):
""" """
Initialize device Initialize device
...@@ -122,7 +133,7 @@ class HMD_Base: ...@@ -122,7 +133,7 @@ class HMD_Base:
""" """
try: try:
for i in range(2): for i in range(2):
self._offscreen_object[i] = gpu.offscreen_object_create(self._width, self._height) self._offscreen_object[i] = gpu.offscreen_object_create(self._width[i], self._height[i])
self._framebuffer_object[i] = self._offscreen_object[i].framebuffer_object self._framebuffer_object[i] = self._offscreen_object[i].framebuffer_object
self._color_object[i] = self._offscreen_object[i].color_object self._color_object[i] = self._offscreen_object[i].color_object
...@@ -185,3 +196,13 @@ class HMD_Base: ...@@ -185,3 +196,13 @@ class HMD_Base:
""" """
TODO TODO
def _getCamera(self, context):
return context.scene.camera
def _getCameraClipping(self, context):
camera_ob = self._getCamera(context)
camera = camera_ob.data
near = camera.clip_start
far = camera.clip_end
return near, far
...@@ -18,17 +18,7 @@ class Debug(HMD_Base): ...@@ -18,17 +18,7 @@ class Debug(HMD_Base):
def __init__(self, error_callback): def __init__(self, error_callback):
super(Debug, self).__init__('Debug', error_callback) super(Debug, self).__init__('Debug', error_callback)
def isConnected(self): def init(self, context):
"""
Check if device is connected
:return: return True if the device is connected
:rtype: bool
"""
print_debug('isConnected()')
return True
def init(self):
""" """
Initialize device Initialize device
...@@ -37,8 +27,8 @@ class Debug(HMD_Base): ...@@ -37,8 +27,8 @@ class Debug(HMD_Base):
""" """
print_debug('init()') print_debug('init()')
self._width = 512 self._width = [512, 512]
self._height = 512 self._height = [512, 512]
return super(Debug, self).init() return super(Debug, self).init()
......
...@@ -25,22 +25,21 @@ class Oculus(HMD_Base): ...@@ -25,22 +25,21 @@ class Oculus(HMD_Base):
super(Oculus, self).__init__('Oculus', error_callback) super(Oculus, self).__init__('Oculus', error_callback)
checkModule('oculus_sdk_bridge') checkModule('oculus_sdk_bridge')
def isConnected(self): # self._debug()
"""
Check if device is connected
:return: return True if the device is connected def _debug(self):
:rtype: bool import bridge
""" import bridge_wrapper
try:
from bridge.oculus import HMD
return HMD.isConnected()
except Exception as E: input = 3
self.error("isConnected", E, True) device = bridge_wrapper.Debug_new(input)
return False factor = bridge_wrapper.Debug_multiplicationFactor()
print("Multiplication factor is {0}".format(factor))
output = bridge_wrapper.Debug_multiplicationResult(device)
print("Return of {0} is {1}".format(input, output))
def init(self): def init(self, context):
""" """
Initialize device Initialize device
...@@ -52,12 +51,18 @@ class Oculus(HMD_Base): ...@@ -52,12 +51,18 @@ class Oculus(HMD_Base):
self._hmd = HMD() self._hmd = HMD()
# gather arguments from HMD # gather arguments from HMD
self._width[0] = self._hmd.width_left
self._height[0] = self._hmd.height_left near, far = self._getCameraClipping(context)
self._width[1] = self._hmd.width_right
self._height[1] = self._hmd.height_right self.setEye(0)
self._projection_matrix[0] = self._hmd.projection_matrix_left self.width = self._hmd.width_left
self._projection_matrix[1] = self._hmd.projection_matrix_right self.height = self._hmd.height_left
self.projection_matrix = self._hmd.getProjectionMatrixLeft(near, far)
self.setEye(1)
self.width = self._hmd.width_right
self.height = self._hmd.height_right
self.projection_matrix = self._hmd.getProjectionMatrixRight(near, far)
# initialize FBO # initialize FBO
super(Oculus, self).init() super(Oculus, self).init()
...@@ -89,7 +94,7 @@ class Oculus(HMD_Base): ...@@ -89,7 +94,7 @@ class Oculus(HMD_Base):
super(Oculus, self).loop(context) super(Oculus, self).loop(context)
except Exception as E: except Exception as E:
self.error("look", E, False) self.error("loop", E, False)
return False return False
return True return True
......
...@@ -136,18 +136,11 @@ class VirtualRealityDisplayOperator(bpy.types.Operator): ...@@ -136,18 +136,11 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
self._hmd = HMD(display_backend, self._error_callback) self._hmd = HMD(display_backend, self._error_callback)
self._preview = Preview() self._preview = Preview()
if not self._hmd.isConnected(): if not self._hmd.init(context):
self.report({'ERROR'}, "Device not connected")
return False
if not self._hmd.init():
self.report({'ERROR'}, "Error initializing device") self.report({'ERROR'}, "Error initializing device")
return False return False
# get the data from device # get the data from device
width = self._hmd.width
height = self._hmd.height
color_object = [0, 0] color_object = [0, 0]
for i in range(2): for i in range(2):
self._hmd.setEye(i) self._hmd.setEye(i)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment