diff --git a/ropy-11.blend b/ropy-11.blend new file mode 100644 index 0000000..4672d40 Binary files /dev/null and b/ropy-11.blend differ diff --git a/rp.py b/rp.py index 67ac6d1..1b66a2e 100644 --- a/rp.py +++ b/rp.py @@ -99,7 +99,11 @@ def points_maj (cont): scene.objects['Points-Step-text']['Text']=str(scene.objects['Points']['step']) scene.objects['Points-Level-text']['Text']=str(scene.objects['Points']['level']) scene.objects['Points-Nbligne-text']['Text']=str(scene.objects['Points']['nbligne']) - scene.objects['Points']['tics'] +=1 + + # Position du rover + obj=scene.objects['Rover'] + # print ("Rover position :", obj.worldPosition.x, obj.worldPosition.y, obj.worldPosition.z) + obj['position']=str(obj.worldPosition.x)+","+str(obj.worldPosition.y)+","+str(obj.worldPosition.z) # Fin de la mission # FIXME @@ -664,6 +668,9 @@ def manip_reset(): scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx'] scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly'] scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz'] + scene.objects['Camera']['current_lx'] = scene.objects['Camera'].worldPosition.x + scene.objects['Camera']['current_ly'] = scene.objects['Camera'].worldPosition.y + scene.objects['Camera']['current_lz'] = scene.objects['Camera'].worldPosition.z applyRotationTo(scene.objects['Terrain'], 0, 0, 0) scene.objects['Cmd-text']['Text']= "" diff --git a/rp_cmd.py b/rp_cmd.py index 79f2fde..00d48ef 100644 --- a/rp_cmd.py +++ b/rp_cmd.py @@ -26,16 +26,19 @@ def commandes(): rp_gauche() mrp_avancer() mrp_avancer() + mrp_avancer() + mrp_avancer() rp_droite() mrp_avancer() mrp_avancer() mrp_avancer() mrp_avancer() + + rp_droite() + mrp_avancer() mrp_avancer() mrp_avancer() - - rp_avancer() rp_fin() diff --git a/rp_config.xml b/rp_config.xml index aa9d0d1..216e61b 100644 --- a/rp_config.xml +++ b/rp_config.xml @@ -1,11 +1,11 @@ 1.0 - True + False - -7.927214622497559 - -9.915717124938965 - 10.973342895507812 + -6.930208683013916 + -18.326568603515625 + 19.9746036529541 diff --git a/rp_lib.py b/rp_lib.py index 3237da5..f3cf032 100644 --- a/rp_lib.py +++ b/rp_lib.py @@ -1,4 +1,5 @@ import bge # Blender Game Engine (UPBGE) +import bpy # Blender import aud # Sounds import threading # Multithreading import trace @@ -179,21 +180,75 @@ def sound_play (sound): def rp_avancer (): print ("rp_avancer()") scene.objects['Points']['step'] +=1 - step =1 obj=scene.objects['Rover'] + + # Rapide + if scene.objects['Commands']['speed'] == 10: + x0 = obj.worldPosition.x + y0 = obj.worldPosition.y + z0 = obj.worldPosition.z + if round(obj.worldOrientation.to_euler().z, 2) == 0.00: # Sud + obj.worldPosition=[x0, y0-1, z0] + if round(obj.worldOrientation.to_euler().z, 2) == round(math.pi,2) or round(obj.worldOrientation.to_euler().z, 2) == - round(math.pi,2) : # Nord + obj.worldPosition=[x0, y0+1, z0] + if round(obj.worldOrientation.to_euler().z, 2) == round(math.pi/2,2) or round(obj.worldOrientation.to_euler().z, 2) == -round(3*(math.pi/2),2) : # Est + obj.worldPosition=[x0+1, y0, z0] + if round(obj.worldOrientation.to_euler().z, 2) == round(-math.pi/2,2) or round(obj.worldOrientation.to_euler().z, 2) == round(3*(math.pi/2),2) : # Ouest + obj.worldPosition=[x0-1, y0, z0] + rp_tempo (0.1) + return True + + # FIXME : Animation sacadée + # step =1/100 # print (obj.worldOrientation.to_euler().z) - x0 = obj.worldPosition.x - y0 = obj.worldPosition.y - z0 = obj.worldPosition.z + # x0 = obj.worldPosition.x + # y0 = obj.worldPosition.y + # z0 = obj.worldPosition.z + # for i in range (100) : + # if round(obj.worldOrientation.to_euler().z, 2) == 0.00: # Sud + # obj.worldPosition=[x0, y0-step*i, z0] + # if round(obj.worldOrientation.to_euler().z, 2) == round(math.pi,2) or round(obj.worldOrientation.to_euler().z, 2) == - round(math.pi,2) : # Nord + # obj.worldPosition=[x0, y0+step*i, z0] + # if round(obj.worldOrientation.to_euler().z, 2) == round(math.pi/2,2) or round(obj.worldOrientation.to_euler().z, 2) == -round(3*(math.pi/2),2) : # Est + # obj.worldPosition=[x0+step*i, y0, z0] + # if round(obj.worldOrientation.to_euler().z, 2) == round(-math.pi/2,2) or round(obj.worldOrientation.to_euler().z, 2) == round(3*(math.pi/2),2) : # Ouest + # obj.worldPosition=[x0-step*i, y0, z0] + # rp_tempo (0.1*step) + + # Animation + # obj['avancer_anim']=True + start = 1 + end = 100 + layer = 0 + priority = 1 + blendin = 1.0 + mode = bge.logic.KX_ACTION_MODE_PLAY + layerWeight = 0.0 + ipoFlags = 0 + speed = scene.objects['Commands']['speed']*4 if round(obj.worldOrientation.to_euler().z, 2) == 0.00: # Sud - obj.worldPosition=[x0, y0-step, z0] + scene.objects['Rover'].playAction('Rover-Avancer-Y-', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + # obj.worldPosition=[x0, y0-step*i, z0] if round(obj.worldOrientation.to_euler().z, 2) == round(math.pi,2) or round(obj.worldOrientation.to_euler().z, 2) == - round(math.pi,2) : # Nord - obj.worldPosition=[x0, y0+step, z0] + scene.objects['Rover'].playAction('Rover-Avancer-Y+', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + # obj.worldPosition=[x0, y0+step*i, z0] if round(obj.worldOrientation.to_euler().z, 2) == round(math.pi/2,2) or round(obj.worldOrientation.to_euler().z, 2) == -round(3*(math.pi/2),2) : # Est - obj.worldPosition=[x0+step, y0, z0] + scene.objects['Rover'].playAction('Rover-Avancer-X+', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + # obj.worldPosition=[x0+step*i, y0, z0] if round(obj.worldOrientation.to_euler().z, 2) == round(-math.pi/2,2) or round(obj.worldOrientation.to_euler().z, 2) == round(3*(math.pi/2),2) : # Ouest - obj.worldPosition=[x0-step, y0, z0] + scene.objects['Rover'].playAction('Rover-Avancer-X-', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + # obj.worldPosition=[x0-step*i, y0, z0] + scene.objects['Wheel-right-front'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-right-mid'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-right-rear'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-front'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-mid'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-rear'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + while scene.objects['Wheel-right-front'].isPlayingAction(): # Forçage du redraw + # scene.objects['Camera'].applyMovement((0, 0, 0), True) + scene.objects['Sun'].applyMovement((0, 0, 0), True) rp_tempo (0.1) + return True ## # Tourner à gauche @@ -204,8 +259,35 @@ def rp_gauche (): scene.objects['Points']['step'] +=1 step=math.pi/2 # Pas angulaire obj=scene.objects['Rover'] - obj.applyRotation((0, 0, step), True) + + # Rapide + if scene.objects['Commands']['speed'] == 10: + obj.applyRotation((0, 0, step), True) + rp_tempo (0.1) + return True + + # Animation + start = 1 + end = 100 + layer = 0 + priority = 1 + blendin = 1.0 + mode = bge.logic.KX_ACTION_MODE_PLAY + layerWeight = 0.0 + ipoFlags = 0 + speed = scene.objects['Commands']['speed']*4 + scene.objects['Rover'].playAction('Rover-Gauche', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-right-front'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-right-mid'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-right-rear'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-front'].playAction('Wheel-Reculer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-mid'].playAction('Wheel-Reculer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-rear'].playAction('Wheel-Reculer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + while scene.objects['Wheel-right-front'].isPlayingAction(): # Forçage du redraw + # scene.objects['Camera'].applyMovement((0, 0, 0), True) + scene.objects['Sun'].applyMovement((0, 0, 0), True) rp_tempo (0.1) + return True ## # Tourner à droite @@ -216,8 +298,35 @@ def rp_droite (): scene.objects['Points']['step'] +=1 step=math.pi/2 # Pas angulaire obj=scene.objects['Rover'] - obj.applyRotation((0, 0, -step), True) + + # Rapide + if scene.objects['Commands']['speed'] == 10: + obj.applyRotation((0, 0, -step), True) + rp_tempo (0.1) + return True + + # Animation + start = 1 + end = 100 + layer = 0 + priority = 1 + blendin = 1.0 + mode = bge.logic.KX_ACTION_MODE_PLAY + layerWeight = 0.0 + ipoFlags = 0 + speed = scene.objects['Commands']['speed']*4 + scene.objects['Rover'].playAction('Rover-Droite', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-right-front'].playAction('Wheel-Reculer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-right-mid'].playAction('Wheel-Reculer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-right-rear'].playAction('Wheel-Reculer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-front'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-mid'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + scene.objects['Wheel-left-rear'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed) + while scene.objects['Wheel-right-front'].isPlayingAction(): # Forçage du redraw + # scene.objects['Camera'].applyMovement((0, 0, 0), True) + scene.objects['Sun'].applyMovement((0, 0, 0), True) rp_tempo (0.1) + return True ## # Marquer @@ -292,9 +401,11 @@ def rover_colision (): # Temporisation ############################################################################### +# Temporisation basée sur l'horloge de l'OS def rp_sleep (duration): time.sleep(duration) +# Temporisation basée par l'horloge de UPBGE def rp_tempo (duration): # time.sleep(duration*(1/scene.objects['Commands']['speed'])) scene.objects['Commands']['time']=0 diff --git a/rp_map1.py b/rp_map1.py index cc54c73..6fe349a 100644 --- a/rp_map1.py +++ b/rp_map1.py @@ -136,7 +136,7 @@ def map_reset(): obj = scene.objects['Rover'] obj.worldPosition.x = mission_init[0] obj.worldPosition.y = mission_init[1] - obj.worldPosition.z = 0.2 + obj.worldPosition.z = 0.25 applyRotationTo(obj, 0, 0, 0, True) if mission_init[2] == "n": obj.applyRotation((0, 0, math.pi), True)