提交 58a6255b 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 91524f90
......@@ -43,8 +43,56 @@ class WaterDrop(Obj):
}
super().__init__(**params)
from ursina.prefabs.primitives import Shader
matcap_shader = Shader(name='matcap_shader', language=Shader.GLSL, vertex = '''#version 140
uniform mat4 p3d_ModelViewProjectionMatrix;
uniform mat4 p3d_ModelMatrix;
uniform mat4 p3d_ModelViewMatrix;
uniform mat3 p3d_NormalMatrix;
in vec4 p3d_Vertex;
in vec3 p3d_Normal;
out vec3 eye;
out vec3 view_normal;
// reflect alternative:
// r = e - 2. * dot( n, e ) * n;
void main() {
gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
eye = normalize(vec3(p3d_ModelViewMatrix * vec4(p3d_Vertex.xyz, 1.0)));
view_normal = normalize( p3d_NormalMatrix * p3d_Normal );
}
''',
fragment='''
#version 130
uniform sampler2D p3d_Texture0;
uniform vec4 p3d_ColorScale;
in vec3 eye;
in vec3 view_normal;
out vec4 fragColor;
void main() {
vec3 r = reflect( eye, view_normal );
float m = 2. * sqrt( pow( r.x, 2. ) + pow( r.y, 2. ) + pow( r.z + 1., 2. ) );
vec2 vN = r.xy / m + .5;
vec3 base = texture2D( p3d_Texture0, vN ).rgb;
// vec3 base = texture2D( p3d_Texture0, uv ).rgb;
fragColor = vec4( base, 1. ) * p3d_ColorScale;
}
''',
)
if __name__ == '__main__':
shader = matcap_shader
water_drop = WaterDrop(
# texture="drops_normal.png"
# texture="drops_uvw.png"
......@@ -56,6 +104,7 @@ if __name__ == '__main__':
def on_ready():
water_drop.planet.rotation_x = 90
water_drop.planet.shader = shader,
water_drop.show_demo(size_scale=1000000, on_ready_fun=on_ready)
......@@ -250,6 +250,8 @@ if __name__ == '__main__':
# print(time_data.get_datetime(str(current_time)))
ControlUI.current_ui.show_message(dt.strftime('%Y-%m-%d %H:%M:%S'),
position=(0.60, -0.465),
origin=(-0.5, 0.5),
font="verdana.ttf",
close_time=-1)
......@@ -267,4 +269,5 @@ if __name__ == '__main__':
position=(0, 0.2 * AU, -3 * AU),
gravity_works=False, # 关闭万有引力的计算
show_grid=False,
show_camera_info=False,
timer_enabled=True)
......@@ -16,6 +16,7 @@ from simulators.ursina.entities.body_timer import TimeData
from simulators.ursina.entities.entity_utils import create_directional_light
from simulators.ursina.ursina_config import UrsinaConfig
from simulators.ursina.ursina_event import UrsinaEvent
from ursina import camera
if __name__ == '__main__':
"""
......@@ -45,7 +46,9 @@ if __name__ == '__main__':
texture="drops_bright.png",
# trail_color=[200, 200, 255],
init_velocity=[-WATER_SPEED, 0, 0],
size_scale=4e4).set_ignore_gravity(True).set_light_disable(True)
# size_scale=4e4,
size_scale=1e3
).set_ignore_gravity(True).set_light_disable(True)
# moon = Moon(init_position=[0, 0, 363104], # 距地距离约: 363104 至 405696 km
# init_velocity=[-1.03, 0, 0], size_scale=2e1) # 月球放大 10 倍,距离保持不变
# moon.set_light_disable(True)
......@@ -88,15 +91,18 @@ if __name__ == '__main__':
def on_timer_changed(time_data: TimeData):
if time_data.total_days > 27.5:
exit(0)
if water_drop.position[0] < -WATER_RANGE:
water_drop.planet.rotation_z = -90
water_drop.velocity = [WATER_SPEED, 0, 0]
elif water_drop.position[0] > WATER_RANGE:
water_drop.planet.rotation_z = 90
water_drop.velocity = [-WATER_SPEED, 0, 0]
# camera_look_at(water_drop, rotation_z=0)
if time_data.total_days > 0.2:
if water_drop.position[0] < -WATER_RANGE:
water_drop.planet.rotation_z = -90
water_drop.velocity = [WATER_SPEED, 0, 0]
elif water_drop.position[0] > WATER_RANGE:
water_drop.planet.rotation_z = 90
water_drop.velocity = [-WATER_SPEED, 0, 0]
else:
water_drop.acceleration = [-9.8e-4, 0, 0]
camera_look_at(water_drop, rotation_z=0)
# camera.y += UrsinaConfig.SCALE_FACTOR * 100
def on_ready():
......@@ -110,8 +116,8 @@ if __name__ == '__main__':
water_drop.planet.rotation_z = 90
# water_drop.init_position = (0, 0, 0)
# water_drop.init_velocity = [0, 0, 0]
water_drop.init_position = (0, 0, 0)
water_drop.init_velocity = [0, 0, 0]
# 订阅事件后,上面2个函数功能才会起作用
......@@ -127,11 +133,13 @@ if __name__ == '__main__':
SECONDS_PER_DAY / 24,
# SECONDS_PER_WEEK * 4,
# position=(0, 0, -220000),
position=(0, 0, 0),
position=(0, 0, -20000),
# position=(0, 0, 0),
show_grid=False,
# cosmic_bg="",
# gravity_works=False,
# save_cube_map=True,
show_timer=True,
timer_enabled=True,
show_camera_info=False,
show_control_info=False,
......
......@@ -63,7 +63,7 @@ class UiPanel(WindowPanel):
"""
pass
def show_message(self, message, font=None, close_time=3):
def show_message(self, message, font=None, origin=(0, 0), position=(0, .25), close_time=3):
"""
显示消息框
@param message: 消息内容
......@@ -78,7 +78,7 @@ class UiPanel(WindowPanel):
# else:
# font = None
# 创建消息框
message_box = Text(text=message, font=font, background=True, origin=(0, 0), y=.25)
message_box = Text(text=message, font=font, background=True, origin=origin, position=position)
self.last_message_box = message_box
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册