def maj_zoom(la_camera): zoom=la_camera.GetCamera().GetZoomFactor() pas_zoom=0.1 if input.key_down(gs.InputDevice.KeyAdd): zoom+=pas_zoom elif input.key_down(gs.InputDevice.KeySub): zoom-=pas_zoom if zoom<1.: zoom=1. la_camera.GetCamera().SetZoomFactor(zoom)
def play_simulation(): while not input.key_press(gs.InputDevice.KeyEscape): clock.update() fps.update(clock.get_dt()) render.set_camera3d(fps.pos.x, fps.pos.y, fps.pos.z, fps.rot.x, fps.rot.y, fps.rot.z) render.clear() for perso in array_perso: perso.draw() perso.update(physic_world) array_perso[0].kohonen_behaviour.draw(render.get_renderer().GetCurrentOutputWindow().GetSize().x, render.get_renderer().GetCurrentOutputWindow().GetSize().y) physic_world.draw() # render text if input.key_down(gs.InputDevice.KeyL): render.text2d(10, 120, 'Frag in Mem: %d' % KohonenBehaviour.memory.GetNbFragment()) for action in range(perso_actions.nb_actions): render.text2d(10, 140 + 20*action, 'Frag for %s: %d, %d%%' % (perso_actions.get_current_action_name(action), KohonenBehaviour.memory.m_NbFragmentPerActionArray[action], KohonenBehaviour.memory.m_TabPercentFragmentPerAction[action]), 12, array_perso[0].kohonen_behaviour.color_array[action]) render.text2d(10, 50, str(perso.selected_action)+" "+perso_actions.get_current_action_name(perso.selected_action)) #draw it to the screen render.flip()
def update(self): if plus_input.key_down(gs.InputDevice.KeyA): memory.save() if plus_input.key_down(gs.InputDevice.KeyZ): memory.load() if plus_input.key_down(gs.InputDevice.KeyM) or memory.GetNbFragment() - self.last_messed_up_nb_fragment_in_memory > 1500: self.last_messed_up_nb_fragment_in_memory = memory.GetNbFragment() neural_network.MessedUpNeuroneInputs(self.node_inputs) not_training_use_directly_the_brain = False if not_training_use_directly_the_brain: current_fragment = self.node_inputs.GetCurrentNodeFragment() map_neural_network_on_memory = False else: map_neural_network_on_memory = True if randrange(100) < 30 and memory.GetNbFragment() > 0: # get a value from the memory to train de map, this is a test for the moment TODO # print('random fragment: '+str(randrange(memory.GetNbFragment()))) current_fragment = memory.fragment_array[randrange(memory.GetNbFragment())] else: current_fragment = self.node_inputs.GetCurrentNodeFragment() map_neural_network_on_memory = False # randomly label the neurone to keep it fresh with the new input if randrange(1000) == 1 and memory.GetNbFragment() > 0: neural_network.labelling() # update the kohonen neural network with the new input # get the action from the neural network for this fragment selected_action = int(neural_network.Update(current_fragment.input_array, map_neural_network_on_memory)) if not not_training_use_directly_the_brain: # sometime don't listen to the brain and do instinct stupidity if randrange(1000) < 30 or selected_action == -1: selected_action = randrange(self.nb_actions) # if the selected action is validate as good by the decision maker, keep in memory if self.decision_maker.is_good_action(current_fragment, selected_action): # add the framgent only it there not too much of this one already in memory if memory.m_TabPercentFragmentPerAction[selected_action] < 1/self.nb_actions*100 + 30: current_fragment.associated_action = selected_action memory.PushBackState(current_fragment) return selected_action
def edit_lumiere(le_noeud): sr=le_noeud.GetLight().GetShadowRange() sb=le_noeud.GetLight().GetShadowBias() #sd=le_noeud.GetLight().GetShadowDistribution() di=le_noeud.GetLight().GetDiffuseIntensity() lr=le_noeud.GetLight().GetRange() f=1 if input.key_down(gs.InputDevice.KeyLShift): f=10 if input.key_down(gs.InputDevice.KeyU): sr-=1*f if sr<1: sr=1 elif input.key_down(gs.InputDevice.KeyI): sr+=1*f if input.key_down(gs.InputDevice.KeyO): sb-=0.0001*f if sb<0.0001: sb=0.0001 elif input.key_down(gs.InputDevice.KeyP): sb+=0.0001*f """ if input.key_down(gs.InputDevice.KeyK): sd-=0.001*f if sd<0.001: sd=0.001 elif input.key_down(gs.InputDevice.KeyL): sd+=0.001*f """ if input.key_down(gs.InputDevice.KeyB): di-=0.01*f #if di<0: # di=0 elif input.key_down(gs.InputDevice.KeyN): di+=0.01*f if input.key_down(gs.InputDevice.KeyH): lr-=0.01*f if lr<0.01: lr=0.01 elif input.key_down(gs.InputDevice.KeyJ): lr+=0.01*f le_noeud.GetLight().SetShadowBias(sb) le_noeud.GetLight().SetShadowRange(sr) #le_noeud.GetLight().SetShadowDistribution(sd) le_noeud.GetLight().SetDiffuseIntensity(di) le_noeud.GetLight().SetRange(lr)
def maj_position(le_noeud): mat=le_noeud.GetTransform() pas_dep=1/180*pi position=mat.GetPosition() """ for key in range(0, gs.InputDevice.KeyLast): if input.key_press(key): print("Keyboard key pressed: %d" % key) """ # Switch contrôle Danel / élément scène: if not Demo.drapeau_camera_controle_utilisateur: if input.key_down(gs.InputDevice.KeyLeft): position.x-=pas_dep elif input.key_down(gs.InputDevice.KeyRight): position.x+=pas_dep elif input.key_down(gs.InputDevice.KeyPageDown): position.y-=pas_dep elif input.key_down(gs.InputDevice.KeyPageUp): position.y+=pas_dep elif input.key_down(gs.InputDevice.KeyDown): position.z-=pas_dep elif input.key_down(gs.InputDevice.KeyUp): position.z+=pas_dep le_noeud.GetTransform().SetPosition(position)
def edition(cls): noeuds = cls.scene3d.GetNodes() if input.key_press(gs.InputDevice.KeySpace): if input.key_down(gs.InputDevice.KeyLShift): cls.noeud_actuel -= 1 if cls.noeud_actuel < 0: cls.noeud_actuel = len(noeuds) - 1 else: cls.noeud_actuel += 1 if cls.noeud_actuel >= len(noeuds): cls.noeud_actuel = 0 if input.key_press(gs.InputDevice.KeyBackspace): cls.drapeau_lumieres_actives = not cls.drapeau_lumieres_actives if not cls.drapeau_lumieres_actives: for noeud in noeuds: if not noeud.GetLight() == None: noeud.GetLight().SetDiffuseIntensity(0.) noeud.GetLight().SetSpecularIntensity(0.) else: i = 0 for noeud in noeuds: if not noeud.GetLight() == None: noeud.GetLight().SetDiffuseIntensity( cls.lumieres_intens_mem[2 * i]) noeud.GetLight().SetSpecularIntensity( cls.lumieres_intens_mem[2 * i + 1]) i += 1 listing_sprites(cls.liste_sprites_scene, cls.sprite_actuel, gs.Color.Red, gs.Color.Green) listing_noeuds(noeuds, cls.noeud_actuel, gs.Color.Red, gs.Color.Green) listing_components(cls.components, 0) affiche_donnees_environnement(cls.environnement, 300, 450) affiche_donnees_camera(cls.camera, 300) affiche_donnees_lumiere(cls.lumiere_soleil, 600) affiche_donnees_noeud(noeuds[cls.noeud_actuel], gs.Color.Yellow) maj_zoom(cls.camera) edit_noeud(noeuds[cls.noeud_actuel]) cls.cube_l_clair_obscur.GetTransform().SetPosition( cls.lumiere_clair_obscur.GetTransform().GetPosition()) cls.cube_l_clair_obscur.GetTransform().SetRotation( cls.lumiere_clair_obscur.GetTransform().GetRotation()) cls.cube_l_soleil.GetTransform().SetPosition( cls.lumiere_soleil.GetTransform().GetPosition()) cls.cube_l_soleil.GetTransform().SetRotation( cls.lumiere_soleil.GetTransform().GetRotation())
def draw(self, width, height): if not plus_input.key_down(gs.InputDevice.KeyK): return width = width-10 # draw neural network previous_point = np.empty((neural_network.nb_neurone)) y_part = (height*0.75) / (neural_network.m_NbInput+1) color = gs.Color(1, 1, 1) for input in range(neural_network.m_NbInput): y = (height*0.25) + y_part * (input + 1) val_input = self.node_inputs.min_max_inputs[input] min = val_input[0] max = val_input[1] for id_neurone in range(neural_network.nb_neurone): value_input_neurone = neural_network.inputs_array[input][id_neurone] if neural_network.neurone_action_array[id_neurone] != -1: color = self.color_array[neural_network.neurone_action_array[id_neurone]] range_value_input = range_adjust(value_input_neurone, min, max, 10, width) render.line2d(range_value_input, y, range_value_input, y+2, color, color) if input != 0: render.line2d(previous_point[id_neurone], y-y_part+2, range_value_input, y, color, color) previous_point[id_neurone] = range_value_input # return # draw memory if memory.fragment_array.shape[0] != 0: for fragment in range(memory.fragment_array.shape[0]): input_count = 0 color = self.color_array[memory.fragment_array[fragment].associated_action] for value_input_neurone in np.nditer(memory.fragment_array[fragment].input_array): y = (height*0.25) / (neural_network.m_NbInput+1) * (input_count + 1) val_input = self.node_inputs.min_max_inputs[input_count] min = val_input[0] max = val_input[1] range_value_int = range_adjust(value_input_neurone, min, max, 10, width) + randrange(100)*0.1 render.line2d(range_value_int, y, range_value_int, y+20, color, color) input_count += 1
def edition_scene3d(cls): noeuds=cls.scene3d.GetNodes() if input.key_press(gs.InputDevice.KeySpace): if input.key_down(gs.InputDevice.KeyLShift): cls.noeud_actuel-=1 if cls.noeud_actuel<0: cls.noeud_actuel=len(noeuds)-1 else: cls.noeud_actuel+=1 if cls.noeud_actuel>=len(noeuds): cls.noeud_actuel=0 if input.key_press(gs.InputDevice.KeyBackspace): cls.drapeau_lumieres_actives=not cls.drapeau_lumieres_actives if not cls.drapeau_lumieres_actives: for noeud in noeuds: if not noeud.GetLight()==None: noeud.GetLight().SetDiffuseIntensity(0.) noeud.GetLight().SetSpecularIntensity(0.) else: i=0 for noeud in noeuds: if not noeud.GetLight()==None: noeud.GetLight().SetDiffuseIntensity(cls.lumieres_intens_mem[2*i]) noeud.GetLight().SetSpecularIntensity(cls.lumieres_intens_mem[2*i+1]) i+=1 listing_sprites(cls.liste_sprites_scene,cls.sprite_actuel,gs.Color.Red,gs.Color.Green) listing_noeuds(noeuds,cls.noeud_actuel,gs.Color.Red,gs.Color.Green) listing_components(cls.components,0) affiche_donnees_environnement(cls.environnement,300,450) affiche_donnees_camera(cls.camera,300) affiche_donnees_lumiere(cls.lumiere_soleil,600) affiche_donnees_noeud(noeuds[cls.noeud_actuel], gs.Color.Yellow) maj_zoom(cls.camera) edit_noeud(noeuds[cls.noeud_actuel]) cls.cube_l_ciel.GetTransform().SetPosition(cls.lumiere_ciel.GetTransform().GetPosition()) cls.cube_l_ciel.GetTransform().SetRotation(cls.lumiere_ciel.GetTransform().GetRotation()) cls.cube_l_soleil.GetTransform().SetPosition(cls.lumiere_soleil.GetTransform().GetPosition()) cls.cube_l_soleil.GetTransform().SetRotation(cls.lumiere_soleil.GetTransform().GetRotation())
def maj_orientation(le_noeud): mat=le_noeud.GetTransform() pas_rot=1/180*pi orientation=mat.GetRotation() if input.key_down(gs.InputDevice.KeyA): orientation.y-=pas_rot elif input.key_down(gs.InputDevice.KeyZ): orientation.y+=pas_rot elif input.key_down(gs.InputDevice.KeyE): orientation.x-=pas_rot elif input.key_down(gs.InputDevice.KeyR): orientation.x+=pas_rot elif input.key_down(gs.InputDevice.KeyT): orientation.z-=pas_rot elif input.key_down(gs.InputDevice.KeyY): orientation.z+=pas_rot le_noeud.GetTransform().SetRotation(orientation)
def update(self, physic_world): self.physic_world = physic_world self.inputs.update(physic_world) current_action = self.kohonen_behaviour.update() if self.timer_update <= 0: self.timer_update = randrange(25) self.selected_action = current_action self.timer_update -= 1 new_pos = self.actions.execute_action(self.selected_action, self) #check no intersection with physic word if not physic_world.in_collision_with_spheres(new_pos, 1.0): self.pos = new_pos # move randomly somewhere if plus_input.key_down(gs.InputDevice.KeyR): while True: self.pos.x = -1 + randrange(100) * 0.01 * (10 - 1) self.pos.y = -1 + randrange(100) * 0.01 * (10 - 1) if not physic_world.in_collision_with_spheres(self.pos, 1): self.decision_maker.reset_progress(self.pos) break
active_scene_actuelle() Demo.Scene_actuelle.restart() scene.update_scene(Demo.Scene_actuelle.scene3d, 1 / 60) # ============================================================================================================================ # BOUCLE PRINCIPALE # ============================================================================================================================ Demo.depart_demo() #C'est bon, tout est prêt, Le Temps 0 de la demo commence ici... while render.has_output_window() and not input.key_down(gs.InputDevice.KeyEscape): # ---- Mise à jour timing: Demo.horloge.Update() Demo.temps = Demo.horloge.Get().to_sec() Demo.delta_t = Demo.horloge.GetDelta().to_sec() Demo.numero_frame+=1 #------ Premier rendu: #Demo.systeme.SetOutputRenderTarget(Demo.pr_fbo_rendu) Demo.rendu.SetRenderTarget(Demo.renvoie_fbo(Demo.FBO_RENDU_1)) #Demo.rendu.Clear(gs.Color(0,0,1,0),1) window_size = Demo.rendu.GetDefaultOutputWindow().GetSize() Demo.rendu.SetViewport(gs.fRect(0, 0, window_size.x, window_size.y))# fit viewport to texture dimensions # ---- Gestion du signal du rendu précedent: # Placé ici car il faut laissé au rendu précédent le temps de se dérouler normalement.
def maj_filtres(): if not Demo.drapeau_camera_controle_utilisateur: if input.key_down(gs.InputDevice.KeyA): Demo.pr_taille_aura+=1 elif input.key_down(gs.InputDevice.KeyQ): Demo.pr_taille_aura-=1 if Demo.pr_taille_aura<1: Demo.pr_taille_aura=1 elif input.key_down(gs.InputDevice.KeyZ): Demo.pr_intensite_aura+=0.1 elif input.key_down(gs.InputDevice.KeyS): Demo.pr_intensite_aura-=0.1 if Demo.pr_intensite_aura<0.1: Demo.pr_intensite_aura=0.1 elif input.key_down(gs.InputDevice.KeyE): Demo.pr_aura_contraste+=0.1 elif input.key_down(gs.InputDevice.KeyD): Demo.pr_aura_contraste-=0.1 if Demo.pr_aura_contraste<0.1: Demo.pr_aura_contraste=0.1 elif input.key_down(gs.InputDevice.KeyR): Demo.pr_aura_seuil_contraste+=0.01 elif input.key_down(gs.InputDevice.KeyF): Demo.pr_aura_seuil_contraste-=0.01 if Demo.pr_aura_seuil_contraste<0.01: Demo.pr_aura_seuil_contraste=0.01 elif input.key_down(gs.InputDevice.KeyT): Demo.pr_aura_hue+=1 elif input.key_down(gs.InputDevice.KeyG): Demo.pr_aura_hue-=1 elif input.key_down(gs.InputDevice.KeyY): Demo.pr_aura_saturation+=0.1 elif input.key_down(gs.InputDevice.KeyH): Demo.pr_aura_saturation-=0.1 if Demo.pr_aura_saturation<0: Demo.pr_aura_saturation=0 elif input.key_down(gs.InputDevice.KeyU): Demo.pr_aura_value+=0.1 elif input.key_down(gs.InputDevice.KeyJ): Demo.pr_aura_value-=0.1 if Demo.pr_aura_value<0: Demo.pr_aura_value=0 elif input.key_down(gs.InputDevice.KeyI): Demo.pr_alpha_aura+=0.1 elif input.key_down(gs.InputDevice.KeyK): Demo.pr_alpha_aura-=0.1 if Demo.pr_alpha_aura<0: Demo.pr_alpha_aura=0 elif input.key_down(gs.InputDevice.KeyO): Demo.pr_alpha_rendu+=0.1 elif input.key_down(gs.InputDevice.KeyL): Demo.pr_alpha_rendu-=0.1 if Demo.pr_alpha_rendu<0: Demo.pr_alpha_rendu=0 elif input.key_down(gs.InputDevice.KeyNumpad2): Demo.pr_Contraste+=0.1 elif input.key_down(gs.InputDevice.KeyNumpad1): Demo.pr_Contraste-=0.1 if Demo.pr_Contraste<0: Demo.pr_Contraste=0 elif input.key_down(gs.InputDevice.KeyNumpad4): Demo.pr_Seuil_contraste+=0.01 elif input.key_down(gs.InputDevice.KeyNumpad3): Demo.pr_Seuil_contraste-=0.01 if Demo.pr_Seuil_contraste<0.01: Demo.pr_Seuil_contraste=0.01 elif input.key_down(gs.InputDevice.KeyNumpad6): Demo.pr_Hue+=1 elif input.key_down(gs.InputDevice.KeyNumpad5): Demo.pr_Hue-=1 elif input.key_down(gs.InputDevice.KeyNumpad8): Demo.pr_Saturation+=0.1 elif input.key_down(gs.InputDevice.KeyNumpad7): Demo.pr_Saturation-=0.1 if Demo.pr_Saturation<0: Demo.pr_Saturation=0 elif input.key_down(gs.InputDevice.KeyNumpad0): Demo.pr_Value+=0.1 elif input.key_down(gs.InputDevice.KeyNumpad9): Demo.pr_Value-=0.1 if Demo.pr_Value<0: Demo.pr_Value=0
def edition_terrain(cls): if input.key_down(gs.InputDevice.KeyA): cls.facteur_echelle_terrain_l1.x+=100 elif input.key_down(gs.InputDevice.KeyQ): cls.facteur_echelle_terrain_l1.x-=100 if cls.facteur_echelle_terrain_l1.x<100: cls.facteur_echelle_terrain_l1.x=100 if input.key_down(gs.InputDevice.KeyZ): cls.facteur_echelle_terrain_l1.y+=100 elif input.key_down(gs.InputDevice.KeyS): cls.facteur_echelle_terrain_l1.y-=100 if cls.facteur_echelle_terrain_l1.y<100: cls.facteur_echelle_terrain_l1.y=100 if input.key_down(gs.InputDevice.KeyE): cls.facteur_echelle_terrain_l2.x+=100 elif input.key_down(gs.InputDevice.KeyD): cls.facteur_echelle_terrain_l2.x-=100 if cls.facteur_echelle_terrain_l2.x<100: cls.facteur_echelle_terrain_l2.x=100 if input.key_down(gs.InputDevice.KeyR): cls.facteur_echelle_terrain_l2.y+=100 elif input.key_down(gs.InputDevice.KeyF): cls.facteur_echelle_terrain_l2.y-=100 if cls.facteur_echelle_terrain_l2.y<100: cls.facteur_echelle_terrain_l2.y=100 if input.key_down(gs.InputDevice.KeyT): cls.facteur_echelle_terrain_l3.x+=100 elif input.key_down(gs.InputDevice.KeyG): cls.facteur_echelle_terrain_l3.x-=100 if cls.facteur_echelle_terrain_l3.x<100: cls.facteur_echelle_terrain_l3.x=100 if input.key_down(gs.InputDevice.KeyY): cls.facteur_echelle_terrain_l3.y+=100 elif input.key_down(gs.InputDevice.KeyH): cls.facteur_echelle_terrain_l3.y-=100 if cls.facteur_echelle_terrain_l3.y<100: cls.facteur_echelle_terrain_l3.y=100 elif input.key_down(gs.InputDevice.KeyU): cls.amplitude_l1+=100 elif input.key_down(gs.InputDevice.KeyJ): cls.amplitude_l1-=100 if cls.amplitude_l1<100: cls.amplitude_l1=100 elif input.key_down(gs.InputDevice.KeyI): cls.amplitude_l2+=1 elif input.key_down(gs.InputDevice.KeyK): cls.amplitude_l2-=1 if cls.amplitude_l2<1: cls.amplitude_l2=1 elif input.key_down(gs.InputDevice.KeyO): cls.amplitude_l3+=0.05 elif input.key_down(gs.InputDevice.KeyL): cls.amplitude_l3-=0.05 if cls.amplitude_l3<0.05: cls.amplitude_l3=0.05 elif input.key_down(gs.InputDevice.KeyP): cls.facteur_precision_distance+=0.001 elif input.key_down(gs.InputDevice.KeyM): cls.facteur_precision_distance-=0.001 if cls.facteur_precision_distance<1.001: cls.facteur_precision_distance=1.001 elif input.key_down(gs.InputDevice.KeyNumpad2): cls.altitude_eau+=1 elif input.key_down(gs.InputDevice.KeyNumpad1): cls.altitude_eau-=1 window_size = Demo.rendu.GetDefaultOutputWindow().GetSize() xPos=10 yPos=window_size.y-30 c=gs.Color(1.,0,0,1.) render.text2d(xPos,yPos,"A/Q facteur_echelle_terrain_l1.x: "+str(cls.facteur_echelle_terrain_l1.x),16, c) render.text2d(xPos,yPos-15,"Z/S facteur_echelle_terrain_l1.y: "+str(cls.facteur_echelle_terrain_l1.y),16, c) render.text2d(xPos,yPos-15*2,"E/D facteur_echelle_terrain_l2.x: "+str(cls.facteur_echelle_terrain_l2.x),16, c) render.text2d(xPos,yPos-15*3,"R/F facteur_echelle_terrain_l2.y: "+str(cls.facteur_echelle_terrain_l2.y),16, c) render.text2d(xPos,yPos-15*4,"T/G facteur_echelle_terrain_l3.x: "+str(cls.facteur_echelle_terrain_l3.x),16, c) render.text2d(xPos,yPos-15*5,"Y/H facteur_echelle_terrain_l3.y: "+str(cls.facteur_echelle_terrain_l3.y),16, c) render.text2d(xPos,yPos-15*6,"U/J amplitude_l1: "+str(cls.amplitude_l1),16, c) render.text2d(xPos,yPos-15*7,"I/K amplitude_l2: "+str(cls.amplitude_l2),16, c) render.text2d(xPos,yPos-15*8,"O/L amplitude_l3: "+str(cls.amplitude_l3),16, c) render.text2d(xPos,yPos-15*9,"P/M facteur_precision_distance: "+str(cls.facteur_precision_distance),16, c) render.text2d(xPos,yPos-15*10,"1/2 altitude_eau: "+str(cls.altitude_eau),16, c)
def edition_terrain(cls): if input.key_down(gs.InputDevice.KeyA): cls.facteur_echelle_terrain_l1.x += 100 elif input.key_down(gs.InputDevice.KeyQ): cls.facteur_echelle_terrain_l1.x -= 100 if cls.facteur_echelle_terrain_l1.x < 100: cls.facteur_echelle_terrain_l1.x = 100 if input.key_down(gs.InputDevice.KeyZ): cls.facteur_echelle_terrain_l1.y += 100 elif input.key_down(gs.InputDevice.KeyS): cls.facteur_echelle_terrain_l1.y -= 100 if cls.facteur_echelle_terrain_l1.y < 100: cls.facteur_echelle_terrain_l1.y = 100 if input.key_down(gs.InputDevice.KeyE): cls.facteur_echelle_terrain_l2.x += 100 elif input.key_down(gs.InputDevice.KeyD): cls.facteur_echelle_terrain_l2.x -= 100 if cls.facteur_echelle_terrain_l2.x < 100: cls.facteur_echelle_terrain_l2.x = 100 if input.key_down(gs.InputDevice.KeyR): cls.facteur_echelle_terrain_l2.y += 100 elif input.key_down(gs.InputDevice.KeyF): cls.facteur_echelle_terrain_l2.y -= 100 if cls.facteur_echelle_terrain_l2.y < 100: cls.facteur_echelle_terrain_l2.y = 100 if input.key_down(gs.InputDevice.KeyT): cls.facteur_echelle_terrain_l3.x += 100 elif input.key_down(gs.InputDevice.KeyG): cls.facteur_echelle_terrain_l3.x -= 100 if cls.facteur_echelle_terrain_l3.x < 100: cls.facteur_echelle_terrain_l3.x = 100 if input.key_down(gs.InputDevice.KeyY): cls.facteur_echelle_terrain_l3.y += 100 elif input.key_down(gs.InputDevice.KeyH): cls.facteur_echelle_terrain_l3.y -= 100 if cls.facteur_echelle_terrain_l3.y < 100: cls.facteur_echelle_terrain_l3.y = 100 elif input.key_down(gs.InputDevice.KeyU): cls.amplitude_l1 += 100 elif input.key_down(gs.InputDevice.KeyJ): cls.amplitude_l1 -= 100 if cls.amplitude_l1 < 100: cls.amplitude_l1 = 100 elif input.key_down(gs.InputDevice.KeyI): cls.amplitude_l2 += 1 elif input.key_down(gs.InputDevice.KeyK): cls.amplitude_l2 -= 1 if cls.amplitude_l2 < 1: cls.amplitude_l2 = 1 elif input.key_down(gs.InputDevice.KeyO): cls.amplitude_l3 += 0.05 elif input.key_down(gs.InputDevice.KeyL): cls.amplitude_l3 -= 0.05 if cls.amplitude_l3 < 0.05: cls.amplitude_l3 = 0.05 elif input.key_down(gs.InputDevice.KeyP): cls.facteur_precision_distance += 0.001 elif input.key_down(gs.InputDevice.KeyM): cls.facteur_precision_distance -= 0.001 if cls.facteur_precision_distance < 1.001: cls.facteur_precision_distance = 1.001 elif input.key_down(gs.InputDevice.KeyNumpad2): cls.altitude_eau += 1 elif input.key_down(gs.InputDevice.KeyNumpad1): cls.altitude_eau -= 1 window_size = Demo.rendu.GetDefaultOutputWindow().GetSize() xPos = 10 yPos = window_size.y - 30 c = gs.Color(1., 0, 0, 1.) render.text2d( xPos, yPos, "A/Q facteur_echelle_terrain_l1.x: " + str(cls.facteur_echelle_terrain_l1.x), 16, c) render.text2d( xPos, yPos - 15, "Z/S facteur_echelle_terrain_l1.y: " + str(cls.facteur_echelle_terrain_l1.y), 16, c) render.text2d( xPos, yPos - 15 * 2, "E/D facteur_echelle_terrain_l2.x: " + str(cls.facteur_echelle_terrain_l2.x), 16, c) render.text2d( xPos, yPos - 15 * 3, "R/F facteur_echelle_terrain_l2.y: " + str(cls.facteur_echelle_terrain_l2.y), 16, c) render.text2d( xPos, yPos - 15 * 4, "T/G facteur_echelle_terrain_l3.x: " + str(cls.facteur_echelle_terrain_l3.x), 16, c) render.text2d( xPos, yPos - 15 * 5, "Y/H facteur_echelle_terrain_l3.y: " + str(cls.facteur_echelle_terrain_l3.y), 16, c) render.text2d(xPos, yPos - 15 * 6, "U/J amplitude_l1: " + str(cls.amplitude_l1), 16, c) render.text2d(xPos, yPos - 15 * 7, "I/K amplitude_l2: " + str(cls.amplitude_l2), 16, c) render.text2d(xPos, yPos - 15 * 8, "O/L amplitude_l3: " + str(cls.amplitude_l3), 16, c) render.text2d( xPos, yPos - 15 * 9, "P/M facteur_precision_distance: " + str(cls.facteur_precision_distance), 16, c) render.text2d(xPos, yPos - 15 * 10, "1/2 altitude_eau: " + str(cls.altitude_eau), 16, c)
# ----------- Positionnement initial: active_scene_actuelle() Demo.Scene_actuelle.restart() scene.update_scene(Demo.Scene_actuelle.scene3d, 1 / 60) # ============================================================================================================================ # BOUCLE PRINCIPALE # ============================================================================================================================ Demo.depart_demo( ) #C'est bon, tout est prêt, Le Temps 0 de la demo commence ici... while render.has_output_window() and not input.key_down( gs.InputDevice.KeyEscape): # ---- Mise à jour timing: Demo.horloge.Update() Demo.temps = Demo.horloge.Get().to_sec() Demo.delta_t = Demo.horloge.GetDelta().to_sec() Demo.numero_frame += 1 #------ Premier rendu: #Demo.systeme.SetOutputRenderTarget(Demo.pr_fbo_rendu) Demo.rendu.SetRenderTarget(Demo.renvoie_fbo(Demo.FBO_RENDU_1)) #Demo.rendu.Clear(gs.Color(0,0,1,0),1) window_size = Demo.rendu.GetDefaultOutputWindow().GetSize() Demo.rendu.SetViewport( gs.fRect(0, 0, window_size.x, window_size.y)) # fit viewport to texture dimensions