#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
简单颜色测试程序
"""

from direct.showbase.ShowBase import ShowBase
from panda3d.core import LineSegs, Vec3, Vec4
from direct.task import Task

class ColorTest(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        
        # 设置背景色
        self.setBackgroundColor(0.2, 0.2, 0.3)
        
        # 设置相机位置
        self.cam.setPos(0, -10, 0)
        self.cam.lookAt(0, 0, 0)
        
        # 创建测试线段
        self.createTestLines()
        
        # 颜色变化任务
        self.taskMgr.add(self.colorChangeTask, "colorChange")
        
        self.time = 0
        
    def createTestLines(self):
        """创建测试线段"""
        # 创建X轴线段
        x_lines = LineSegs()
        x_lines.setThickness(5.0)
        x_lines.moveTo(-3, 0, 0)
        x_lines.drawTo(3, 0, 0)
        
        self.x_axis = self.render.attachNewNode(x_lines.create())
        self.x_axis.setColor(1, 0, 0, 1)  # 红色
        self.x_axis.setLightOff()
        
        # 创建Y轴线段  
        y_lines = LineSegs()
        y_lines.setThickness(5.0)
        y_lines.moveTo(0, -3, 0)
        y_lines.drawTo(0, 3, 0)
        
        self.y_axis = self.render.attachNewNode(y_lines.create())
        self.y_axis.setColor(0, 1, 0, 1)  # 绿色
        self.y_axis.setLightOff()
        
        # 创建Z轴线段
        z_lines = LineSegs()
        z_lines.setThickness(5.0)
        z_lines.moveTo(0, 0, -3)
        z_lines.drawTo(0, 0, 3)
        
        self.z_axis = self.render.attachNewNode(z_lines.create())
        self.z_axis.setColor(0, 0, 1, 1)  # 蓝色
        self.z_axis.setLightOff()
        
        print("测试轴创建完成")
        print("X轴颜色:", self.x_axis.getColor())
        print("Y轴颜色:", self.y_axis.getColor())
        print("Z轴颜色:", self.z_axis.getColor())
    
    def colorChangeTask(self, task):
        """颜色变化任务"""
        self.time += globalClock.getDt()
        
        # 每2秒变换一次颜色
        if int(self.time) % 2 == 0:
            # 原色
            self.x_axis.setColor(1, 0, 0, 1)
            self.y_axis.setColor(0, 1, 0, 1)
            self.z_axis.setColor(0, 0, 1, 1)
        else:
            # 白色
            self.x_axis.setColor(1, 1, 1, 1)
            self.y_axis.setColor(1, 1, 1, 1)
            self.z_axis.setColor(1, 1, 1, 1)
        
        return task.cont

if __name__ == "__main__":
    app = ColorTest()
    app.run() 