69 lines
2.0 KiB
Plaintext
69 lines
2.0 KiB
Plaintext
import vpsdk.window as window
|
|
import vpsdk.process as process
|
|
import vpsdk.vpui as vpui
|
|
import string
|
|
from stdint import *
|
|
import gfx
|
|
|
|
define SCENE_W = 640
|
|
define SCENE_H = 360
|
|
|
|
_zbuf_mem: [SCENE_W * SCENE_H * 8]uint8 = []
|
|
_fb_mem: [SCENE_W * SCENE_H]uint32 = []
|
|
|
|
_root_ptr: vpui.Tk*
|
|
_canvas_ptr: vpui.FBCanvas*
|
|
_s3d_ptr: gfx.Scene3D*
|
|
_time_val: float = float(0.0)
|
|
# 时间回绕周期 = 4π:Render 里 time*1 / time*2 / time*1.5 的 sin/cos 参数整体平移 2π 的整数倍
|
|
# ⇒ 动画严格连续;同时让相位半径永远很小,避免 float32 精度随运行时间退化
|
|
# (x 变大后相邻采样点的相位差被量化 ⇒ 曲线塌成一条平线、热力图颜色失去层次)。
|
|
define TIME_WRAP = float(12.566370614359172)
|
|
|
|
def _render_thread(arg: t.CPtr):
|
|
global _time_val
|
|
root: vpui.Tk* = _root_ptr
|
|
canvas: vpui.FBCanvas* = _canvas_ptr
|
|
s3d: gfx.Scene3D* = _s3d_ptr
|
|
while root.winfo_exists():
|
|
s3d.Render(_time_val)
|
|
_time_val += float(0.02)
|
|
if _time_val >= TIME_WRAP: _time_val = _time_val - TIME_WRAP
|
|
root.update()
|
|
process.yield_cpu()
|
|
|
|
@__attribute__(section(".text.startup"), aligned(16))
|
|
export def _start() -> int:
|
|
root: vpui.Tk = vpui.Tk()
|
|
root.title("3D Scene")
|
|
root.set_style(window.STYLE_WIN11)
|
|
root.bg_color = uint32(0x0F0F19)
|
|
master: vpui.Tk* = &root
|
|
|
|
canvas: vpui.FBCanvas = vpui.FBCanvas(master, SCENE_W, SCENE_H)
|
|
root.pack(0, vpui.PACK_TOP, vpui.FILL_BOTH, 1, 0, 0)
|
|
|
|
zbuf: float* = &_zbuf_mem
|
|
string.memset(zbuf, 0, SCENE_W * SCENE_H * 8)
|
|
|
|
fb: UINT32PTR = &_fb_mem
|
|
string.memset(fb, 0, SCENE_W * SCENE_H * 4)
|
|
canvas.set_fb(fb, SCENE_W, SCENE_H)
|
|
|
|
s3d: gfx.Scene3D = gfx.Scene3D(fb, zbuf, SCENE_W, SCENE_H)
|
|
|
|
root.geometry(100, 30, SCENE_W, SCENE_H + 32)
|
|
|
|
global _root_ptr, _canvas_ptr, _s3d_ptr
|
|
|
|
_root_ptr = &root
|
|
_canvas_ptr = &canvas
|
|
_s3d_ptr = &s3d
|
|
|
|
process.thread_create(_render_thread, None)
|
|
|
|
root.mainloop()
|
|
|
|
process.exit(0)
|
|
return 0
|