chore(metadata): update beads and sisyphus planning artifacts
This commit is contained in:
+183
-112
@@ -34,7 +34,7 @@ void main() {
|
||||
}
|
||||
"""
|
||||
|
||||
POINTCLOUD_VERTEX_SHADER ="""
|
||||
POINTCLOUD_VERTEX_SHADER = """
|
||||
#version 330 core
|
||||
layout(location = 0) in vec4 in_VertexRGBA;
|
||||
uniform mat4 u_mvpMatrix;
|
||||
@@ -184,7 +184,9 @@ try:
|
||||
try:
|
||||
if cudart is not None: # Check if cudart is still available
|
||||
check_cudart_err(
|
||||
cudart.cudaGraphicsUnmapResources(1, self._graphics_ressource, stream)
|
||||
cudart.cudaGraphicsUnmapResources(
|
||||
1, self._graphics_ressource, stream
|
||||
)
|
||||
)
|
||||
self._cuda_buffer = None
|
||||
except Exception:
|
||||
@@ -193,7 +195,7 @@ try:
|
||||
return self
|
||||
|
||||
class CudaOpenGLMappedArray(CudaOpenGLMappedBuffer):
|
||||
def __init__(self, dtype, shape, gl_buffer, flags=0, strides=None, order='C'):
|
||||
def __init__(self, dtype, shape, gl_buffer, flags=0, strides=None, order="C"):
|
||||
super().__init__(gl_buffer, flags)
|
||||
self._dtype = dtype
|
||||
self._shape = shape
|
||||
@@ -227,19 +229,27 @@ class Shader:
|
||||
|
||||
glAttachShader(self.program_id, vertex_id)
|
||||
glAttachShader(self.program_id, fragment_id)
|
||||
glBindAttribLocation( self.program_id, 0, "in_vertex")
|
||||
glBindAttribLocation( self.program_id, 1, "in_texCoord")
|
||||
glBindAttribLocation(self.program_id, 0, "in_vertex")
|
||||
glBindAttribLocation(self.program_id, 1, "in_texCoord")
|
||||
glLinkProgram(self.program_id)
|
||||
|
||||
if glGetProgramiv(self.program_id, GL_LINK_STATUS) != GL_TRUE:
|
||||
info = glGetProgramInfoLog(self.program_id)
|
||||
if (self.program_id is not None) and (self.program_id > 0) and glIsProgram(self.program_id):
|
||||
if (
|
||||
(self.program_id is not None)
|
||||
and (self.program_id > 0)
|
||||
and glIsProgram(self.program_id)
|
||||
):
|
||||
glDeleteProgram(self.program_id)
|
||||
if (vertex_id is not None) and (vertex_id > 0) and glIsShader(vertex_id):
|
||||
glDeleteShader(vertex_id)
|
||||
if (fragment_id is not None) and (fragment_id > 0) and glIsShader(fragment_id):
|
||||
if (
|
||||
(fragment_id is not None)
|
||||
and (fragment_id > 0)
|
||||
and glIsShader(fragment_id)
|
||||
):
|
||||
glDeleteShader(fragment_id)
|
||||
raise RuntimeError('Error linking program: %s' % (info))
|
||||
raise RuntimeError("Error linking program: %s" % (info))
|
||||
if (vertex_id is not None) and (vertex_id > 0) and glIsShader(vertex_id):
|
||||
glDeleteShader(vertex_id)
|
||||
if (fragment_id is not None) and (fragment_id > 0) and glIsShader(fragment_id):
|
||||
@@ -257,9 +267,13 @@ class Shader:
|
||||
glCompileShader(shader_id)
|
||||
if glGetShaderiv(shader_id, GL_COMPILE_STATUS) != GL_TRUE:
|
||||
info = glGetShaderInfoLog(shader_id)
|
||||
if (shader_id is not None) and (shader_id > 0) and glIsShader(shader_id):
|
||||
if (
|
||||
(shader_id is not None)
|
||||
and (shader_id > 0)
|
||||
and glIsShader(shader_id)
|
||||
):
|
||||
glDeleteShader(shader_id)
|
||||
raise RuntimeError('Shader compilation failed: %s' % (info))
|
||||
raise RuntimeError("Shader compilation failed: %s" % (info))
|
||||
return shader_id
|
||||
except:
|
||||
if (shader_id is not None) and (shader_id > 0) and glIsShader(shader_id):
|
||||
@@ -269,8 +283,9 @@ class Shader:
|
||||
def get_program_id(self):
|
||||
return self.program_id
|
||||
|
||||
|
||||
class Simple3DObject:
|
||||
def __init__(self, _is_static, pts_size = 3, clr_size = 3):
|
||||
def __init__(self, _is_static, pts_size=3, clr_size=3):
|
||||
self.is_init = False
|
||||
self.drawing_type = GL_TRIANGLES
|
||||
self.is_static = _is_static
|
||||
@@ -285,7 +300,7 @@ class Simple3DObject:
|
||||
for pt in _pts:
|
||||
self.vertices.append(pt)
|
||||
|
||||
def add_clr(self, _clrs): # _clr [r,g,b]
|
||||
def add_clr(self, _clrs): # _clr [r,g,b]
|
||||
for clr in _clrs:
|
||||
self.colors.append(clr)
|
||||
|
||||
@@ -315,15 +330,30 @@ class Simple3DObject:
|
||||
|
||||
if len(self.vertices):
|
||||
glBindBuffer(GL_ARRAY_BUFFER, self.vboID[0])
|
||||
glBufferData(GL_ARRAY_BUFFER, len(self.vertices) * self.vertices.itemsize, (GLfloat * len(self.vertices))(*self.vertices), type_draw)
|
||||
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
len(self.vertices) * self.vertices.itemsize,
|
||||
(GLfloat * len(self.vertices))(*self.vertices),
|
||||
type_draw,
|
||||
)
|
||||
|
||||
if len(self.colors):
|
||||
glBindBuffer(GL_ARRAY_BUFFER, self.vboID[1])
|
||||
glBufferData(GL_ARRAY_BUFFER, len(self.colors) * self.colors.itemsize, (GLfloat * len(self.colors))(*self.colors), type_draw)
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
len(self.colors) * self.colors.itemsize,
|
||||
(GLfloat * len(self.colors))(*self.colors),
|
||||
type_draw,
|
||||
)
|
||||
|
||||
if len(self.indices):
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.vboID[2])
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER,len(self.indices) * self.indices.itemsize,(GLuint * len(self.indices))(*self.indices), type_draw)
|
||||
glBufferData(
|
||||
GL_ELEMENT_ARRAY_BUFFER,
|
||||
len(self.indices) * self.indices.itemsize,
|
||||
(GLuint * len(self.indices))(*self.indices),
|
||||
type_draw,
|
||||
)
|
||||
|
||||
self.elementbufferSize = len(self.indices)
|
||||
|
||||
@@ -341,33 +371,52 @@ class Simple3DObject:
|
||||
|
||||
# Initialize vertex buffer (for XYZRGBA data)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, self.vboID[0])
|
||||
glBufferData(GL_ARRAY_BUFFER, self.elementbufferSize * self.pt_type * self.vertices.itemsize, None, type_draw)
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
self.elementbufferSize * self.pt_type * self.vertices.itemsize,
|
||||
None,
|
||||
type_draw,
|
||||
)
|
||||
|
||||
# Try to set up GPU acceleration if available
|
||||
if self.use_gpu:
|
||||
try:
|
||||
flags = cudart.cudaGraphicsRegisterFlags.cudaGraphicsRegisterFlagsWriteDiscard
|
||||
flags = (
|
||||
cudart.cudaGraphicsRegisterFlags.cudaGraphicsRegisterFlagsWriteDiscard
|
||||
)
|
||||
self.cuda_mapped_buffer = CudaOpenGLMappedArray(
|
||||
dtype=np.float32,
|
||||
shape=(self.elementbufferSize, self.pt_type),
|
||||
gl_buffer=self.vboID[0],
|
||||
flags=flags
|
||||
dtype=np.float32,
|
||||
shape=(self.elementbufferSize, self.pt_type),
|
||||
gl_buffer=self.vboID[0],
|
||||
flags=flags,
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Failed to initialize GPU acceleration, falling back to CPU: {e}")
|
||||
print(
|
||||
f"Failed to initialize GPU acceleration, falling back to CPU: {e}"
|
||||
)
|
||||
self.use_gpu = False
|
||||
self.cuda_mapped_buffer = None
|
||||
|
||||
# Initialize color buffer (not used for point clouds with XYZRGBA)
|
||||
if self.clr_type:
|
||||
glBindBuffer(GL_ARRAY_BUFFER, self.vboID[1])
|
||||
glBufferData(GL_ARRAY_BUFFER, self.elementbufferSize * self.clr_type * self.colors.itemsize, None, type_draw)
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
self.elementbufferSize * self.clr_type * self.colors.itemsize,
|
||||
None,
|
||||
type_draw,
|
||||
)
|
||||
|
||||
for i in range (0, self.elementbufferSize):
|
||||
for i in range(0, self.elementbufferSize):
|
||||
self.indices.append(i)
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.vboID[2])
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER,len(self.indices) * self.indices.itemsize,(GLuint * len(self.indices))(*self.indices), type_draw)
|
||||
glBufferData(
|
||||
GL_ELEMENT_ARRAY_BUFFER,
|
||||
len(self.indices) * self.indices.itemsize,
|
||||
(GLuint * len(self.indices))(*self.indices),
|
||||
type_draw,
|
||||
)
|
||||
|
||||
def setPoints(self, pc):
|
||||
"""Update point cloud data from sl.Mat"""
|
||||
@@ -375,7 +424,11 @@ class Simple3DObject:
|
||||
return
|
||||
|
||||
try:
|
||||
if self.use_gpu and self.cuda_mapped_buffer and pc.get_memory_type() in (sl.MEM.GPU, sl.MEM.BOTH):
|
||||
if (
|
||||
self.use_gpu
|
||||
and self.cuda_mapped_buffer
|
||||
and pc.get_memory_type() in (sl.MEM.GPU, sl.MEM.BOTH)
|
||||
):
|
||||
self.setPointsGPU(pc)
|
||||
else:
|
||||
self.setPointsCPU(pc)
|
||||
@@ -423,7 +476,9 @@ class Simple3DObject:
|
||||
# Get CPU pointer and upload to GPU buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, self.vboID[0])
|
||||
data_ptr = pc.get_pointer(sl.MEM.CPU)
|
||||
buffer_size = self.elementbufferSize * self.pt_type * 4 # 4 bytes per float32
|
||||
buffer_size = (
|
||||
self.elementbufferSize * self.pt_type * 4
|
||||
) # 4 bytes per float32
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, buffer_size, ctypes.c_void_p(data_ptr))
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0)
|
||||
|
||||
@@ -432,9 +487,9 @@ class Simple3DObject:
|
||||
raise
|
||||
|
||||
def clear(self):
|
||||
self.vertices = array.array('f')
|
||||
self.colors = array.array('f')
|
||||
self.indices = array.array('I')
|
||||
self.vertices = array.array("f")
|
||||
self.colors = array.array("f")
|
||||
self.indices = array.array("I")
|
||||
self.elementbufferSize = 0
|
||||
|
||||
def set_drawing_type(self, _type):
|
||||
@@ -444,55 +499,57 @@ class Simple3DObject:
|
||||
if self.elementbufferSize:
|
||||
glEnableVertexAttribArray(0)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, self.vboID[0])
|
||||
glVertexAttribPointer(0,self.pt_type,GL_FLOAT,GL_FALSE,0,None)
|
||||
glVertexAttribPointer(0, self.pt_type, GL_FLOAT, GL_FALSE, 0, None)
|
||||
|
||||
if(self.clr_type):
|
||||
if self.clr_type:
|
||||
glEnableVertexAttribArray(1)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, self.vboID[1])
|
||||
glVertexAttribPointer(1,self.clr_type,GL_FLOAT,GL_FALSE,0,None)
|
||||
|
||||
glVertexAttribPointer(1, self.clr_type, GL_FLOAT, GL_FALSE, 0, None)
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.vboID[2])
|
||||
glDrawElements(self.drawing_type, self.elementbufferSize, GL_UNSIGNED_INT, None)
|
||||
|
||||
glDrawElements(
|
||||
self.drawing_type, self.elementbufferSize, GL_UNSIGNED_INT, None
|
||||
)
|
||||
|
||||
glDisableVertexAttribArray(0)
|
||||
if self.clr_type:
|
||||
glDisableVertexAttribArray(1)
|
||||
|
||||
def __del__(self):
|
||||
"""Cleanup GPU resources"""
|
||||
if hasattr(self, 'cuda_mapped_buffer') and self.cuda_mapped_buffer:
|
||||
if hasattr(self, "cuda_mapped_buffer") and self.cuda_mapped_buffer:
|
||||
try:
|
||||
self.cuda_mapped_buffer.unregister()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
class GLViewer:
|
||||
def __init__(self):
|
||||
self.available = False
|
||||
self.mutex = Lock()
|
||||
self.camera = CameraGL()
|
||||
self.wheelPosition = 0.
|
||||
self.wheelPosition = 0.0
|
||||
self.mouse_button = [False, False]
|
||||
self.mouseCurrentPosition = [0., 0.]
|
||||
self.previousMouseMotion = [0., 0.]
|
||||
self.mouseMotion = [0., 0.]
|
||||
self.mouseCurrentPosition = [0.0, 0.0]
|
||||
self.previousMouseMotion = [0.0, 0.0]
|
||||
self.mouseMotion = [0.0, 0.0]
|
||||
self.zedModel = Simple3DObject(True)
|
||||
self.point_cloud = Simple3DObject(False, 4)
|
||||
self.save_data = False
|
||||
|
||||
def init(self, _argc, _argv, res): # _params = sl.CameraParameters
|
||||
def init(self, _argc, _argv, res): # _params = sl.CameraParameters
|
||||
glutInit(_argc, _argv)
|
||||
wnd_w = int(glutGet(GLUT_SCREEN_WIDTH)*0.9)
|
||||
wnd_h = int(glutGet(GLUT_SCREEN_HEIGHT) *0.9)
|
||||
wnd_w = int(glutGet(GLUT_SCREEN_WIDTH) * 0.9)
|
||||
wnd_h = int(glutGet(GLUT_SCREEN_HEIGHT) * 0.9)
|
||||
glutInitWindowSize(wnd_w, wnd_h)
|
||||
glutInitWindowPosition(int(wnd_w*0.05), int(wnd_h*0.05))
|
||||
glutInitWindowPosition(int(wnd_w * 0.05), int(wnd_h * 0.05))
|
||||
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
|
||||
glutCreateWindow(b"ZED Depth Sensing")
|
||||
glViewport(0, 0, wnd_w, wnd_h)
|
||||
|
||||
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,
|
||||
GLUT_ACTION_CONTINUE_EXECUTION)
|
||||
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION)
|
||||
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
|
||||
@@ -504,17 +561,21 @@ class GLViewer:
|
||||
|
||||
# Compile and create the shader for 3D objects
|
||||
self.shader_image = Shader(VERTEX_SHADER, FRAGMENT_SHADER)
|
||||
self.shader_image_MVP = glGetUniformLocation(self.shader_image.get_program_id(), "u_mvpMatrix")
|
||||
self.shader_image_MVP = glGetUniformLocation(
|
||||
self.shader_image.get_program_id(), "u_mvpMatrix"
|
||||
)
|
||||
|
||||
self.shader_pc = Shader(POINTCLOUD_VERTEX_SHADER, POINTCLOUD_FRAGMENT_SHADER)
|
||||
self.shader_pc_MVP = glGetUniformLocation(self.shader_pc.get_program_id(), "u_mvpMatrix")
|
||||
self.shader_pc_MVP = glGetUniformLocation(
|
||||
self.shader_pc.get_program_id(), "u_mvpMatrix"
|
||||
)
|
||||
|
||||
self.bckgrnd_clr = np.array([223/255., 230/255., 233/255.])
|
||||
self.bckgrnd_clr = np.array([223 / 255.0, 230 / 255.0, 233 / 255.0])
|
||||
|
||||
# Create the camera model
|
||||
Z_ = -0.15
|
||||
Y_ = Z_ * math.tan(95. * M_PI / 180. / 2.)
|
||||
X_ = Y_ * 16./9.
|
||||
Y_ = Z_ * math.tan(95.0 * M_PI / 180.0 / 2.0)
|
||||
X_ = Y_ * 16.0 / 9.0
|
||||
|
||||
A = np.array([0, 0, 0])
|
||||
B = np.array([X_, Y_, Z_])
|
||||
@@ -522,7 +583,7 @@ class GLViewer:
|
||||
D = np.array([-X_, -Y_, Z_])
|
||||
E = np.array([X_, -Y_, Z_])
|
||||
|
||||
lime_clr = np.array([217 / 255, 255/255, 66/255])
|
||||
lime_clr = np.array([217 / 255, 255 / 255, 66 / 255])
|
||||
|
||||
self.zedModel.add_line(A, B, lime_clr)
|
||||
self.zedModel.add_line(A, C, lime_clr)
|
||||
@@ -578,39 +639,40 @@ class GLViewer:
|
||||
def keyPressedCallback(self, key, x, y):
|
||||
if ord(key) == 27:
|
||||
self.close_func()
|
||||
if (ord(key) == 83 or ord(key) == 115):
|
||||
if ord(key) == 83 or ord(key) == 115:
|
||||
self.save_data = True
|
||||
|
||||
|
||||
def on_mouse(self,*args,**kwargs):
|
||||
(key,Up,x,y) = args
|
||||
if key==0:
|
||||
self.mouse_button[0] = (Up == 0)
|
||||
elif key==2 :
|
||||
self.mouse_button[1] = (Up == 0)
|
||||
elif(key == 3):
|
||||
def on_mouse(self, *args, **kwargs):
|
||||
key, Up, x, y = args
|
||||
if key == 0:
|
||||
self.mouse_button[0] = Up == 0
|
||||
elif key == 2:
|
||||
self.mouse_button[1] = Up == 0
|
||||
elif key == 3:
|
||||
self.wheelPosition = self.wheelPosition + 1
|
||||
elif(key == 4):
|
||||
elif key == 4:
|
||||
self.wheelPosition = self.wheelPosition - 1
|
||||
|
||||
self.mouseCurrentPosition = [x, y]
|
||||
self.previousMouseMotion = [x, y]
|
||||
|
||||
def on_mousemove(self,*args,**kwargs):
|
||||
(x,y) = args
|
||||
def on_mousemove(self, *args, **kwargs):
|
||||
x, y = args
|
||||
self.mouseMotion[0] = x - self.previousMouseMotion[0]
|
||||
self.mouseMotion[1] = y - self.previousMouseMotion[1]
|
||||
self.previousMouseMotion = [x, y]
|
||||
glutPostRedisplay()
|
||||
|
||||
def on_resize(self,Width,Height):
|
||||
def on_resize(self, Width, Height):
|
||||
glViewport(0, 0, Width, Height)
|
||||
self.camera.setProjection(Height / Width)
|
||||
|
||||
def draw_callback(self):
|
||||
if self.available:
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
glClearColor(self.bckgrnd_clr[0], self.bckgrnd_clr[1], self.bckgrnd_clr[2], 1.)
|
||||
glClearColor(
|
||||
self.bckgrnd_clr[0], self.bckgrnd_clr[1], self.bckgrnd_clr[2], 1.0
|
||||
)
|
||||
|
||||
self.mutex.acquire()
|
||||
self.update()
|
||||
@@ -621,21 +683,21 @@ class GLViewer:
|
||||
glutPostRedisplay()
|
||||
|
||||
def update(self):
|
||||
if(self.mouse_button[0]):
|
||||
if self.mouse_button[0]:
|
||||
r = sl.Rotation()
|
||||
vert=self.camera.vertical_
|
||||
vert = self.camera.vertical_
|
||||
tmp = vert.get()
|
||||
vert.init_vector(tmp[0] * 1.,tmp[1] * 1., tmp[2] * 1.)
|
||||
vert.init_vector(tmp[0] * 1.0, tmp[1] * 1.0, tmp[2] * 1.0)
|
||||
r.init_angle_translation(self.mouseMotion[0] * 0.02, vert)
|
||||
self.camera.rotate(r)
|
||||
|
||||
r.init_angle_translation(self.mouseMotion[1] * 0.02, self.camera.right_)
|
||||
self.camera.rotate(r)
|
||||
|
||||
if(self.mouse_button[1]):
|
||||
if self.mouse_button[1]:
|
||||
t = sl.Translation()
|
||||
tmp = self.camera.right_.get()
|
||||
scale = self.mouseMotion[0] *-0.05
|
||||
scale = self.mouseMotion[0] * -0.05
|
||||
t.init_vector(tmp[0] * scale, tmp[1] * scale, tmp[2] * scale)
|
||||
self.camera.translate(t)
|
||||
|
||||
@@ -644,7 +706,7 @@ class GLViewer:
|
||||
t.init_vector(tmp[0] * scale, tmp[1] * scale, tmp[2] * scale)
|
||||
self.camera.translate(t)
|
||||
|
||||
if (self.wheelPosition != 0):
|
||||
if self.wheelPosition != 0:
|
||||
t = sl.Translation()
|
||||
tmp = self.camera.forward_.get()
|
||||
scale = self.wheelPosition * -0.065
|
||||
@@ -653,34 +715,39 @@ class GLViewer:
|
||||
|
||||
self.camera.update()
|
||||
|
||||
self.mouseMotion = [0., 0.]
|
||||
self.mouseMotion = [0.0, 0.0]
|
||||
self.wheelPosition = 0
|
||||
|
||||
def draw(self):
|
||||
vpMatrix = self.camera.getViewProjectionMatrix()
|
||||
glUseProgram(self.shader_image.get_program_id())
|
||||
glUniformMatrix4fv(self.shader_image_MVP, 1, GL_TRUE, (GLfloat * len(vpMatrix))(*vpMatrix))
|
||||
glUniformMatrix4fv(
|
||||
self.shader_image_MVP, 1, GL_TRUE, (GLfloat * len(vpMatrix))(*vpMatrix)
|
||||
)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
|
||||
self.zedModel.draw()
|
||||
glUseProgram(0)
|
||||
|
||||
glUseProgram(self.shader_pc.get_program_id())
|
||||
glUniformMatrix4fv(self.shader_pc_MVP, 1, GL_TRUE, (GLfloat * len(vpMatrix))(*vpMatrix))
|
||||
glPointSize(1.)
|
||||
glUniformMatrix4fv(
|
||||
self.shader_pc_MVP, 1, GL_TRUE, (GLfloat * len(vpMatrix))(*vpMatrix)
|
||||
)
|
||||
glPointSize(1.0)
|
||||
self.point_cloud.draw()
|
||||
glUseProgram(0)
|
||||
|
||||
|
||||
|
||||
class CameraGL:
|
||||
def __init__(self):
|
||||
self.ORIGINAL_FORWARD = sl.Translation()
|
||||
self.ORIGINAL_FORWARD.init_vector(0,0,1)
|
||||
self.ORIGINAL_FORWARD.init_vector(0, 0, 1)
|
||||
self.ORIGINAL_UP = sl.Translation()
|
||||
self.ORIGINAL_UP.init_vector(0,1,0)
|
||||
self.ORIGINAL_UP.init_vector(0, 1, 0)
|
||||
self.ORIGINAL_RIGHT = sl.Translation()
|
||||
self.ORIGINAL_RIGHT.init_vector(1,0,0)
|
||||
self.ORIGINAL_RIGHT.init_vector(1, 0, 0)
|
||||
self.znear = 0.5
|
||||
self.zfar = 100.
|
||||
self.horizontalFOV = 70.
|
||||
self.zfar = 100.0
|
||||
self.horizontalFOV = 70.0
|
||||
self.orientation_ = sl.Orientation()
|
||||
self.position_ = sl.Translation()
|
||||
self.forward_ = sl.Translation()
|
||||
@@ -689,58 +756,62 @@ class CameraGL:
|
||||
self.vertical_ = sl.Translation()
|
||||
self.vpMatrix_ = sl.Matrix4f()
|
||||
self.offset_ = sl.Translation()
|
||||
self.offset_.init_vector(0,0,5)
|
||||
self.offset_.init_vector(0, 0, 5)
|
||||
self.projection_ = sl.Matrix4f()
|
||||
self.projection_.set_identity()
|
||||
self.setProjection(1.78)
|
||||
|
||||
self.position_.init_vector(0., 0., 0.)
|
||||
self.position_.init_vector(0.0, 0.0, 0.0)
|
||||
tmp = sl.Translation()
|
||||
tmp.init_vector(0, 0, -.1)
|
||||
tmp.init_vector(0, 0, -0.1)
|
||||
tmp2 = sl.Translation()
|
||||
tmp2.init_vector(0, 1, 0)
|
||||
self.setDirection(tmp, tmp2)
|
||||
self.setDirection(tmp, tmp2)
|
||||
|
||||
def update(self):
|
||||
def update(self):
|
||||
dot_ = sl.Translation.dot_translation(self.vertical_, self.up_)
|
||||
if(dot_ < 0.):
|
||||
if dot_ < 0.0:
|
||||
tmp = self.vertical_.get()
|
||||
self.vertical_.init_vector(tmp[0] * -1.,tmp[1] * -1., tmp[2] * -1.)
|
||||
self.vertical_.init_vector(tmp[0] * -1.0, tmp[1] * -1.0, tmp[2] * -1.0)
|
||||
transformation = sl.Transform()
|
||||
|
||||
tmp_position = self.position_.get()
|
||||
tmp = (self.offset_ * self.orientation_).get()
|
||||
new_position = sl.Translation()
|
||||
new_position.init_vector(tmp_position[0] + tmp[0], tmp_position[1] + tmp[1], tmp_position[2] + tmp[2])
|
||||
new_position.init_vector(
|
||||
tmp_position[0] + tmp[0], tmp_position[1] + tmp[1], tmp_position[2] + tmp[2]
|
||||
)
|
||||
transformation.init_orientation_translation(self.orientation_, new_position)
|
||||
transformation.inverse()
|
||||
self.vpMatrix_ = self.projection_ * transformation
|
||||
|
||||
def setProjection(self, im_ratio):
|
||||
fov_x = self.horizontalFOV * 3.1416 / 180.
|
||||
fov_y = self.horizontalFOV * im_ratio * 3.1416 / 180.
|
||||
|
||||
self.projection_[(0,0)] = 1. / math.tan(fov_x * .5)
|
||||
self.projection_[(1,1)] = 1. / math.tan(fov_y * .5)
|
||||
self.projection_[(2,2)] = -(self.zfar + self.znear) / (self.zfar - self.znear)
|
||||
self.projection_[(3,2)] = -1.
|
||||
self.projection_[(2,3)] = -(2. * self.zfar * self.znear) / (self.zfar - self.znear)
|
||||
self.projection_[(3,3)] = 0.
|
||||
|
||||
def setProjection(self, im_ratio):
|
||||
fov_x = self.horizontalFOV * 3.1416 / 180.0
|
||||
fov_y = self.horizontalFOV * im_ratio * 3.1416 / 180.0
|
||||
|
||||
self.projection_[(0, 0)] = 1.0 / math.tan(fov_x * 0.5)
|
||||
self.projection_[(1, 1)] = 1.0 / math.tan(fov_y * 0.5)
|
||||
self.projection_[(2, 2)] = -(self.zfar + self.znear) / (self.zfar - self.znear)
|
||||
self.projection_[(3, 2)] = -1.0
|
||||
self.projection_[(2, 3)] = -(2.0 * self.zfar * self.znear) / (
|
||||
self.zfar - self.znear
|
||||
)
|
||||
self.projection_[(3, 3)] = 0.0
|
||||
|
||||
def getViewProjectionMatrix(self):
|
||||
tmp = self.vpMatrix_.m
|
||||
vpMat = array.array('f')
|
||||
vpMat = array.array("f")
|
||||
for row in tmp:
|
||||
for v in row:
|
||||
vpMat.append(v)
|
||||
return vpMat
|
||||
|
||||
|
||||
def getViewProjectionMatrixRT(self, tr):
|
||||
tmp = self.vpMatrix_
|
||||
tmp.transpose()
|
||||
tr.transpose()
|
||||
tmp = (tr * tmp).m
|
||||
vpMat = array.array('f')
|
||||
tmp = (tr * tmp).m
|
||||
vpMat = array.array("f")
|
||||
for row in tmp:
|
||||
for v in row:
|
||||
vpMat.append(v)
|
||||
@@ -749,15 +820,15 @@ class CameraGL:
|
||||
def setDirection(self, dir, vert):
|
||||
dir.normalize()
|
||||
tmp = dir.get()
|
||||
dir.init_vector(tmp[0] * -1.,tmp[1] * -1., tmp[2] * -1.)
|
||||
dir.init_vector(tmp[0] * -1.0, tmp[1] * -1.0, tmp[2] * -1.0)
|
||||
self.orientation_.init_translation(self.ORIGINAL_FORWARD, dir)
|
||||
self.updateVectors()
|
||||
self.vertical_ = vert
|
||||
if(sl.Translation.dot_translation(self.vertical_, self.up_) < 0.):
|
||||
if sl.Translation.dot_translation(self.vertical_, self.up_) < 0.0:
|
||||
tmp = sl.Rotation()
|
||||
tmp.init_angle_translation(3.14, self.ORIGINAL_FORWARD)
|
||||
self.rotate(tmp)
|
||||
|
||||
|
||||
def translate(self, t):
|
||||
ref = self.position_.get()
|
||||
tmp = t.get()
|
||||
@@ -766,7 +837,7 @@ class CameraGL:
|
||||
def setPosition(self, p):
|
||||
self.position_ = p
|
||||
|
||||
def rotate(self, r):
|
||||
def rotate(self, r):
|
||||
tmp = sl.Orientation()
|
||||
tmp.init_rotation(r)
|
||||
self.orientation_ = tmp * self.orientation_
|
||||
@@ -781,5 +852,5 @@ class CameraGL:
|
||||
self.up_ = self.ORIGINAL_UP * self.orientation_
|
||||
right = self.ORIGINAL_RIGHT
|
||||
tmp = right.get()
|
||||
right.init_vector(tmp[0] * -1.,tmp[1] * -1., tmp[2] * -1.)
|
||||
right.init_vector(tmp[0] * -1.0, tmp[1] * -1.0, tmp[2] * -1.0)
|
||||
self.right_ = right * self.orientation_
|
||||
|
||||
Reference in New Issue
Block a user