zhong (钟鹏群) 3 тижнів тому
батько
коміт
23026603df
1 змінених файлів з 38 додано та 0 видалено
  1. 38 0
      src/ball-demo.py

+ 38 - 0
src/ball-demo.py

@@ -500,6 +500,44 @@ while running:
         glVertex3f(x2, y2, z2)
     glEnd()
     
+    # 绘制锥形表面(连接父文件夹与其子节点形成锥形)
+    glDisable(GL_LIGHTING)  # 临时禁用光照以使用纯色
+    glColor4f(0.5, 0.5, 0.5, 0.2)  # 半透明灰色
+    
+    # 启用混合以实现透明效果
+    glEnable(GL_BLEND)
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
+    
+    # 遍历所有节点,查找作为父节点的文件夹
+    for i, (name, is_dir, parent_id, depth, full_path) in enumerate(tree_nodes):
+        if is_dir:  # 如果是文件夹节点
+            # 获取该文件夹的所有子节点
+            child_nodes = tree_children[i]
+            if len(child_nodes) > 0:
+                # 获取父节点坐标
+                parent_x, parent_y, parent_z = node_positions[i]
+                
+                # 如果只有一个子节点,无法形成锥形,跳过
+                if len(child_nodes) < 2:
+                    continue
+                
+                # 开始绘制三角形扇形来形成锥形表面
+                glBegin(GL_TRIANGLE_FAN)
+                glVertex3f(parent_x, parent_y, parent_z)  # 锥形顶点(父节点)
+                
+                # 按顺序连接子节点形成锥形侧面
+                for child_id in child_nodes:
+                    child_x, child_y, child_z = node_positions[child_id]
+                    glVertex3f(child_x, child_y, child_z)
+                
+                # 闭合扇形,再次指定第一个子节点
+                if len(child_nodes) > 0:
+                    first_child_x, first_child_y, first_child_z = node_positions[child_nodes[0]]
+                    glVertex3f(first_child_x, first_child_y, first_child_z)
+                
+                glEnd()
+    
+    glDisable(GL_BLEND)  # 禁用混合
     glEnable(GL_LIGHTING)  # 重新启用光照
     
     # 绘制所有节点球(根据类型使用不同颜色)