V0.5.2 commit
not done
This commit is contained in:
parent
ec6b76197c
commit
515e476657
@ -32,6 +32,7 @@ if __name__ == '__main__':
|
|||||||
print(hi)
|
print(hi)
|
||||||
try:
|
try:
|
||||||
from Difficult_Rocket import main
|
from Difficult_Rocket import main
|
||||||
|
from Difficult_Rocket import crash
|
||||||
|
|
||||||
game = main.Game()
|
game = main.Game()
|
||||||
game.start()
|
game.start()
|
||||||
@ -39,13 +40,11 @@ if __name__ == '__main__':
|
|||||||
print('the game has error , now outputting error message')
|
print('the game has error , now outputting error message')
|
||||||
error = traceback.format_exc()
|
error = traceback.format_exc()
|
||||||
print(error)
|
print(error)
|
||||||
from Difficult_Rocket import crash
|
from Difficult_Rocket.api import thread
|
||||||
|
|
||||||
crash_thread = threading.Thread(target=crash.create_crash_report, args=(error,), name='Crash report thread')
|
crash_thread = thread.Threads(target=crash.create_crash_report, args=(error,), name='Crash report thread')
|
||||||
crash_thread.start()
|
crash_thread.start()
|
||||||
crash_thread.join()
|
crash_thread.join()
|
||||||
print(crash_thread.__str__())
|
|
||||||
else:
|
else:
|
||||||
for thread in threading.enumerate():
|
crash.record_thread = False
|
||||||
if thread == threading.main_thread(): continue
|
print(crash.all_thread)
|
||||||
print(thread.__str__())
|
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# import folders
|
# import folders
|
||||||
|
|
||||||
# import in this folder
|
# import in this folder
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
@ -5,6 +11,8 @@ github: @shenjackyuanjie
|
|||||||
gitee: @shenjackyuanjie
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from .api import *
|
from .api import *
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
@ -6,6 +12,7 @@ gitee: @shenjackyuanjie
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
"""基础 Exception"""
|
"""基础 Exception"""
|
||||||
pass
|
pass
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
@ -5,6 +11,7 @@ github: @shenjackyuanjie
|
|||||||
gitee: @shenjackyuanjie
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from .Exp import TexturesError, LanguageError
|
from .Exp import TexturesError, LanguageError
|
||||||
from .delivery import Delivery
|
from .delivery import Delivery
|
||||||
from .new_thread import new_thread
|
from .new_thread import new_thread
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Delivery:
|
class Delivery:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# bool
|
# bool
|
||||||
|
@ -3,6 +3,7 @@ import inspect
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from typing import Optional, Callable
|
from typing import Optional, Callable
|
||||||
|
from Difficult_Rocket.api import thread
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This part of code come from MCDReforged(https://github.com/Fallen_Breath/MCDReforged)
|
This part of code come from MCDReforged(https://github.com/Fallen_Breath/MCDReforged)
|
||||||
@ -21,9 +22,9 @@ def new_thread(thread_name: Optional[str or Callable] = None):
|
|||||||
def wrapper(func):
|
def wrapper(func):
|
||||||
@functools.wraps(func) # to preserve the origin function information
|
@functools.wraps(func) # to preserve the origin function information
|
||||||
def wrap(*args, **kwargs):
|
def wrap(*args, **kwargs):
|
||||||
thread = threading.Thread(target=func, args=args, kwargs=kwargs, name=thread_name)
|
thread_ = thread.Threads(target=func, args=args, kwargs=kwargs, name=thread_name)
|
||||||
thread.setDaemon(False)
|
thread_.setDaemon(False)
|
||||||
thread.start()
|
thread_.start()
|
||||||
return thread
|
return thread
|
||||||
|
|
||||||
# bring the signature of the func to the wrap function
|
# bring the signature of the func to the wrap function
|
||||||
|
23
Difficult_Rocket/api/thread.py
Normal file
23
Difficult_Rocket/api/thread.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
|
"""
|
||||||
|
writen by shenjackyuanjie
|
||||||
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
|
"""
|
||||||
|
|
||||||
|
import threading
|
||||||
|
|
||||||
|
from Difficult_Rocket import crash
|
||||||
|
|
||||||
|
|
||||||
|
class Threads(threading.Thread):
|
||||||
|
def run(self) -> None:
|
||||||
|
if crash.record_thread:
|
||||||
|
crash.all_thread[self.name] = self
|
||||||
|
super(Threads, self).run()
|
@ -1,9 +1,17 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
github: @shenjackyuanjie
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import decimal
|
import decimal
|
||||||
import logging
|
import logging
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -12,11 +21,10 @@ if __name__ == '__main__': # been start will not run this
|
|||||||
sys.path.append('/bin/libs')
|
sys.path.append('/bin/libs')
|
||||||
sys.path.append('/bin')
|
sys.path.append('/bin')
|
||||||
|
|
||||||
from Difficult_Rocket.libs import pyglet
|
import pyglet
|
||||||
from Difficult_Rocket.libs.pyglet.window import key, mouse
|
from pyglet.window import key, mouse
|
||||||
from Difficult_Rocket.api import Exp, tools, config
|
from Difficult_Rocket.drag_sprite import DragSprite
|
||||||
from drag_sprite import DragSprite
|
from Difficult_Rocket.api import Exp, tools, config, new_thread
|
||||||
from api.new_thread import new_thread
|
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
@ -90,17 +98,16 @@ class ClientWindow(pyglet.window.Window):
|
|||||||
self.label_batch = pyglet.graphics.Batch()
|
self.label_batch = pyglet.graphics.Batch()
|
||||||
# frame
|
# frame
|
||||||
self.frame = pyglet.gui.Frame(self)
|
self.frame = pyglet.gui.Frame(self)
|
||||||
self.logger.info(self.lang['setup.done'])
|
|
||||||
# setup
|
# setup
|
||||||
self.setup()
|
self.setup()
|
||||||
self.info_label = pyglet.text.Label(x=10, y=self.height - 10,
|
self.info_label = pyglet.text.Label(x=10, y=self.height - 10,
|
||||||
anchor_x='left', anchor_y='top',
|
anchor_x='left', anchor_y='top',
|
||||||
batch=self.label_batch)
|
batch=self.label_batch)
|
||||||
self.fps_display = pyglet.window.FPSDisplay(self)
|
|
||||||
pyglet.clock.schedule_interval(self.update, self.SPF)
|
pyglet.clock.schedule_interval(self.update, self.SPF)
|
||||||
self.times.append(time.time())
|
self.times.append(time.time())
|
||||||
self.times.append(self.times[1] - self.times[0])
|
self.times.append(self.times[1] - self.times[0])
|
||||||
self.logger.debug(self.times[2])
|
self.logger.debug(self.times[2])
|
||||||
|
self.logger.info(self.lang['setup.done'])
|
||||||
|
|
||||||
@new_thread('client_load_environment')
|
@new_thread('client_load_environment')
|
||||||
def load_environment(self) -> None:
|
def load_environment(self) -> None:
|
||||||
@ -157,7 +164,6 @@ class ClientWindow(pyglet.window.Window):
|
|||||||
def draw_batch(self):
|
def draw_batch(self):
|
||||||
self.part_batch.draw()
|
self.part_batch.draw()
|
||||||
self.label_batch.draw()
|
self.label_batch.draw()
|
||||||
self.fps_display.draw()
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
keyboard and mouse input
|
keyboard and mouse input
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import decimal
|
import decimal
|
||||||
import logging
|
import logging
|
||||||
# import re
|
# import re
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
@ -5,6 +11,7 @@ github: @shenjackyuanjie
|
|||||||
gitee: @shenjackyuanjie
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
@ -26,22 +33,8 @@ Thread_message = """## Thread info
|
|||||||
System_message = """## System info
|
System_message = """## System info
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
all_thread = {threading.main_thread().name: threading.main_thread()}
|
||||||
def thread_crash_check() -> None:
|
record_thread = True
|
||||||
"""
|
|
||||||
Need to run in a new thread
|
|
||||||
will raise error when any thread raise error
|
|
||||||
maybe will create a crash report
|
|
||||||
"""
|
|
||||||
all_thread = {}
|
|
||||||
thread_local = threading.local()
|
|
||||||
for thread in threading.enumerate():
|
|
||||||
if thread not in all_thread:
|
|
||||||
all_thread[thread.name] = thread
|
|
||||||
for any_thread in all_thread:
|
|
||||||
if not all_thread[any_thread].is_alive():
|
|
||||||
pass
|
|
||||||
# if all_thread[any_thread].exitcode
|
|
||||||
|
|
||||||
|
|
||||||
def crash_info_handler(info: str = None) -> str:
|
def crash_info_handler(info: str = None) -> str:
|
||||||
@ -71,7 +64,7 @@ def create_crash_report(info: str = None) -> None:
|
|||||||
crash_file.write(Head_message) # 开头信息
|
crash_file.write(Head_message) # 开头信息
|
||||||
crash_file.write(crash_info)
|
crash_file.write(crash_info)
|
||||||
crash_file.write(Thread_message)
|
crash_file.write(Thread_message)
|
||||||
for thread in threading.enumerate():
|
for thread in all_thread:
|
||||||
crash_file.write(markdown_line_handler(thread.name, code=True))
|
crash_file.write(markdown_line_handler(thread.name, code=True))
|
||||||
crash_file.write(markdown_line_handler(f'Ident: {thread.ident}', level=2))
|
crash_file.write(markdown_line_handler(f'Ident: {thread.ident}', level=2))
|
||||||
crash_file.write(markdown_line_handler(f'Daemon: {thread.isDaemon()}', level=2))
|
crash_file.write(markdown_line_handler(f'Daemon: {thread.isDaemon()}', level=2))
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -14,7 +23,7 @@ if __name__ == '__main__': # been start will not run this
|
|||||||
sys.path.append('/bin')
|
sys.path.append('/bin')
|
||||||
|
|
||||||
from Difficult_Rocket import client, server
|
from Difficult_Rocket import client, server
|
||||||
from Difficult_Rocket.libs import pyglet
|
from libs import pyglet
|
||||||
from Difficult_Rocket.api import tools
|
from Difficult_Rocket.api import tools
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,17 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
|
# -------------------------------
|
||||||
|
# Difficult Rocket
|
||||||
|
# Copyright © 2021 by shenjackyuanjie
|
||||||
|
# All rights reserved
|
||||||
|
# -------------------------------
|
||||||
|
|
||||||
"""
|
"""
|
||||||
writen by shenjackyuanjie
|
writen by shenjackyuanjie
|
||||||
mail: 3695888@qq.com
|
mail: 3695888@qq.com
|
||||||
|
github: @shenjackyuanjie
|
||||||
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
|
||||||
from bin import tools
|
from Difficult_Rocket.api import tools
|
||||||
except (ModuleNotFoundError, ImportError, ImportWarning):
|
|
||||||
import tools
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import PIL.Image
|
import PIL.Image
|
||||||
|
352
tests/openGL_test.py
Normal file
352
tests/openGL_test.py
Normal file
@ -0,0 +1,352 @@
|
|||||||
|
|
||||||
|
from pyglet.gl import *
|
||||||
|
from pyglet.gl.gl import *
|
||||||
|
from pyglet.gl.glu import *
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
IS_PERSPECTIVE = True # 透视投影
|
||||||
|
|
||||||
|
VIEW = np.array([-0.8, 0.8, -0.8, 0.8, 1.0, 20.0]) # 视景体的left/right/bottom/top/near/far六个面
|
||||||
|
|
||||||
|
SCALE_K = np.array([1.0, 1.0, 1.0]) # 模型缩放比例
|
||||||
|
|
||||||
|
EYE = np.array([0.0, 0.0, 2.0]) # 眼睛的位置(默认z轴的正方向)
|
||||||
|
|
||||||
|
LOOK_AT = np.array([0.0, 0.0, 0.0]) # 瞄准方向的参考点(默认在坐标原点)
|
||||||
|
|
||||||
|
EYE_UP = np.array([0.0, 1.0, 0.0]) # 定义对观察者而言的上方(默认y轴的正方向)
|
||||||
|
|
||||||
|
WIN_W, WIN_H = 640, 480 # 保存窗口宽度和高度的变量
|
||||||
|
|
||||||
|
LEFT_IS_DOWNED = False # 鼠标左键被按下
|
||||||
|
|
||||||
|
MOUSE_X, MOUSE_Y = 0, 0 # 考察鼠标位移量时保存的起始位置
|
||||||
|
|
||||||
|
def getposture():
|
||||||
|
|
||||||
|
global EYE, LOOK_AT
|
||||||
|
|
||||||
|
dist = np.sqrt(np.power((EYE-LOOK_AT), 2).sum())
|
||||||
|
|
||||||
|
if dist > 0:
|
||||||
|
|
||||||
|
phi = np.arcsin((EYE[1]-LOOK_AT[1])/dist)
|
||||||
|
|
||||||
|
theta = np.arcsin((EYE[0]-LOOK_AT[0])/(dist*np.cos(phi)))
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
phi = 0.0
|
||||||
|
|
||||||
|
theta = 0.0
|
||||||
|
|
||||||
|
return dist, phi, theta
|
||||||
|
|
||||||
|
DIST, PHI, THETA = getposture() # 眼睛与观察目标之间的距离、仰角、方位角
|
||||||
|
|
||||||
|
def init():
|
||||||
|
|
||||||
|
glClearColor(0.0, 0.0, 0.0, 1.0) # 设置画布背景色。注意:这里必须是4个参数
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST) # 开启深度测试,实现遮挡关系
|
||||||
|
|
||||||
|
glDepthFunc(GL_LEQUAL) # 设置深度测试函数(GL_LEQUAL只是选项之一)
|
||||||
|
|
||||||
|
def draw():
|
||||||
|
|
||||||
|
global IS_PERSPECTIVE, VIEW
|
||||||
|
|
||||||
|
global EYE, LOOK_AT, EYE_UP
|
||||||
|
|
||||||
|
global SCALE_K
|
||||||
|
|
||||||
|
global WIN_W, WIN_H
|
||||||
|
|
||||||
|
# 清除屏幕及深度缓存
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||||
|
|
||||||
|
# 设置投影(透视投影)
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION)
|
||||||
|
|
||||||
|
glLoadIdentity()
|
||||||
|
|
||||||
|
if WIN_W > WIN_H:
|
||||||
|
|
||||||
|
if IS_PERSPECTIVE:
|
||||||
|
|
||||||
|
glFrustum(VIEW[0]*WIN_W/WIN_H, VIEW[1]*WIN_W/WIN_H, VIEW[2], VIEW[3], VIEW[4], VIEW[5])
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
glOrtho(VIEW[0]*WIN_W/WIN_H, VIEW[1]*WIN_W/WIN_H, VIEW[2], VIEW[3], VIEW[4], VIEW[5])
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
if IS_PERSPECTIVE:
|
||||||
|
|
||||||
|
glFrustum(VIEW[0], VIEW[1], VIEW[2]*WIN_H/WIN_W, VIEW[3]*WIN_H/WIN_W, VIEW[4], VIEW[5])
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
glOrtho(VIEW[0], VIEW[1], VIEW[2]*WIN_H/WIN_W, VIEW[3]*WIN_H/WIN_W, VIEW[4], VIEW[5])
|
||||||
|
|
||||||
|
|
||||||
|
# 设置模型视图
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW)
|
||||||
|
|
||||||
|
glLoadIdentity()
|
||||||
|
|
||||||
|
# 几何变换
|
||||||
|
|
||||||
|
glScaled(SCALE_K[0], SCALE_K[1], SCALE_K[2])
|
||||||
|
|
||||||
|
# 设置视点
|
||||||
|
|
||||||
|
gluLookAt(
|
||||||
|
|
||||||
|
EYE[0], EYE[1], EYE[2],
|
||||||
|
|
||||||
|
LOOK_AT[0], LOOK_AT[1], LOOK_AT[2],
|
||||||
|
|
||||||
|
EYE_UP[0], EYE_UP[1], EYE_UP[2]
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
# 设置视口
|
||||||
|
|
||||||
|
glViewport(0, 0, WIN_W, WIN_H)
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
glBegin(GL_LINES) # 开始绘制线段(世界坐标系)
|
||||||
|
# 以红色绘制x轴
|
||||||
|
|
||||||
|
glColor4f(1.0, 0.0, 0.0, 1.0) # 设置当前颜色为红色不透明
|
||||||
|
|
||||||
|
glVertex3f(-0.8, 0.0, 0.0) # 设置x轴顶点(x轴负方向)
|
||||||
|
|
||||||
|
glVertex3f(0.8, 0.0, 0.0) # 设置x轴顶点(x轴正方向)
|
||||||
|
|
||||||
|
# 以绿色绘制y轴
|
||||||
|
|
||||||
|
glColor4f(0.0, 1.0, 0.0, 1.0) # 设置当前颜色为绿色不透明
|
||||||
|
|
||||||
|
glVertex3f(0.0, -0.8, 0.0) # 设置y轴顶点(y轴负方向)
|
||||||
|
|
||||||
|
glVertex3f(0.0, 0.8, 0.0) # 设置y轴顶点(y轴正方向)
|
||||||
|
|
||||||
|
# 以蓝色绘制z轴
|
||||||
|
|
||||||
|
glColor4f(0.0, 0.0, 1.0, 1.0) # 设置当前颜色为蓝色不透明
|
||||||
|
|
||||||
|
glVertex3f(0.0, 0.0, -0.8) # 设置z轴顶点(z轴负方向)
|
||||||
|
|
||||||
|
glVertex3f(0.0, 0.0, 0.8) # 设置z轴顶点(z轴正方向)
|
||||||
|
|
||||||
|
glEnd() # 结束绘制线段
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
glBegin(GL_TRIANGLES) # 开始绘制三角形(z轴负半区)
|
||||||
|
|
||||||
|
glColor4f(1.0, 0.0, 0.0, 1.0) # 设置当前颜色为红色不透明
|
||||||
|
|
||||||
|
glVertex3f(-0.5, -0.366, -0.5) # 设置三角形顶点
|
||||||
|
|
||||||
|
glColor4f(0.0, 1.0, 0.0, 1.0) # 设置当前颜色为绿色不透明
|
||||||
|
|
||||||
|
glVertex3f(0.5, -0.366, -0.5) # 设置三角形顶点
|
||||||
|
|
||||||
|
glColor4f(0.0, 0.0, 1.0, 1.0) # 设置当前颜色为蓝色不透明
|
||||||
|
|
||||||
|
glVertex3f(0.0, 0.5, -0.5) # 设置三角形顶点
|
||||||
|
|
||||||
|
glEnd() # 结束绘制三角形
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
glBegin(GL_TRIANGLES) # 开始绘制三角形(z轴正半区)
|
||||||
|
glColor4f(1.0, 0.0, 0.0, 1.0) # 设置当前颜色为红色不透明
|
||||||
|
|
||||||
|
glVertex3f(-0.5, 0.5, 0.5) # 设置三角形顶点
|
||||||
|
|
||||||
|
glColor4f(0.0, 1.0, 0.0, 1.0) # 设置当前颜色为绿色不透明
|
||||||
|
|
||||||
|
glVertex3f(0.5, 0.5, 0.5) # 设置三角形顶点
|
||||||
|
|
||||||
|
glColor4f(0.0, 0.0, 1.0, 1.0) # 设置当前颜色为蓝色不透明
|
||||||
|
|
||||||
|
glVertex3f(0.0, -0.366, 0.5) # 设置三角形顶点
|
||||||
|
|
||||||
|
glEnd() # 结束绘制三角形
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------
|
||||||
|
|
||||||
|
# glutSwapBuffers() # 切换缓冲区,以显示绘制内容
|
||||||
|
|
||||||
|
def reshape(width, height):
|
||||||
|
|
||||||
|
global WIN_W, WIN_H
|
||||||
|
|
||||||
|
WIN_W, WIN_H = width, height
|
||||||
|
|
||||||
|
glutPostRedisplay()
|
||||||
|
|
||||||
|
def mouseclick(button, state, x, y):
|
||||||
|
|
||||||
|
global SCALE_K
|
||||||
|
|
||||||
|
global LEFT_IS_DOWNED
|
||||||
|
|
||||||
|
global MOUSE_X, MOUSE_Y
|
||||||
|
|
||||||
|
MOUSE_X, MOUSE_Y = x, y
|
||||||
|
|
||||||
|
if button == GLUT_LEFT_BUTTON:
|
||||||
|
|
||||||
|
LEFT_IS_DOWNED = state==GLUT_DOWN
|
||||||
|
|
||||||
|
elif button == 3:
|
||||||
|
|
||||||
|
SCALE_K *= 1.05
|
||||||
|
|
||||||
|
glutPostRedisplay()
|
||||||
|
|
||||||
|
elif button == 4:
|
||||||
|
|
||||||
|
SCALE_K *= 0.95
|
||||||
|
|
||||||
|
glutPostRedisplay()
|
||||||
|
|
||||||
|
def mousemotion(x, y):
|
||||||
|
|
||||||
|
global LEFT_IS_DOWNED
|
||||||
|
|
||||||
|
global EYE, EYE_UP
|
||||||
|
|
||||||
|
global MOUSE_X, MOUSE_Y
|
||||||
|
|
||||||
|
global DIST, PHI, THETA
|
||||||
|
|
||||||
|
global WIN_W, WIN_H
|
||||||
|
|
||||||
|
if LEFT_IS_DOWNED:
|
||||||
|
|
||||||
|
dx = MOUSE_X - x
|
||||||
|
|
||||||
|
dy = y - MOUSE_Y
|
||||||
|
|
||||||
|
MOUSE_X, MOUSE_Y = x, y
|
||||||
|
|
||||||
|
PHI += 2*np.pi*dy/WIN_H
|
||||||
|
|
||||||
|
PHI %= 2*np.pi
|
||||||
|
|
||||||
|
THETA += 2*np.pi*dx/WIN_W
|
||||||
|
|
||||||
|
THETA %= 2*np.pi
|
||||||
|
|
||||||
|
r = DIST*np.cos(PHI)
|
||||||
|
|
||||||
|
EYE[1] = DIST*np.sin(PHI)
|
||||||
|
|
||||||
|
EYE[0] = r*np.sin(THETA)
|
||||||
|
|
||||||
|
EYE[2] = r*np.cos(THETA)
|
||||||
|
|
||||||
|
if 0.5*np.pi < PHI < 1.5*np.pi:
|
||||||
|
|
||||||
|
EYE_UP[1] = -1.0
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
EYE_UP[1] = 1.0
|
||||||
|
|
||||||
|
glutPostRedisplay()
|
||||||
|
|
||||||
|
def keydown(key, x, y):
|
||||||
|
|
||||||
|
global DIST, PHI, THETA
|
||||||
|
|
||||||
|
global EYE, LOOK_AT, EYE_UP
|
||||||
|
|
||||||
|
global IS_PERSPECTIVE, VIEW
|
||||||
|
|
||||||
|
if key in [b'x', b'X', b'y', b'Y', b'z', b'Z']:
|
||||||
|
|
||||||
|
if key == b'x': # 瞄准参考点 x 减小
|
||||||
|
|
||||||
|
LOOK_AT[0] -= 0.01
|
||||||
|
|
||||||
|
elif key == b'X': # 瞄准参考 x 增大
|
||||||
|
|
||||||
|
LOOK_AT[0] += 0.01
|
||||||
|
|
||||||
|
elif key == b'y': # 瞄准参考点 y 减小
|
||||||
|
|
||||||
|
LOOK_AT[1] -= 0.01
|
||||||
|
|
||||||
|
elif key == b'Y': # 瞄准参考点 y 增大
|
||||||
|
|
||||||
|
LOOK_AT[1] += 0.01
|
||||||
|
|
||||||
|
elif key == b'z': # 瞄准参考点 z 减小
|
||||||
|
|
||||||
|
LOOK_AT[2] -= 0.01
|
||||||
|
|
||||||
|
elif key == b'Z': # 瞄准参考点 z 增大
|
||||||
|
|
||||||
|
LOOK_AT[2] += 0.01
|
||||||
|
|
||||||
|
DIST, PHI, THETA = getposture()
|
||||||
|
|
||||||
|
glutPostRedisplay()
|
||||||
|
|
||||||
|
elif key == b'\r': # 回车键,视点前进
|
||||||
|
|
||||||
|
EYE = LOOK_AT + (EYE - LOOK_AT) * 0.9
|
||||||
|
|
||||||
|
DIST, PHI, THETA = getposture()
|
||||||
|
|
||||||
|
glutPostRedisplay()
|
||||||
|
|
||||||
|
elif key == b'\x08': # 退格键,视点后退
|
||||||
|
|
||||||
|
EYE = LOOK_AT + (EYE - LOOK_AT) * 1.1
|
||||||
|
|
||||||
|
DIST, PHI, THETA = getposture()
|
||||||
|
|
||||||
|
glutPostRedisplay()
|
||||||
|
|
||||||
|
elif key == b' ': # 空格键,切换投影模式
|
||||||
|
|
||||||
|
IS_PERSPECTIVE = not IS_PERSPECTIVE
|
||||||
|
|
||||||
|
glutPostRedisplay()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
glutInit()
|
||||||
|
|
||||||
|
displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH
|
||||||
|
|
||||||
|
glutInitDisplayMode(displayMode)
|
||||||
|
|
||||||
|
glutInitWindowSize(WIN_W, WIN_H)
|
||||||
|
|
||||||
|
glutInitWindowPosition(300, 200)
|
||||||
|
|
||||||
|
glutCreateWindow('Quidam Of OpenGL')
|
||||||
|
|
||||||
|
init() # 初始化画布
|
||||||
|
|
||||||
|
glutDisplayFunc(draw) # 注册回调函数draw()
|
||||||
|
|
||||||
|
glutReshapeFunc(reshape) # 注册响应窗口改变的函数reshape()
|
||||||
|
|
||||||
|
glutMouseFunc(mouseclick) # 注册响应鼠标点击的函数mouseclick()
|
||||||
|
|
||||||
|
glutMotionFunc(mousemotion) # 注册响应鼠标拖拽的函数mousemotion()
|
||||||
|
|
||||||
|
glutKeyboardFunc(keydown) # 注册键盘输入的函数keydown()
|
||||||
|
|
||||||
|
glutMainLoop() # 进入glut主循环
|
@ -1,5 +0,0 @@
|
|||||||
import re
|
|
||||||
|
|
||||||
ipv4 = re.compile('[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}')
|
|
||||||
|
|
||||||
print(re.match(ipv4, '1.2.3.2'))
|
|
70
tests/奇怪的东西.py
Normal file
70
tests/奇怪的东西.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
from math import sin, cos, sqrt
|
||||||
|
import pyglet
|
||||||
|
from pyglet.gl import *
|
||||||
|
|
||||||
|
|
||||||
|
def vec(*args):
|
||||||
|
return (GLfloat * len(args))(*args)
|
||||||
|
|
||||||
|
|
||||||
|
class GameEventHandler(object): # 这里用GameEventHandler把事件包装了一下
|
||||||
|
rx, ry = 0, 0
|
||||||
|
track = []
|
||||||
|
|
||||||
|
def on_draw(self):
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||||
|
|
||||||
|
# glLoadIdentity()
|
||||||
|
position = (sin(integral_drift[0] / 2) / sqrt(integral_drift[0]),
|
||||||
|
cos(integral_drift[1] / 2) / sqrt(integral_drift[1]))
|
||||||
|
self.track.append(position)
|
||||||
|
|
||||||
|
|
||||||
|
glColor3f(1, 1, 1)
|
||||||
|
glBegin(GL_LINE_STRIP)
|
||||||
|
for v in self.track:
|
||||||
|
glVertex3f(v[0], v[1], 0)
|
||||||
|
glEnd()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def on_resize(width, height):
|
||||||
|
return pyglet.event.EVENT_HANDLED
|
||||||
|
|
||||||
|
|
||||||
|
def scene_init():
|
||||||
|
# One-time GL setup
|
||||||
|
glClearColor(0, 0, 0, 1)
|
||||||
|
glEnable(GL_DEPTH_TEST)
|
||||||
|
glEnable(GL_CULL_FACE)
|
||||||
|
glEnable(GL_BLEND) # 启用混合功能,将图形颜色同周围颜色相混合
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||||
|
|
||||||
|
glEnable(GL_POLYGON_SMOOTH) # 多边形抗锯齿
|
||||||
|
# glHint(GL_POLYGON_SMOOTH, GL_NICEST)
|
||||||
|
|
||||||
|
glEnable(GL_LINE_SMOOTH) # 线抗锯齿
|
||||||
|
# glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
|
||||||
|
|
||||||
|
glEnable(GL_POINT_SMOOTH) # 点抗锯齿
|
||||||
|
# glHint(GL_POINT_SMOOTH, GL_NICEST)
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def update(dt):
|
||||||
|
delta_x = 5 * dt
|
||||||
|
delta_y = 5 * dt
|
||||||
|
delta_z = 5 * dt
|
||||||
|
integral_drift[0] += delta_x
|
||||||
|
integral_drift[1] += delta_y
|
||||||
|
integral_drift[2] += delta_z
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
window = pyglet.window.Window(resizable=True)
|
||||||
|
scene_init()
|
||||||
|
integral_drift = [0.1, 0.1, 0.1] # 位移的总和
|
||||||
|
game_event = GameEventHandler()
|
||||||
|
window.push_handlers(game_event.on_draw)
|
||||||
|
pyglet.app.event_loop.clock.schedule(update) # 单位时间触发update
|
||||||
|
pyglet.app.run()
|
Loading…
Reference in New Issue
Block a user