Пример #1
0
#screenshot number
scshots = 1

#avatar camera
rot = 0.0
tilt = 0.0
roll = 0.0001  # to trick the camera update first time through loop before mouse movement
avhgt = 3.5
xm = 0.0
zm = 0.0
ym = mymap.calcHeight(xm, zm) + avhgt

# Fetch key presses
mykeys = pi3d.Keyboard()
mymouse = pi3d.Mouse(restrict=False)
mymouse.start()

start_vector = CAMERA.camera_3d.get_direction()

# Display scene and rotate cuboid
while DISPLAY.loop_running():
    l_or_k_pressed = False  # to stop routine camera movement for cases where l or k pressed
    #Press ESCAPE to terminate
    mx, my = mymouse.position()
    buttons = mymouse.button_status()
    k = mykeys.read()
    if k > -1:  # or buttons > mymouse.BUTTON_UP:
        dx, dy, dz = CAMERA.get_direction()
        if k == 119 or buttons == mymouse.LEFT_BUTTON:  #key W
            xm += dx
Пример #2
0
flatsh = pi3d.Shader("uv_flat")
postsh = pi3d.Shader('post_pixelize')
post = pi3d.PostProcess(camera=cam, shader=postsh, scale=SCALE)

# Create texture for video
tex = pi3d.Texture(
    image)  # can pass numpy array or PIL.Image rather than path as string

# Create 2D flat sprite for the video texture
sprite = pi3d.Sprite(camera=cam, w=display.width, h=display.height)
sprite.set_shader(flatsh)
sprite.set_draw_details(flatsh, [tex])

## interactive inputs ##
kbd = pi3d.Keyboard()
mouse = pi3d.Mouse()  # pi3d.Mouse(restrict = True) # changes input coordinates
mouse.start()
MX, MY = mouse.position()
MXC, MYC = mouse.position()
MC = mouse.button_status(
)  # 8 = hover, 9 = right Click down, 10 = left C, 12 = middle C
MouseClicked = False

## set up time ##
iTIME = 0
iTIMEDELTA = 0
iFRAME = 0
iDate = datetime.datetime.now()
#print ("The current local date time is ", iDate)
(YR, MTH, DAY) = (iDate.year, iDate.month, iDate.day)
iDateSecondsSinceMidnight = iDate.hour * 60 * 60 + iDate.minute * 60 + iDate.second
Пример #3
0
mi112 = pi3d.MenuItem(gui, "x2", callback=cb)
mi121 = pi3d.MenuItem(gui, "v3", callback=cb)
mi122 = pi3d.MenuItem(gui, "v4", callback=cb)

menu1 = pi3d.Menu(parent_item=None, menuitems=[mi1, mi2, mi3],
          x=-ww, y=hh-32, visible=True)
menu2 = pi3d.Menu(parent_item=mi1, menuitems=[mi11, mi12], horiz=False, position='below')
menu3 = pi3d.Menu(parent_item=mi11, menuitems=[mi111, mi112], horiz=False, position='right')
menu4 = pi3d.Menu(parent_item=mi12, menuitems=[mi121, mi122], horiz=False, position='right')

textbox = pi3d.TextBox(gui, "type here", 100, -180, callback=cb, label='TextBox (KEY t to edit)',
                        shortcut='t')

mx, my = 0, 0
#inputs = pi3d.InputEvents()
mouse = pi3d.Mouse(use_x=True, restrict=True)
if pi3d.PLATFORM == pi3d.PLATFORM_PI:
  x_off = -DISPLAY.left - DISPLAY.width / 2
  y_off = DISPLAY.top + DISPLAY.height / 2 - DISPLAY.max_height
#inputs.get_mouse_movement()
mouse.start()
keyboard = pi3d.Keyboard()
shifted = False
caps = False

while DISPLAY.loop_running(): #and not inputs.key_state("KEY_ESC"):
  mx, my = mouse.position()
  if pi3d.PLATFORM == pi3d.PLATFORM_PI:
    mx += x_off
    my += y_off
  buttons = mouse.button_status()
Пример #4
0
    tm = time.time()

    skip_ahead = False

    # Check for new files and reset to latest if so
    if config.LATEST_FIRST:
        temp_iFiles, temp_nFi = get_files(date_from, date_to)
        if (temp_nFi != nFi):
            print('New file, resetting...')
            iFiles = temp_iFiles
            nFi = temp_nFi
            next_pic_num = 0
            skip_ahead = True

    if config.MOUSE:
        mouse = pi3d.Mouse()
        mouse.start()
        current_button = mouse.button_status()
        if current_button == 9 and last_button != current_button:
            print('Mouse click detected, skipping to next photo...')
            skip_ahead = True
        last_button = current_button

    if skip_ahead or (tm > nexttm and not paused) or (
            tm - nexttm) >= 86400.0:  # this must run first iteration of loop
        if nFi > 0:
            nexttm = tm + time_delay
            sbg = sfg
            sfg = None
            start_pic_num = next_pic_num
            loop_count = 0
Пример #5
0
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()