mirror of
https://forge.apps.education.fr/blender-edutech/ropy.git
synced 2024-01-27 08:23:20 +01:00
Ajout des animations : avancer et tourner
This commit is contained in:
parent
29fa4d1a6e
commit
fe2629e7ab
BIN
ropy-11.blend
Normal file
BIN
ropy-11.blend
Normal file
Binary file not shown.
9
rp.py
9
rp.py
@ -99,7 +99,11 @@ def points_maj (cont):
|
|||||||
scene.objects['Points-Step-text']['Text']=str(scene.objects['Points']['step'])
|
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-Level-text']['Text']=str(scene.objects['Points']['level'])
|
||||||
scene.objects['Points-Nbligne-text']['Text']=str(scene.objects['Points']['nbligne'])
|
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
|
# Fin de la mission
|
||||||
# FIXME
|
# FIXME
|
||||||
@ -664,6 +668,9 @@ def manip_reset():
|
|||||||
scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx']
|
scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx']
|
||||||
scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly']
|
scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly']
|
||||||
scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz']
|
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)
|
applyRotationTo(scene.objects['Terrain'], 0, 0, 0)
|
||||||
scene.objects['Cmd-text']['Text']= ""
|
scene.objects['Cmd-text']['Text']= ""
|
||||||
|
|
||||||
|
@ -26,16 +26,19 @@ def commandes():
|
|||||||
rp_gauche()
|
rp_gauche()
|
||||||
mrp_avancer()
|
mrp_avancer()
|
||||||
mrp_avancer()
|
mrp_avancer()
|
||||||
|
mrp_avancer()
|
||||||
|
mrp_avancer()
|
||||||
|
|
||||||
rp_droite()
|
rp_droite()
|
||||||
mrp_avancer()
|
mrp_avancer()
|
||||||
mrp_avancer()
|
mrp_avancer()
|
||||||
mrp_avancer()
|
mrp_avancer()
|
||||||
mrp_avancer()
|
mrp_avancer()
|
||||||
|
|
||||||
|
rp_droite()
|
||||||
|
mrp_avancer()
|
||||||
mrp_avancer()
|
mrp_avancer()
|
||||||
mrp_avancer()
|
mrp_avancer()
|
||||||
|
|
||||||
rp_avancer()
|
|
||||||
|
|
||||||
rp_fin()
|
rp_fin()
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<data>
|
<data>
|
||||||
<config>
|
<config>
|
||||||
<speed>1.0</speed>
|
<speed>1.0</speed>
|
||||||
<sound>True</sound>
|
<sound>False</sound>
|
||||||
<cam>
|
<cam>
|
||||||
<worldPosition.x>-7.927214622497559</worldPosition.x>
|
<worldPosition.x>-6.930208683013916</worldPosition.x>
|
||||||
<worldPosition.y>-9.915717124938965</worldPosition.y>
|
<worldPosition.y>-18.326568603515625</worldPosition.y>
|
||||||
<worldPosition.z>10.973342895507812</worldPosition.z>
|
<worldPosition.z>19.9746036529541</worldPosition.z>
|
||||||
</cam>
|
</cam>
|
||||||
</config>
|
</config>
|
||||||
<mission>
|
<mission>
|
||||||
|
131
rp_lib.py
131
rp_lib.py
@ -1,4 +1,5 @@
|
|||||||
import bge # Blender Game Engine (UPBGE)
|
import bge # Blender Game Engine (UPBGE)
|
||||||
|
import bpy # Blender
|
||||||
import aud # Sounds
|
import aud # Sounds
|
||||||
import threading # Multithreading
|
import threading # Multithreading
|
||||||
import trace
|
import trace
|
||||||
@ -179,21 +180,75 @@ def sound_play (sound):
|
|||||||
def rp_avancer ():
|
def rp_avancer ():
|
||||||
print ("rp_avancer()")
|
print ("rp_avancer()")
|
||||||
scene.objects['Points']['step'] +=1
|
scene.objects['Points']['step'] +=1
|
||||||
step =1
|
|
||||||
obj=scene.objects['Rover']
|
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)
|
# print (obj.worldOrientation.to_euler().z)
|
||||||
x0 = obj.worldPosition.x
|
# x0 = obj.worldPosition.x
|
||||||
y0 = obj.worldPosition.y
|
# y0 = obj.worldPosition.y
|
||||||
z0 = obj.worldPosition.z
|
# 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
|
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
|
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
|
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
|
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)
|
rp_tempo (0.1)
|
||||||
|
return True
|
||||||
|
|
||||||
##
|
##
|
||||||
# Tourner à gauche
|
# Tourner à gauche
|
||||||
@ -204,8 +259,35 @@ def rp_gauche ():
|
|||||||
scene.objects['Points']['step'] +=1
|
scene.objects['Points']['step'] +=1
|
||||||
step=math.pi/2 # Pas angulaire
|
step=math.pi/2 # Pas angulaire
|
||||||
obj=scene.objects['Rover']
|
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)
|
rp_tempo (0.1)
|
||||||
|
return True
|
||||||
|
|
||||||
##
|
##
|
||||||
# Tourner à droite
|
# Tourner à droite
|
||||||
@ -216,8 +298,35 @@ def rp_droite ():
|
|||||||
scene.objects['Points']['step'] +=1
|
scene.objects['Points']['step'] +=1
|
||||||
step=math.pi/2 # Pas angulaire
|
step=math.pi/2 # Pas angulaire
|
||||||
obj=scene.objects['Rover']
|
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)
|
rp_tempo (0.1)
|
||||||
|
return True
|
||||||
|
|
||||||
##
|
##
|
||||||
# Marquer
|
# Marquer
|
||||||
@ -292,9 +401,11 @@ def rover_colision ():
|
|||||||
# Temporisation
|
# Temporisation
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
# Temporisation basée sur l'horloge de l'OS
|
||||||
def rp_sleep (duration):
|
def rp_sleep (duration):
|
||||||
time.sleep(duration)
|
time.sleep(duration)
|
||||||
|
|
||||||
|
# Temporisation basée par l'horloge de UPBGE
|
||||||
def rp_tempo (duration):
|
def rp_tempo (duration):
|
||||||
# time.sleep(duration*(1/scene.objects['Commands']['speed']))
|
# time.sleep(duration*(1/scene.objects['Commands']['speed']))
|
||||||
scene.objects['Commands']['time']=0
|
scene.objects['Commands']['time']=0
|
||||||
|
@ -136,7 +136,7 @@ def map_reset():
|
|||||||
obj = scene.objects['Rover']
|
obj = scene.objects['Rover']
|
||||||
obj.worldPosition.x = mission_init[0]
|
obj.worldPosition.x = mission_init[0]
|
||||||
obj.worldPosition.y = mission_init[1]
|
obj.worldPosition.y = mission_init[1]
|
||||||
obj.worldPosition.z = 0.2
|
obj.worldPosition.z = 0.25
|
||||||
applyRotationTo(obj, 0, 0, 0, True)
|
applyRotationTo(obj, 0, 0, 0, True)
|
||||||
if mission_init[2] == "n":
|
if mission_init[2] == "n":
|
||||||
obj.applyRotation((0, 0, math.pi), True)
|
obj.applyRotation((0, 0, math.pi), True)
|
||||||
|
Loading…
Reference in New Issue
Block a user