def read_inputs(): global mymouse, my, mx, rot, tilt, keep_running, xm, zm, mv_run, mv_run_diff, body_orientation, flag_jump, flag_view k = mykeys.read() # Read Keyboard inputs if k >-1: if k == 119: #key w forward zm+=1 mv_run += math.fabs(avatar_speed*2/3) mv_run_diff = 1 body_orientation = 180 elif k == 115: #kry s back zm+= -1 mv_run += math.fabs(avatar_speed*2/3) mv_run_diff = 1 body_orientation = 0 elif k == 97: #key a left xm+= -1 mv_run += math.fabs(avatar_speed*2/3) mv_run_diff = 1 body_orientation = 90 elif k == 100: #key d right xm+=1 mv_run += math.fabs(avatar_speed*2/3) mv_run_diff = 1 body_orientation = 270 elif k == 99: #key c jump flag_jump = 28 elif k == 111: #key c jump view = flag_view flag_view = not view elif k == 112: #key p picture pi3d.screenshot("forestWalk" + str(scshots) + ".jpg") scshots += 1 elif k == 10: #key RETURN mc = 0 elif k == 27: #Escape key to exit print("***** EXIT *****") DISPLAY.destroy() keep_running = False mykeys.close() if USE_SERIAL: ser.stop() mymouse.stop() DISPLAY.stop() elif k == ord('f'): roll = 1.0 mx, my = mymouse.velocity() #change to position() if Camera switched to absolute=True (default) buttons = mymouse.button_status() rot = - mx * 0.8 tilt = my * 0.8
def pi3d_loop(self): self.DISPLAY.loop_running() if self.cube.show_flag: self.cube.draw() im = QtGui.QImage(pi3d.screenshot(), W, H, QtGui.QImage.Format_RGB888) self.img.setPixmap(QtGui.QPixmap.fromImage(im)) self.cube.show_flag = False
def read_inputs(): global step, crab, mymouse, my, mx, rot, tilt, keep_running #Press ESCAPE to terminate k = mykeys.read() if k > -1: if k == 119: #key w forward step = [0.5, 0.0, 0.5] crab = False elif k == 115: #kry s back step = [-0.25, 0.0, -0.25] crab = False elif k == 97: #key a crab left step = [0.25, 0.0, 0.25] crab = True elif k == 100: #key d crab right step = [-0.25, 0.0, -0.25] crab = True elif k == 112: #key p picture pi3d.screenshot("forestWalk" + str(scshots) + ".jpg") scshots += 1 elif k == 10: #key RETURN mc = 0 elif k == 27: #Escape key keep_running = False mykeys.close() if USE_SERIAL: ser.stop() mymouse.stop() DISPLAY.stop() elif k == ord('f'): roll = 1.0 mx, my = mymouse.velocity( ) #change to position() if Camera switched to absolute=True (default) buttons = mymouse.button_status() rot = -mx * 0.2 tilt = my * 0.2
def key_handler_func(self, sourceType, sourceIndex, key, value): if self.debug: print("key=" + str(key), pi3d.event.Event.code_to_key(key), "[", sourceIndex, "] =", value) if DEFAULT_KEY_FORWARD == key: self.is_forward_pressed = value > 0 elif DEFAULT_KEY_BACKWARD == key: self.is_backward_pressed = value > 0 elif DEFAULT_KEY_STRAFE_RIGHT == key: self.is_strafe_right_pressed = value > 0 elif DEFAULT_KEY_STRAFE_LEFT == key: self.is_strafe_left_pressed = value > 0 elif ((DEFAULT_KEY_ACTION == key) or (DEFAULT_JOYPAD_BUTTON_ACTION == key) or (DEFAULT_MOUSE_BUTTON_ACTION == key)): if value == 0: self.on_action_released() elif value == 1: self.on_action_pressed() elif ((DEFAULT_KEY_JUMP == key) or (DEFAULT_JOYPAD_BUTTON_JUMP == key) or (DEFAULT_MOUSE_BUTTON_JUMP == key)): if value == 0: self.on_jump_released() elif value == 1: self.on_jump_pressed() elif DEFAULT_KEY_SCREENSHOT == key and value == 1: pi3d.screenshot("vr_screenshot_" + str(self.screenshot_count) + ".jpg") self.screenshot_count += 1 elif DEFAULT_KEY_QUIT == key or DEFAULT_JOYPAD_BUTTON_QUIT == key: self.stop()
if inFlag and abs(man.z() - building.zpos) > 55: inFlag = False for b in building.model: b.set_light(outLight, 0) mymap.set_light(outLight, 0) if inputs.key_state("KEY_APOSTROPHE"): #key ' tilt -= 2.0 if inputs.key_state("KEY_SLASH"): #key / tilt += 2.0 if inputs.key_state("KEY_A"): #key A rot += 2 if inputs.key_state("KEY_D"): #key D rot -= 2 if inputs.key_state("KEY_P"): #key P #record = not(record) while inputs.key_state("KEY_P"): inputs.do_input_events() # wait for key to go up pi3d.screenshot("silo" + str(scshots) + ".jpg") scshots += 1 if inputs.key_state("KEY_ENTER"): #key RETURN mc = 0 if inputs.key_state("KEY_X"): #key RETURN while inputs.key_state("KEY_X"): inputs.do_input_events() # wait for key to go up mouseOn != mouseOn inputs.grab_by_type("keyboard", grab=mouseOn) inputs.release() DISPLAY.destroy()
mycylinder.draw(shader, [patimg, shapebump, shapeshine], 4.0, 0.1) mycylinder.rotateIncY(2) mycylinder.rotateIncZ(1) mytcone.draw(shader, [coffimg]) mytcone.rotateIncY(2) mytcone.rotateIncZ(-1) mytorus.draw(shader, [patimg, shapebump, shapeshine], 4.0, 0.6) mytorus.rotateIncY(3) mytorus.rotateIncZ(1) mylathe.draw(shader, [patimg]) mylathe.rotateIncY(2) mylathe.rotateIncZ(1) myPlane.draw(shader, [coffimg]) myPlane.rotateIncX(9) mystring.draw() mystring.rotateIncZ(0.5) k = mykeys.read() if k >-1: if k==112: pi3d.screenshot("shapesPic.jpg") elif k==27: mykeys.close() DISPLAY.destroy() break
def main(): print("pi3d Geodesic Plotter: {}".format(argv)) if len(argv) < 2: raise Exception('>>> ERROR! Please supply a parameter file name <<<') parameters = loads(open(argv[1]).read())['IC'] interval = parameters['plotratio'] m = parameters['M'] if 'M' in parameters else 1.0 a = parameters['Lfac'] if 'Lfac' in parameters else parameters['a'] if 'a' in parameters else 1.0 a2 = a**2 # Setup display and initialise pi3d display = Display.create(x=0, y=0, frames_per_second=0) display.set_background(0, 0, 0, 1) # r,g,b,alpha # Camera camera = Camera() rot = tilt = 0 rot_tilt = True cam_rad = 30.0 # Bodies body_shader = Shader("mat_light") track_shader = Shader("mat_flat") black_hole = Body(body_shader, (0.0, 0.0, 1.0), m * (1.0 + sqrt(1.0 - a2)), position=[0.0, 0.0, 0.0]) particle = Body(body_shader, (0.0, 1.0, 0.0), 0.125, track_shader=track_shader) # Enable key presses axis = Lines(vertices=[(0, 0, 5,), (0, 0, -5,)]) keys = Keyboard() # Display scene counter = 1 cumulative_error = 0.0 line = stdin.readline() while display.loop_running(): data = loads(line) # monitor errors current_error = data['v4e'] cumulative_error += current_error if current_error >= 0.0 else -current_error # camera control if rot_tilt: camera.reset() camera.rotate(-tilt, rot, 0) camera.position((cam_rad * sin(radians(rot)) * cos(radians(tilt)), cam_rad * sin(radians(tilt)), -cam_rad * cos(radians(rot)) * cos(radians(tilt)))) rot_tilt = False # plot the black hole black_hole.position_and_draw() axis.draw() # plot the orbiter if counter % interval == 0: r = float(data['r']) th = float(data['th']) ph = float(data['ph']) ra_sth = sqrt(r**2 + a2) * sin(th) particle.pos = [ra_sth * cos(ph), ra_sth * sin(ph), r * cos(th)] particle.set_material(error_colour(current_error)) particle.position_and_draw(trace_material=error_colour(cumulative_error / counter)) # process keyboard input key = keys.read() if key > -1: rot_tilt = True if key == 112: screenshot("orbit.jpg") elif key == 119: # key W rotate camera up tilt += 2.0 elif key == 115: # kry S down tilt -= 2.0 elif key == 97: # key A left rot -= 2 elif key == 100: # key D right rot += 2 elif key == 61: # key += in cam_rad -= 0.5 elif key == 45: # key _- out cam_rad += 0.5 elif key == 27: keys.close() display.destroy() break # prepare for next iteration line = stdin.readline() counter += 1 if not line: display.stop()
for i in range(5): # make time interval for physics fifth of frame time sun.pull([earth, moon, jupiter]) earth.pull([sun, moon, jupiter]) moon.pull([sun, earth, jupiter]) jupiter.pull([sun, earth, moon]) sun.position_and_draw() earth.position_and_draw() moon.position_and_draw() jupiter.position_and_draw() myecube.draw() k = mykeys.read() if k > -1: rottilt = True if k == 112: pi3d.screenshot("orbit.jpg") elif k == 119: #key W rotate camera up tilt += 2.0 elif k == 115: #kry S down tilt -= 2.0 elif k == 97: #key A left rot -= 2 elif k == 100: #key D right rot += 2 elif k == 61: #key += in camRad -= 0.5 elif k == 45: #key _- out camRad += 0.5 elif k == 27: mykeys.close() DISPLAY.destroy()
if inFlag and abs(man.z() - building.zpos) > 55: inFlag = False for b in building.model: b.set_light(outLight, 0) mymap.set_light(outLight, 0) if inputs.key_state("KEY_APOSTROPHE"): #key ' tilt -= 2.0 if inputs.key_state("KEY_SLASH"): #key / tilt += 2.0 if inputs.key_state("KEY_A"): #key A rot += 2 if inputs.key_state("KEY_D"): #key D rot -= 2 if inputs.key_state("KEY_P"): #key P #record = not(record) while inputs.key_state("KEY_P"): inputs.do_input_events() # wait for key to go up pi3d.screenshot("silo"+str(scshots)+".jpg") scshots += 1 if inputs.key_state("KEY_ENTER"): #key RETURN mc = 0 if inputs.key_state("KEY_X"): #key RETURN while inputs.key_state("KEY_X"): inputs.do_input_events() # wait for key to go up mouseOn != mouseOn inputs.grab_by_type("keyboard", grab=mouseOn) inputs.release() DISPLAY.destroy()
def world3dA(inHeightmap, inWidth, inDepth, inHeight, inTextureMap, inBumpMap): from PIL import Image import numpy as np DISPLAY = pi3d.Display.create(x=50, y=50, far=5000, near=0.5) CAMERA = pi3d.Camera.instance() base_tex = np.array(Image.open(inTextureMap)) # texture for land base_gr = base_tex.copy() ix = np.where(base_gr[:,:,2] > 20) # i.e. was blue base_gr[ix[0], ix[1], 1] += 50 # increase green base_gr[ix[0], ix[1], 2] = 0 # reduce blue texg = pi3d.Texture(base_gr) # texture for water base_bl = base_tex.copy() base_bl[:,:] = [0, 0, 60, 170] # uniform slightly transparrent texb = pi3d.Texture(base_bl) grass_tex = pi3d.Texture('/home/patrick/raspberry_pi/pi3d_demos/textures/grasstile_n.jpg') w_norm = pi3d.Texture('/home/patrick/raspberry_pi/pi3d_demos/textures/water/n_norm000.png') shader = pi3d.Shader("uv_bump") rshader = pi3d.Shader("uv_reflect") mapwidth = inWidth mapdepth = inDepth mapheight = inHeight mymap = pi3d.ElevationMap(inHeightmap, width=mapwidth, depth=mapdepth, height=mapheight, divx=199, divy=199, ntiles=1, name="sub", y=-0.0) mymap.set_draw_details(shader, [texg, grass_tex], 200.0) wmap = pi3d.ElevationMap(inHeightmap, width=mapwidth, depth=mapdepth, height=mapheight * 0.1, divx=40, divy=40, ntiles=1, name="water", y=25.0) wmap.set_draw_details(rshader, [texb, w_norm, texg], 500.0, 0.2) rot = 0.0 tilt = 0.0 height = 20.0 viewHeight = 1.5 sky = 2000 xm, ym, zm = 0.0, height, 0.0 onGround = False mykeys = pi3d.Keyboard() mymouse = pi3d.Mouse(restrict=False) mymouse.start() omx, omy = mymouse.position() fr = 0 while DISPLAY.loop_running(): mx, my = mymouse.position() rot -= (mx - omx) * 0.2 tilt -= (my - omy) * 0.2 omx = mx omy = my CAMERA.reset() CAMERA.rotate(-tilt, rot, 0) CAMERA.position((xm, ym, zm)) mymap.draw() wmap.draw() k = mykeys.read() if k > -1: if k == 48: # ESCAPE key - '0' Key DISPLAY.destroy() mykeys.close() mymouse.stop() break elif k == 87 or k == 119: # if inputs.key_state("KEY_W"): xm -= sin(radians(rot)) * 2.0 zm += cos(radians(rot)) * 2.0 elif k == 83 or k == 115: # elif inputs.key_state("KEY_S"): xm += sin(radians(rot)) * 2.0 zm -= cos(radians(rot)) * 2.0 elif k == 82 or k == 114: # elif inputs.key_state("KEY_R"): ym += 4 onGround = False elif k == 84 or k == 116: # elif inputs.key_state("KEY_T"): ym -= 4 ym -= 0.2 xm = limit(xm, -(mapwidth / 2), (mapwidth / 2)) zm = limit(zm, -(mapdepth / 2), (mapdepth / 2)) if ym >= sky: ym = sky ground = max(mymap.calcHeight(xm, zm), wmap.calcHeight(xm, zm)) + viewHeight if (onGround is True) or (ym <= ground): ym = ground onGround = True pi3d.screenshot("/home/patrick/Downloads/Untitled Folder/scr_caps/world{:04d}.jpg".format(fr)) fr += 1
#Press ESCAPE to terminate k = mykeys.read() if k >-1: if k==119: #key W xm -= math.sin(math.radians(rot)) zm += math.cos(math.radians(rot)) ym = mymap.calcHeight(xm, zm) + avhgt elif k==115: #kry S xm += math.sin(math.radians(rot)) zm -= math.cos(math.radians(rot)) ym = mymap.calcHeight(xm, zm) + avhgt elif k==39: #key ' tilt -= 2.0 elif k==47: #key / tilt += 2.0 elif k==97: #key A rot -= 2 elif k==100: #key D rot += 2 elif k==112: #key P pi3d.screenshot("forestWalk"+str(scshots)+".jpg") scshots += 1 elif k==10: #key RETURN mc = 0 elif k==27: #Escape key mykeys.close() mymouse.stop() DISPLAY.stop() break
mymap.draw() myecube.draw() #defocus.end_blur() #<<<<<<<<<<<<<<< #defocus.blur(ball, 4, 15, 2) #<<<<<<<<<<<<<<< #defocus.blur(mymap, 4, 15, 2) #<<<<<<<<<<<<<<< #defocus.blur(myecube, 4, 15, 2) #<<<<<<<<<<<<<<< monster.draw() # write up the score score0.draw() score1.draw() camera.was_moved = False #Press ESCAPE to terminate k = mykeys.read() if k == 27: #Escape key #defocus.delete_buffers() #<<<<<<<<<<<<<<< DISPLAY.destroy() mykeys.close() mymouse.stop() break elif k == 112: #key P pi3d.screenshot("pong.jpg") # attempt to tidy up! quit()
#======================================== # load model_loadmodel mymodel = pi3d.Model(file_string='models/Triceratops/Triceratops.egg', name='Triceratops', x=0, y=-1, z=40, sx=0.005, sy=0.005, sz=0.005) mymodel.set_shader(shader) # Fetch key presses mykeys = pi3d.Keyboard() while 1: DISPLAY.clear() mymodel.draw() mymodel.rotateIncZ(0.001) mymodel.rotateIncX(-0.00317543) mymodel.rotateIncY(0.11) k = mykeys.read() if k >-1: if k==112: pi3d.screenshot('Triceratops.jpg') elif k==27: mykeys.close() DISPLAY.destroy() break else: print(k) DISPLAY.swap_buffers()
mymap.draw() myecube.draw() #defocus.end_blur() #<<<<<<<<<<<<<<< #defocus.blur(ball, 4, 15, 2) #<<<<<<<<<<<<<<< #defocus.blur(mymap, 4, 15, 2) #<<<<<<<<<<<<<<< #defocus.blur(myecube, 4, 15, 2) #<<<<<<<<<<<<<<< monster.draw() # write up the score score0.draw() score1.draw() camera.was_moved = False #Press ESCAPE to terminate k = mykeys.read() if k==27: #Escape key #defocus.delete_buffers() #<<<<<<<<<<<<<<< DISPLAY.destroy() mykeys.close() mymouse.stop() break elif k==112: #key P pi3d.screenshot("pong.jpg") # attempt to tidy up! quit()
offset = (offset + do) % 1.0 # move texture offset in v direction mywater.set_offset((0.0, offset)) mystring.draw() mystring.rotateIncZ(0.05) if time.time() > next_time: i_n = (i_n + 1) % num_n mywater.buf[0].textures[0] = waterbump[i_n] next_time = time.time() + spf av_fps = av_fps*0.75 + tick/spf*0.25 # exp smooth moving average print("{:5.1f} FPS".format(av_fps)) tick = 0 tick += 1 fr += 1 myshape.set_material((math.sin(fr*0.102) * 0.25 + 0.5, math.sin(fr*0.073) * 0.25 + 0.5, math.sin(fr*0.067) * 0.25 + 0.5)) k = mykeys.read() if k==112: pi3d.screenshot("water1.jpg") elif k==27: mykeys.close() DISPLAY.destroy() break quit()
myshape.draw() defocus.end_blur() # 2. drawing now back to screen. The texture can now be used by defocus.blur() # 3. redraw these two objects applying a distance blur effect ############### defocus.blur(myshape, 4, 9, 5) # 4 is focal distance, >= 9 distance will get defocus.blur(mysprite, 4, 9, 5) # 5 x blurring, nearer than focus also blurs myshape.rotateIncY(1.247) myshape.rotateIncX(0.1613) mystring.draw() mystring.rotateIncZ(0.05) if time.time() > next_time: print("FPS:", tick / 2.0) tick=0 next_time = time.time() + 2.0 tick+=1 k = mykeys.read() if k==112: pi3d.screenshot("blur1.jpg") elif k==27: mykeys.close() defocus.delete_buffers() DISPLAY.destroy() break quit()
#Press ESCAPE to terminate k = mykeys.read() if k > -1: if k == 119: #key W xm -= math.sin(math.radians(rot)) zm += math.cos(math.radians(rot)) elif k == 115: #kry S xm += math.sin(math.radians(rot)) zm -= math.cos(math.radians(rot)) elif k == 39: #key ' tilt -= 2.0 print(tilt) elif k == 47: #key / tilt += 2.0 elif k == 97: #key A rot -= 2 elif k == 100: #key D rot += 2 elif k == 112: #key P pi3d.screenshot("BuckfastAbbey"+str(scshots)+".jpg") scshots += 1 elif k == 27: #Escape key mykeys.close() mymouse.stop() DISPLAY.destroy() break else: print(k) quit()
post.draw({ 2: iTIME, 3: iTIMEDELTA, 5: iFRAME, 12: YR, 13: MTH, 14: DAY, 15: iDateSecondsSinceMidnight }) ## updating variables ## iFRAME += 1 #print(int(FRAME/fps)) # calculate seconds based on framerate, not time.time # draw the buffer into a PIL image imageMatrix = Image.fromarray(pi3d.screenshot()) ## DRAW MATRIX ## # draw the video like this if it matches the pixel resolution of the matrix (32 x 32) # if the video is larger than the resolution of the matrix, it will sample lower left corner of you video matrix.SetImage(imageMatrix, 0, 0) # Another option is to sample from a subset of the video pixels # This will sample 32 x 32 from location sampleX, sampleY in the video. # NOTE: must have the minus) #sampleX = (W/2) #sampleY = (H/2) #matrix.SetImage(imageMatrix,-sampleX,-sampleY)
skull_model = pi3d.Model(file_string='models/skull_1.obj', name='skull_1', y=-1.8, z=6.0, sx=0.5, sy=0.5, sz=0.5) skull_model.set_shader(skull_shader) # Fetch key presses the_keys = pi3d.Keyboard() # Display scene while DISPLAY.loop_running(): earth_sphere.rotateIncY(-0.1) atmo_sphere.rotateIncY(-0.14) skull_model.rotateIncY(-0.1) skull_model.draw() earth_sphere.draw(shader, [earth_image]) star_plane.draw(flatsh,[stars_image]) atmo_sphere.draw(shader, [clouds_image]) # this has to be last as blend = True k = the_keys.read() if k >-1: # p key pressed if k==112: pi3d.screenshot("earth_skull.jpg") # escape key pressed elif k==27: the_keys.close() DISPLAY.stop() break
# Display scene and rotate cuboid while DISPLAY.loop_running(): CAMERA.reset() CAMERA.rotate(tilt, 0, 0) CAMERA.rotate(0, rot, 0) myecube.draw() mx, my = mymouse.position() #if mx>display.left and mx<display.right and my>display.top and my<display.bottom: rot -= (mx - omx) * 0.4 tilt += (my - omy) * 0.4 omx = mx omy = my #Press ESCAPE to terminate k = mykeys.read() if k > -1: if k == 112: #key P pi3d.screenshot('envcube.jpg') elif k == 27: #Escape key mykeys.close() mymouse.stop() DISPLAY.stop() break else: print(k)
CAMERA.reset((DISPLAY.near, DISPLAY.far, DISPLAY.fov, DISPLAY.width / float(DISPLAY.height))) win.resized = False if win.ev == "key": if win.key == "w": xm -= math.sin(mouserot * rads) * 2 zm += math.cos(mouserot * rads) * 2 if win.key == "s": xm += math.sin(mouserot * rads) * 2 zm -= math.cos(mouserot * rads) * 2 if win.key == "a": mouserot -= 2 if win.key == "d": mouserot += 2 if win.key == "p": pi3d.screenshot("MarsStation.jpg") if win.key == "Escape": try: print("bye,bye1") DISPLAY.destroy() try: win.destroy() except: pass mymouse.stop() exit() except: pass if win.ev == "drag" or win.ev == "click" or win.ev == "wheel": xm -= math.sin(mouserot * rads) * 2 zm += math.cos(mouserot * rads) * 2
image_box.connect("motion_notify_event", mot, cube) image_box.set_events(gtk.gdk.EXPOSURE_MASK |gtk.gdk.LEAVE_NOTIFY_MASK |gtk.gdk.BUTTON_PRESS_MASK |gtk.gdk.POINTER_MOTION_MASK |gtk.gdk.POINTER_MOTION_HINT_MASK) box1.show() box2.show() win.show_all() ''' gtk needs to run in its own thread to allow the pi3d drawing to happen at the same time''' gdk.threads_init() t = threading.Thread(target=gtk.main, name='GTK thread') t.daemon = True t.start() while DISPLAY.loop_running(): if cube.show_flag: cube.draw() img_gtk.set_from_pixbuf(gtk.gdk.pixbuf_new_from_array( pi3d.screenshot(), gtk.gdk.COLORSPACE_RGB, 8)) ''' see note above about python 3 img_gtk.set_from_pixbuf(GdkPixbuf.Pixbuf.new_from_data(pi3d.screenshot(), GdkPixbuf.Colorspace.RGB, True, 8, W, H, W * 4)) ''' win.show_all() cube.show_flag = False
myshadows.start_cast([LX, LY, LZ]) #[xm, ym, zm]) for cube in cubes: myshadows.cast_shadow(cube) myshadows.end_cast() mymap.draw(shader, [mountimg1, bumpimg, myshadows], 128.0, 0.0, light_camera=myshadows.LIGHT_CAM) for cube in cubes: cube.draw(lightsh, [checkerboard]) #, light_camera=myshadows.LIGHT_CAM) k = mykeys.read() if k == 112: pi3d.screenshot("capture" + str(camera_seed) + "_" + str(shadow_seed) + ".jpg") with open( "receipt" + str(camera_seed) + "_" + str(shadow_seed) + ".txt", 'w') as f: f.write("Time:%02d-%02d-%02d-%02d-%04d\n" % (minute, hour, day, month, year)) f.write("Pos:%0.4f,%0.4f\n" % (lat, lon)) f.write("Camera:%0.4f,%0.4f\n" % (-camera_az, camera_ev)) f.write("Light:%0.4f,%0.4f\n" % (light_az, light_ev)) break elif k == 27: #Escape key break CAMERA.was_moved = False mykeys.close() DISPLAY.stop()
CAMERA.reset((DISPLAY.near, DISPLAY.far, DISPLAY.fov, DISPLAY.width / float(DISPLAY.height))) win.resized = False if win.ev == "key": if win.key == "w": xm-=math.sin(mouserot*rads)*2 zm+=math.cos(mouserot*rads)*2 if win.key == "s": xm+=math.sin(mouserot*rads)*2 zm-=math.cos(mouserot*rads)*2 if win.key == "a": mouserot -= 2 if win.key == "d": mouserot += 2 if win.key == "p": pi3d.screenshot("ConferenceHall.jpg") if win.key == "Escape": try: print("bye,bye1") DISPLAY.destroy() try: win.destroy() except: pass mymouse.stop() exit() except: pass if win.ev=="drag" or win.ev=="click" or win.ev=="wheel": xm-=math.sin(mouserot*rads)*2 zm+=math.cos(mouserot*rads)*2
#Press ESCAPE to terminate k = mykeys.read() if k > -1: if k == 119: #key W xm -= math.sin(math.radians(rot)) zm += math.cos(math.radians(rot)) elif k == 115: #kry S xm += math.sin(math.radians(rot)) zm -= math.cos(math.radians(rot)) elif k == 39: #key ' tilt -= 2.0 print(tilt) elif k == 47: #key / tilt += 2.0 elif k == 97: #key A rot -= 2 elif k == 100: #key D rot += 2 elif k == 112: #key P pi3d.screenshot("BuckfastAbbey" + str(scshots) + ".jpg") scshots += 1 elif k == 27: #Escape key mykeys.close() mymouse.stop() DISPLAY.destroy() break else: print(k) quit()
mycylinder.rotateIncY(2) mycylinder.rotateIncZ(1) mytcone.draw(shader, [coffimg]) mytcone.rotateIncY(2) mytcone.rotateIncZ(-1) mytorus.draw(shinesh, [patimg, shapebump, shapeshine], 4.0, 0.3) mytorus.rotateIncY(3) mytorus.rotateIncZ(1) myPlane.draw(shader, [coffimg]) myPlane.rotateIncX(3.1) mylathe.draw( ) # draw details set previously. NB after Plane as transparent mylathe.rotateIncY(0.2) mylathe.rotateIncZ(0.4) mylathe.rotateIncX(0.11) mystring.draw() mystring.rotateIncZ(0.5) k = mykeys.read() if k > -1: if k == 112: pi3d.screenshot("shapesPic.jpg") elif k == 27: mykeys.close() DISPLAY.destroy() break
# distance from the camera. dist = random.uniform(2.0, 10.0) rasp.position(random.uniform(-1.0, 1.0) * dist, random.uniform(0.0, 4.0) * dist, dist) rasp.rotateToZ(random.uniform(0.0, 360.0)) RASPBERRIES.append(rasp) DISPLAY.add_sprites(rasp) # Fetch key presses KEYBOARD = pi3d.Keyboard() while DISPLAY.loop_running(): for b in RASPBERRIES: b.translateY(-0.3) b.rotateIncZ(1) if b.y() < -2 * b.z(): b.positionX((random.uniform(0.0, 2.0) - 1) * b.z()) b.translateY(4.0 * b.z()) k = KEYBOARD.read() if k >-1: if k == 27: KEYBOARD.close() DISPLAY.stop() break elif k == 112: pi3d.screenshot('raspberryRain.jpg')
# distance from the camera. dist = random.uniform(2.0, 10.0) rasp.position( random.uniform(-1.0, 1.0) * dist, random.uniform(0.0, 4.0) * dist, dist) rasp.rotateToZ(random.uniform(0.0, 360.0)) RASPBERRIES.append(rasp) DISPLAY.add_sprites(rasp) # Fetch key presses KEYBOARD = pi3d.Keyboard() while DISPLAY.loop_running(): for b in RASPBERRIES: b.translateY(-0.3) b.rotateIncZ(1) if b.y() < -2 * b.z(): b.positionX((random.uniform(0.0, 2.0) - 1) * b.z()) b.translateY(4.0 * b.z()) k = KEYBOARD.read() if k > -1: if k == 27: KEYBOARD.close() DISPLAY.stop() break elif k == 112: pi3d.screenshot('raspberryRain.jpg')
size = random.uniform(0.5, 2.5) rasp = pi3d.ImageSprite(texture=TEXTURE, shader=SHADER, w=size, h=size) # distance from the camera. dist = random.uniform(2.0, 10.0) rasp.position(random.uniform(-1.0, 1.0) * dist, random.uniform(0.0, 4.0) * dist, dist) rasp.rotateToZ(random.uniform(0.0, 360.0)) RASPBERRIES.append(rasp) DISPLAY.add_sprites(rasp) # Fetch key presses KEYBOARD = pi3d.Keyboard() while DISPLAY.loop_running(): for b in RASPBERRIES: b.translateY(-0.1) b.rotateIncZ(1) if b.y() < -2 * b.z(): b.positionX((random.uniform(0.0, 2.0) - 1) * b.z()) b.translateY(4.0 * b.z()) k = KEYBOARD.read() if k > -1: if k == 27: KEYBOARD.close() DISPLAY.stop() break elif k == 112: pi3d.screenshot("raspberryRain.jpg")
while DISPLAY.loop_running(): CAMERA.reset() CAMERA.rotate(tilt, 0, 0) CAMERA.rotate(0, rot, 0) myecube.draw() mx, my = mymouse.position() #if mx>display.left and mx<display.right and my>display.top and my<display.bottom: rot -= (mx - omx)*0.4 tilt += (my - omy)*0.4 omx = mx omy = my #Press ESCAPE to terminate k = mykeys.read() if k >-1: if k==112: #key P pi3d.screenshot('envcube.jpg') elif k==27: #Escape key mykeys.close() mymouse.stop() DISPLAY.stop() break else: print(k)
import pi3d # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=100, y=100, background=(0.2, 0.4, 0.6, 1)) shader = pi3d.Shader("shaders/uv_reflect") # ======================================== # load bump and reflection textures bumptex = pi3d.Texture("textures/floor_nm.jpg") shinetex = pi3d.Texture("textures/stars.jpg") # load model_loadmodel mymodel = pi3d.Model(file_string="models/teapot.obj", name="teapot", z=4) mymodel.set_shader(shader) mymodel.set_normal_shine(bumptex, 16.0, shinetex, 0.5) # Fetch key presses mykeys = pi3d.Keyboard() while DISPLAY.loop_running(): mymodel.draw() mymodel.rotateIncY(2.0) mymodel.rotateIncZ(0.1) mymodel.rotateIncX(0.3) k = mykeys.read() if k > -1: if k == 112: pi3d.screenshot("teapot.jpg") elif k == 27: mykeys.close() DISPLAY.destroy() break
tilt = my * 0.1 -10.0 if tilt > 5.0: tilt = 5.0 #Press ESCAPE to terminate k = mykeys.read() if k >-1: cam_vec = CAMERA.get_direction() if k==119: #key W xm += cam_vec[0] zm += cam_vec[2] elif k==115: #kry S xm -= cam_vec[0] zm -= cam_vec[2] elif k==97: #key A xm -= cam_vec[2] * 0.25 zm += cam_vec[0] * 0.25 elif k==100: #key D xm += cam_vec[2] * 0.25 zm -= cam_vec[0] * 0.25 elif k==112: #key P pi3d.screenshot("walkaboutRobot.jpg") elif k==27: #Escape key mykeys.close() mymouse.stop() DISPLAY.destroy() break else: print(k) ym = mymap.calcHeight(xm, zm) + avhgt
dy = -1.0 elif my < 0.0: dy = 1.0 mx += dx * rgb[1] / 100.0 my += dy * rgb[2] / 50.0 myshape.scale(mx, my, mx) myshape.rotateIncY(0.6471 + rgb[0]) myshape.rotateIncX(0.513 - rgb[2]) mysprite.rotateIncZ(0.5) if tm > pic_next: """change the pictures and start a thread to load into tex_list""" pic_next += pic_dt myshape.set_draw_details(shader, [tex_list[slot % 2]]) mysprite.set_draw_details(flatsh, [tex_list[slot % 2]]) slot += 1 t = threading.Thread(target=_tex_load, args=(tex_list, slot % 2, tFiles[slot % nTex])) t.daemon = True t.start() k = mykeys.read() if k==112: pi3d.screenshot("post.jpg") elif k==27: mykeys.close() DISPLAY.destroy() break p.stdin.write(b'QUIT\n')
sc = (sc + ds) % 10.0 myshape.set_custom_data(48, [tm, sc, -0.5 * sc]) # NB NB for pi3d prior to v1.15 the array index would be 48 rather than 16 post.start_capture(clear=clear) # 1. drawing objects now renders to an offscreen texture #################### mysprite.draw() myshape.draw() post.end_capture() # 2. drawing now back to screen. The texture can now be used by post.draw() # 3. redraw these two objects applying a shader effect ############### x = (x + dx) % 5.0 post.draw({48: (2.0 + x), 49: 0.0, 50: 0.0}) mx, my = DISPLAY.mouse.position() myshape.scale(1.0 + mx / 1000.0, 1.0 + my / 1000.0, 1.0 + mx / 1000.0) myshape.rotateIncY(0.6471) myshape.rotateIncX(0.0613) k = mykeys.read() if k == ord('p'): # take screen shot pi3d.screenshot("post.jpg") elif k == 27: # escape mykeys.close() DISPLAY.destroy() break elif k > -1: # any other key toggle OffScreenTexture clear clear = not clear
delta = newes - es es = newes DISPLAY.clear() post.sprite.set_custom_data(48, [es]) post.start_capture() ##<<<<<<<<<<<<<< mymodel.draw() post.end_capture() ##>>>>>>>>>>>>>> post1.start_capture() post.draw() post1.end_capture() post1.draw() mymodel.rotateIncY(0.21) mymodel.set_custom_data(48, [es]) k = mykeys.read() if k > -1: if k == 112: pi3d.screenshot('screen.jpg') elif k == 27: mykeys.close() DISPLAY.destroy() break else: print(k) DISPLAY.swap_buffers()
delayMode = True if setPositions == True: videoPosition = 9500000 clientPlayer.play_at_position(positionCount, videoPosition) positionCount += 1 #delay before playing the next movie time.sleep(.7) if positionCount >= 5: setPositions = False positionCount = 0 if finalCountdown >= 300: #need to insure that the delays are not truncated by this function... isPlayingVideoLoop = False clientPlayer.play_screensaver() finalCountdown = 0 DISPLAY.set_background(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3]) k = mykeys.read() if k > -1: if k == 112: #'p' key is pressed pi3d.screenshot('screenshot.jpg') elif k == 100: #'d' key pressed DEBUG = not DEBUG elif k == 27: clientPlayer.stop_all_runningmovies() mykeys.close() DISPLAY.destroy() break
g.draw() #key press ESCAPE to terminate k = mykeys.read() if k >-1: if k==119: #key W toggle NB no longer need to hold down all the time walk = not(walk) elif k==115: #kry S walk = False dy = -(mymap.calcHeight(xm - dx, zm - dz)+avhgt) - ym if dy > -1.0: xm -= dx zm -= dz ym += dy elif k==112: #key P pi3d.screenshot("amazing"+str(scshots)+".jpg") scshots += 1 elif k==32 and hp > 0: #key SPACE walk = False dy = mymap.calcHeight(xm + dx, zm + dz) + avhgt + ym xm += dx zm += dz ym += dy hp -= 1 #elif k==102: #f key to fire # missile.fire(xm, ym, zm, -dx, -math.sin(tilt*rads), -dz, 10) elif k==27: #Escape key DISPLAY.destroy() mykeys.close() mymouse.stop() break
# 2. drawing now back to screen. The texture can now be used by defocus.blur() # 3. redraw these two objects applying a distance blur effect ############### defocus.blur(myshape, 4, 9, 5) # 4 is focal distance, >= 9 distance will get defocus.blur(mysprite, 4, 9, 5) # 5 x blurring, nearer than focus also blurs myshape.rotateIncY(1.247) myshape.rotateIncX(0.1613) mystring.draw() mystring.rotateIncZ(0.05) if time.time() > next_time: print("FPS:", tick / 2.0) tick = 0 next_time = time.time() + 2.0 tick += 1 k = mykeys.read() if k == 112: pi3d.screenshot("blur1.jpg") elif k == 27: mykeys.close() defocus.delete_buffers() DISPLAY.destroy() break quit()
# Display scene while DISPLAY.loop_running(): myplane.rotateIncZ(0.01) mysphere.rotateIncY(-0.1) mysphere2.rotateIncY(-0.14) mymoon.position(mysphere.x() + m1Rad * sin(rot1), mysphere.y(), mysphere.z() - m1Rad * cos(rot1)) mymoon.rotateIncY(-0.1) mymoon2.position(mymoon.x() - m2Rad * sin(rot2), mymoon.y(), mymoon.z() + m2Rad * cos(rot2)) mymoon2.rotateIncZ(-0.61) mysphere.draw(shader, [earthimg]) mymoon.draw(shinesh, [moonimg, moonbmp], 6.0, 0.0) mymoon2.draw(shinesh, [watimg, moonbmp, starsimg], 3.0, 0.8) myplane.draw(flatsh, [starsimg]) mysphere2.draw(shader, [cloudimg]) # this has to be last as blend = True rot1 += 0.005 rot2 += 0.021 k = mykeys.read() if k > -1: if k == 112: pi3d.screenshot("earth1.jpg") elif k == 27: mykeys.close() DISPLAY.stop() break
offset = (offset + do) % 1.0 # move texture offset in v direction mywater.set_offset((0.0, offset)) mystring.draw() mystring.rotateIncZ(0.05) if time.time() > next_time: i_n = (i_n + 1) % num_n mywater.buf[0].textures[0] = waterbump[i_n] next_time = time.time() + spf av_fps = av_fps * 0.75 + tick / spf * 0.25 # exp smooth moving average print("{:5.1f} FPS".format(av_fps)) tick = 0 tick += 1 fr += 1 myshape.set_material( (math.sin(fr * 0.102) * 0.25 + 0.5, math.sin(fr * 0.073) * 0.25 + 0.5, math.sin(fr * 0.067) * 0.25 + 0.5)) k = mykeys.read() if k == 112: pi3d.screenshot("water1.jpg") elif k == 27: mykeys.close() DISPLAY.destroy() break quit()
tilt = my * 0.1 - 10.0 if tilt > 5.0: tilt = 5.0 #Press ESCAPE to terminate k = mykeys.read() if k > -1: cam_vec = CAMERA.get_direction() if k == 119: #key W xm += cam_vec[0] zm += cam_vec[2] elif k == 115: #kry S xm -= cam_vec[0] zm -= cam_vec[2] elif k == 97: #key A xm -= cam_vec[2] * 0.25 zm += cam_vec[0] * 0.25 elif k == 100: #key D xm += cam_vec[2] * 0.25 zm -= cam_vec[0] * 0.25 elif k == 112: #key P pi3d.screenshot("walkaboutRobot.jpg") elif k == 27: #Escape key mykeys.close() mymouse.stop() DISPLAY.destroy() break else: print(k) ym = mymap.calcHeight(xm, zm) + avhgt
import pi3d # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=100, y=100, background=(0.2, 0.4, 0.6, 1)) shader = pi3d.Shader("shaders/uv_reflect") #======================================== # load bump and reflection textures bumptex = pi3d.Texture("textures/floor_nm.jpg") shinetex = pi3d.Texture("textures/stars.jpg") # load model_loadmodel mymodel = pi3d.Model(file_string='models/teapot.obj', name='teapot', z=4) mymodel.set_shader(shader) mymodel.set_normal_shine(bumptex, 16.0, shinetex, 0.5) # Fetch key presses mykeys = pi3d.Keyboard() while DISPLAY.loop_running(): mymodel.draw() mymodel.rotateIncY(2.0) mymodel.rotateIncZ(0.1) mymodel.rotateIncX(0.3) k = mykeys.read() if k >-1: if k==112: pi3d.screenshot('teapot.jpg') elif k==27: mykeys.close() DISPLAY.destroy() break
box2.pack_start(message, True, True, 5) image_box.connect("motion_notify_event", mot, cube) image_box.set_events(gtk.gdk.EXPOSURE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK) box1.show() box2.show() win.show_all() ''' gtk needs to run in its own thread to allow the pi3d drawing to happen at the same time''' gdk.threads_init() t = threading.Thread(target=gtk.main, name='GTK thread') t.daemon = True t.start() while DISPLAY.loop_running(): if cube.show_flag: cube.draw() img_gtk.set_from_pixbuf( gtk.gdk.pixbuf_new_from_array(pi3d.screenshot(), gtk.gdk.COLORSPACE_RGB, 8)) ''' see note above about python 3 img_gtk.set_from_pixbuf(GdkPixbuf.Pixbuf.new_from_data(pi3d.screenshot(), GdkPixbuf.Colorspace.RGB, True, 8, W, H, W * 4)) ''' win.show_all() cube.show_flag = False
(YR, MTH, DAY) = (iDate.year, iDate.month, iDate.day) iDateSecondsSinceMidnight = iDate.hour * 60 * 60 + iDate.minute * 60 + iDate.second iTIMEDELTA = display.time - last_time # display.time is set at start of each frame last_time = display.time ## pass only the changed shadertoy uniforms into our base shader from shadertoy ## sprite.unif[2] = iTIME # iTime - shader playback time sprite.unif[3] = iTIMEDELTA # iTimeDelta - render time (in seconds) sprite.unif[5] = iFRAME # iFrame - shader playback frame sprite.unif[12:15] = [YR, MTH, DAY] # iDate sprite.unif[15] = iDateSecondsSinceMidnight # seconds since midnight ## pass only the changed uniforms into postprocessing postsh ## post.draw({ 2: iTIME, 3: iTIMEDELTA, 5: iFRAME, 12: YR, 13: MTH, 14: DAY, 15: iDateSecondsSinceMidnight }) ## updating variables ## iFRAME += 1 #print(int(FRAME/fps)) # calculate seconds based on framerate, not time.time # draw the shader buffer into a PIL image image = Image.fromarray(pi3d.screenshot()) matrix.SetImage(image, 0, 0)
sun.pull([earth, moon, jupiter]) earth.pull([sun, moon, jupiter]) moon.pull([sun, earth, jupiter]) jupiter.pull([sun, earth, moon]) sun.position_and_draw() earth.position_and_draw() moon.position_and_draw() jupiter.position_and_draw() myecube.draw() mx, my = mymouse.position() if rot != (mx * -0.1) or tilt != (my * 0.1): rot = mx * -0.1 tilt = my * 0.1 rottilt = True k = mykeys.read() if k >-1: rottilt = True if k==112: pi3d.screenshot("orbit.jpg") elif k==61: #key += in camRad = [r + 0.5 for r in camRad] elif k==45: #key _- out camRad = [r - 0.5 for r in camRad] elif k==27: mykeys.close() DISPLAY.destroy() break
while DISPLAY.loop_running(): mymodel.draw() #mymodel.rotateIncY(0.41) #mymodel.rotateIncZ(0.12) #mymodel.rotateIncX(0.23) k = mykeys.read() if k >-1: #print (k) #if k==32: if k==97: mymodel.rotateIncX(0.23) elif k==115: mymodel.rotateIncX(-0.23) elif k==100: mymodel.rotateIncY(0.41) elif k==102: mymodel.rotateIncY(-0.41) elif k==103: mymodel.rotateIncZ(0.12) elif k==104: mymodel.rotateIncZ(-0.12) elif k==32: print(mymodel.unif[3], mymodel.unif[4], mymodel.unif[5], '\n') if k==112: pi3d.screenshot('teapot.jpg') elif k==27: mykeys.close() DISPLAY.destroy() break
def main(): print(f'Multi 3D ODE Plotter: {argv}', file=stderr) argc = len(argv) - 1 if argc == 0 or argc == 1: # single particle plot from stdin, optional arg is track length files = [stdin] elif argc == 7: # called by IC script, 1 + 6 particle file names files = [] for arg in argv[1:]: files.append(open(arg)) else: raise Exception('>>> ERROR! Please supply 1, 2 or 7 arguments! <<<') # Setup display and initialise pi3d display = Display.create(x=0, y=0, frames_per_second=60) display.set_background(0, 0, 0, 1) # r,g,b,alpha # Camera camera = Camera() rot, tilt = 135.0, 90.0 - 54.73561 cam_rad = 50.0 font = Font( '/usr/share/fonts/truetype/liberation2/LiberationMono-Regular.ttf', color='green', codepoints='-0123456789. txyz:=+', font_size=18) font.blend = True hud = String( camera=Camera(is_3d=False), font=font, is_3d=False, string=f' t {0.0:-5.1f} x {0.0:-5.1f} y {0.0:-5.1f} z {0.0:-5.1f}') hud.set_shader(Shader('uv_flat')) (lt, bm, ft, rt, tp, bk) = hud.get_bounds() hud.position((-display.width + rt - lt) / 2.0, (0.9 * display.height - tp + bm) / 2.0, 1.0) hud.draw( ) # NB has to be drawn before quick_change() is called as buffer needs to exist particles = [] if argc == 0: particles.append( Body(Shader('mat_light'), (0.0, 1.0, 1.0), 0.1, track_shader=Shader('mat_flat'))) elif argc == 1: particles.append( Body(Shader('mat_light'), (0.0, 1.0, 1.0), 0.05, track_shader=Shader('mat_flat'), track_max=int(argv[1]))) elif argc == 7: particles.append( Body(Shader('mat_light'), (0.0, 1.0, 1.0), 0.1, track_shader=Shader('mat_flat'))) particles.append( Body(Shader('mat_light'), (0.0, 1.0, 1.0), 0.1, track_shader=Shader('mat_flat'))) particles.append( Body(Shader('mat_light'), (1.0, 1.0, 0.0), 0.1, track_shader=Shader('mat_flat'))) particles.append( Body(Shader('mat_light'), (1.0, 1.0, 0.0), 0.1, track_shader=Shader('mat_flat'))) particles.append( Body(Shader('mat_light'), (1.0, 0.0, 1.0), 0.1, track_shader=Shader('mat_flat'))) particles.append( Body(Shader('mat_light'), (1.0, 0.0, 1.0), 0.1, track_shader=Shader('mat_flat'))) particles.append( Body(Shader('mat_light'), (1.0, 1.0, 1.0), 0.1, track_shader=Shader('mat_flat'))) # Enable key presses and mouse keys = Keyboard() mouse = Mouse(restrict=False) mouse.start() omx, omy = mouse.position() # Display scene while display.loop_running(): # prepare for next iteration lines = [] for file in files: lines.append(file.readline()) if not lines[0]: display.stop() data = [[float(item) for item in lines[0].split()[:4]]] if argc == 7: data = [] for line in lines: data.append([float(item) for item in line.split()[:4]]) hud.quick_change( f' t{data[0][3]:-5.1f} x{data[0][0]:-5.1f} y{data[0][1]:-5.1f} z{data[0][2]:-5.1f}' ) hud.draw() # camera control camera.reset() camera.rotate(-tilt, rot, 0) r_rot, r_tilt = radians(rot), radians(tilt) camera.position( (cam_rad * sin(r_rot) * cos(r_tilt), cam_rad * sin(r_tilt), -cam_rad * cos(r_rot) * cos(r_tilt))) # plot the particles particles[0].pos = [data[0][0], data[0][1], data[0][2]] particles[0].position_and_draw(trace_material=(0.0, 0.25, 0.0)) if argc == 7: particles[1].pos = [data[1][0], data[1][1], data[1][2]] particles[1].position_and_draw(trace_material=(0.0, 0.25, 0.0)) particles[2].pos = [data[2][0], data[2][1], data[2][2]] particles[2].position_and_draw(trace_material=(0.4, 0.0, 0.0)) particles[3].pos = [data[3][0], data[3][1], data[3][2]] particles[3].position_and_draw(trace_material=(0.4, 0.0, 0.0)) particles[4].pos = [data[4][0], data[4][1], data[4][2]] particles[4].position_and_draw(trace_material=(0.0, 0.0, 0.5)) particles[5].pos = [data[5][0], data[5][1], data[5][2]] particles[5].position_and_draw(trace_material=(0.0, 0.0, 0.5)) particles[6].pos = [data[6][0], data[6][1], data[6][2]] particles[6].position_and_draw(trace_material=(0.25, 0.25, 0.25)) # process mouse & keyboard input mx, my = mouse.position() if mouse.button_status() == mouse.LEFT_BUTTON: rot -= (mx - omx) * 0.2 tilt -= (my - omy) * 0.2 elif mouse.button_status() == mouse.RIGHT_BUTTON: cam_rad += (my - omy) * 0.1 omx, omy = mx, my key = keys.read() if key > -1: if key == 112: # 'p' screenshot('trajectory.jpg') elif key == 27: # 'ESC' keys.close() mouse.stop() display.stop() break
if win.ev == "key": mv = False if win.key == "w": xm -= math.sin(math.radians(tankrot)) * 2 zm -= math.cos(math.radians(tankrot)) * 2 mv = True elif win.key == "s": xm += math.sin(math.radians(tankrot)) * 2 zm += math.cos(math.radians(tankrot)) * 2 mv = True if win.key == "a": tankrot -= 2 if win.key == "d": tankrot += 2 if win.key == "p": pi3d.screenshot("TigerTank.jpg") if win.key == "Escape": try: print("bye,bye1") myshadows.delete_buffers() DISPLAY.destroy() try: win.destroy() except: pass mymouse.stop() exit() except: pass if mv: # moved so recalc pitch_roll pitch, roll = mymap.pitch_roll(xm, zm)
CAMERA.reset((DISPLAY.near, DISPLAY.far, DISPLAY.fov, DISPLAY.width / float(DISPLAY.height))) win.resized = False if win.ev == "key": if win.key == "w": xm-=math.sin(mouserot*rads)*2 zm+=math.cos(mouserot*rads)*2 if win.key == "s": xm+=math.sin(mouserot*rads)*2 zm-=math.cos(mouserot*rads)*2 if win.key == "a": mouserot -= 2 if win.key == "d": mouserot += 2 if win.key == "p": pi3d.screenshot("MarsStation.jpg") if win.key == "Escape": try: print("bye,bye1") DISPLAY.destroy() try: win.destroy() except: pass mymouse.stop() exit() except: pass if win.ev=="drag" or win.ev=="click" or win.ev=="wheel": xm-=math.sin(mouserot*rads)*2 zm+=math.cos(mouserot*rads)*2
# Display scene while DISPLAY.loop_running(): myplane.rotateIncZ(0.01) mysphere.rotateIncY(-0.1) mysphere2.rotateIncY(-0.14) mymoon.position(mysphere.x() + m1Rad*sin(rot1), mysphere.y(), mysphere.z() - m1Rad*cos(rot1)) mymoon.rotateIncY(-0.1) mymoon2.position(mymoon.x() - m2Rad*sin(rot2), mymoon.y(), mymoon.z() + m2Rad*cos(rot2)) mymoon2.rotateIncZ(-0.61) mysphere.draw(shader, [earthimg]) mymoon.draw(shader, [moonimg, moonbmp], 6.0, 0.0) mymoon2.draw(shader, [watimg, moonbmp, starsimg], 3.0, 0.8) myplane.draw(flatsh,[starsimg]) mysphere2.draw(shader, [cloudimg]) # this has to be last as blend = True rot1 += 0.005 rot2 += 0.021 k = mykeys.read() if k >-1: if k==112: pi3d.screenshot("earth1.jpg") elif k==27: mykeys.close() DISPLAY.stop() break
win.resized = False if win.ev == "key": if win.key == "w": xm -= math.sin(math.radians(tankrot)) * 2 zm -= math.cos(math.radians(tankrot)) * 2 ym = (mymap.calcHeight(xm, zm) + avhgt) if win.key == "s": xm += math.sin(math.radians(tankrot)) * 2 zm += math.cos(math.radians(tankrot)) * 2 ym = (mymap.calcHeight(xm, zm) + avhgt) if win.key == "a": tankrot -= 2 if win.key == "d": tankrot += 2 if win.key == "p": pi3d.screenshot("TigerTank.jpg") if win.key == "Escape": try: print("bye,bye1") myshadows.delete_buffers() DISPLAY.destroy() try: win.destroy() except: pass mymouse.stop() exit() except: pass if win.ev=="drag" or win.ev=="click" or win.ev=="wheel": xm -= math.sin(math.radians(tankrot)) * 2
x=0, y=-1, z=40, sx=0.005, sy=0.005, sz=0.005) mymodel.set_shader(shader) # Fetch key presses mykeys = pi3d.Keyboard() while 1: DISPLAY.clear() mymodel.draw() mymodel.rotateIncZ(0.001) mymodel.rotateIncX(-0.00317543) mymodel.rotateIncY(0.11) k = mykeys.read() if k > -1: if k == 112: pi3d.screenshot('Triceratops.jpg') elif k == 27: mykeys.close() DISPLAY.destroy() break else: print(k) DISPLAY.swap_buffers()
grey_sprite.draw() sobel_sprite.draw() hog_sprite.draw() hidden_sprite.draw() for st in str_list: st.draw() arrow.draw() k = mykeys.read() if k >-1: if k == 27: mykeys.close() DISPLAY.destroy() break elif k == ord(' '): im = np.array(Image.open(random.choice(flist))) outlayer = mlp.feed_forward(ip.get_hog(im)) grey_tex.update_ndarray(false_colour(ip.grey_scale)) sobel_tex.update_ndarray(false_colour(ip.edges)) hog_tex.update_ndarray(false_colour(ip.hog.reshape(16, 128))) hidden_tex.update_ndarray(false_colour(mlp.ah.reshape(8, 8))) arrow.positionY(1.0 - 0.5 * outlayer.argmax()) str_colours = false_colour(outlayer.reshape(5,1)) / 255.0 for i, st in enumerate(str_list): st.set_material(str_colours[i, 0]) elif k == ord('p'): pi3d.screenshot("/home/patrick/Downloads/scr_caps_pi3d/scr_caps/fr{:03d}.jpg".format(fr)) fr += 1
xm -= math.sin(math.radians(rot)) zm += math.cos(math.radians(rot)) ym = mymap.calcHeight(xm, zm) + avhgt elif k==115: #kry S xm += math.sin(math.radians(rot)) zm -= math.cos(math.radians(rot)) ym = mymap.calcHeight(xm, zm) + avhgt elif k==39: #key ' tilt -= 2.0 elif k==47: #key / tilt += 2.0 elif k==97: #key A rot -= 2 elif k==100: #key D rot += 2 elif k==112: #key P pi3d.screenshot("forestWalk"+str(scshots)+".jpg") scshots += 1 elif k==10: #key RETURN mc = 0 elif k==27: #Escape key mykeys.close() mymouse.stop() DISPLAY.stop() break else: print(k) CAMERA.was_moved = False quit()
a.set_elevator(0) if inputs.key_state("KEY_C") or inputs.key_state("BTN_BASE"): #control mode print("control mode") cam_toggle = True cam_rot, cam_pitch = 0, 0 if inputs.key_state("KEY_1"): print("Toggle Instuments") if instdisplay==True: instdisplay=False else: instdisplay=True if inputs.key_state("KEY_0"): print("Screenshot") pi3d.screenshot("screenshots/screenshot.jpg") #if inputs.key_state("BTN_LEFT") or inputs.key_state("BTN_PINKIE") or inputs.key_state("KEY_P"): #shoot if inputs.key_state("KEY_P"): #shoot print("shoot") #target is always nearest others set during last json_load() #tx, ty, tz = 0., 0.0, 0.0 if a.nearest: tx, ty, tz = a.nearest.x, a.nearest.y, a.nearest.z a.nearest.other_damage += a.shoot([tx, ty, tz]) a.update_variables() loc = a.update_position(mymap.calcHeight(a.x, a.z)) CAMERA.reset() #CAMERA.rotate(-20 + cam_pitch, -loc[3] + cam_rot, 0) #unreal view CAMERA.rotate(-20 + cam_pitch, -loc[3] + cam_rot, -a.roll) #air-sick view