def change_details(self, star_ref, planet_tex, obj_object, v): self.star_ref = star_ref star_loc = v[star_ref, 0:3] star_rgb = v[star_ref, 3:6] light = pi3d.Light(is_point=True, lightpos=star_loc, lightcol=star_rgb * 15.0, lightamb=(0.01, 0.01, 0.01)) if self.star is None: self.star = pi3d.Sphere(radius=0.4, slices=24, sides=24) self.star.set_draw_details(self.flatsh, [self.star_tex]) self.star.set_material(star_rgb) self.star.position(*star_loc) if self.planet is None: self.planet = pi3d.Sphere(radius=0.1, slices=24, sides=24, light=light) self.planet.set_draw_details(self.shader, planet_tex, 1.0, 0.0) self.planet.set_light(light) self.planet.position(star_loc[0], star_loc[1], star_loc[2] - 2.2) self.obj_object = obj_object self.obj_object.set_shader(self.shader) self.obj_object.set_light(light) self.obj_object.position(star_loc[0] + 0.2, star_loc[1], star_loc[2] - 1.75)
def __init__(self, width=320, height=480): self.width = width self.height = height self.gap = 0 #self.width // 2 displayWidth = 2 * self.width + self.gap displayHeight = self.height # Display must be created before the eyes or their draw() method throws... display = pi3d.Display.create(samples=4, w=displayWidth, h=displayHeight) # make background green while debugging and refactoring so it is easier to see individual eye pieces display.set_background(0, 0, 0, 1) # r,g,b,alpha # A 2D camera is used, mostly to allow for pixel-accurate eye placement, # but also because perspective isn't really helpful or needed here, and # also this allows eyelids to be handled somewhat easily as 2D planes. # Line of sight is down Z axis, allowing conventional X/Y cartesion # coords for 2D positions. cam = pi3d.Camera(is_3d=False, at=(0, 0, 0), eye=(0, 0, -1000)) light = pi3d.Light(lightpos=(0, -500, -500), lightamb=(0.2, 0.2, 0.2)) # eyeRadius is the size, in pixels, at which the whole eye will be rendered # onscreen. eyePosition, also pixels, is the offset (left or right) from # the center point of the screen to the center of each eye. eyePosition = self.width // 2 + self.gap // 2 eyeRadius = self.width / 2.1 rightEye = eye.Eye(eyeRadius, -eyePosition, 0, True) leftEye = eye.Eye(eyeRadius, eyePosition, 0, False) self.eyesModel = model.TwoEyesModel() self.renderer = renderer.Renderer(display, [leftEye, rightEye], self.eyesModel)
def __init__(self, size, dist, img): self.size = size self.dist = dist #distance from Sun self.freq = 1 / dist #frequency is based on distance self.img = pi3d.Texture(img) #declare image self.offset = randint(0, 1000) #sets it randomly along orbit self.light = pi3d.Light(is_point=True, lightpos=(0, 0, 0), lightcol=(5000, 5000, 5000), lightamb=(0.05, 0.05, 0.05)) self.obj = pi3d.Sphere(light=self.light, radius=self.size, x=self.dist) print(self, "size:", self.size, "dist:", self.dist, "freq:", self.freq)
NB also, no camera has been explicitly assigned to the objects so they all use the default instance and this will be CAMERA.camera_3d so long as the StereoCam instance was created before any other Camera instance. """ import math, random import demo import pi3d # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(w=1200, h=600) DISPLAY.set_background(0.4, 0.8, 0.8, 1) # r,g,b,alpha # yellowish directional light blueish ambient light pi3d.Light(lightpos=(1, -1, -3), lightcol=(1.0, 1.0, 0.8), lightamb=(0.25, 0.2, 0.3)) CAMERA = pi3d.StereoCam(separation=-0.5, interlace=0) """ If CAMERA is set with interlace <= 0 (default) then CAMERA.draw() will produce two images side by side (each viewed from `separation` apart) i.e. -ve requires viewing slightly cross-eyed. If interlace is set to a positive value then the two images are interlaced in vertical stripes this number of pixels wide. The resultant image needs to be viewed through a grid. See https://github.com/pi3d/pi3d_demos/make_grid.py """ # load shader shader = pi3d.Shader("uv_bump") shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat")
winw, winh, bord = 1200, 800, 0 #64MB GPU memory setting # winw,winh,bord = 1920,1200,0 #128MB GPU memory setting DISPLAY = pi3d.Display.create(tk=True, window_title='Tiger Tank demo in Pi3D', w=winw, h=winh - bord, far=3000.0, background=(0.4, 0.8, 0.8, 1), frames_per_second=16) #inputs = InputEvents() #inputs.get_mouse_movement() mylight = pi3d.Light(lightpos=(1.0, -1.0, 1.0), lightcol=(0.8, 0.8, 0.8), lightamb=(0.10, 0.10, 0.12)) win = DISPLAY.tkwin shader = pi3d.Shader('shadow_uv_bump') flatsh = pi3d.Shader('uv_flat') shade2d = pi3d.Shader('2d_flat') CAMERA = pi3d.Camera() #======================================== # create splash screen and draw it splash = pi3d.ImageSprite("textures/tiger_splash.jpg", shade2d, w=10,
import json import logging import speak '''if config.CAMEENABLED: import camerathread #import facedetect as face ''' logging.basicConfig(filename='aiqubase.log', level=logging.DEBUG) sys.path.insert(1, '/home/pi/aiqu') os.putenv('SDL_FBDEV', '/dev/fb1') #this = sys.modules[__name__] DISPLAY = pi3d.Display.create() DISPLAY.set_background(0, 0, 0, 1) light = pi3d.Light(lightpos=(0, -500, -500), lightamb=(0.2, 0.2, 0.2)) global sleeping global mode global state global oldState global mode global canvas #Variables are defined here #Aiqu modes, EYE, RADIO, WEATHER, SLEEP, DEEP mode = "EYE" #sleepTimer = 0 sleeping = False
import demo import pi3d #helpful messages print("############################################################") print("Mouse to move left and right and up and down") print("############################################################") print() # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=100, y=50, frames_per_second=20) DISPLAY.set_background(0.4, 0.8, 0.8, 1) # r,g,b,alpha camera = pi3d.Camera((0, 0, 0), (0, 0, -1), (1, 1000, 30.0, DISPLAY.width / DISPLAY.height)) light = pi3d.Light((10, -10, 20)) # load shader shader = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") #defocus = pi3d.Defocus() #<<<<<<<<<<<<<<< #======================================== # Setting 2nd param to True renders 'True' Blending # (this can be changed later to 'False' with 'rockimg2.blend = False') groundimg = pi3d.Texture("textures/stripwood.jpg") monstimg = pi3d.Texture("textures/pong3.png") ballimg = pi3d.Texture("textures/pong2.jpg") # environment cube ectex = pi3d.Texture("textures/ecubes/skybox_stormydays.jpg") myecube = pi3d.EnvironmentCube(camera, light, 900.0, "CROSS")
There is also demonstration of the point_at method of Camera, press the D key """ from __future__ import absolute_import import math, random import demo import pi3d # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=100, y=100) DISPLAY.set_background(0.4, 0.8, 0.8, 1) # r,g,b,alpha # yellowish directional light blueish ambient light pi3d.Light(lightpos=(1, -1, -3), lightcol=(1.0, 1.0, 0.7), lightamb=(0.15, 0.1, 0.3)) #======================================== # load shader shader = pi3d.Shader("shaders/uv_reflect") flatsh = pi3d.Shader("shaders/uv_flat") tree2img = pi3d.Texture("textures/tree2.png") tree1img = pi3d.Texture("textures/tree1.png") hb2img = pi3d.Texture("textures/hornbeam2.png") bumpimg = pi3d.Texture("textures/grasstile_n.jpg") reflimg = pi3d.Texture("textures/stars.jpg") rockimg = pi3d.Texture("textures/rock1.jpg")
justified multiline unicode æ ö ¼ Strings """ + unichr(255) + ' ' + unichr(256) + ' ' + unichr(257) # character 255 should appear, character 256 should not. # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=10, y=10, w=900, h=600, frames_per_second=25) DISPLAY.set_background(0.4, 0.6, 0.8, 1.0) # r,g,b,alpha persp_cam = pi3d.Camera.instance() # default instance camera perspecive view ortho_cam = pi3d.Camera(is_3d=False) # 2d orthographic view camera #setup textures, light position and initial model position pi3d.Light((0, 5, 0)) #create shaders shader = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") defocus = pi3d.Defocus() #Create textures shapeimg = pi3d.Texture("textures/straw1.jpg") shapebump = pi3d.Texture("textures/floor_nm.jpg") shapeshine = pi3d.Texture("textures/pong3.png") #Create shape myshape = pi3d.MergeShape(camera=persp_cam) #specify perspective view asphere = pi3d.Sphere(sides=16, slices=16) myshape.radialCopy(asphere, step=72) myshape.position(0.0, 0.0, 5.0)
""" Simple textruring of Sphere objects against a plane. The atmosphere has blend set to True and so has to be drawn after object behind it to allow them to show through. Normal map used for moon is just a 'normal' pictures so normals are calculated strangely and create odd shadows. Uses the import pi3d method to load *everything* """ from math import sin, cos import demo import pi3d # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=50, y=50, frames_per_second=30) DISPLAY.set_background(0, 0, 0, 1) # r,g,b,alpha shader = pi3d.Shader("uv_light") shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") light = pi3d.Light(lightpos=(1.0, 0.0, 0.1)) #======================================== # Setting 2nd param to True renders 'True' Blending # (this can be changed later to 'False' with 'cloudimg.blend = False') cloudimg = pi3d.Texture("textures/earth_clouds.png", True) earthimg = pi3d.Texture("textures/world_map.jpg") moonimg = pi3d.Texture("textures/moon.jpg") starsimg = pi3d.Texture("textures/stars2.jpg") watimg = pi3d.Texture("textures/water.jpg") moonbmp = pi3d.Texture("textures/moon_nm.jpg") # Load shapes mysphere = pi3d.Sphere(radius=2, slices=24, sides=24, name="earth", z=5.8) mysphere2 = pi3d.Sphere(radius=2.05, slices=24, sides=24, name="clouds", z=5.8) mymoon = pi3d.Sphere(radius=0.4, slices=16, sides=16, name="moon") mymoon2 = pi3d.Sphere(radius=0.15, slices=16, sides=16, name="moon2") myplane = pi3d.Plane(w=50, h=50, name="stars", z=30)
def main(fname="assets/dictionaries/words.txt", N=12): # create display DISPLAY = pi3d.Display.create(background=(0.7, 0.3, 0.9, 1)) # create camera and move it back a bit CAM = pi3d.Camera(at=(0.5, N / 2, 0.0), eye=(0.25, N / 2, -1.5 * N)) letter_matrix = create_letter_matrix(N) cubeMap = [] heightMap = gen_heightMap(N) draw_cubeMap(cubeMap, heightMap, N) # create keyboard listener keys = pi3d.Keyboard() # load shaders shader = pi3d.Shader("uv_bump") lshader = pi3d.Shader('uv_light') shinesh = pi3d.Shader("uv_reflect") matsh = pi3d.Shader("mat_reflect") #Place the words in the matrix placeWords(fname, letter_matrix, N) randomize_empty_cells(letter_matrix, N) print(letter_matrix) r = 0 light = pi3d.Light(lightpos=(-3, -10, 5), lightcol=(0.5, 0.5, 0.5), lightamb=(0.5, 0.5, 0.5), is_point=False) # set cube details for i, cuberow in enumerate(cubeMap): for j, cube in enumerate(cuberow): string1 = pi3d.FixedString(camera=CAM, font="fonts/FreeSans.ttf", font_size=12, string=letter_matrix[i][j] + ("\n" * int(math.ceil(cube.height))), color="#FFFFFF", justify="C", f_type="SMOOTH", background_color="#000000" ) # EMBOSS, CONTOUR, BLUR, SMOOTH, BUMP cube.set_draw_details(lshader, [string1], 1.0) cube.set_light(light, 0) # display loop try: while DISPLAY.loop_running(): CAM.relocate(rot=r, distance=[-5, -5, -5]) #draw loop for cuberow in cubeMap: for cube in cuberow: cube.draw() # take a screenshot every 90 degree rotation if r % 90 == 0: pi3d.util.Screenshot.screenshot("screen_" + str(r) + ".png") r += 1 # only do one rotation if r == 360: break # handle escape if keys.read() == 27: break finally: # can also except KeyboardInterrup: for ctrl c specific things keys.close() DISPLAY.destroy()
#!/usr/bin/python from __future__ import absolute_import, division, print_function, unicode_literals """ 3D model loading: complex architectural model with multiple vertex groups and images """ import math, random import demo import pi3d # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=100, y=100) DISPLAY.set_background(1.0, 0.4, 0.6, 1) # r,g,b,alpha pi3d.Light((5, -10, -20), (0.6, 0.6, 0.5), (0.3, 0.3, 0.4)) # load shader shader = pi3d.Shader("shaders/uv_light") flatsh = pi3d.Shader("shaders/uv_flat") print("==============================================================") print("Instructions:") print("") print("Keys- W - Forward,") print(" A - Left S - Back D - right") print("") print("Move mouse to pan view. Click mouse to exit or press ESCAPE") print("==============================================================") ectex = pi3d.loadECfiles("textures/ecubes", "sbox") myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="bfa", y=50.0) myecube.set_draw_details(flatsh, ectex)
camera_az = random.random() * (C_MAXA - C_MINA) + C_MINA + 90. * random.randint(0, 3) # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(frames_per_second=30, w=2048, h=2048) DISPLAY.set_background(0.4, 0.8, 0.8, 1) # r,g,b,alpha # yellowish directional light blueish ambient light #TODO doesn't cope with z direction properly LA = math.radians(light_az) LE = -math.radians(light_ev) LC = 1 LZ = LC * math.cos(LA) * math.cos(LE) LX = LC * math.sin(LA) * math.cos(LE) LY = LC * math.sin(LE) mylight = pi3d.Light(lightpos=(LX, LY, LZ), lightcol=(1.0, 1.0, 1.0), lightamb=(0.40, 0.35, 0.35)) CA = math.radians(camera_az) CE = -math.radians(camera_ev) CC = CALT CZ = CC * math.cos(CA) * math.cos(CE) CX = CC * math.sin(CA) * math.cos(CE) CY = CC * math.sin(CE) CAMERA = pi3d.Camera.instance() if light_az > 180.: light_az -= 360. elif light_az < -180.: light_az += 360 if camera_az > 180.:
#!/usr/bin/python from __future__ import absolute_import, division, print_function, unicode_literals """ Wavefront obj model loading. Material properties set in mtl file. Uses the import pi3d method to load *everything* """ import demo 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("mat_reflect") # pi3d.Shader("uv_reflect") light = pi3d.Light( ) #lightpos=(-1.0, 0.0, 10.0), lightcol=(1.0, 1.0, 1.0), lightamb=(0.2, 0.1, 0.3), is_point=True) #======================================== # this is a bit of a one off because the texture has transparent parts # comment out and google to see why it's included here. from pi3d import opengles, GL_CULL_FACE opengles.glDisable(GL_CULL_FACE) #======================================== # load bump and reflection textures bumptex = pi3d.Texture("textures/floor_nm.jpg") shinetex = pi3d.Texture("textures/stars.jpg") flatwhite = pi3d.Texture("textures/white.png") # load model_loadmodel mymodel = pi3d.Model(file_string='models/teapot.obj', name='teapot', z=4) mymodel.set_shader(shader) #mymodel.set_light(light) mymodel.set_normal_shine(flatwhite, 16.0, flatwhite, 0.5) #mymodel.set_normal_shine(bumptex, 16.0, shinetex, 0.5) # Fetch key presses mykeys = pi3d.Keyboard()
print("Good turnings are often greener and tend to be near") print("(but in the opposite direction to) big holes") print("############################################################") print("If you get touched by a monster you will return to the start!") print("############################################################") print() # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=100, y=100, background=(0.4, 0.8, 0.8, 1), use_pygame=True) shader = pi3d.Shader("uv_bump") flatsh = pi3d.Shader("uv_flat") light = pi3d.Light((1, 1, 1), (400.0, 400.0, 350.0), (0.03, 0.03, 0.05), True) #======================================== # load Textures rockimg1 = pi3d.Texture("textures/techy1.jpg") rockimg2 = pi3d.Texture("textures/rocktile2.jpg") tree2img = pi3d.Texture("textures/tree2.png") raspimg = pi3d.Texture("textures/Raspi256x256.png") monstimg = pi3d.Texture("textures/pong2.jpg") monsttex = pi3d.Texture("textures/floor_nm.jpg") shineimg = pi3d.Texture("textures/stars.jpg") # environment cube ectex = pi3d.Texture("textures/ecubes/skybox_stormydays.jpg") myecube = pi3d.EnvironmentCube(size=900.0, maptype="CROSS") myecube.set_draw_details(flatsh, ectex)
from Matrix import Matrix, SPHERE, CUBE import pi3d import math import random import time display = pi3d.Display.create(x=20, y=20, w=1920, h=1080, background=(0.0, 0.0, 0.1, 1.0)) pi3d.Light(lightpos=(-10.0, 4.0, 10.0), lightcol=(3.0, 3.0, 2.0), lightamb=(0.5, 0.5, 0.7), is_point=True) camera = pi3d.Camera() EDGE_SIZE = 24 RADIUS = 60 TILT = -10 WIDTH = EDGE_SIZE HEIGHT = EDGE_SIZE DEPTH = EDGE_SIZE angle = 0.0 delta = 0.5 counter = 5.0 direction = 1
READKNOB = False READBUTTON = False ROTARYKNOB = True # Setup display and initialise pi3d backgroundColor = (0, 0, 0, 1) DISPLAY = pi3d.Display.create( x=0, y=0, background=backgroundColor, frames_per_second=60) #anti-alias use 'samples=4' CAMERA = pi3d.Camera() CAMERA2D = pi3d.Camera(is_3d=False) #light = pi3d.Light(lightpos=(-2.0, 3.0, 5.0), lightcol=(10.0, 10.0, 30.0), lightamb=(1.02, 10.01, 5.03), is_point=False) light = pi3d.Light(lightpos=(1, -1, -3), lightcol=(1.0, 1.0, 1.0), lightamb=(0.75, 0.75, 0.75), is_point=False) flatsh = pi3d.Shader("uv_flat") shadermat = pi3d.Shader("mat_light") #Set up the 3D models xyz = .03 names = ["gun", "bear", "fork", "knife", "cake"] models = [] for objname in names: temp = selectable.MySelectableObject() temp.obj = pi3d.Model(file_string=home_path + 'models/' + objname + '.obj', camera=CAMERA,
# Shaders -------------------------------- shader = pi3d.Shader("uv_light") flatsh = pi3d.Shader("uv_flat") tracksh = pi3d.Shader("mat_flat") # Textures ------------------------------- cloudimg = pi3d.Texture("textures/earth_clouds.png",True) sunimg = pi3d.Texture("textures/sun.jpg") sunshellimg = pi3d.Texture("textures/sun_shell.png", True) earthimg = pi3d.Texture("textures/world_map.jpg") moonimg = pi3d.Texture("textures/moon.jpg") # EnvironmentCube ------------------------ ectex = [pi3d.Texture('textures/ecubes/skybox_grimmnight.jpg')] myecube = pi3d.EnvironmentCube(size=900.0, maptype='CROSS') myecube.set_draw_details(flatsh, ectex) # Lights --------------------------------- sunlight = pi3d.Light(is_point=True, lightpos=(0, 0, 0), # from the sun lightcol=(100.0, 100.0, 100.0), lightamb=(0.05, 0.05, 0.05)) selflight = pi3d.Light(lightamb=(1.1, 1.1, 1.1)) # on the sun # Planets -------------------------------- sun = Planet([sunimg, sunshellimg], shader, 1.0, 8000000, pos=[0.0, 0.0, 0.0], vel=[-0.01, 0.0, 0.0], light=selflight) #to keep total momentum of system zero! earth = Planet([earthimg, cloudimg], shader, 0.125, 80000000, pos=[0.0, -1.0, -9.0], vel=[0.5, 0.1, 0.0], track_shader=tracksh, light=sunlight) moon = Planet([moonimg], shader, 0.025, 80000000, pos=[0.0, -1.0, -9.6], vel=[0.72, 0.144, 0.0], track_shader=tracksh, light=sunlight) jupiter = Planet([moonimg, sunshellimg], shader, 0.2, 8000000, pos=[0.0, 0.0, 14.0], vel=[-0.2, 0.3, 0.0], track_shader=tracksh, light=sunlight) # Fetch key presses ---------------------- mykeys = pi3d.Keyboard() # Mouse ---------------------------------- mymouse = pi3d.Mouse(restrict = False) mymouse.start()
import math, random, time, glob import demo import pi3d print("=====================================================") print("press escape to escape") print("move this terminal window to top of screen to see FPS") print("=====================================================") # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=200, y=150, frames_per_second=25.0) DISPLAY.set_background(0.4, 0.6, 0.8, 0.5) # r,g,b,alpha #setup textures, light position and initial model position pi3d.Light((5, -5, 8)) #create shaders shader = pi3d.Shader("uv_reflect") matsh = pi3d.Shader("mat_reflect") flatsh = pi3d.Shader("uv_flat") #Create textures shapeimg = pi3d.Texture("textures/straw1.jpg") shapebump = pi3d.Texture("textures/straw1.jpg", normal_map=-6.0) waterbump = [] iFiles = glob.glob("textures/water/n_norm???.png") iFiles.sort() # order is vital to animation! for f in iFiles: waterbump.append(pi3d.Texture(f)) num_n = len(waterbump) shapeshine = pi3d.Texture("textures/stars.jpg")
lightamb=(0.05, 0.05, 0.05)) self.obj = pi3d.Sphere(light=self.light, radius=self.size, x=self.dist) print(self, "size:", self.size, "dist:", self.dist, "freq:", self.freq) def update(self, t): self.obj.position(self.dist * cos(self.freq * (t + self.offset)), 0, self.dist * sin(self.freq * (t + self.offset))) self.obj.draw(shader, [self.img]) #create shader shader = pi3d.Shader('uv_light') sunimg = pi3d.Texture('sun.jpg') #create lights: sunlight = pi3d.Light(lightamb=(1.0, 1.0, 1.0)) #create our objects planets = [] sun = pi3d.Sphere(light=sunlight, radius=15.0, sides=96) mercury = Planet(0.5, 20, 'mercury.jpg') venus = Planet(0.7, 25, 'venus.jpg') earth = Planet(1, 30, 'earth.jpg') mars = Planet(0.7, 40, 'mars.jpg') jupiter = Planet(3, 50, 'jupiter.jpg')
def main(): #Load a level level = 0 building = loadLevel(level) lights = pi3d.Light(lightpos=(10, -10, 20), lightcol=(0.7, 0.7, 0.7), lightamb=(0.7, 0.7, 0.7)) rot = 0.0 tilt = 0.0 CAMERA = pi3d.Camera.instance() while DISPLAY.loop_running() and not \ inputs.key_state("KEY_ESC"): CAMERA.reset() CAMERA.rotate(tilt, rot, 0) CAMERA.position( (person.x(), person.y(), person.z() - aveyeleveladjust)) #draw objects person.drawall() building.drawAll() mymap.draw() startobject.draw() endobject.draw() #Apply the light to all the objects in the building for b in building.model: b.set_light(lights, 0) mymap.set_light(lights, 0) inputs.do_input_events() #Note:Some mice devices will be located on #get_mouse_movement(1) instead of get_mouse_movement() mx, my, mv, mh, md = inputs.get_mouse_movement() #mx, my, mv, mh, md = inputs.get_mouse_movement(1) rot -= (mx) * 0.2 tilt -= (my) * 0.2 xm = person.x() ym = person.y() zm = person.z() 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"): rot += 2 if inputs.key_state("KEY_D"): rot -= 2 if inputs.key_state("KEY_H"): #Use point_at as help - will turn the player to face # the direction of the end point tilt, rot = CAMERA.point_at( [endobject.x(), endobject.y(), endobject.z()]) if inputs.key_state("KEY_W"): xm -= sin(radians(rot)) zm += cos(radians(rot)) if inputs.key_state("KEY_S"): xm += sin(radians(rot)) zm -= cos(radians(rot)) NewPos = Position(xm, ym, zm) collisions = person.CollisionList(NewPos) if collisions: #If we reach end, reset to start position! for obj in collisions: if obj.name == "end": inputs.do_input_events() #clear any pending inputs #Required to remove the building walls from the # solidobject list building.remove_walls() showMessage("Loading Level", rot) DISPLAY.loop_running() level += 1 building = loadLevel(level) showMessage("") person.move(Position(startpos[0], startpos[1], startpos[2])) else: person.move(NewPos)
print("Subscribing to event") yield self.subscribe(on_event, 'com.myapp.topic1') def onDisconnect(self): print("disconnected") reactor.stop() #from autobahn.twisted.wamp import ApplicationRunner #runner = ApplicationRunner("ws://10.81.2.132:8080/ws", "realm1") #runner.run(Component) print("Starting game") pi3d.Light(lightpos=(1, -1, -3), lightcol=(1.0, 1.0, 1.0), lightamb=(1.0, 1.0, 1.0)) refid = "00:00:00:00:00:00" #create the instances of Aeroplane a = Aeroplane("models/gooddove11.obj", 0.02, refid) a.z, a.direction = 900, 180 #create instance of instruments #inst = Instruments() others = {"start": 0.0} #contains a dictionary of other players keyed by refid # Load textures for the environment cube ectex = pi3d.loadECfiles("textures/ecubes", "sbox") myecube = pi3d.EnvironmentCube(size=7000.0, maptype="FACES", camera=CAMERA) myecube.set_draw_details(FLATSH, ectex) myecube.set_fog((0.5, 0.5, 0.5, 1.0), 4000) # Create elevation map
#!/usr/bin/python from __future__ import absolute_import, division, print_function, unicode_literals """ Example showing use of FixedString. ESC to quit FixedString should be faster for rendering large quantities of text as it only requires two triangles for the whole text rather than two triangles for each letter""" import demo import pi3d DISPLAY = pi3d.Display.create(x=150, y=150) flatsh = pi3d.Shader("uv_flat") shader = pi3d.Shader("uv_bump") CAMERA = pi3d.Camera() CAMERA2D = pi3d.Camera(is_3d=False) pi3d.Light(lightpos=(10, -10, 2)) tex = pi3d.Texture('textures/rock1.jpg') mytext = '''Pi3D is a Python module that aims to greatly simplify writing 3D in Python whilst giving access to the power of the Raspberry Pi GPU. It enables both 3D and 2D rendering and aims to provide a host of exciting commands.''' # 'normal' FixedString on a (fairly) solid background str1 = pi3d.FixedString('fonts/NotoSans-Regular.ttf', mytext, font_size=32, background_color=(200, 140, 20, 235), camera=CAMERA2D,
NORTH, SOUTH = (0.0, 0.0, 1.0), (0.0, 0.0, -1.0) # (dx, dy, dz) EAST, WEST = (1.0, 0.0, 0.0), (-1.0, 0.0, 0.0) # (dx, dy, dz) UP, DOWN = (0.0, 1.0, 0.0), (0.0, -1.0, 0.0) # (dx, dy, dz) TURN_LEFT = {NORTH: WEST, WEST: SOUTH, SOUTH: EAST, EAST: NORTH} TURN_RIGHT = {NORTH: EAST, EAST: SOUTH, SOUTH: WEST, WEST: NORTH} SIZE = 100.0 BLOCK_SIZE = 4.0 # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=100, y=100, frames_per_second=10) DISPLAY.set_background(0.4, 0.8, 0.8, 1) # r,g,b,alpha #======================================== CAMERA = pi3d.Camera() LIGHT = pi3d.Light(lightamb=(0.6, 0.6, 0.8)) # load shader shader = pi3d.Shader("uv_light") flatsh = pi3d.Shader("uv_flat") foodTex = pi3d.Texture("textures/Raspi256x256.png") partTex = pi3d.Texture("textures/world_map256x256.jpg") ectex = pi3d.loadECfiles("textures/ecubes", "skybox_hall") myecube = pi3d.EnvironmentCube(size=2.0 * SIZE, maptype="FACES", name="cube") myecube.set_draw_details(shader, ectex) class Food: def __init__(self, snake): self.snake = snake plane = pi3d.Plane(w=BLOCK_SIZE * 2.0, h=BLOCK_SIZE * 2.0)
import pi3d LOGGER = pi3d.Log(__name__, level='INFO') # Create a Tkinter window winw, winh, bord = 1200, 600, 0 #64MB GPU memory setting # winw,winh,bord = 1920,1200,0 #128MB GPU memory setting DISPLAY = pi3d.Display.create(tk=True, window_title='Tiger Tank demo in Pi3D', w=winw, h=winh - bord, far=3000.0, background=(0.4, 0.8, 0.8, 1), frames_per_second=16) #inputs = InputEvents() #inputs.get_mouse_movement() pi3d.Light(lightpos=(-1, -1, 1), lightcol =(0.8, 0.8, 0.8), lightamb=(0.30, 0.30, 0.32)) win = DISPLAY.tkwin shader = pi3d.Shader('uv_bump') flatsh = pi3d.Shader('uv_flat') shade2d = pi3d.Shader('2d_flat') #======================================== # create splash screen and draw it splash = pi3d.ImageSprite("textures/tiger_splash.jpg", shade2d, w=10, h=10, z=0.2) splash.draw() DISPLAY.swap_buffers() # create environment cube ectex = pi3d.loadECfiles('textures/ecubes/Miramar', 'miramar_256',
lifts = peg_plan[:, draft_plan] # generate an up/down map for the plan # then fill it with the yarn for warp if it's up or weft if it's down yarn_plan = lifts * warp_plan + (lifts * -1 + 1) * weft_plan wv = yarn_colours[yarn_plan].astype( np.uint8) # wv takes the [R,G,B] from yarn colours clothimg = pi3d.Texture(wv) ######################################################################## # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=100, y=100, frames_per_second=30) DISPLAY.set_background(0.4, 0.8, 0.8, 1.0) # r,g,b,alpha # yellowish directional light blueish ambient light pi3d.Light(lightpos=(1, -1, -3), lightcol=(1.0, 1.0, 0.8), lightamb=(0.45, 0.5, 0.6)) #======================================== # load shader shader = pi3d.Shader("uv_bump") shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") bumpimg = pi3d.Texture("textures/weave.png") reflimg = pi3d.Texture("textures/stars.jpg") rockimg = pi3d.Texture("textures/rock1.jpg") FOG = ((0.3, 0.3, 0.4, 0.8), 650.0) TFOG = ((0.2, 0.24, 0.22, 1.0), 150.0)
import pi3d # Load diplay, nearly full screen DISPLAY = pi3d.Display.create(x=20, y=20, background=(0.0, 0.0, 0.1, 1.0)) # Load shaders shader = pi3d.Shader("uv_light") shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") matsh = pi3d.Shader("mat_reflect") ########################################## # Load textures patimg = pi3d.Texture("textures/PATRN.PNG") coffimg = pi3d.Texture("textures/COFFEE.PNG") shapebump = pi3d.Texture("textures/floor_nm.jpg") shapeshine = pi3d.Texture("textures/stars.jpg") light = pi3d.Light(lightpos=(-1.0, 0.0, 10.0), lightcol=(3.0, 3.0, 2.0), lightamb=(0.02, 0.01, 0.03), is_point=True) #Create inbuilt shapes mysphere = pi3d.Sphere(radius=1, sides=24, slices=24, name="sphere", x=-4, y=2, z=10) mytcone = pi3d.TCone(radiusBot=0.8, radiusTop=0.6, height=1, sides=24, name="TCone",
] building = pi3d.Building("textures/silo_map.png", 0, 0, mymap, width=15.0, depth=15.0, height=70.0, name="", draw_details=details, yoff=-15, scheme=openSectionSchemeMultimodel) outLight = pi3d.Light(lightpos=(10, -10, 20), lightcol=(1.0, 1.0, 0.7), lightamb=(0.35, 0.35, 0.4)) inLight = pi3d.Light(lightpos=(10, -10, 20), lightcol=(0.1, 0.1, 0.15), lightamb=(0.05, 0.15, 0.1)) for b in building.model: b.set_light(inLight, 0) mymap.set_light(inLight, 0) inFlag = True #screenshot number scshots = 1 #avatar camera rot = 0.0 tilt = 0.0
the ShadowCaster class. Also demonstrates passing an array of objects to the MergeShape.merge() method which is much faster for adding large numbers of objects """ import math, random import demo import pi3d # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(frames_per_second=30) DISPLAY.set_background(0.4,0.8,0.8,1) # r,g,b,alpha # yellowish directional light blueish ambient light #TODO doesn't cope with z direction properly mylight = pi3d.Light(lightpos=(-2.0, -1.0, 0.0), lightcol=(1.0, 1.0, 0.8), lightamb=(0.25, 0.2, 0.3)) CAMERA = pi3d.Camera.instance() #======================================== # load shader shader = pi3d.Shader("shadow_uv_bump") shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") tree2img = pi3d.Texture("textures/tree2.png", mipmap=False) tree1img = pi3d.Texture("textures/tree1.png", mipmap=False) hb2img = pi3d.Texture("textures/hornbeam2.png", mipmap=False) bumpimg = pi3d.Texture("textures/grasstile_n.jpg") reflimg = pi3d.Texture("textures/stars.jpg") rockimg = pi3d.Texture("textures/rock1.jpg")
def pi_3d(inHeightmap, inWidth, inDepth, inHeight, inTextureMap, inBumpMap): rads = 0.017453292512 # degrees to radians # helpful messages # Esc to quit, W to go forward, Mouse to steer # At the edge you will turn into a ghost and be able to fly and pass through rocks! # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=100, y=100, background=(0.4, 0.8, 0.8, 1), use_pygame=True) shader = pi3d.Shader("uv_bump") flatsh = pi3d.Shader("uv_flat") light = pi3d.Light((1, 1, 1), (400.0, 400.0, 350.0), (0.03, 0.03, 0.05), True) # sun = pi3d.Light((0.0, 1000.0, 0.0), (0.5, 1.0, 0.7), (0.3, 0.1, 0.1), is_point=True) # load Textures rockimg1 = pi3d.Texture("textures/techy1.jpg") rockimg2 = pi3d.Texture("textures/rocktile2.jpg") shineimg = pi3d.Texture("textures/stars.jpg") # environment cube ectex = pi3d.Texture("textures/ecubes/skybox_stormydays.jpg") myecube = pi3d.EnvironmentCube(size=900.0, maptype="CROSS") myecube.set_draw_details(flatsh, ectex) # Create elevation map # inWidth = Width of Map (i.e. 1024.0) # inDepth = Depth of Map (i.e. 1024.0) # inHeight = Height of Map (i.e 0.5) mapwidth = inWidth mapdepth = inDepth mapheight = inHeight bumpsh = pi3d.Shader('uv_bump') # inHeightmap = Maps/seed_XXXXX_grayscale.png # inTextureMap = Maps/seed_XXXXX_elevation.png # inBumpMap = Maps/seed_XXXXX_normal.png mymap = pi3d.ElevationMap(inHeightmap, width=mapwidth, depth=mapdepth, height=mapheight, divx=199, divy=199, name="sub") mymap.set_draw_details(shader, [rockimg1, rockimg2, shineimg], 128.0, 0.05) redplanet = pi3d.Texture(inTextureMap) bumpimg = pi3d.Texture(inBumpMap) mymap.set_draw_details(bumpsh, [redplanet, bumpimg], 128.0, 0.0) mymap.set_fog((0.3, 0.15, 0.1, 0.0), 1000.0) rot = 0.0 tilt = 0.0 avhgt = 3.0 xm, oxm = 0.0, -1.0 zm, ozm = 0.0, -1.0 ym = mymap.calcHeight(xm, zm) + avhgt # Fetch key presses mykeys = pi3d.Keyboard() mymouse = pi3d.Mouse(restrict=False) mymouse.start() omx, omy = mymouse.position() fly = False walk = True CAMERA = pi3d.Camera.instance() print ('at line 71 - Code3D') while DISPLAY.loop_running(): # movement of camera mx, my = mymouse.position() rot -= (mx - omx) * 0.2 tilt += (my - omy) * 0.1 dx = -math.sin(rot * rads) dz = math.cos(rot * rads) dy = math.sin(tilt * rads) if walk: if fly: xm += dx * 3 zm += dz * 3 ym += dy * 3 else: dy = mymap.calcHeight(xm + dx * 1.5, zm + dz * 1.5) + avhgt - ym if dy < 1.2: # limit steepness so can't climb up walls xm += dx * 0.5 zm += dz * 0.5 ym += dy * 0.5 if xm < -490 or xm > 490 or zm < -490 or zm > 490: fly = True # reached the edge if not (mx == omx and my == omy and oxm == xm and ozm == zm): CAMERA.reset() CAMERA.rotate(tilt, 0, 0) CAMERA.rotate(0, rot, 0) CAMERA.position((xm, ym, zm)) omx = mx omy = my oxm = xm ozm = zm light.position((xm, ym + 15.0, zm)) light.is_point = True mymap.set_light(light) myecube.position(xm, ym, zm) myecube.draw() mymap.draw() # key presses (ESCAPE to terminate) k = mykeys.read() if k > -1: if k == 119: # W Key toggle walk = not walk elif k == 115: # S Key walk = False dy = -(mymap.calcHeight(xm - dx, zm - dz) + avhgt) - ym if dy > -1.0: xm -= dx zm -= dz ym += dy elif k == 27: # ESCAPE key DISPLAY.destroy() mykeys.close() mymouse.stop() break # this will save a little time each loop if the camera is not moved CAMERA.was_moved = False quit()