scshots = 1 #avatar camera rot=0.0 tilt=0.0 avhgt = 2.0 xm=0.0 zm=0.0 ym= -(mymap.calcHeight(xm,zm)+avhgt) # setup matrices mtrx = Matrix() # Fetch key presses mykeys = Keyboard() mymouse = Mouse() mymouse.start() omx=mymouse.x omy=mymouse.y # Display scene and rotate cuboid while 1: display.clear() mtrx.identity() mtrx.rotate(tilt, 0, 0) mtrx.rotate(0, rot, 0) mtrx.translate(xm,ym,zm) myecube.draw(ectex,xm,ym,zm)
def create(x=None, y=None, w=None, h=None, near=None, far=None, fov=DEFAULT_FOV, depth=DEFAULT_DEPTH, background=None, tk=False, window_title='', window_parent=None, mouse=False, frames_per_second=None, samples=DEFAULT_SAMPLES, use_pygame=False, layer=0, display_config=DISPLAY_CONFIG_DEFAULT): """ Creates a pi3d Display. *x* Left x coordinate of the display. If None, defaults to the x coordinate of the tkwindow parent, if any. *y* Top y coordinate of the display. If None, defaults to the y coordinate of the tkwindow parent, if any. *w* Width of the display. If None, full the width of the screen. *h* Height of the display. If None, full the height of the screen. *near* This will be used for the default instance of Camera *near* plane *far* This will be used for the default instance of Camera *far* plane *fov* Used to define the Camera lens field of view *depth* The bit depth of the display - must be 8, 16 or 24. *background* r,g,b,alpha (opacity) *tk* Do we use the tk windowing system? *window_title* A window title for tk windows only. *window_parent* An optional tk parent window. *mouse* Automatically create a Mouse. *frames_per_second* Maximum frames per second to render (None means "free running"). *samples* EGL_SAMPLES default 0, set to 4 for improved anti-aliasing *use_pygame* To use pygame for display surface, mouse and keyboard - as per windows This almost certainly would conflict if attempting to use in combination with tk=True. Default False *layer* display layer height - used by dispmanx on Raspberry Pi only. -128 will move the pi3d window behind the X11 desktop *display_config* Configuration of display - See pi3d.constants for DISPLAY_CONFIG options """ if tk: #NB this happens before Display created so use_pygame will not work on linux if PLATFORM != PLATFORM_PI and PLATFORM != PLATFORM_ANDROID: #just use python-xlib same as non-tk but need dummy behaviour from pi3d.Keyboard import Keyboard class DummyTkWin(object): def __init__(self): self.tkKeyboard = Keyboard() self.ev = "" self.key = "" self.winx, self.winy = 0, 0 self.width, self.height = 1920, 1180 self.event_list = [] def update(self): if PLATFORM == PLATFORM_WINDOWS or pi3d.USE_PYGAME: #uses pygame UI k = self.tkKeyboard.read() if k == -1: self.key = "" self.ev = "" else: if k == 27: self.key = "Escape" else: self.key = chr(k) self.ev = "key" else: self.key = self.tkKeyboard.read_code() if self.key == "": self.ev = "" else: self.ev = "key" tkwin = DummyTkWin() x = x or 0 y = y or 0 else: from pi3d.util import TkWin if not (w and h): # TODO: how do we do full-screen in tk? #LOGGER.error('Can't compute default window size when using tk') #raise Exception # ... just force full screen - TK will automatically fit itself into the screen w = 1920 h = 1180 if background is not None: bg_i = [int(i * 255) for i in background] bg = '#{:02X}{:02X}{:02X}'.format(bg_i[0], bg_i[1], bg_i[2]) else: bg = '#000000' tkwin = TkWin.TkWin(window_parent, window_title, w, h, bg) tkwin.update() w = tkwin.winfo_width() h = tkwin.winfo_height() if x is None: x = tkwin.winx if y is None: y = tkwin.winy else: tkwin = None x = x or 0 y = y or 0 display = Display(tkwin, use_pygame) if (w or 0) <= 0: w = display.max_width - 2 * x if w <= 0: w = display.max_width if (h or 0) <= 0: h = display.max_height - 2 * y if h <= 0: h = display.max_height LOGGER.debug('Display size is w=%d, h=%d', w, h) display.frames_per_second = frames_per_second if near is None: near = DEFAULT_NEAR if far is None: far = DEFAULT_FAR display.width = w display.height = h display.near = near display.far = far display.fov = fov display.left = x display.top = y display.right = x + w display.bottom = y + h display.layer = layer display.opengl.create_display(x, y, w, h, depth=depth, samples=samples, layer=layer, display_config=display_config) if PLATFORM == PLATFORM_ANDROID: display.width = display.right = display.max_width = display.opengl.width #not available until after create_display display.height = display.bottom = display.max_height = display.opengl.height display.top = display.bottom = 0 if frames_per_second is not None: display.android.frames_per_second = frames_per_second display.frames_per_second = None #to avoid clash between two systems! display.mouse = None if mouse: from pi3d.Mouse import Mouse display.mouse = Mouse(width=w, height=h, restrict=False) display.mouse.start() if background is not None: display.set_background(*background) return display
def create(x=None, y=None, w=None, h=None, near=None, far=None, fov=DEFAULT_FOV, depth=DEFAULT_DEPTH, background=None, tk=False, window_title='', window_parent=None, mouse=False, frames_per_second=None): """ Creates a pi3d Display. *x* Left x coordinate of the display. If None, defaults to the x coordinate of the tkwindow parent, if any. *y* Top y coordinate of the display. If None, defaults to the y coordinate of the tkwindow parent, if any. *w* Width of the display. If None, full the width of the screen. *h* Height of the display. If None, full the height of the screen. *near* This will be used for the default instance of Camera *near* plane *far* This will be used for the default instance of Camera *far* plane *fov* Used to define the Camera lens field of view *depth* The bit depth of the display - must be 8, 16 or 24. *background* r,g,b,alpha (opacity) *tk* Do we use the tk windowing system? *window_title* A window title for tk windows only. *window_parent* An optional tk parent window. *mouse* Automatically create a Mouse. *frames_per_second* Maximum frames per second to render (None means "free running"). """ if tk: from pi3d.util import TkWin if not (w and h): # TODO: how do we do full-screen in tk? #LOGGER.error("Can't compute default window size when using tk") #raise Exception # ... just force full screen - TK will automatically fit itself into the screen w = 1920 h = 1180 tkwin = TkWin.TkWin(window_parent, window_title, w, h) tkwin.update() if x is None: x = tkwin.winx if y is None: y = tkwin.winy else: tkwin = None x = x or 0 y = y or 0 display = Display(tkwin) if (w or 0) <= 0: w = display.max_width - 2 * x if w <= 0: w = display.max_width if (h or 0) <= 0: h = display.max_height - 2 * y if h <= 0: h = display.max_height LOGGER.debug('Display size is w=%d, h=%d', w, h) display.frames_per_second = frames_per_second if near is None: near = DEFAULT_NEAR if far is None: far = DEFAULT_FAR display.width = w display.height = h display.near = near display.far = far display.fov = fov display.left = x display.top = y display.right = x + w display.bottom = y + h display.opengl.create_display(x, y, w, h, depth) display.mouse = None if mouse: from pi3d.Mouse import Mouse display.mouse = Mouse(width=w, height=h) display.mouse.start() # This code now replaced by camera 'lens' """opengles.glMatrixMode(GL_PROJECTION) Utility.load_identity() if is_3d: hht = near * math.tan(math.radians(aspect / 2.0)) hwd = hht * w / h opengles.glFrustumf(c_float(-hwd), c_float(hwd), c_float(-hht), c_float(hht), c_float(near), c_float(far)) opengles.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) else: opengles.glOrthof(c_float(0), c_float(w), c_float(0), c_float(h), c_float(near), c_float(far)) """ opengles.glMatrixMode(GL_MODELVIEW) Utility.load_identity() if background: display.set_background(*background) return display
smmap = ImageSprite(mountimg1, shade2d, w=10, h=10, z=0.2) smmap.set_2d_size(w=200, h=200, x=DISPLAY.width - 200, y=DISPLAY.height - 200) #dot1tex = Texture("textures/red_ball.png") dot1 = ImageSprite("textures/red_ball.png", shade2d, w=10, h=10, z=0.1) dot1.set_2d_size(w=10, h=10) # 10x10 pixels dot2 = ImageSprite("textures/blu_ball.png", shade2d, w=10, h=10, z=0.05) dot2.set_2d_size(w=10, h=10) #player tank vars tankrot = 180.0 turret = 0.0 tankroll = 0.0 #side-to-side roll of tank on ground tankpitch = 0.0 #too and fro pitch of tank on ground lol catface #key presses mymouse = Mouse(restrict = False) mymouse.start() omx, omy = mymouse.position() #position vars mouserot = 0.0 tilt = 0.0 avhgt = 0.85 xm, oxm = 0.0, -1.0 zm, ozm = -200.0, -1.0 ym = mymap.calcHeight(xm, zm) + avhgt #enemy tank vars etx = 120 etz = -120 etr = 0.0
def create(x=None, y=None, w=None, h=None, near=None, far=None, fov=DEFAULT_FOV, depth=DEFAULT_DEPTH, background=None, tk=False, window_title='', window_parent=None, mouse=False, frames_per_second=None): """ Creates a pi3d Display. *x* Left x coordinate of the display. If None, defaults to the x coordinate of the tkwindow parent, if any. *y* Top y coordinate of the display. If None, defaults to the y coordinate of the tkwindow parent, if any. *w* Width of the display. If None, full the width of the screen. *h* Height of the display. If None, full the height of the screen. *near* This will be used for the default instance of Camera *near* plane *far* This will be used for the default instance of Camera *far* plane *fov* Used to define the Camera lens field of view *depth* The bit depth of the display - must be 8, 16 or 24. *background* r,g,b,alpha (opacity) *tk* Do we use the tk windowing system? *window_title* A window title for tk windows only. *window_parent* An optional tk parent window. *mouse* Automatically create a Mouse. *frames_per_second* Maximum frames per second to render (None means "free running"). """ if tk: if PLATFORM != PLATFORM_PI: #just use python-xlib same as non-tk but need dummy behaviour class DummyTkWin(object): def __init__(self): self.tkKeyboard = Keyboard() self.ev = "" self.key = "" self.winx, self.winy = 0, 0 self.width, self.height = 1920, 1180 self.event_list = [] def update(self): self.key = self.tkKeyboard.read_code() if self.key == "": self.ev = "" else: self.ev = "key" tkwin = DummyTkWin() x = x or 0 y = y or 0 else: from pi3d.util import TkWin if not (w and h): # TODO: how do we do full-screen in tk? #LOGGER.error('Can't compute default window size when using tk') #raise Exception # ... just force full screen - TK will automatically fit itself into the screen w = 1920 h = 1180 tkwin = TkWin.TkWin(window_parent, window_title, w, h) tkwin.update() if x is None: x = tkwin.winx if y is None: y = tkwin.winy else: tkwin = None x = x or 0 y = y or 0 display = Display(tkwin) if (w or 0) <= 0: w = display.max_width - 2 * x if w <= 0: w = display.max_width if (h or 0) <= 0: h = display.max_height - 2 * y if h <= 0: h = display.max_height LOGGER.debug('Display size is w=%d, h=%d', w, h) display.frames_per_second = frames_per_second if near is None: near = DEFAULT_NEAR if far is None: far = DEFAULT_FAR display.width = w display.height = h display.near = near display.far = far display.fov = fov display.left = x display.top = y display.right = x + w display.bottom = y + h display.opengl.create_display(x, y, w, h, depth) display.mouse = None if mouse: from pi3d.Mouse import Mouse display.mouse = Mouse(width=w, height=h, restrict=False) display.mouse.start() if background: display.set_background(*background) return display
mapdepth=50.0 maphalf=23.0 mapheight=8 #set smooth to give proper normals mymap = ElevationMap("textures/Piom1b.jpg",mapwidth,mapdepth,mapheight,64,64,128,"sub",0,0,0, smooth=True) ################### increased tiles to 32 # lighting. The default light is a point light but I have made the position method capable of creating # a directional light and this is what I do inside the loop. If you want a torch you don't need to move it about light = Light(0, 2, 2, 1, "", 1,2,3, 0.1,0.1,0.2) #yellowish 'torch' or 'sun' with low level blueish ambient light.position(1,2,3,0) # set to directional light by settin position with 0 fourth parameter light.on() ########## need to create instances of these before using them in the loop! ################# camera = Matrix() #################### mykeys = Key() #################### mymouse = Mouse() #################### mymouse.start() #################### omx=mymouse.x #################### omy=mymouse.y #################### xm, zm = 0, 0 #################### avhgt = 2.0 #################### ym = -(mymap.calcHeight(xm,zm)+avhgt) #################### rot, tilt = 0.0, 0.0 #################### sx, sy, sz = 5, 5, -5 #################### dsx, dsy, dsz = 0.1, 0.0, -0.1 #################### gravity = 0.02 #################### ############################################################################################# while 1: