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

Python超人-宇宙模拟器

上级 0d1da2e1
...@@ -45,7 +45,7 @@ class Rock(Obj): ...@@ -45,7 +45,7 @@ class Rock(Obj):
# 对岩石进行缩放,保证 create_rock 保证创建的岩石大小差异不会过大 # 对岩石进行缩放,保证 create_rock 保证创建的岩石大小差异不会过大
ROCK_SIZE_SCALE_FACTOR = { ROCK_SIZE_SCALE_FACTOR = {
6: 1e-2, 6: 0.5,
7: 1e-2 7: 1e-2
} }
......
...@@ -24,3 +24,6 @@ ...@@ -24,3 +24,6 @@
### 三体的场景模拟 ### 三体的场景模拟
**sim_scenes/tri_bodies** **sim_scenes/tri_bodies**
### 天文奇观模拟
**sim_scenes/wonders**
...@@ -10,6 +10,7 @@ from bodies import Sun, Earth, Moon ...@@ -10,6 +10,7 @@ from bodies import Sun, Earth, Moon
from common.consts import SECONDS_PER_HOUR, SECONDS_PER_HALF_DAY, SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH from common.consts import SECONDS_PER_HOUR, SECONDS_PER_HALF_DAY, SECONDS_PER_DAY, SECONDS_PER_WEEK, SECONDS_PER_MONTH
from sim_scenes.func import ursina_run, camera_look_at from sim_scenes.func import ursina_run, camera_look_at
from bodies.body import AU from bodies.body import AU
from simulators.ursina.entities.entity_utils import create_directional_light
from simulators.ursina.ursina_event import UrsinaEvent from simulators.ursina.ursina_event import UrsinaEvent
if __name__ == '__main__': if __name__ == '__main__':
...@@ -28,9 +29,16 @@ if __name__ == '__main__': ...@@ -28,9 +29,16 @@ if __name__ == '__main__':
def on_ready(): def on_ready():
# 运行前触发
# 运行开始前,将摄像机指向地球 # 运行开始前,将摄像机指向地球
earth = bodies[0] earth = bodies[0]
moon = bodies[1]
# 摄像机看向地球
camera_look_at(earth) camera_look_at(earth)
# 创建太阳光
shadows_shader = create_directional_light(position=(200, 0, -300), target=earth,shadows=True)
earth.planet.shadows = shadows_shader
moon.planet.shadows = shadows_shader
UrsinaEvent.on_ready_subscription(on_ready) UrsinaEvent.on_ready_subscription(on_ready)
...@@ -38,7 +46,7 @@ if __name__ == '__main__': ...@@ -38,7 +46,7 @@ if __name__ == '__main__':
# 使用 ursina 查看的运行效果 # 使用 ursina 查看的运行效果
# 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹
# position = 左-右+、上+下-、前+后- # position = 左-右+、上+下-、前+后-
ursina_run(bodies, SECONDS_PER_MONTH, ursina_run(bodies, SECONDS_PER_DAY,
position=(-300000, 1500000, -1000), position=(-300000, 1500000, -1000),
show_timer=True, show_timer=True,
show_trail=True) show_trail=True)
...@@ -57,7 +57,7 @@ if __name__ == '__main__': ...@@ -57,7 +57,7 @@ if __name__ == '__main__':
comets = [] comets = []
r = jupiter.raduis r = jupiter.raduis
for i in range(30): for i in range(20):
# 随机生成石头 # 随机生成石头
comet = create_comet(i, gravity_only_for=jupiter) comet = create_comet(i, gravity_only_for=jupiter)
bodies.append(comet) bodies.append(comet)
......
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
# title :水星、金星凌日 # title :水星、金星凌日
# description :水星、金星凌日 # description :天象奇观:水星、金星凌日
# author :Python超人 # author :Python超人
# date :2023-02-11 # date :2023-02-11
# link :https://gitcode.net/pythoncr/ # link :https://gitcode.net/pythoncr/
......
...@@ -176,6 +176,10 @@ def create_directional_light(position, target=None, shadows=False, light_color=N ...@@ -176,6 +176,10 @@ def create_directional_light(position, target=None, shadows=False, light_color=N
else: else:
light_color = color.rgba(light_color[0] / 255, light_color[1] / 255, light_color[2] / 255, 1) light_color = color.rgba(light_color[0] / 255, light_color[1] / 255, light_color[2] / 255, 1)
light = DirectionalLight(position=position, intensity=10, range=10, color=light_color) light = DirectionalLight(position=position, intensity=10, range=10, color=light_color)
if shadows:
light.shadows = lit_with_shadows_shader
if target is not None: if target is not None:
if hasattr(target, "planet"): if hasattr(target, "planet"):
if hasattr(target.planet, "main_entity"): if hasattr(target.planet, "main_entity"):
...@@ -185,6 +189,11 @@ def create_directional_light(position, target=None, shadows=False, light_color=N ...@@ -185,6 +189,11 @@ def create_directional_light(position, target=None, shadows=False, light_color=N
else: else:
light.look_at(target) light.look_at(target)
if shadows:
return lit_with_shadows_shader
else:
return None
def create_trail_line(parent, pos): def create_trail_line(parent, pos):
""" """
......
...@@ -101,6 +101,7 @@ class UrsinaSimulator(Simulator): ...@@ -101,6 +101,7 @@ class UrsinaSimulator(Simulator):
volume_scale = pow(body.planet.model.get_bounds().volume, 1 / 3) volume_scale = pow(body.planet.model.get_bounds().volume, 1 / 3)
# 根据体积、大小缩放判断爆炸的量 # 根据体积、大小缩放判断爆炸的量
scale = 3 * volume_scale * body.size_scale * UrsinaConfig.SCALE_FACTOR scale = 3 * volume_scale * body.size_scale * UrsinaConfig.SCALE_FACTOR
print(scale, body)
explode_ani = Animation(explosion_file, explode_ani = Animation(explosion_file,
position=body.planet.position, position=body.planet.position,
scale=scale, fps=6, scale=scale, fps=6,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册