def main(): """ Fonction principale d'animation """ global t while True: for obj in Obj.objects: # Pour tous les objets existants obj.calcule() # On calcule la variation de vitesse for obj in Obj.objects: obj.move() # Déplace les astres dans le ciel t += dt # Avancement du temps # Retard artificiel pour l'animation rate(freq) # Affichage du temps if t%(3600*24)==0: # Si un jour passe: print(str(t/(3600*24))+' jours') k = keysdown() if 'esc' in k: print("Fin annimation") break exit() sys.exit("Fin du programme")
def main(): """main game function""" create_world() create_widgets() create_grid() recalc_y_values() make_water() #create_rover() while True: v.rate(1 / Game.dt) keys = v.keysdown() if "f" in keys: print("f was pressed")
def anim_thread(fps = 60): dt = 1/fps move_error = 0.05 #update this value turn_error = 0.05 #update this value move_vel = 0.8 turn_vel = 1 while running: vp.rate(fps) k = vp.keysdown() u = np.array([0.,0.,0.,0.,0.,0.]) u = u.astype('float64') if 'w' in k: #print(scene.forward.norm()*move_vel*dt*(1+move_error*randn())) delta = scene.forward.norm()*move_vel*dt*(1+move_error*randn()) u += np.array([delta.x,delta.y,delta.z,0.,0.,0.]) scene.camera.pos += delta if 's' in k: delta = scene.forward.norm()*move_vel*dt*(1+move_error*randn()) u += np.array([delta.x,delta.y,delta.z,0.,0.,0.]) scene.camera.pos -= delta if 'd' in k: delta = scene.forward.cross(scene.up).norm()*move_vel*dt*(1+move_error*randn()) u += np.array([delta.x,delta.y,delta.z,0.,0.,0.]) scene.camera.pos += delta if 'a' in k: delta = scene.forward.cross(scene.up).norm()*move_vel*dt*(1+move_error*randn()) u += np.array([delta.x,delta.y,delta.z,0.,0.,0.]) scene.camera.pos -= delta if 'up' in k: epsilon = scene.camera.axis.rotate(angle = turn_vel*dt*(1+turn_error*randn()), axis = scene.camera.axis.cross(scene.up)).norm() delta = (epsilon - scene.camera.axis.norm()).norm() u += np.array([0.,0.,0.,delta.x,delta.y,delta.z]) scene.camera.axis = epsilon if 'down' in k: epsilon = scene.camera.axis.rotate(angle = -1*turn_vel*dt*(1+turn_error*randn()), axis = scene.camera.axis.cross(scene.up)).norm() delta = (epsilon - scene.camera.axis.norm()).norm() u += np.array([0.,0.,0.,delta.x,delta.y,delta.z]) scene.camera.axis = epsilon if 'right' in k: epsilon = scene.camera.axis.rotate(angle = -1*turn_vel*dt*(1+turn_error*randn()),axis = scene.up).norm() delta = (epsilon - scene.camera.axis.norm()).norm() u += np.array([0.,0.,0.,delta.x,delta.y,delta.z]) scene.camera.axis = epsilon if 'left' in k: epsilon = scene.camera.axis.rotate(angle = turn_vel*dt*(1+turn_error*randn()),axis = scene.up).norm() delta = (epsilon - scene.camera.axis).norm() u += np.array([0.,0.,0.,delta.x,delta.y,delta.z]) scene.camera.axis = epsilon scene.camera.axis.mag = 1 scene.forward.mag = 1 scene.up.mag = 1 #Update Pos - do I need error in this? pos = np.array([scene.camera.pos.x,scene.camera.pos.y,scene.camera.pos.z, scene.camera.axis.norm().x,scene.camera.axis.norm().y,scene.camera.axis.norm().z]) #x y z x bearing y bearing z bearing #Predict predict(particles = particles, u = u, std = [move_error,move_error,move_error,turn_error,turn_error,turn_error], dt = 1.) #update update(particles = particles, weights = weights, z = pos, R = [move_error,move_error,move_error,turn_error,turn_error,turn_error]) #Neff and resample if neff(weights) < threshold: indexes = systematic_resample(weights) resample_from_index(particles, weights, indexes) assert np.allclose(weights, 1/N) #print out error maybe est = estimate(particles, weights) compare_est_pos(est = est, pos = pos)
def __handle_keyboard_inputs(self): """ Pans amount dependent on distance between camera and focus point. Closer = smaller pan amount A = move left (pan) D = move right (pan) W = move up (pan) S = move down (pan) <- = rotate left along camera axes (rotate) -> = rotate right along camera axes (rotate) ^ = rotate up along camera axes (rotate) V = rotate down along camera axes (rotate) Q = roll left (rotate) E = roll right (rotate) ctrl + LMB = rotate (Default Vpython) """ # If camera lock, just skip the function if self.__camera_lock: return # Constants pan_amount = 0.02 # units rot_amount = 1.0 # deg # Current settings cam_distance = self.scene.camera.axis.mag cam_pos = vector(self.scene.camera.pos) cam_focus = vector(self.scene.center) # Weird manipulation to get correct vector directions. (scene.camera.up always defaults to world up) cam_axis = (vector(self.scene.camera.axis)) # X cam_side_axis = self.scene.camera.up.cross(cam_axis) # Y cam_up = cam_axis.cross(cam_side_axis) # Z cam_up.mag = cam_axis.mag # Get a list of keys keys = keysdown() # Userpan uses ctrl, so skip this check to avoid changing camera pose while shift is held if 'shift' in keys: return ################################################################################################################ # PANNING # Check if the keys are pressed, update vectors as required # Changing camera position updates the scene center to follow same changes if 'w' in keys: cam_pos = cam_pos + cam_up * pan_amount if 's' in keys: cam_pos = cam_pos - cam_up * pan_amount if 'a' in keys: cam_pos = cam_pos + cam_side_axis * pan_amount if 'd' in keys: cam_pos = cam_pos - cam_side_axis * pan_amount # Update camera position before rotation (to keep pan and rotate separate) self.scene.camera.pos = cam_pos ################################################################################################################ # Camera Roll # If only one rotation key is pressed if 'q' in keys and 'e' not in keys: # Rotate camera up cam_up = cam_up.rotate(angle=-radians(rot_amount), axis=cam_axis) # Set magnitude as it went to inf cam_up.mag = cam_axis.mag # Set self.scene.up = cam_up # If only one rotation key is pressed if 'e' in keys and 'q' not in keys: # Rotate camera up cam_up = cam_up.rotate(angle=radians(rot_amount), axis=cam_axis) # Set magnitude as it went to inf cam_up.mag = cam_axis.mag # Set self.scene.up = cam_up ################################################################################################################ # CAMERA ROTATION d = cam_distance move_dist = sqrt(d ** 2 + d ** 2 - 2 * d * d * cos(radians(rot_amount))) # SAS Cosine # If only left not right key if 'left' in keys and 'right' not in keys: # Calculate distance to translate cam_pos = cam_pos + norm(cam_side_axis) * move_dist # Calculate new camera axis cam_axis = -(cam_pos - cam_focus) if 'right' in keys and 'left' not in keys: cam_pos = cam_pos - norm(cam_side_axis) * move_dist cam_axis = -(cam_pos - cam_focus) if 'up' in keys and 'down' not in keys: cam_pos = cam_pos + norm(cam_up) * move_dist cam_axis = -(cam_pos - cam_focus) if 'down' in keys and 'up' not in keys: cam_pos = cam_pos - norm(cam_up) * move_dist cam_axis = -(cam_pos - cam_focus) # Update camera position and axis self.scene.camera.pos = cam_pos self.scene.camera.axis = cam_axis