mirror of
https://forge.apps.education.fr/blender-edutech/ropy.git
synced 2024-01-27 08:23:20 +01:00
Gestion de la caméra (limite de zoom et mémorisation de la position)
This commit is contained in:
parent
bfcd674677
commit
d8efdad277
BIN
ropy-07.blend
BIN
ropy-07.blend
Binary file not shown.
171
rp.py
171
rp.py
@ -120,6 +120,26 @@ def terrain_init ():
|
||||
scene.objects['Sun'].setVisible(True,True)
|
||||
scene.addOverlayCollection(scene.cameras['Camera-Hud'], bpy.data.collections['Hud'])
|
||||
|
||||
# Mémorisation des positions par défaut
|
||||
# <worldPosition.x>0.0057830810546875</worldPosition.x>
|
||||
# <worldPosition.y>-26.440298080444336</worldPosition.y>
|
||||
# <worldPosition.z>20.22315788269043</worldPosition.z>
|
||||
scene.objects['Camera']['init_lx']=0.0057830810546875
|
||||
scene.objects['Camera']['init_ly']=-26.440298080444336
|
||||
scene.objects['Camera']['init_lz']=20.22315788269043
|
||||
# scene.objects['Camera']['init_lx']=scene.objects['Camera'].worldPosition.x
|
||||
# scene.objects['Camera']['init_ly']=scene.objects['Camera'].worldPosition.y
|
||||
# scene.objects['Camera']['init_lz']=scene.objects['Camera'].worldPosition.z
|
||||
scene.objects['Camera']['past_lx']=scene.objects['Camera'].worldPosition.x
|
||||
scene.objects['Camera']['past_ly']=scene.objects['Camera'].worldPosition.y
|
||||
scene.objects['Camera']['past_lz']=scene.objects['Camera'].worldPosition.z
|
||||
scene.objects['Terrain']['init_lx']=scene.objects['Terrain'].worldPosition.x
|
||||
scene.objects['Terrain']['init_ly']=scene.objects['Terrain'].worldPosition.y
|
||||
scene.objects['Terrain']['init_lz']=scene.objects['Terrain'].worldPosition.z
|
||||
scene.objects['Terrain']['init_rx']=scene.objects['Terrain'].worldOrientation.to_euler().x
|
||||
scene.objects['Terrain']['init_ry']=scene.objects['Terrain'].worldOrientation.to_euler().y
|
||||
scene.objects['Terrain']['init_rz']=scene.objects['Terrain'].worldOrientation.to_euler().z
|
||||
|
||||
# Configuration du moteur de rendu
|
||||
eevee.use_eevee_smaa = True
|
||||
|
||||
@ -127,6 +147,11 @@ def terrain_init ():
|
||||
rp_map.map_init()
|
||||
rp_map.map_reset()
|
||||
|
||||
# Récupération de la position de la caméra
|
||||
scene.objects['Camera'].worldPosition.x = float(rp_config_tree[0][2][0].text)
|
||||
scene.objects['Camera'].worldPosition.y = float(rp_config_tree[0][2][1].text)
|
||||
scene.objects['Camera'].worldPosition.z = float(rp_config_tree[0][2][2].text)
|
||||
|
||||
##
|
||||
# Mise en route et pause du cycle
|
||||
##
|
||||
@ -231,7 +256,7 @@ def terrain_speed (obj):
|
||||
scene.objects['Commands']['speed']=speed_mode[i-1]
|
||||
scene.objects['Text_speed']['Text']=speed_mode_txt[i-1]
|
||||
|
||||
# Maj du fichier de config (vitesse du jeu : data/config/speed)
|
||||
# Maj du fichier de config (vitesse du jeu : data/config/speed -> [0][0].text)
|
||||
rp_config_tree[0][0].text=str(scene.objects['Commands']['speed'])
|
||||
buffer_xml = ET.tostring(rp_config_tree)
|
||||
with open("rp_config.xml", "wb") as f:
|
||||
@ -376,10 +401,10 @@ def cmd_init():
|
||||
rp_doc.init()
|
||||
|
||||
# Missions
|
||||
# Read config (mission actuelle : data/config/mission_current -> [0][2].text)
|
||||
# Read config (niveau atteint : data/config/mission_success -> [0][3].text)
|
||||
scene.objects['Terrain']['mission_current']=int(rp_config_tree[0][2].text)
|
||||
scene.objects['Terrain']['mission_success']=int(rp_config_tree[0][3].text)
|
||||
# Read config (mission actuelle : data/config/mission_current -> [1][0].text)
|
||||
# Read config (niveau atteint : data/config/mission_success -> [1][1].text)
|
||||
scene.objects['Terrain']['mission_current']=int(rp_config_tree[1][0].text)
|
||||
scene.objects['Terrain']['mission_success']=int(rp_config_tree[1][1].text)
|
||||
scene.objects['Points-Map-text']['Text']="Mission "+str(scene.objects['Terrain']['mission_current'])
|
||||
|
||||
##
|
||||
@ -531,8 +556,17 @@ def mode(cont):
|
||||
if scene.objects['About'].visible:
|
||||
about_close()
|
||||
return
|
||||
else: # Sortir du jeux
|
||||
else: # Sortir du jeu
|
||||
terrain_stop ()
|
||||
|
||||
# Maj du fichier de config (position de la camera : data/config/cam_x,y,z -> [0][2][0].text, [0][2][1].text, [0][2][2].text)
|
||||
rp_config_tree[0][2][0].text=str(scene.objects['Camera'].worldPosition.x)
|
||||
rp_config_tree[0][2][1].text=str(scene.objects['Camera'].worldPosition.y)
|
||||
rp_config_tree[0][2][2].text=str(scene.objects['Camera'].worldPosition.z)
|
||||
# print ("Fin :", scene.objects['Camera'].worldPosition.x, scene.objects['Camera'].worldPosition.y, scene.objects['Camera'].worldPosition.z)
|
||||
buffer_xml = ET.tostring(rp_config_tree)
|
||||
with open("rp_config.xml", "wb") as f:
|
||||
f.write(buffer_xml)
|
||||
bge.logic.endGame()
|
||||
|
||||
# Fenêtre modale (inhibition des touches hors ESC)
|
||||
@ -564,13 +598,12 @@ def mode(cont):
|
||||
# Touche Home -> Reset de la vue
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.HOMEKEY].queue:
|
||||
manip_reset()
|
||||
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
bge.render.setMousePosition(int(bge.render.getWindowWidth() / 2), int(bge.render.getWindowHeight() / 2))
|
||||
scene.objects['Mouse_main'].worldPosition = [0.07, -8.11, 4.71035] # Vielle version : [0.118161, -8.24305, 4.71035] ; [0, -3.5, 2], [0, -8, 6]
|
||||
scene.objects['Mouse_main'].worldScale=[30, 30, 30]
|
||||
scene.objects['Mouse_main']['past_x']=0
|
||||
scene.objects['Mouse_main']['past_y']=0
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# bge.render.setMousePosition(int(bge.render.getWindowWidth() / 2), int(bge.render.getWindowHeight() / 2))
|
||||
# scene.objects['Mouse_main'].worldPosition = [0.07, -8.11, 4.71035] # Vielle version : [0.118161, -8.24305, 4.71035] ; [0, -3.5, 2], [0, -8, 6]
|
||||
# scene.objects['Mouse_main'].worldScale=[30, 30, 30]
|
||||
# scene.objects['Mouse_main']['past_x']=0
|
||||
# scene.objects['Mouse_main']['past_y']=0
|
||||
|
||||
# Touche F5 -> Run et Pause
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.F5KEY].queue:
|
||||
@ -591,24 +624,6 @@ def mode(cont):
|
||||
# Manipulation 3D de la scène
|
||||
###############################################################################
|
||||
|
||||
##
|
||||
# Mémorisation de la position et orientation initiales du modèle 3D et de la caméra
|
||||
##
|
||||
|
||||
def manip_init(cont):
|
||||
scene.objects['Camera']['init_lx']=scene.objects['Camera'].worldPosition.x
|
||||
scene.objects['Camera']['init_ly']=scene.objects['Camera'].worldPosition.y
|
||||
scene.objects['Camera']['init_lz']=scene.objects['Camera'].worldPosition.z
|
||||
scene.objects['Camera']['past_lx']=scene.objects['Camera'].worldPosition.x
|
||||
scene.objects['Camera']['past_ly']=scene.objects['Camera'].worldPosition.y
|
||||
scene.objects['Camera']['past_lz']=scene.objects['Camera'].worldPosition.z
|
||||
scene.objects['Terrain']['init_lx']=scene.objects['Terrain'].worldPosition.x
|
||||
scene.objects['Terrain']['init_ly']=scene.objects['Terrain'].worldPosition.y
|
||||
scene.objects['Terrain']['init_lz']=scene.objects['Terrain'].worldPosition.z
|
||||
scene.objects['Terrain']['init_rx']=scene.objects['Terrain'].worldOrientation.to_euler().x
|
||||
scene.objects['Terrain']['init_ry']=scene.objects['Terrain'].worldOrientation.to_euler().y
|
||||
scene.objects['Terrain']['init_rz']=scene.objects['Terrain'].worldOrientation.to_euler().z
|
||||
|
||||
##
|
||||
# Atteindre une orientation (bas niveau)
|
||||
##
|
||||
@ -690,25 +705,29 @@ def manip(cont):
|
||||
# scene.objects['Commands-colbox'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
|
||||
# scene.objects['Commands-colbox'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan*math.cos(50*2*math.pi*(1/360)), delta_y*sensibilite_pan*math.sin(50*2*math.pi*(1/360))), True)
|
||||
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
scene.objects['Mouse_main'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# scene.objects['Mouse_main'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
|
||||
|
||||
# Zoom FIXME : marche pas au niveau de la souris
|
||||
if obj['manip_mode']==2: # Ctrl
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
position_scale_x = 0.0005
|
||||
position_scale_y = position_scale_x
|
||||
mouse_x=scene.objects['Mouse_main'].sensors["Mouse"].position[0]-int(bge.render.getWindowWidth() / 2)
|
||||
mouse_y=scene.objects['Mouse_main'].sensors["Mouse"].position[1]-int(bge.render.getWindowHeight() / 2)
|
||||
distance_cam_past= math.sqrt(scene.objects['Camera']['past_ly']**2+scene.objects['Camera']['past_lz']**2)
|
||||
distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
size_scale = (distance_cam/distance_cam_past) * 0.23
|
||||
scene.objects['Camera'].applyMovement((0, 0, (delta_x+delta_y)*sensibilite_zoom), True)
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
scene.objects['Mouse_main'].applyMovement((mouse_x*(delta_x+delta_y)*sensibilite_zoom*position_scale_x, -mouse_y*(delta_x+delta_y)*sensibilite_zoom*position_scale_y, 0), True)
|
||||
scene.objects['Mouse_main'].worldScale *= (delta_x+delta_y)*sensibilite_zoom*size_scale
|
||||
scene.objects['Camera']['past_ly']=scene.objects['Camera'].worldPosition.y
|
||||
scene.objects['Camera']['past_lz']=scene.objects['Camera'].worldPosition.z
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# position_scale_x = 0.0005
|
||||
# position_scale_y = position_scale_x
|
||||
# mouse_x=scene.objects['Mouse_main'].sensors["Mouse"].position[0]-int(bge.render.getWindowWidth() / 2)
|
||||
# mouse_y=scene.objects['Mouse_main'].sensors["Mouse"].position[1]-int(bge.render.getWindowHeight() / 2)
|
||||
# distance_cam_past= math.sqrt(scene.objects['Camera']['past_ly']**2+scene.objects['Camera']['past_lz']**2)
|
||||
# distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
# size_scale = (distance_cam/distance_cam_past) * 0.23
|
||||
print ("scene.objects['Camera']", scene.objects['Camera'].worldPosition.x, scene.objects['Camera'].worldPosition.y, scene.objects['Camera'].worldPosition.z)
|
||||
if scene.objects['Camera'].worldPosition.z >0.5 and scene.objects['Camera'].worldPosition.z <57:
|
||||
scene.objects['Camera'].applyMovement((0, 0, (delta_x+delta_y)*sensibilite_zoom), True)
|
||||
if scene.objects['Camera'].worldPosition.z <=0.5 or scene.objects['Camera'].worldPosition.z >=57 :
|
||||
scene.objects['Camera'].applyMovement((0, 0, -(delta_x+delta_y)*sensibilite_zoom), True)
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# scene.objects['Mouse_main'].applyMovement((mouse_x*(delta_x+delta_y)*sensibilite_zoom*position_scale_x, -mouse_y*(delta_x+delta_y)*sensibilite_zoom*position_scale_y, 0), True)
|
||||
# scene.objects['Mouse_main'].worldScale *= (delta_x+delta_y)*sensibilite_zoom*size_scale
|
||||
# scene.objects['Camera']['past_ly']=scene.objects['Camera'].worldPosition.y
|
||||
# scene.objects['Camera']['past_lz']=scene.objects['Camera'].worldPosition.z
|
||||
|
||||
##
|
||||
# Manipulation du modèle ou de la caméra
|
||||
@ -717,28 +736,30 @@ def manip(cont):
|
||||
def manip_wheel(cont):
|
||||
if scene.objects['Terrain']['manip_mode']!=9: # Fenêtre modale
|
||||
obj = cont.owner
|
||||
sensibilite_wheel = 5 # Base : 20
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
position_scale_x = 0.0005
|
||||
position_scale_y = position_scale_x
|
||||
mouse_x=scene.objects['Mouse_main'].sensors["Mouse"].position[0]-int(bge.render.getWindowWidth() / 2)
|
||||
mouse_y=scene.objects['Mouse_main'].sensors["Mouse"].position[1]-int(bge.render.getWindowHeight() / 2)
|
||||
distance_cam_past = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
# size_scale = (distance_cam/distance_cam_past) * 0.23
|
||||
size_scale = 0.2
|
||||
# size_scale = 0.23
|
||||
if cont.sensors['WheelUp'].positive:
|
||||
# sensibilite_wheel = 5 # Base : 20
|
||||
sensibilite_wheel = scene.objects['Camera'].worldPosition.z/5 # Sensibilité progressive
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# position_scale_x = 0.0005
|
||||
# position_scale_y = position_scale_x
|
||||
# mouse_x=scene.objects['Mouse_main'].sensors["Mouse"].position[0]-int(bge.render.getWindowWidth() / 2)
|
||||
# mouse_y=scene.objects['Mouse_main'].sensors["Mouse"].position[1]-int(bge.render.getWindowHeight() / 2)
|
||||
# distance_cam_past = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
# # size_scale = (distance_cam/distance_cam_past) * 0.23
|
||||
# size_scale = 0.2
|
||||
# # size_scale = 0.23
|
||||
print ("scene.objects['Camera']", scene.objects['Camera'].worldPosition.x, scene.objects['Camera'].worldPosition.y, scene.objects['Camera'].worldPosition.z)
|
||||
if cont.sensors['WheelUp'].positive :
|
||||
scene.objects['Camera'].applyMovement((0, 0, -sensibilite_wheel), True)
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
scene.objects['Mouse_main'].applyMovement((-mouse_x*sensibilite_wheel*position_scale_x, mouse_y*sensibilite_wheel*position_scale_y, 0), True)
|
||||
scene.objects['Mouse_main'].worldScale *= sensibilite_wheel* (distance_cam/distance_cam_past) *size_scale
|
||||
elif cont.sensors['WheelDown'].positive:
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
# scene.objects['Mouse_main'].applyMovement((-mouse_x*sensibilite_wheel*position_scale_x, mouse_y*sensibilite_wheel*position_scale_y, 0), True)
|
||||
# scene.objects['Mouse_main'].worldScale *= sensibilite_wheel* (distance_cam/distance_cam_past) *size_scale
|
||||
elif cont.sensors['WheelDown'].positive and scene.objects['Camera'].worldPosition.z<50:
|
||||
scene.objects['Camera'].applyMovement((0, 0, sensibilite_wheel), True)
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
scene.objects['Mouse_main'].applyMovement((mouse_x*sensibilite_wheel*position_scale_x, -mouse_y*sensibilite_wheel*position_scale_y, 0), True)
|
||||
scene.objects['Mouse_main'].worldScale /= sensibilite_wheel* (distance_cam_past/distance_cam) *size_scale
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2))
|
||||
# scene.objects['Mouse_main'].applyMovement((mouse_x*sensibilite_wheel*position_scale_x, -mouse_y*sensibilite_wheel*position_scale_y, 0), True)
|
||||
# scene.objects['Mouse_main'].worldScale /= sensibilite_wheel* (distance_cam_past/distance_cam) *size_scale
|
||||
else:
|
||||
return
|
||||
|
||||
@ -939,15 +960,15 @@ def about_open_anim():
|
||||
|
||||
def about_hl(cont):
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED:
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
mouse_up()
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# mouse_up()
|
||||
obj = cont.owner
|
||||
name=obj.name[:-7]
|
||||
scene.objects[name].color = color_link_hl
|
||||
|
||||
if cont.sensors['MO'].status == JUST_RELEASED:
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
mouse_down()
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# mouse_down()
|
||||
obj = cont.owner
|
||||
name=obj.name[:-7]
|
||||
scene.objects[name].color = color_link
|
||||
@ -997,12 +1018,12 @@ def about_link_hl(cont):
|
||||
obj = cont.owner
|
||||
name=obj.name[:-7]
|
||||
scene.objects[name].color = color_link_hl
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
mouse_up()
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# mouse_up()
|
||||
|
||||
if cont.sensors['MO'].status == JUST_RELEASED :
|
||||
obj = cont.owner
|
||||
name=obj.name[:-7]
|
||||
scene.objects[name].color = color_link
|
||||
if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
mouse_down()
|
||||
# if scene.objects['Mouse_main']['mouse_graphic']:
|
||||
# mouse_down()
|
||||
|
@ -1,8 +1,15 @@
|
||||
<data>
|
||||
<config>
|
||||
<speed>2.0</speed>
|
||||
<speed>10.0</speed>
|
||||
<sound>True</sound>
|
||||
<mission_current>3</mission_current>
|
||||
<mission_success>1</mission_success>
|
||||
<cam>
|
||||
<worldPosition.x>-4.190211772918701</worldPosition.x>
|
||||
<worldPosition.y>-12.807374954223633</worldPosition.y>
|
||||
<worldPosition.z>12.73536491394043</worldPosition.z>
|
||||
</cam>
|
||||
</config>
|
||||
<mission>
|
||||
<current>3</current>
|
||||
<success>1</success>
|
||||
</mission>
|
||||
</data>
|
@ -200,12 +200,6 @@ def init():
|
||||
scene.objects[missions_card[i]].color = color_doc_fct
|
||||
scene.objects[missions_card[i]+"-icon"].color = color_doc_fct
|
||||
scene.objects[missions_card[i]+"-text"].color = color_doc_fct
|
||||
# scene.objects[missions_card[i][:-5]+"-current"].color = color_doc_mission
|
||||
# scene.objects[missions_card[i][:-5]+"-current-icon"].color = color_doc_mission
|
||||
# scene.objects[missions_card[i][:-5]+"-current-text"].color = color_doc_mission
|
||||
# scene.objects[missions_card[i][:-5]+"-current"].setVisible(False,True)
|
||||
# scene.objects[missions_card[i][:-5]+"-current-icon"].setVisible(False,True)
|
||||
# scene.objects[missions_card[i][:-5]+"-current-text"].setVisible(False,True)
|
||||
for i in range(len(rover_card)):
|
||||
scene.objects[rover_card[i]].color = color_doc_fct
|
||||
scene.objects[rover_card[i]+"-icon"].color = color_doc_fct
|
||||
|
Loading…
Reference in New Issue
Block a user