8
8
DEFAULT_GRID_RGBA = [0.75 , 0.75 , 0.75 , 0.3 ]
9
9
DEFAULT_FRUSTUM_RGBA = [0.75 , 0.75 , 0.75 , 0.4 ]
10
10
DEFAULT_KEYFRAME_RGBA = [0.9 , 0.4 , 0.0 , 0.75 ]
11
- DEFAULT_CAMERA_MODEL_RGB = [1.0 , 0.0 , 0.0 ]
11
+ DEFAULT_CAMERA_RGBA = [1.0 , 0.0 , 0.0 , 0.75 ]
12
12
13
- class KeyFrameRenderer :
14
- def __init__ (self , color = np .array (DEFAULT_KEYFRAME_RGBA ), scale = 0.05 , lineWidth = 2 ):
13
+ class CameraWireframeRenderer :
14
+ def __init__ (self , color = np .array (DEFAULT_CAMERA_RGBA ), scale = 0.05 , lineWidth = 2 ):
15
15
self .color = color
16
16
self .lineWidth = lineWidth
17
17
self .vertices = np .array ([
@@ -33,7 +33,7 @@ def __init__(self, color=np.array(DEFAULT_KEYFRAME_RGBA), scale=0.05, lineWidth=
33
33
[4 , 1 ],
34
34
]
35
35
36
- def render (self , keyFrameCameraToWorldMatrices , viewMatrix , projectionMatrix ):
36
+ def render (self , modelMatrix , viewMatrix , projectionMatrix ):
37
37
glLineWidth (self .lineWidth )
38
38
glEnable (GL_BLEND )
39
39
glBlendFunc (GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA )
@@ -42,6 +42,37 @@ def render(self, keyFrameCameraToWorldMatrices, viewMatrix, projectionMatrix):
42
42
glEnable (GL_DEPTH_TEST )
43
43
glColor4fv (self .color )
44
44
45
+ modelView = viewMatrix @ modelMatrix
46
+ glMatrixMode (GL_MODELVIEW )
47
+ glLoadMatrixf (modelView .transpose ())
48
+ glMatrixMode (GL_PROJECTION )
49
+ glLoadMatrixf (projectionMatrix .transpose ())
50
+
51
+ glBegin (GL_LINES )
52
+ for edge in self .edges :
53
+ p0 = self .vertices [edge [0 ]]
54
+ p1 = self .vertices [edge [1 ]]
55
+ glVertex3f (p0 [0 ], p0 [1 ], p0 [2 ])
56
+ glVertex3f (p1 [0 ], p1 [1 ], p1 [2 ])
57
+ glEnd ()
58
+
59
+ glDisable (GL_BLEND )
60
+ glDisable (GL_LINE_SMOOTH )
61
+ glDisable (GL_DEPTH_TEST )
62
+
63
+ class KeyFrameRenderer :
64
+ def __init__ (self , color = np .array (DEFAULT_KEYFRAME_RGBA ), scale = 0.05 , lineWidth = 2 ):
65
+ self .cameraWireframe = CameraWireframeRenderer (color , scale , lineWidth )
66
+
67
+ def render (self , keyFrameCameraToWorldMatrices , viewMatrix , projectionMatrix ):
68
+ glLineWidth (self .cameraWireframe .lineWidth )
69
+ glEnable (GL_BLEND )
70
+ glBlendFunc (GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA )
71
+ glEnable (GL_LINE_SMOOTH )
72
+ glHint (GL_LINE_SMOOTH_HINT , GL_NICEST )
73
+ glEnable (GL_DEPTH_TEST )
74
+ glColor4fv (self .cameraWireframe .color )
75
+
45
76
for kfId in keyFrameCameraToWorldMatrices :
46
77
modelMatrix = keyFrameCameraToWorldMatrices [kfId ]
47
78
modelView = viewMatrix @ modelMatrix
@@ -51,9 +82,9 @@ def render(self, keyFrameCameraToWorldMatrices, viewMatrix, projectionMatrix):
51
82
glLoadMatrixf (projectionMatrix .transpose ())
52
83
53
84
glBegin (GL_LINES )
54
- for edge in self .edges :
55
- p0 = self .vertices [edge [0 ]]
56
- p1 = self .vertices [edge [1 ]]
85
+ for edge in self .cameraWireframe . edges :
86
+ p0 = self .cameraWireframe . vertices [edge [0 ]]
87
+ p1 = self .cameraWireframe . vertices [edge [1 ]]
57
88
glVertex3f (p0 [0 ], p0 [1 ], p0 [2 ])
58
89
glVertex3f (p1 [0 ], p1 [1 ], p1 [2 ])
59
90
glEnd ()
@@ -383,44 +414,6 @@ def render(self, modelMatrix, viewMatrix, projectionMatrix, render2d):
383
414
384
415
glDisable (GL_DEPTH_TEST )
385
416
386
- def createCameraModelMesh (scale = 1.0 , color = np .array (DEFAULT_CAMERA_MODEL_RGB )):
387
- scale = 0.2 * scale
388
- vertices = np .array ([
389
- - 0.5 , - 0.5 , 0.0 , # Vertex 0: Near top-left
390
- 0.5 , - 0.5 , 0.0 , # Vertex 1: Near top-right
391
- 0.5 , 0.5 , 0.0 , # Vertex 2: Near bottom-right
392
- - 0.5 , 0.5 , 0.0 , # Vertex 3: Near bottom-left
393
- - 1.0 , - 1.0 , 1.0 , # Vertex 4: Far top-left
394
- 1.0 , - 1.0 , 1.0 , # Vertex 5: Far top-right
395
- 1.0 , 1.0 , 1.0 , # Vertex 6: Far bottom-right
396
- - 1.0 , 1.0 , 1.0 # Vertex 7: Far bottom-left
397
- ], dtype = np .float32 )
398
-
399
- vertices *= scale
400
-
401
- colors = np .array ([
402
- color ,
403
- color ,
404
- color ,
405
- color ,
406
- # add some shading
407
- 0.5 * color ,
408
- 0.5 * color ,
409
- 0.5 * color ,
410
- 0.5 * color
411
- ], dtype = np .float32 )
412
-
413
- triangles = np .array ([
414
- 0 , 1 , 2 , 0 , 2 , 3 , # Near face
415
- 4 , 5 , 6 , 4 , 6 , 7 , # Far face
416
- 0 , 1 , 5 , 0 , 5 , 4 , # Bottom face
417
- 1 , 2 , 6 , 1 , 6 , 5 , # Right face
418
- 2 , 3 , 7 , 2 , 7 , 6 , # Top face
419
- 3 , 0 , 4 , 3 , 4 , 7 # Left face
420
- ], dtype = np .uint32 )
421
-
422
- return Mesh (vertices , colors , triangles )
423
-
424
417
def createPlaneMesh (scale , position , color ):
425
418
# 3 ---- 2
426
419
# | |
0 commit comments