def __init__(self): shader = pi3d.Shader("uv_reflect") bumpsh = pi3d.Shader("uv_bump") flatsh = pi3d.Shader("uv_flat") #shade2d = pi3d.Shader('2d_flat') ectex = pi3d.loadECfiles("../textures/ecubes/RedPlanet", "redplanet_256", "png", True) self.myecube = pi3d.EnvironmentCube(size=1800.0, maptype="FACES") self.myecube.set_draw_details(flatsh,ectex) # Create elevation map mapwidth=2000.0 mapdepth=2000.0 mapheight=100.0 redplanet = pi3d.Texture("../textures/mars_colour.png") bumpimg = pi3d.Texture("../textures/mudnormal.jpg") self.mymap = pi3d.ElevationMap(mapfile='../textures/mars_height.png', width=mapwidth, depth=mapdepth, height=mapheight, divx=64, divy=64) self.mymap.set_draw_details(bumpsh,[redplanet, bumpimg],128.0, 0.0) self.mymap.set_fog((0.3, 0.15, 0.1, 0.0), 1000.0) #Load Corridors sections sttnbmp = pi3d.Texture("../textures/floor_nm.jpg") sttnshn = pi3d.Texture("../textures/stars.jpg") x,z = 0,0 y = self.mymap.calcHeight(x, z) #corridor with windows self.cor_win = pi3d.Model(file_string="../models/MarsStation/corridor_win_lowpoly.egg", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1) self.cor_win.set_shader(shader) #normal corridor self.corridor = pi3d.Model(file_string="../models/MarsStation/corridor_lowpoly.egg", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1) self.corridor.set_shader(shader) #corridor crossing self.cor_cross = pi3d.Model(file_string="../models/MarsStation/cross_room.egg", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1) self.cor_cross.set_shader(shader) self.cor_cross.set_normal_shine(sttnbmp, 32.0, sttnshn, 0.1) #corridor crossing with doors self.cor_cross_doors = pi3d.Model(file_string="../models/MarsStation/cross_room_doors.egg", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1) self.cor_cross_doors.set_shader(shader) self.cor_cross_doors.set_normal_shine(sttnbmp, 32.0, sttnshn, 0.1) #corridor with 90 degree bend self.cor_bend = pi3d.Model(file_string="../models/MarsStation/bend_lowpoly.egg", x=x, y=y, z=z, sx=0.1, sy=0.1, sz=0.1) self.cor_bend.set_shader(shader) self.cor_bend.set_normal_shine(sttnbmp, 32.0) self.cor_bend.rotateToY(180)
def __init__(self): #Setup shaders flatsh = pi3d.Shader("uv_flat") #shade2d = pi3d.Shader('2d_flat') # create splash screen and draw it #splash = pi3d.ImageSprite("../textures/pi3d_splash.jpg", shade2d, w=10, h=10, z=0.2) #splash.draw() #DISPLAY.swap_buffers() #Setup environment cube ectex = pi3d.loadECfiles("../textures/ecubes/Miramar", "miramar_256", "png", nobottom = True) self.myecube = pi3d.EnvironmentCube(size=1800.0, maptype="FACES", nobottom=True) self.myecube.set_draw_details(flatsh, ectex) #Load Hall model self.mymap = pi3d.Model(file_string="../models/ConferenceHall/conferencehall.egg", name="Hall", sx=0.1, sy=0.1, sz=0.1) self.mymap.set_shader(flatsh) self.mymap.position(0.0,10.0, 0.0)
def main(): #Model textures and shaders shader = pi3d.Shader("uv_reflect") bumptex = pi3d.Texture("textures/floor_nm.jpg") shinetex = pi3d.Texture("textures/stars.jpg") # load model mymodel = pi3d.Model(file_string='models/teapot.obj', z=10) mymodel.set_shader(shader) mymodel.set_normal_shine(bumptex, 4.0, shinetex, 0.5) #Create environment box flatsh = pi3d.Shader("uv_flat") ectex=pi3d.loadECfiles("textures/ecubes","sbox") myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="cube") myecube.set_draw_details(flatsh, ectex) CAMERA = pi3d.Camera.instance() rot = 0.0 # rotation of camera tilt = 0.0 # tilt of camera while DISPLAY.loop_running() and not \ inputs.key_state("KEY_ESC"): #Rotate camera inputs.do_input_events() # camera steered by mouse #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 CAMERA.reset() CAMERA.rotate(tilt, rot, 0) #Rotate object mymodel.rotateIncY(2.0) mymodel.rotateIncZ(0.1) mymodel.rotateIncX(0.3) #Draw objects mymodel.draw() myecube.draw()
rads = 0.017453292512 # degrees to radians #Create a Tkinter window winx,winy,winw,winh = 360,150,1200,800 #64MB GPU memory setting #winx,winy,winw,winh = 0,0,1920,1080 #128MB GPU memory setting win = pi3d.tkwin("Mars Station in Pi3D",winx,winy,winw,winh) win.update() #requires a window update first so that window sizes can be retreived # Setup display and initialise pi3d viewport over the window display = pi3d.display(winx,winy,winw,winh,24,0.5,2200,60) display.setBackColour(0.4,0.8,0.8,1) # r,g,b,alpha #texture storage for loading textures texs = pi3d.textures() ectex=pi3d.loadECfiles("textures/ecubes/RedPlanet","redplanet_256","png",texs,True) myecube = pi3d.createEnvironmentCube(1800.0,"FACES") # Create elevation map mapwidth=2000.0 mapdepth=2000.0 mapheight=100.0 redplanet = texs.loadTexture("textures/mars_colour.png") mymap = pi3d.createElevationMapFromTexture("textures/mars_height.png",mapwidth,mapdepth,mapheight,64,64) #Load Corridors sections x,z = 0,0 y = mymap.calcHeight(-x,-z) corridor_win = pi3d.loadModel("models/MarsStation/corridor_win_lowpoly.egg",texs,"", x,y,z, -90,0,0, .1,.1,.1) corridor = pi3d.loadModel("models/MarsStation/corridor_lowpoly.egg",texs,"", x,y,z, -90,0,0, .1,.1,.1)
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, h=10, z=0.2) splash.draw() DISPLAY.swap_buffers() # create environment cube ectex = pi3d.loadECfiles('textures/ecubes/Miramar', 'miramar_256', suffix='png') myecube = pi3d.EnvironmentCube(size=1800.0, maptype='FACES') myecube.set_draw_details(flatsh, ectex) # Create elevation map mapwidth = 1800.0 mapdepth = 1800.0 mapheight = 120.0 mountimg1 = pi3d.Texture('textures/mountains3_512.jpg') bumpimg = pi3d.Texture('textures/grasstile_n.jpg') tigerbmp = pi3d.Texture('models/Tiger/tiger_bump.jpg') topbmp = pi3d.Texture('models/Tiger/top_bump.jpg') #roadway = pi3d.Texture('textures/road5.png') mymap = pi3d.ElevationMap(mapfile='textures/mountainsHgt2.png', width=mapwidth, depth=mapdepth, height=mapheight, divx=64, divy=64)
class Main(object): # Setup display and initialise pi3d DISPLAY = pi3d.Display.create() pi3d.Light(lightpos=(1, -1, -3), lightcol=(1.0, 1.0, 0.8), lightamb=(0.25, 0.2, 0.3)) # load shader shader = pi3d.Shader("uv_bump") shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("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") FOG = ((0.3, 0.3, 0.4, 0.8), 650.0) TFOG = ((0.2, 0.24, 0.22, 1.0), 150.0) #myecube = pi3d.EnvironmentCube(900.0,"HALFCROSS") ectex = pi3d.loadECfiles("textures/ecubes", "sbox") myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="cube") myecube.set_draw_details(flatsh, ectex) # Create elevation map mapsize = 1000.0 mapheight = 60.0 mountimg1 = pi3d.Texture("textures/mountains3_512.jpg") mymap = pi3d.ElevationMap("textures/mountainsHgt.png", name="map", width=mapsize, depth=mapsize, height=mapheight, divx=32, divy=32) mymap.set_draw_details(shader, [mountimg1, bumpimg, reflimg], 128.0, 0.0) mymap.set_fog(*FOG) #Create tree models treeplane = pi3d.Plane(w=4.0, h=5.0) treemodel1 = pi3d.MergeShape(name="baretree") treemodel1.add(treeplane.buf[0], 0, 0, 0) treemodel1.add(treeplane.buf[0], 0, 0, 0, 0, 90, 0) treemodel2 = pi3d.MergeShape(name="bushytree") treemodel2.add(treeplane.buf[0], 0, 0, 0) treemodel2.add(treeplane.buf[0], 0, 0, 0, 0, 60, 0) treemodel2.add(treeplane.buf[0], 0, 0, 0, 0, 120, 0) #Scatter them on map using Merge shape's cluster function mytrees1 = pi3d.MergeShape(name="trees1") mytrees1.cluster(treemodel1.buf[0], mymap, 0.0, 0.0, 200.0, 200.0, 20, "", 8.0, 3.0) mytrees1.set_draw_details(flatsh, [tree2img], 0.0, 0.0) mytrees1.set_fog(*TFOG) mytrees2 = pi3d.MergeShape(name="trees2") mytrees2.cluster(treemodel2.buf[0], mymap, 0.0, 0.0, 200.0, 200.0, 20, "", 6.0, 3.0) mytrees2.set_draw_details(flatsh, [tree1img], 0.0, 0.0) mytrees2.set_fog(*TFOG) mytrees3 = pi3d.MergeShape(name="trees3") mytrees3.cluster(treemodel2, mymap, 0.0, 0.0, 300.0, 300.0, 20, "", 4.0, 2.0) mytrees3.set_draw_details(flatsh, [hb2img], 0.0, 0.0) mytrees3.set_fog(*TFOG) #Create monument monument = pi3d.Model(file_string="models/pi3d.obj", name="monument") monument.set_shader(shinesh) monument.set_normal_shine(bumpimg, 16.0, reflimg, 0.4) monument.set_fog(*FOG) monument.translate(100.0, -mymap.calcHeight(100.0, 235) + 12.0, 235.0) monument.scale(20.0, 20.0, 20.0) monument.rotateToY(65) #avatar camera rot = 0.0 tilt = 0.0 avhgt = 3.5 xm = 0.0 zm = 0.0 ym = mymap.calcHeight(xm, zm) + avhgt go_flag = False go_speed = 0.2 CAMERA = pi3d.Camera.instance() def pi3dloop(self, dt): self.DISPLAY.loop_running() self.CAMERA.reset() self.CAMERA.rotate(self.tilt, self.rot, 0) self.CAMERA.position((self.xm, self.ym, self.zm)) self.myecube.position(self.xm, self.ym, self.zm) # for opaque objects it is more efficient to draw from near to far as the # shader will not calculate pixels already concealed by something nearer self.myecube.draw() self.mymap.draw() dx = math.copysign(self.mapsize, self.xm) dz = math.copysign(self.mapsize, self.zm) mid = 0.3 * self.mapsize if abs(self.xm) > mid: #nearing edge self.mymap.position(dx, 0.0, 0.0) self.mymap.draw() if abs(self.zm) > mid: #other edge self.mymap.position(0.0, 0.0, dz) self.mymap.draw() if abs(self.xm) > mid: #i.e. in corner, both edges self.mymap.position(dx, 0.0, dz) self.mymap.draw() self.mymap.position(0.0, 0.0, 0.0) self.monument.draw() self.mytrees1.draw() self.mytrees2.draw() self.mytrees3.draw() if pi3d.PLATFORM == PLATFORM_ANDROID: #***************************** if self.DISPLAY.android.screen.moved: self.rot -= self.DISPLAY.android.screen.touch.dx * 0.25 self.tilt += self.DISPLAY.android.screen.touch.dy * 0.25 self.DISPLAY.android.screen.moved = False self.DISPLAY.android.screen.tapped = False elif self.DISPLAY.android.screen.tapped: self.go_speed *= 1.5 self.DISPLAY.android.screen.tapped = False elif self.DISPLAY.android.screen.double_tapped: self.go_flag = not self.go_flag self.DISPLAY.android.screen.double_tapped = False else: mx, my = self.mymouse.position() #if mx>display.left and mx<display.right and my>display.top and my<display.bottom: self.rot -= (mx - self.omx) * 0.2 self.tilt += (my - self.omy) * 0.2 self.omx = mx self.omy = my #Press ESCAPE to terminate k = self.mykeys.read() if k > -1: if k == ord('w'): #key W self.go_flag = not self.go_flag elif k == 27: #Escape key return False if self.go_flag: self.xm -= math.sin(math.radians(self.rot)) * self.go_speed self.zm += math.cos(math.radians(self.rot)) * self.go_speed self.ym = self.mymap.calcHeight(self.xm, self.zm) + self.avhgt halfmap = self.mapsize / 2.0 # save doing this four times! self.xm = (self.xm + halfmap) % self.mapsize - halfmap self.zm = (self.zm + halfmap) % self.mapsize - halfmap else: self.go_speed = 0.2 return True def run(self): if pi3d.PLATFORM == PLATFORM_ANDROID: #***************************** self.DISPLAY.android.set_loop(self.pi3dloop) self.DISPLAY.android.run() else: # Fetch key presses self.mykeys = pi3d.Keyboard() self.mymouse = pi3d.Mouse(restrict=False) self.mymouse.start() self.omx, self.omy = self.mymouse.position() while self.pi3dloop(0.0): pass self.mykeys.close() self.mymouse.stop() self.DISPLAY.stop()
DISPLAY = pi3d.Display.create(tk=True, window_title='ConferenceHall demo in Pi3D', w=winw, h=winh, far=2200.0, fov = 60, background=(0.4, 0.8, 0.8, 1), frames_per_second=20) win = DISPLAY.tkwin #Setup shaders flatsh = pi3d.Shader("shaders/uv_flat") shade2d = pi3d.Shader('shaders/2d_flat') # create splash screen and draw it splash = pi3d.ImageSprite("textures/pi3d_splash.jpg", shade2d, w=10, h=10, z=0.2) splash.draw() DISPLAY.swap_buffers() #Setup environment cube ectex = pi3d.loadECfiles("textures/ecubes/Miramar", "miramar_256", "png", nobottom = True) myecube = pi3d.EnvironmentCube(size=1800.0, maptype="FACES", nobottom=True) myecube.set_draw_details(flatsh, ectex) #Load Hall model hall = pi3d.Model(file_string="models/ConferenceHall/conferencehall.egg", name="Hall", sx=0.1, sy=0.1, sz=0.1) hall.set_shader(flatsh) #key presses mymouse = pi3d.Mouse(restrict = False) mymouse.start() omx, omy = mymouse.position() #position vars mouserot = -70.0 tilt = 10.0
import demo import pi3d # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=150, y=150, background=(0.4, 0.8, 0.8, 1), frames_per_second=30) shader = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") ############################# # Load textures blockimg = pi3d.Texture("textures/squareblocks4.png") roofedgeimg = pi3d.Texture("textures/roofedging.png") roofimg = pi3d.Texture("textures/Roof.png") greenimg = pi3d.Texture("textures/squareblocks4green.png") ectex = pi3d.loadECfiles("textures/ecubes", "sbox", "jpg") myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES") myecube.set_draw_details(flatsh, ectex) # Create elevation map mapwidth=1000.0 mapdepth=1000.0 mapheight=60.0 floorimg = pi3d.Texture("textures/dunes3_512.jpg") bumpimg = pi3d.Texture("textures/mudnormal.jpg") mymap = pi3d.ElevationMap(mapfile="textures/mountainsHgt2.png", width=mapwidth, depth=mapdepth, height=mapheight, divx=64, divy=64) mymap.set_draw_details(shader,[floorimg, bumpimg],128.0, 0.0) mymap.set_fog((0.3,0.25,0.1,0.8), 500.0)
DISPLAY = pi3d.Display.create(x=50, y=50) shader = pi3d.Shader('shaders/uv_flat') #======================================== #select the environment cube with 'box'... box = 3 if box == 0: ectex = [pi3d.Texture('textures/ecubes/skybox_interstellar.jpg')] myecube = pi3d.EnvironmentCube(size=900.0, maptype='CROSS') elif box == 1: ectex = [pi3d.Texture('textures/ecubes/SkyBox.jpg')] myecube = pi3d.EnvironmentCube(size=900.0, maptype='HALFCROSS') elif box == 2: ectex = pi3d.loadECfiles('textures/ecubes', 'sbox_interstellar', nobottom=True) myecube = pi3d.EnvironmentCube(size=900.0, maptype='FACES', nobottom=True) else: ectex = pi3d.loadECfiles('textures/ecubes', 'skybox_hall') myecube = pi3d.EnvironmentCube(size=900.0, maptype='FACES') myecube.set_draw_details(shader, ectex) rot = 0.0 tilt = 0.0 # Fetch key presses mykeys = pi3d.Keyboard() mymouse = pi3d.Mouse(restrict=False) mymouse.start()
import pi3d,math,random rads = 0.017453292512 # degrees to radians # Create a Tkinter window winx,winy,winw,winh = 360,200,1200,800 #64MB GPU memory setting #winx,winy,winw,winh = 0,0,1920,1200 #128MB GPU memory setting win = pi3d.tkwin("Tiger Tank demo in Pi3D",winx,winy,winw,winh,"textures/tiger_splash.jpg") win.update() #display window now with splash # Setup display and initialise pi3d viewport over the window display = pi3d.display(winx,winy,winw,winh) display.setBackColour(0.7,0.8,0.8,1.0) # r,g,b,alpha # texture storage for loading textures texs = pi3d.textures() ectex = pi3d.loadECfiles("textures/ecubes/Miramar","miramar_256","png",texs,True) myecube = pi3d.createEnvironmentCube(1800.0,"FACES") # create a font arialFont = pi3d.font("MicrosoftSansSerif","#88ff88") # Create elevation map mapwidth=2000.0 mapdepth=2000.0 mapheight=100.0 mountimg1 = texs.loadTexture("textures/mountains3_512.jpg") #roadway = texs.loadTexture("textures/road5.png") mymap = pi3d.createElevationMapFromTexture("textures/mountainsHgt2.png",mapwidth,mapdepth,mapheight,64,64) # map dots and settings dotsize=8
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) self.shape = pi3d.MergeShape() self.shape.add(plane, 0,0,0) self.shape.add(plane, 0,0,0, 0,90,0) self.shape.set_draw_details(shader, [foodTex]) self.spawn() def spawn(self): collision = True
class Main(object): # Setup display and initialise pi3d DISPLAY = pi3d.Display.create(depth=16) pi3d.Light(lightpos=(1, -1, -3), lightcol=(1.0, 1.0, 0.8), lightamb=(0.25, 0.2, 0.3)) # load shader shader = pi3d.Shader("uv_bump") shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") bumpimg = pi3d.Texture("textures/grasstile_n.jpg") reflimg = pi3d.Texture("textures/stars.jpg") rockimg = pi3d.Texture("textures/rock1.jpg") FOG = ((0.3, 0.3, 0.4, 0.8), 650.0) ectex = pi3d.loadECfiles("textures/ecubes", "sbox") myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="cube") myecube.set_draw_details(flatsh, ectex) # Create elevation map mapsize = 1000.0 mapheight = 60.0 mountimg1 = pi3d.Texture("textures/mountains3_512.jpg") mymap = pi3d.ElevationMap("textures/mountainsHgt.png", name="map", width=mapsize, depth=mapsize, height=mapheight, divx=32, divy=32) mymap.set_draw_details(shader, [mountimg1, bumpimg, reflimg], 128.0, 0.0) mymap.set_fog(*FOG) #Create monument monument = pi3d.Model(file_string="models/pi3d.obj", name="monument") monument.set_shader(shinesh) monument.set_normal_shine(bumpimg, 16.0, reflimg, 0.4) monument.set_fog(*FOG) monument.translate(100.0, -mymap.calcHeight(100.0, 235) + 12.0, 235.0) monument.scale(20.0, 20.0, 20.0) monument.rotateToY(65) #Ball ball = pi3d.Triangle(corners=((-0.01, 0.0), (0.0, 0.01), (0.01, 0.0))) sphere = pi3d.Sphere() sphere.set_draw_details(shader, [rockimg, bumpimg], 1.0) ball.add_child(sphere) #avatar camera rot = 0.0 tilt = 0.0 avhgt = 1.0 xm = 0.0 zm = 0.0 ym = mymap.calcHeight(xm, zm) + avhgt go_flag = False vx, vz = 0.0, 0.0 gx, gz = 0.0, 0.0 CAMERA = pi3d.Camera.instance() CAMERA2D = pi3d.Camera(is_3d=False) font = pi3d.Pngfont("fonts/GillSansMT.png", (200, 30, 10, 255)) font.blend = True txt = None if pi3d.PLATFORM == pi3d.PLATFORM_ANDROID: #***************************** from jnius import autoclass Hardware = autoclass(b'org.renpy.android.Hardware') Hardware.accelerometerEnable(True) def pi3dloop(self, dt): self.DISPLAY.loop_running() self.CAMERA.relocate(self.rot, self.tilt, [self.xm, self.ym, self.zm], [-OFFSET, -OFFSET, -OFFSET]) self.myecube.position(self.xm, self.ym, self.zm) self.ball.position(self.xm, self.ym, self.zm) # for opaque objects it is more efficient to draw from near to far as the # shader will not calculate pixels already concealed by something nearer self.ball.draw() self.mymap.draw() self.myecube.draw() dx = math.copysign(self.mapsize, self.xm) dz = math.copysign(self.mapsize, self.zm) mid = 0.3 * self.mapsize if abs(self.xm) > mid: #nearing edge self.mymap.position(dx, 0.0, 0.0) self.mymap.draw() if abs(self.zm) > mid: #other edge self.mymap.position(0.0, 0.0, dz) self.mymap.draw() if abs(self.xm) > mid: #i.e. in corner, both edges self.mymap.position(dx, 0.0, dz) self.mymap.draw() self.mymap.position(0.0, 0.0, 0.0) self.monument.draw() if pi3d.PLATFORM == pi3d.PLATFORM_ANDROID: #***************************** if self.DISPLAY.android.screen.moved: self.rot -= self.DISPLAY.android.screen.touch.dx * 0.25 self.tilt += self.DISPLAY.android.screen.touch.dy * 0.25 self.DISPLAY.android.screen.moved = False self.DISPLAY.android.screen.tapped = False elif self.DISPLAY.android.screen.double_tapped: self.go_flag = not self.go_flag self.DISPLAY.android.screen.double_tapped = False from kivy.network.urlrequest import UrlRequest def url_success(req, results): self.txt = pi3d.String(camera=self.CAMERA2D, font=self.font, string=results, is_3d=False, y=self.DISPLAY.height / 2.0 + 30.0) self.txt.set_shader(self.flatsh) self.monument.rotateIncY(4) # rotate by some random amount req = UrlRequest( "http://www.eldwick.org.uk/files/rogo/test2.php?num=1", url_success) if self.txt is not None: self.txt.draw() (x, y, z) = self.Hardware.accelerometerReading() sr, _, cr = self.CAMERA.get_direction() self.gx = y * cr + (z - x) * sr self.gz = ( z - x) * cr - y * sr # i.e. hold at 45 degrees for neutral else: mx, my = self.mymouse.position() #if mx>display.left and mx<display.right and my>display.top and my<display.bottom: self.rot -= (mx - self.omx) * 0.2 self.tilt += (my - self.omy) * 0.2 self.omx = mx self.omy = my #Press ESCAPE to terminate k = self.mykeys.read() if k > -1: sr, _, cr = self.CAMERA.get_direction() if k == ord('w'): #key W self.go_flag = not self.go_flag elif k == 261 or k == 137: # rgt self.gx += 0.5 * cr self.gz -= 0.5 * sr elif k == 260 or k == 136: # lft self.gx -= 0.5 * cr self.gz += 0.5 * sr elif k == 259 or k == 134: # up self.gz += 0.5 * cr self.gx += 0.5 * sr elif k == 258 or k == 135: # dwn self.gz -= 0.5 * cr self.gx -= 0.5 * sr elif k == 27: #Escape key return False if self.go_flag: self.xm += self.vx self.zm += self.vz ht, norm = self.mymap.calcHeight(self.xm, self.zm, True) self.ym = ht + self.avhgt self.vx += norm[0] * SLOPE_F + self.gx * TILT_F self.vz += norm[2] * SLOPE_F + self.gz * TILT_F self.vx *= FRICTION self.vz *= FRICTION self.ball.rotateToY(math.degrees(math.atan2(self.vx, self.vz))) self.sphere.rotateIncX(math.degrees( (self.vx**2 + self.vz**2)**0.5)) halfmap = self.mapsize / 2.0 # save doing this four times! self.xm = (self.xm + halfmap) % self.mapsize - halfmap self.zm = (self.zm + halfmap) % self.mapsize - halfmap else: self.vx = 0.0 self.vz = 0.0 self.gx = 0.0 self.gz = 0.0 return True def run(self): if pi3d.PLATFORM == pi3d.PLATFORM_ANDROID: #***************************** self.DISPLAY.android.set_loop(self.pi3dloop) self.DISPLAY.android.run() self.Hardware.accelerometerEnable(False) else: # Fetch key presses self.mykeys = pi3d.Keyboard() self.mymouse = pi3d.Mouse(restrict=False) self.mymouse.start() self.omx, self.omy = self.mymouse.position() while self.pi3dloop(0.0): pass self.mykeys.close() self.mymouse.stop() self.DISPLAY.stop()
def __init__(self): # load shader shader = pi3d.Shader("uv_bump") #shinesh = pi3d.Shader("uv_reflect") flatsh = pi3d.Shader("uv_flat") tree1img = pi3d.Texture("../textures/tree1.png") tree2img = pi3d.Texture("../textures/tree2.png") hb2img = pi3d.Texture("../textures/hornbeam2.png") bumpimg = pi3d.Texture("../textures/grasstile_n.jpg") reflimg = pi3d.Texture("../textures/stars.jpg") floorimg = pi3d.Texture("../textures/floor_nm.jpg") FOG = ((0.3, 0.3, 0.4, 0.8), 650.0) TFOG = ((0.2, 0.24, 0.22, 1.0), 150.0) ectex=pi3d.loadECfiles("../textures/ecubes","sbox") self.myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="cube") self.myecube.set_draw_details(flatsh, ectex) self.myecube.position(0,0,0) # Create elevation map mapsize = 1000.0 mapheight = 60.0 mountimg1 = pi3d.Texture("../textures/mountains3_512.jpg") self.mymap = pi3d.ElevationMap("../textures/mountainsHgt.png", name="map", width=mapsize, depth=mapsize, height=mapheight, divx=32, divy=32) self.mymap.set_draw_details(shader, [mountimg1, bumpimg, reflimg], 128.0, 0.0) self.mymap.set_fog(*FOG) self.building = pi3d.Model(file_string="../models/ConferenceHall/conferencehall.egg", name="Hall", sx=0.1, sy=0.1, sz=0.1) self.building.set_shader(flatsh) #Create tree models treeplane = pi3d.Plane(w=4.0, h=5.0) treemodel1 = pi3d.MergeShape(name="baretree") treemodel1.add(treeplane.buf[0], 0,0,0) treemodel1.add(treeplane.buf[0], 0,0,0, 0,90,0) treemodel2 = pi3d.MergeShape(name="bushytree") treemodel2.add(treeplane.buf[0], 0,0,0) treemodel2.add(treeplane.buf[0], 0,0,0, 0,60,0) treemodel2.add(treeplane.buf[0], 0,0,0, 0,120,0) #Scatter them on map using Merge shape's cluster function self.mytrees1 = pi3d.MergeShape(name="trees1") self.mytrees1.cluster(treemodel1.buf[0], self.mymap,0.0,0.0,200.0,200.0,20,"",8.0,3.0) self.mytrees1.set_draw_details(flatsh, [tree2img], 0.0, 0.0) self.mytrees1.set_fog(*TFOG) self.mytrees2 = pi3d.MergeShape(name="trees2") self.mytrees2.cluster(treemodel2.buf[0], self.mymap,0.0,0.0,200.0,200.0,20,"",6.0,3.0) self.mytrees2.set_draw_details(flatsh, [tree1img], 0.0, 0.0) self.mytrees2.set_fog(*TFOG) self.mytrees3 = pi3d.MergeShape(name="trees3") self.mytrees3.cluster(treemodel2, self.mymap,0.0,0.0,300.0,300.0,20,"",4.0,2.0) self.mytrees3.set_draw_details(flatsh, [hb2img], 0.0, 0.0) self.mytrees3.set_fog(*TFOG) #screenshot number scshots = 1
# Setup display and initialise pi3d display = pi3d.display() display.create3D(100,100,1700,800, 0.5, 800.0, 60.0) # x,y,width,height,near,far,aspect #select the environment cube with 'box'... box=3 texs=pi3d.textures() if box==0: ectex = texs.loadTexture("textures/ecubes/skybox_interstellar.jpg") myecube = pi3d.createEnvironmentCube(900.0,"CROSS") elif box==1: ectex = texs.loadTexture("textures/ecubes/SkyBox.jpg") myecube = pi3d.createEnvironmentCube(900.0,"HALFCROSS") elif box==2: ectex=pi3d.loadECfiles("textures/ecubes","sbox_interstellar",texs) myecube = pi3d.createEnvironmentCube(900.0,"FACES") else: ectex=pi3d.loadECfiles("textures/ecubes","skybox_hall",texs) myecube = pi3d.createEnvironmentCube(900.0,"FACES") rot=0.0 tilt=0.0 # Fetch key presses mykeys = pi3d.key() mymouse = pi3d.mouse() mymouse.start() mtrx=pi3d.matrix()
except Exception as e: print("exception:", e) #create the instances of Aeroplane a = Aeroplane("assets/models/starship.obj", 0.00, refid) ### Our ship a.z, a.direction = 905, 180 #a.z, a.direction = 1200, 180 #create instance of instruments inst = Instruments() others = {"start": 0.0} #contains a dictionary of other players keyed by refid thr = threading.Thread(target=json_load, args=(a, others)) thr.daemon = True #allows the program to exit even if a Thread is still running thr.start() # Load textures for the environment cube ectex = pi3d.loadECfiles("assets/textures/ecubes", "bkg1") myecube = pi3d.EnvironmentCube(size=7000.0, maptype="FACES", camera=CAMERA) myecube.set_draw_details(FLATSH, ectex) myecube.set_fog((0.0, 0.0, 0.0, 1.0), 4000) # Create elevation map mapwidth = 50000.0 #probably need to increase these mapdepth = 50000.0 mapheight = 3000.0 #mountimg1 = pi3d.Texture("assets/textures/mountains3_512.jpg") ### get rid of this (we're in space) mountimg1 = pi3d.Texture( "assets/textures/grid.png") ### get rid of this (we're in space) bumpimg = pi3d.Texture( "assets/textures/grasstile_n.jpg") ### get rid of this (we're in space) reflimg = pi3d.Texture( "assets/textures/stars.jpg") ### update with space skybox #mymap = pi3d.ElevationMap("assets/textures/mountainsHgt.jpg", name="map",
import pi3d # Setup display and initialise pi3d display = pi3d.display(100,100,1700,800) #select the environment cube with 'box'... box=2 texs=pi3d.textures() if box==0: ectex = texs.loadTexture("textures/ecubes/skybox_interstellar.jpg") myecube = pi3d.createEnvironmentCube(900.0,"CROSS") elif box==1: ectex = texs.loadTexture("textures/ecubes/SkyBox.jpg") myecube = pi3d.createEnvironmentCube(900.0,"HALFCROSS") elif box==2: ectex=pi3d.loadECfiles("textures/ecubes/Interstellar","interstellar_256","png",texs) myecube = pi3d.createEnvironmentCube(900.0,"FACES") else: ectex=pi3d.loadECfiles("textures/ecubes","skybox_hall","jpg",texs) myecube = pi3d.createEnvironmentCube(900.0,"FACES") rot=0.0 tilt=0.0 # Fetch key presses mykeys = pi3d.key() mymouse = pi3d.mouse() mymouse.start() mtrx=pi3d.matrix() omx,omy=mymouse.x,mymouse.y
#======================================== # 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) #myecube = pi3d.EnvironmentCube(900.0,"HALFCROSS") ectex = pi3d.loadECfiles("textures/ecubes", "skybox_hall") myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="cube") myecube.set_draw_details(flatsh, ectex) # Create elevation map mapwidth = 1000.0 mapdepth = 1000.0 mapheight = 60.0 mountimg1 = pi3d.Texture("textures/mountains3_512.jpg") mymap = pi3d.ElevationMap("textures/mountainsHgt.jpg", name="map", width=mapwidth, depth=mapdepth, height=mapheight, ntiles=128, divx=32,
import pi3d,math,random rads = 0.017453292512 # degrees to radians # Setup display and initialise pi3d display = pi3d.display(100,100,1600,800) # Load textures texs = pi3d.textures() tree2img = texs.loadTexture("textures/tree2.png") tree1img = texs.loadTexture("textures/tree1.png") grassimg = texs.loadTexture("textures/grass.png") hb2img = texs.loadTexture("textures/hornbeam2.png") #load environment cube ectex = pi3d.loadECfiles("textures/ecubes/Interstellar","interstellar_256","png",texs) myecube = pi3d.createEnvironmentCube(900.0,"FACES") # Create elevation map mapwidth=1000.0 mapdepth=1000.0 mapheight=60.0 mountimg1 = texs.loadTexture("textures/mars_colour.png") mymap = pi3d.createElevationMapFromTexture("textures/mars_height.png",mapwidth,mapdepth,mapheight,128,128) #testislands.jpg #create robot metalimg = texs.loadTexture("textures/metalhull.jpg") robot_head= pi3d.createSphere(2.0,12,12,0.5,"",0,3,0) robot_body = pi3d.createCylinder(2.0,4,12,"",0,1,0) robot_leg = pi3d.createCuboid(0.7,4.0,1.0,"",0,0.8,0)
rads = 0.017453292512 # degrees to radians # Setup display and initialise pi3d display = pi3d.display() display.create3D(100,100,1600,800, 0.5, 800.0, 60.0) # x,y,width,height,near,far,aspect display.setBackColour(0.4,0.8,0.8,1) # r,g,b,alpha # Load textures tree2img = pi3d.loadTextureAlpha("textures/tree2.png") tree1img = pi3d.loadTextureAlpha("textures/tree1.png") grassimg = pi3d.loadTextureAlpha("textures/grass.png") hb2img = pi3d.loadTextureAlpha("textures/hornbeam2.png") #load environment cube ectex = pi3d.loadECfiles("textures/ecubes","sbox_interstellar") myecube = pi3d.createEnvironmentCube(900.0,"FACES") # Create elevation map mapwidth=1000.0 mapdepth=1000.0 mapheight=60.0 mountimg1 = pi3d.loadTexture("textures/mars_colour.png") mymap = pi3d.createElevationMapFromTexture("textures/mars_height.png",mapwidth,mapdepth,mapheight,128,128) #testislands.jpg #create robot metalimg = pi3d.loadTextureAlpha("textures/metalhull.jpg") robot_head= pi3d.createSphere(2.0,12,12,0.5,"",0,3,0) robot_body = pi3d.createCylinder(2.0,4,12,"",0,1,0) robot_leg = pi3d.createCuboid(0.7,4.0,1.0,"",0,0.8,0)
shader = pi3d.Shader("shaders/uv_reflect") flatsh = pi3d.Shader("shaders/uv_flat") shade2d = pi3d.Shader('shaders/2d_flat') #======================================== # create splash screen and draw it splash = pi3d.ImageSprite("textures/pi3d_splash.jpg", shade2d, w=10, h=10, z=0.2) splash.draw() DISPLAY.swap_buffers() ############################# ectex = pi3d.loadECfiles("textures/ecubes/RedPlanet", "redplanet_256", "png", True) myecube = pi3d.EnvironmentCube(size=1800.0, maptype="FACES") myecube.set_draw_details(flatsh, ectex) # Create elevation map mapwidth = 2000.0 mapdepth = 2000.0 mapheight = 100.0 redplanet = pi3d.Texture("textures/mars_colour.png") bumpimg = pi3d.Texture("textures/mudnormal.jpg") mymap = pi3d.ElevationMap(mapfile='textures/mars_height.png', width=mapwidth, depth=mapdepth, height=mapheight, divx=64, divy=64)
# Setup display and initialise pi3d display = pi3d.display() display.create3D(100, 100, 1600, 800, 0.5, 800.0, 60.0) # x,y,width,height,near,far,aspect display.setBackColour(0.4, 0.8, 0.8, 1) # r,g,b,alpha # Load textures texs = pi3d.textures() tree2img = texs.loadTexture("textures/tree2.png") tree1img = texs.loadTexture("textures/tree1.png") grassimg = texs.loadTexture("textures/grass.png") hb2img = texs.loadTexture("textures/hornbeam2.png") #load environment cube ectex = pi3d.loadECfiles("textures/ecubes", "sbox_interstellar", texs) myecube = pi3d.createEnvironmentCube(900.0, "FACES") # Create elevation map mapwidth = 1000.0 mapdepth = 1000.0 mapheight = 60.0 mountimg1 = texs.loadTexture("textures/mars_colour.png") mymap = pi3d.createElevationMapFromTexture("textures/mars_height.png", mapwidth, mapdepth, mapheight, 128, 128) #testislands.jpg #create robot metalimg = texs.loadTexture("textures/metalhull.jpg") robot_head = pi3d.createSphere(2.0, 12, 12, 0.5, "", 0, 3, 0) robot_body = pi3d.createCylinder(2.0, 4, 12, "", 0, 1, 0)
# Setup display and initialise pi3d DISPLAY = pi3d.Display.create(x=50, y=50) shader = pi3d.Shader('uv_flat') #======================================== #select the environment cube with 'box'... box = 3 if box == 0: ectex = [pi3d.Texture('textures/ecubes/skybox_interstellar.jpg')] myecube = pi3d.EnvironmentCube(size=900.0, maptype='CROSS') elif box == 1: ectex = [pi3d.Texture('textures/ecubes/SkyBox.jpg')] myecube = pi3d.EnvironmentCube(size=900.0, maptype='HALFCROSS') elif box == 2: ectex = pi3d.loadECfiles('textures/ecubes','sbox_interstellar', nobottom=True) myecube = pi3d.EnvironmentCube(size=900.0, maptype='FACES', nobottom=True) else: ectex = pi3d.loadECfiles('textures/ecubes','skybox_hall') myecube = pi3d.EnvironmentCube(size=900.0, maptype='FACES') myecube.set_draw_details(shader, ectex) rot = 0.0 tilt = 0.0 # Fetch key presses mykeys = pi3d.Keyboard() mymouse = pi3d.Mouse(restrict=False) mymouse.start()
CAMERA = pi3d.Camera() #======================================== # 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', suffix='png') myecube = pi3d.EnvironmentCube(size=1800.0, maptype='FACES') myecube.set_draw_details(flatsh, ectex) # Create elevation map mapwidth = 1800.0 mapdepth = 1800.0 mapheight = 120.0 mountimg1 = pi3d.Texture('textures/mountains3_512.jpg') bumpimg = pi3d.Texture('textures/grasstile_n.jpg') tigerbmp = pi3d.Texture('models/Tiger/tiger_bump.jpg') topbmp = pi3d.Texture('models/Tiger/top_bump.jpg') #roadway = pi3d.Texture('textures/road5.png') mymap = pi3d.ElevationMap(mapfile='textures/mountainsHgt2.png', width=mapwidth,
import pi3d, time, sys, math from random import randint import ircam ### Initialisze IR camera ircam.cam_init() # DISPLAY parameters DISP = pi3d.Display.create()#(x = 50, y = 50)# h = 1920, w = 1080) flatsh = pi3d.Shader('uv_flat') ectex = pi3d.loadECfiles('skybox_hall/','skybox_hall') #ectex = pi3d.loadECfiles('stripwood/','stripwood') myecube = pi3d.EnvironmentCube(size = 400.0, maptype = 'FACES') myecube.set_draw_details(flatsh, ectex) # Camera Settings CAM = pi3d.Camera(eye=(0.0,10.0,-80.0)) cube_1 = pi3d.Cuboid(w=10,h=10,d=10) cube_1.set_material((1,0,0)) cube_2 = pi3d.Cuboid(x = 40, y = -50, z =50, w=10, h=10, d=10) cube_2.set_material((0,1,0)) ############generate 15 random cubes#################
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") FOG = ((0.3, 0.3, 0.4, 0.8), 650.0) TFOG = ((0.2, 0.24, 0.22, 1.0), 350.0) #myecube = pi3d.EnvironmentCube(900.0,"HALFCROSS") ectex=pi3d.loadECfiles("textures/ecubes","sbox") myecube = pi3d.EnvironmentCube(size=900.0, maptype="FACES", name="cube") myecube.set_draw_details(flatsh, ectex) # Create elevation map mapwidth = 1000.0 mapdepth = 1000.0 mapheight = 45.0 # can't cope with much elevation mountimg1 = pi3d.Texture("textures/mountains3_512.jpg") mymap = pi3d.ElevationMap("textures/mountainsHgt.jpg", name="map", width=mapwidth, depth=mapdepth, height=mapheight, divx=32, divy=32) #testislands.jpg mymap.set_draw_details(shader, [mountimg1, bumpimg, bumpimg], 128.0, 0.0) mymap.set_fog(*FOG) #Create tree models
except Exception as e: print("exception:", e) #create the instances of Aeroplane a = Aeroplane("assets/models/starship.obj", 0.00, refid) ### Our ship a.z, a.direction = 905, 180 #a.z, a.direction = 1200, 180 #create instance of instruments inst = Instruments() others = {"start": 0.0} #contains a dictionary of other players keyed by refid thr = threading.Thread(target=json_load, args=(a, others)) thr.daemon = True #allows the program to exit even if a Thread is still running thr.start() # Load textures for the environment cube ectex = pi3d.loadECfiles("assets/textures/ecubes", "bkg1") myecube = pi3d.EnvironmentCube(size=7000.0, maptype="FACES", camera=CAMERA) myecube.set_draw_details(FLATSH, ectex) myecube.set_fog((0.0,0.0,0.0,1.0), 4000) # Create elevation map mapwidth = 50000.0 #probably need to increase these mapdepth = 50000.0 mapheight = 3000.0 #mountimg1 = pi3d.Texture("assets/textures/mountains3_512.jpg") ### get rid of this (we're in space) mountimg1 = pi3d.Texture("assets/textures/grid.png") ### get rid of this (we're in space) bumpimg = pi3d.Texture("assets/textures/grasstile_n.jpg") ### get rid of this (we're in space) reflimg = pi3d.Texture("assets/textures/stars.jpg") ### update with space skybox #mymap = pi3d.ElevationMap("assets/textures/mountainsHgt.jpg", name="map", # width=mapwidth, depth=mapdepth, height=mapheight, # divx=64, divy=64, camera=CAMERA) ###we don't need this mymap = pi3d.ElevationMap("assets/textures/mountainsHgt.jpg", name="map",