123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550 |
- ################################################
- #joystick flythrough camera for scene testing #
- #shuvit.org #
- ################################################
-
- import bge
-
- def main():
- #####
- #init
- cont = bge.logic.getCurrentController()
- scene = bge.logic.getCurrentScene()
- own = cont.owner
- dict = bge.logic.globalDict #Get the global dictionary
- aXis = cont.sensors['stickDirections']
- bUtt = cont.sensors['buttons']
- reduction = 400000
- axisTh = 0.03
-
- dict['last_aBut'] = own['aBut']
- dict['last_bBut'] = own['bBut']
- dict['last_xBut'] = own['xBut']
- dict['last_yBut'] = own['yBut']
- dict['last_lBump'] = own['lBump']
- dict['last_rBump'] = own['rBump']
- dict['last_stBut'] = own['stBut']
- dict['last_bkBut'] = own['bkBut']
- dict['last_ltsBut'] = own['ltsBut']
- dict['last_rtsBut'] = own['rtsBut']
-
- #hard controller mappings
- lar_lts = 0
- uad_lts = 1
- lar_rts = 2
- uad_rts = 3
- lt = 4
- rt = 5
- a_but = 0
- b_but = 1
- x_but = 2
- y_but = 3
- l_bump = 9
- r_bump = 10
- bk_but = 4
- st_but = 6
- xb_but = 5
- lts_pr = 7
- rts_pr = 8
- l_dp = 13
- r_dp = 14
- u_dp = 11
- d_dp = 12
-
- reduction = 400000
- axisTh = 0.03
-
- #get controller axis value 0-100
- lLR = aXis.axisValues[lar_lts] / reduction / .082 * 100
- lUD = aXis.axisValues[uad_lts] / reduction / .082 * 100 - 20 / 80
- rLR = aXis.axisValues[lar_rts] / reduction / .082 * 100 - 20 / 80
- rUD = aXis.axisValues[uad_rts] / reduction / .082 * 100 - 20 / 80
- lTrig = aXis.axisValues[lt] / reduction / .082 * 100 - 20 / 80
- rTrig = aXis.axisValues[rt] / reduction / .082 * 100 - 20 / 80
-
- aBut = bUtt.getButtonStatus(a_but)
- bBut = bUtt.getButtonStatus(b_but)
- xBut = bUtt.getButtonStatus(x_but)
- yBut = bUtt.getButtonStatus(y_but)
- lBump = bUtt.getButtonStatus(l_bump)
- rBump = bUtt.getButtonStatus(r_bump)
- bkBut = bUtt.getButtonStatus(bk_but)
- stBut = bUtt.getButtonStatus(st_but)
- xbBut = bUtt.getButtonStatus(xb_but)
- ltsBut = bUtt.getButtonStatus(lts_pr)
- rtsBut = bUtt.getButtonStatus(rts_pr)
- ldPad = bUtt.getButtonStatus(l_dp)
- rdPad = bUtt.getButtonStatus(r_dp)
- udPad = bUtt.getButtonStatus(u_dp)
- ddPad = bUtt.getButtonStatus(d_dp)
-
- #check if idle
- idle_trig_list = [lLR, lUD, rLR, rUD, lTrig, rTrig]
- idle_time = 240
- idle_set = 1
- for sens in idle_trig_list:
- if sens > 20 or sens < -20:
- idle_set = 0
- own['idle_timer'] = idle_time
- if idle_set == idle_time:
- pass
- if own['idle_timer'] == 1:
- own['idle'] = True
- #own['idlecampos_x'] = 0
- own['idlecampos_z'] = 0
- else:
- own['idle'] = False
-
- if own['idle_timer'] > 1:
- own['idle_timer'] -= 1
-
- #idle cam movement
- if own['idle']:
- move_len = 1080
- if own['idlecampos_x'] < move_len:
- own['idlecampos_x'] += 1
- if own['idlecampos_x'] == move_len:
- own['idlecampos_x'] = 0
-
- if own['idlecampos_x'] < (move_len / 2):
- move = [.0002, 0, 0]
- own.applyMovement( move, True)
- own.applyRotation([.00004, 0, .00005],True)
- #print('idle2')
- if own['idlecampos_x'] > (move_len / 2):
- move = [-.0002, 0, 0]
- own.applyMovement( move, True)
- own.applyRotation([-.00004, 0, -.00005],True)
-
- #####
- #create modified axis values
- if lLR < -20:
- lmLR = round((lLR + 20) / 80 * 100, 0)
- elif lLR > 20:
- lmLR = round((lLR - 20) / 80 * 100, 0)
- else: lmLR = 0
-
- if lUD > 20:
- lmUD = round((lUD - 20) / 80 * 100, 0)
- elif lUD < -20:
- lmUD = round((lUD + 20) / 80 * 100, 0)
- else: lmUD = 0
-
- if rLR < -20:
- rmLR = round((rLR + 20) / 80 * 100, 0)
- elif rLR > 20:
- rmLR = round((rLR - 20) / 80 * 100, 0)
- else: rmLR = 0
-
- if rUD > 20:
- rmUD = round((rUD - 20) / 80 * 100, 0)
- elif rUD < -20:
- rmUD = round((rUD + 20) / 80 * 100, 0)
- else: rmUD = 0
-
- if lTrig > 3:
- mTrig = lTrig * -1
- elif rTrig > 3:
- mTrig = rTrig
- else: mTrig = 0
-
- #move camera
- damping = .95
- damping2 = 1.005
- mult = .0005 * own['speed_mult']
- move_x = lmUD * mult
- move_y = lmLR * mult
- move_z = (mTrig * -mult) / 4
-
- rot_mult = -.00015 * own['speed_mult']
- rot_x = rmUD * rot_mult
- rot_y = rmLR * rot_mult
-
- if move_x == 0 and own['last_move_x'] != 0:
- move_x = own['last_move_x'] * damping
- if move_y == 0 and own['last_move_y'] != 0:
- move_y = own['last_move_y'] * damping
- if move_z == 0 and own['last_move_z'] != 0:
- move_z = own['last_move_z'] * damping
- if rot_x == 0 and own['last_rot_x'] != 0:
- rot_x = own['last_rot_x'] * damping
- if rot_y == 0 and own['last_rot_y'] != 0:
- rot_y = own['last_rot_y'] * damping
-
- move = [move_y, 0, move_x]
- own.applyMovement( move, True)
- own.applyMovement([0, 0, move_z], False)
- own.applyRotation([rot_x, 0, 0],True)
- own.applyRotation([0, 0, rot_y],False)
-
- mult = .1 #* own['speed_mult']
- if lBump == True and own['lBump'] == False:
- if own['speed_mult'] > .1:
- own['speed_mult'] = round(own['speed_mult'] - mult, 2)
- if rBump == True and own['rBump'] == False:
- if own['speed_mult'] < 5.5:
- own['speed_mult'] = round(own['speed_mult'] + mult, 2)
- if stBut == True and own['stBut'] != True:
- if own['menu_on'] == False:
- own['menu_on'] = True
- else:
- own['menu_on'] = False
- menu_item = own['menu_item']
- menu_list = ['Brightness/Contrast: ', 'FXAA: ', 'SSAO: ', 'HDR: ', 'Camera: ', 'Restart: ', 'Exit: ']
-
- brightnesscontrast_opt = ['On/Off: ', 'Brightness Value: ', 'Contrast Value: ', 'Back: ']
- fxaa_opt = ['On/Off: ', 'FXAA Span Max: ', 'Back: ']
- ssao_opt = ['On/Off: ', 'SSAO Only: ', 'SSAO Width: ', 'SSAO Radius: ', 'Back: ']
- hdr_opt = ['On/Off: ', 'HDR Amount: ', 'HDR AvgL: ', 'Back: ']
- camera_opt = ['Focal Length: ', 'Back: ']
- ################
- submenu_on = own['submenu_on']
- if aBut == False and own['aBut'] == True:
- if submenu_on:
- own['submenu_item'] += 1
- else:
- if own['menu_item'] < (len(menu_list) - 1):
- own['menu_item'] += 1
- if yBut == False and own['yBut'] == True:
- if submenu_on:
- own['submenu_item'] -= 1
- else:
- if own['menu_item'] > 0:
- own['menu_item'] -= 1
- menu_item = own['menu_item']
- submenu_item = own['submenu_item']
- dict['menuText'] = menu_list[menu_item]
- if menu_list[menu_item] == 'Brightness/Contrast: ':
- if submenu_on == True:
- try:
- dict['submenuText'] = brightnesscontrast_opt[submenu_item]
- except:
- submenu_item = 0
- own['submenu_item'] = 0
- dict['submenuText'] = brightnesscontrast_opt[submenu_item]
- if brightnesscontrast_opt[submenu_item] == 'On/Off: ':
- if own['bc'] == False:
- dict['optionText'] = 'Off'
- if own['bc'] == True:
- dict['optionText'] = 'On'
- if brightnesscontrast_opt[submenu_item] == 'Brightness Value: ':
- dict['optionText'] = round(own['BC_BRIGHTNESS'], 2)
- if brightnesscontrast_opt[submenu_item] == 'Contrast Value: ':
- dict['optionText'] = round(own['BC_CONTRAST'], 2)
- if brightnesscontrast_opt[submenu_item] == 'Back: ':
- dict['optionText'] = '_'
- else:
- dict['optionText'] = ''
- if menu_list[menu_item] == 'FXAA: ':
- if submenu_on == True:
- try:
- dict['submenuText'] = fxaa_opt[submenu_item]
- except:
- submenu_item = 0
- own['submenu_item'] = 0
- dict['submenuText'] = fxaa_opt[submenu_item]
- if fxaa_opt[submenu_item] == 'On/Off: ':
- if own['bc'] == False:
- dict['optionText'] = 'Off'
- if own['bc'] == True:
- dict['optionText'] = 'On'
- if fxaa_opt[submenu_item] == 'FXAA Span Max: ':
- dict['optionText'] = round(own['FXAA_SPAN_MAX'], 2)
- if fxaa_opt[submenu_item] == 'Back: ':
- dict['optionText'] = '_'
- else:
- dict['optionText'] = ''
- if menu_list[menu_item] == 'HDR: ':
- if submenu_on == True:
- try:
- dict['submenuText'] = hdr_opt[submenu_item]
- except:
- submenu_item = 0
- own['submenu_item'] = 0
- dict['submenuText'] = hdr_opt[submenu_item]
- if hdr_opt[submenu_item] == 'On/Off: ':
- if own['bc'] == False:
- dict['optionText'] = 'Off'
- if own['bc'] == True:
- dict['optionText'] = 'On'
- if hdr_opt[submenu_item] == 'HDR Amount: ':
- dict['optionText'] = round(own['HDRamount'], 2)
- if hdr_opt[submenu_item] == 'HDR AvgL: ':
- dict['optionText'] = round(own['avgL'], 2)
- if hdr_opt[submenu_item] == 'Back: ':
- dict['optionText'] = '_'
- else:
- dict['optionText'] = ''
- if menu_list[menu_item] == 'SSAO: ':
- if submenu_on == True:
- try:
- dict['submenuText'] = ssao_opt[submenu_item]
- except:
- submenu_item = 0
- own['submenu_item'] = 0
- dict['submenuText'] = ssao_opt[submenu_item]
- if ssao_opt[submenu_item] == 'On/Off: ':
- if own['ao'] == False:
- dict['optionText'] = 'Off'
- if own['ao'] == True:
- dict['optionText'] = 'On'
- if ssao_opt[submenu_item] == 'SSAO Only: ':
- if own['onlyAO'] == False:
- dict['optionText'] = 'Off'
- if own['onlyAO'] == True:
- dict['optionText'] = 'On'
- if ssao_opt[submenu_item] == 'SSAO Width: ':
- dict['optionText'] = round(own['aowidth'], 2)
- if ssao_opt[submenu_item] == 'SSAO Radius: ':
- dict['optionText'] = round(own['aoradius'], 2)
- if ssao_opt[submenu_item] == 'Back: ':
- dict['optionText'] = '_'
- else:
- dict['optionText'] = ''
- if menu_list[menu_item] == 'Camera: ':
- if submenu_on == True:
- try:
- dict['submenuText'] = camera_opt[submenu_item]
- except:
- submenu_item = 0
- own['submenu_item'] = 0
- dict['submenuText'] = camera_opt[submenu_item]
- if camera_opt[submenu_item] == 'Focal Length: ':
- dict['optionText'] = round(own['cam_focal_length'], 2)
- if camera_opt[submenu_item] == 'Back: ':
- dict['optionText'] = '_'
- else:
- dict['optionText'] = ''
- if menu_list[menu_item] == 'Restart: ':
- dict['optionText'] = ''
- if menu_list[menu_item] == 'Exit: ':
- dict['optionText'] = ''
-
- #b button pressed
- if bBut == False and own['bBut'] == True:
- if menu_list[menu_item] == 'Brightness/Contrast: ':
- if submenu_on == False:
- submenu_on = True
- own['submenu_on'] = True
- elif submenu_on:
- if brightnesscontrast_opt[submenu_item] == 'On/Off: ':
- if own['bc'] == False:
- own['bc'] = True
- act = cont.actuators['bc_act']
- cont.activate(act)
- dict['optionText'] = 'On'
- if brightnesscontrast_opt[submenu_item] == 'Brightness Value: ':
- own['BC_BRIGHTNESS'] += .025
- if brightnesscontrast_opt[submenu_item] == 'Contrast Value: ':
- own['BC_CONTRAST'] += .025
- if brightnesscontrast_opt[submenu_item] == 'Back: ':
- own['submenu_on'] = False
- dict['optionText'] = '_'
- own['submenu_item'] = 0
- if menu_list[menu_item] == 'FXAA: ':
- if submenu_on == False:
- submenu_on = True
- own['submenu_on'] = True
- elif submenu_on:
- if fxaa_opt[submenu_item] == 'On/Off: ':
- if own['bc'] == False:
- own['bc'] = True
- act = cont.actuators['fxaa']
- cont.activate(act)
- dict['optionText'] = 'On'
- if fxaa_opt[submenu_item] == 'FXAA Span Max: ':
- own['FXAA_SPAN_MAX'] += 1
- if fxaa_opt[submenu_item] == 'Back: ':
- own['submenu_on'] = False
- dict['optionText'] = '_'
- own['submenu_item'] = 0
- if menu_list[menu_item] == 'SSAO: ':
- if submenu_on == False:
- submenu_on = True
- own['submenu_on'] = True
- elif submenu_on:
- if ssao_opt[submenu_item] == 'On/Off: ':
- if own['ao'] == False:
- own['ao'] = True
- act = cont.actuators['ao_act']
- cont.activate(act)
- dict['optionText'] = 'On'
- if ssao_opt[submenu_item] == 'SSAO Only: ':
- if own['onlyAO'] == False:
- own['onlyAO'] = True
- if ssao_opt[submenu_item] == 'SSAO Width: ':
- own['aowidth'] += 1
- if ssao_opt[submenu_item] == 'SSAO Radius: ':
- own['aoradius'] += 1
- if ssao_opt[submenu_item] == 'Back: ':
- own['submenu_on'] = False
- dict['optionText'] = '_'
- own['submenu_item'] = 0
- if menu_list[menu_item] == 'HDR: ':
- if submenu_on == False:
- submenu_on = True
- own['submenu_on'] = True
- elif submenu_on:
- if hdr_opt[submenu_item] == 'On/Off: ':
- if own['hdr'] == False:
- own['hdr'] = True
- act = cont.actuators['hdr_act']
- cont.activate(act)
- dict['optionText'] = 'On'
- if hdr_opt[submenu_item] == 'HDR Amount: ':
- own['HDRamount'] += .05
- if hdr_opt[submenu_item] == 'HDR AvgL: ':
- own['avgL'] += .05
- if hdr_opt[submenu_item] == 'Back: ':
- own['submenu_on'] = False
- dict['optionText'] = '_'
- own['submenu_item'] = 0
- if menu_list[menu_item] == 'Camera: ':
- if submenu_on == False:
- submenu_on = True
- own['submenu_on'] = True
- elif submenu_on:
- if camera_opt[submenu_item] == 'Focal Length: ':
- own['cam_focal_length'] += 1
- own.lens = own['cam_focal_length']
- if camera_opt[submenu_item] == 'Back: ':
- own['submenu_on'] = False
- dict['optionText'] = '_'
- own['submenu_item'] = 0
- if menu_list[menu_item] == 'Restart: ':
- scene.restart()
- if menu_list[menu_item] == 'Exit: ':
- bge.logic.endGame()
-
- #x button up
- if xBut == False and own['xBut'] == True:
- if menu_list[menu_item] == 'Brightness/Contrast: ':
- if submenu_on == False:
- submenu_on = True
- own['submenu_on'] = True
- if submenu_on:
- if brightnesscontrast_opt[submenu_item] == 'On/Off: ':
- if own['bc'] == True:
- own['bc'] = False
- act = cont.actuators['bc_off']
- cont.activate(act)
- dict['optionText'] = 'Off'
- if brightnesscontrast_opt[submenu_item] == 'Brightness Value: ':
- own['BC_BRIGHTNESS'] -= .025
- if brightnesscontrast_opt[submenu_item] == 'Contrast Value: ':
- own['BC_CONTRAST'] -= .025
- if brightnesscontrast_opt[submenu_item] == 'Back: ':
- own['submenu_on'] = False
- dict['optionText'] = '_'
- own['submenu_item'] = 0
- if menu_list[menu_item] == 'FXAA: ':
- if submenu_on == False:
- submenu_on = True
- own['submenu_on'] = True
- if submenu_on:
- if fxaa_opt[submenu_item] == 'On/Off: ':
- if own['fxaa'] == True:
- own['fxaa'] = False
- act = cont.actuators['fxaa_off']
- cont.activate(act)
- dict['optionText'] = 'Off'
- if fxaa_opt[submenu_item] == 'FXAA Span Max: ':
- own['FXAA_SPAN_MAX'] -= 1
- if fxaa_opt[submenu_item] == 'Back: ':
- own['submenu_on'] = False
- dict['optionText'] = '_'
- own['submenu_item'] = 0
- if menu_list[menu_item] == 'SSAO: ' :
- if submenu_on == False:
- submenu_on = True
- own['submenu_on'] = True
- if submenu_on:
- if ssao_opt[submenu_item] == 'On/Off: ':
- if own['ao'] == True:
- own['ao'] = False
- act = cont.actuators['ao_off']
- cont.activate(act)
- dict['optionText'] = 'Off'
- if ssao_opt[submenu_item] == 'SSAO Only: ':
- if own['onlyAO'] == True:
- own['onlyAO'] = False
- if ssao_opt[submenu_item] == 'SSAO Width: ':
- own['aowidth'] -= 1
- if ssao_opt[submenu_item] == 'SSAO Radius: ':
- own['aoradius'] -= 1
- if ssao_opt[submenu_item] == 'Back: ':
- own['submenu_on'] = False
- dict['optionText'] = '_'
- own['submenu_item'] = 0
- if menu_list[menu_item] == 'HDR: ':
- if submenu_on == False:
- submenu_on = True
- own['submenu_on'] = True
- if submenu_on:
- if hdr_opt[submenu_item] == 'On/Off: ':
- if own['hdr'] == True:
- own['hdr'] = False
- act = cont.actuators['hdr_off']
- cont.activate(act)
- dict['optionText'] = 'Off'
- if hdr_opt[submenu_item] == 'HDR Amount: ':
- own['HDRamount'] -= .05
- if hdr_opt[submenu_item] == 'HDR AvgL: ':
- own['avgL'] -= .05
- if hdr_opt[submenu_item] == 'Back: ':
- own['submenu_on'] = False
- dict['optionText'] = '_'
- own['submenu_item'] = 0
- if menu_list[menu_item] == 'Camera: ':
- if submenu_on == False:
- submenu_on = True
- own['submenu_on'] = True
- elif submenu_on:
- if camera_opt[submenu_item] == 'Focal Length: ':
- own['cam_focal_length'] -= 1
- own.lens = own['cam_focal_length']
- if camera_opt[submenu_item] == 'Back: ':
- own['submenu_on'] = False
- dict['optionText'] = '_'
- own['submenu_item'] = 0
-
-
- own['lmLR'] = lmLR
- own['lmUD'] = lmUD
- own['rmLR'] = rmLR
- own['rmUD'] = rmUD
- own['mTrig'] = mTrig
- own['last_move_x'] = move_x
- own['last_move_y'] = move_y
- own['last_move_z'] = move_z
- own['last_rot_x'] = rot_x
- own['last_rot_y'] = rot_y
- own['aBut'] = aBut
- own['bBut'] = bBut
- own['xBut'] = xBut
- own['yBut'] = yBut
- own['lBump'] = lBump
- own['rBump'] = rBump
- own['stBut'] = stBut
- own['bkBut'] = bkBut
- own['ltsBut'] = ltsBut
- own['rtsBut'] = rtsBut
-
- dict['aBut'] = aBut
- dict['bBut'] = bBut
- dict['xBut'] = xBut
- dict['yBut'] = yBut
- dict['lBump'] = lBump
- dict['rBump'] = rBump
- dict['stBut'] = stBut
- dict['bkBut'] = bkBut
- dict['ltsBut'] = ltsBut
- dict['rtsBut'] = rtsBut
- dict['menu_on'] = own['menu_on']
- dict['submenu_on'] = own['submenu_on']
- dict['menu_item'] = own['menu_item']
- dict['submenu_item'] = own['submenu_item']
- dict['fxaa'] = own['fxaa']
-
- main()
|