|
@@ -16,8 +16,14 @@ from OpenGL.GLU import *
|
|
|
# 初始化 Pygame
|
|
# 初始化 Pygame
|
|
|
pygame.init()
|
|
pygame.init()
|
|
|
|
|
|
|
|
-# 设置窗口大小
|
|
|
|
|
-width, height = 800, 600
|
|
|
|
|
|
|
+# 获取屏幕尺寸
|
|
|
|
|
+info = pygame.display.Info()
|
|
|
|
|
+screen_width = info.current_w
|
|
|
|
|
+screen_height = info.current_h
|
|
|
|
|
+
|
|
|
|
|
+# 设置窗口大小(高度为屏幕高度的80%,保持原始宽高比)
|
|
|
|
|
+height = int(screen_height * 0.8)
|
|
|
|
|
+width = int(height * (800 / 600)) # 保持原始宽高比 800:600
|
|
|
display = pygame.display.set_mode((width, height), DOUBLEBUF | OPENGL)
|
|
display = pygame.display.set_mode((width, height), DOUBLEBUF | OPENGL)
|
|
|
pygame.display.set_caption('3D Yellow Ball')
|
|
pygame.display.set_caption('3D Yellow Ball')
|
|
|
|
|
|
|
@@ -45,10 +51,16 @@ glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient)
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse)
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse)
|
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular)
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular)
|
|
|
|
|
|
|
|
-# 设置视角
|
|
|
|
|
|
|
+# 设置投影矩阵(透视投影)
|
|
|
|
|
+glMatrixMode(GL_PROJECTION)
|
|
|
|
|
+glLoadIdentity()
|
|
|
gluPerspective(45, (width/height), 0.1, 50.0)
|
|
gluPerspective(45, (width/height), 0.1, 50.0)
|
|
|
-# 移动相机
|
|
|
|
|
-glTranslatef(0.0, 0.0, -5)
|
|
|
|
|
|
|
+
|
|
|
|
|
+# 设置模型视图矩阵
|
|
|
|
|
+glMatrixMode(GL_MODELVIEW)
|
|
|
|
|
+glLoadIdentity()
|
|
|
|
|
+# 移动相机(现在在主循环中每帧设置)
|
|
|
|
|
+# glTranslatef(0.0, 0.0, -5)
|
|
|
|
|
|
|
|
def build_directory_tree(root_path, max_depth=3, max_children_per_node=30):
|
|
def build_directory_tree(root_path, max_depth=3, max_children_per_node=30):
|
|
|
# 递归扫描目录树
|
|
# 递归扫描目录树
|
|
@@ -122,7 +134,7 @@ def build_directory_tree(root_path, max_depth=3, max_children_per_node=30):
|
|
|
|
|
|
|
|
# 计算当前节点位置
|
|
# 计算当前节点位置
|
|
|
if node_id == 0: # 根节点
|
|
if node_id == 0: # 根节点
|
|
|
- positions[node_id] = [0.0, max_depth_found * 0.8, 0.0] # 顶部
|
|
|
|
|
|
|
+ positions[node_id] = [0.0, max_depth_found * 0.4, 0.0] # 顶部,高度减半
|
|
|
else:
|
|
else:
|
|
|
parent_id = nodes[node_id][2]
|
|
parent_id = nodes[node_id][2]
|
|
|
if parent_id >= 0:
|
|
if parent_id >= 0:
|
|
@@ -134,12 +146,12 @@ def build_directory_tree(root_path, max_depth=3, max_children_per_node=30):
|
|
|
angle = start_angle + (end_angle - start_angle) * (child_index / max(num_siblings, 1))
|
|
angle = start_angle + (end_angle - start_angle) * (child_index / max(num_siblings, 1))
|
|
|
|
|
|
|
|
# 半径随深度减小
|
|
# 半径随深度减小
|
|
|
- radius = 1.5 * (0.75 ** depth) # 深度越大,半径越小
|
|
|
|
|
|
|
+ radius = 0.75 * (0.75 ** depth) # 深度越大,半径越小,基础半径减半
|
|
|
|
|
|
|
|
# 计算位置
|
|
# 计算位置
|
|
|
px, py, pz = positions[parent_id]
|
|
px, py, pz = positions[parent_id]
|
|
|
x = px + radius * math.cos(angle)
|
|
x = px + radius * math.cos(angle)
|
|
|
- y = py - 1.3 # 每层向下移动
|
|
|
|
|
|
|
+ y = py - 0.65 # 每层向下移动,垂直距离减半
|
|
|
z = pz + radius * math.sin(angle)
|
|
z = pz + radius * math.sin(angle)
|
|
|
|
|
|
|
|
positions[node_id] = [x, y, z]
|
|
positions[node_id] = [x, y, z]
|
|
@@ -176,12 +188,18 @@ blinking_nodes = set()
|
|
|
file_content_cache = {}
|
|
file_content_cache = {}
|
|
|
blink_start_time = pygame.time.get_ticks()
|
|
blink_start_time = pygame.time.get_ticks()
|
|
|
|
|
|
|
|
|
|
+# 旋转控制变量
|
|
|
|
|
+rotation_angle = 0.0
|
|
|
|
|
+
|
|
|
# 主循环
|
|
# 主循环
|
|
|
running = True
|
|
running = True
|
|
|
while running:
|
|
while running:
|
|
|
# 获取当前时间(用于闪烁效果)
|
|
# 获取当前时间(用于闪烁效果)
|
|
|
current_time = pygame.time.get_ticks()
|
|
current_time = pygame.time.get_ticks()
|
|
|
|
|
|
|
|
|
|
+ # 更新旋转角度(每10秒旋转一圈)
|
|
|
|
|
+ rotation_angle = (current_time * 0.036) % 360.0
|
|
|
|
|
+
|
|
|
# 检查剪贴板内容是否变化(如果剪贴板功能可用)
|
|
# 检查剪贴板内容是否变化(如果剪贴板功能可用)
|
|
|
if clipboard_available:
|
|
if clipboard_available:
|
|
|
if current_time - clipboard_check_time > 1000: # 每秒检查一次
|
|
if current_time - clipboard_check_time > 1000: # 每秒检查一次
|
|
@@ -245,6 +263,11 @@ while running:
|
|
|
# 清除屏幕
|
|
# 清除屏幕
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
|
|
|
|
|
|
|
|
|
+ # 重置模型视图矩阵并设置相机位置
|
|
|
|
|
+ glLoadIdentity()
|
|
|
|
|
+ glTranslatef(0.0, 0.0, -5) # 相机向后移动
|
|
|
|
|
+ glRotatef(rotation_angle, 0.0, 1.0, 0.0) # 绕竖直中线/Y轴旋转
|
|
|
|
|
+
|
|
|
# 目录树可视化
|
|
# 目录树可视化
|
|
|
ball_radius = 0.0667 # 节点球的半径(原来的1/3)
|
|
ball_radius = 0.0667 # 节点球的半径(原来的1/3)
|
|
|
|
|
|