MCPcopy Create free account
hub / github.com/ICE27182/Python-3D-renderer / key_control

Function key_control

v1.0/renderer.py:467–560  ·  view source on GitHub ↗

If you use the keyinput function in the module, which I don't recommend, you can call the function have some basic control on your camera. But still, I recommend you do it yourself as it'd be more customizable.

(cam, display, step)

Source from the content-addressed store, hash-verified

465
466
467def key_control(cam, display, step):
468 """If you use the keyinput function in the module, which I don't recommend, you can call the function have some basic control
469 on your camera. But still, I recommend you do it yourself as it'd be more customizable.
470 """
471 global key
472 if key != None:
473 if key == "r":
474 display.refresh()
475 key = None
476 elif key == "w":
477 movement = [val * step for val in cam[5][2]]
478 cam[:3] = [cam[:3][index] + movement[index] for index in (0, 1, 2)]
479 # meshes["Cube_2"].move_mesh((cam[0] + cam[5][2][0], cam[1] + cam[5][2][1], cam[2] + cam[5][2][2]))
480 key = None
481 elif key == "a":
482 movement = [val * step for val in cam[5][0]]
483 cam[:3] = [cam[:3][index] - movement[index] for index in (0, 1, 2)]
484 # meshes["Cube_2"].move_mesh((cam[0] + cam[5][2][0], cam[1] + cam[5][2][1], cam[2] + cam[5][2][2]))
485 key = None
486 elif key == "s":
487 movement = [val * step for val in cam[5][2]]
488 cam[:3] = [cam[:3][index] - movement[index] for index in (0, 1, 2)]
489 # meshes["Cube_2"].move_mesh((cam[0] + cam[5][2][0], cam[1] + cam[5][2][1], cam[2] + cam[5][2][2]))
490 # meshes["Cube_2"].get_normal()
491 key = None
492 elif key == "d":
493 movement = [val * step for val in cam[5][0]]
494 cam[:3] = [cam[:3][index] + movement[index] for index in (0, 1, 2)]
495 # meshes["Cube_2"].move_mesh((cam[0] + cam[5][2][0], cam[1] + cam[5][2][1], cam[2] + cam[5][2][2]))
496 # meshes["Cube_2"].get_normal()
497 key = None
498 elif key == "e":
499 cam[1] += step
500 # meshes["Cube_2"].move_mesh((cam[0] + cam[5][2][0], cam[1] + cam[5][2][1], cam[2] + cam[5][2][2]))
501 key = None
502 elif key == "f":
503 cam[1] -= step
504 # meshes["Cube_2"].move_mesh((cam[0] + cam[5][2][0], cam[1] + cam[5][2][1], cam[2] + cam[5][2][2]))
505 key = None
506 elif key == "8":
507 cam[4] += 2
508 cam[4] = max(-90, min(90, cam[4]))
509 cam[5] = calculate_camera_matrix(cam)
510 # meshes["Cube_2"].move_mesh((cam[0] + cam[5][2][0], cam[1] + cam[5][2][1], cam[2] + cam[5][2][2]))
511 # meshes["Cube_2"].rotate_mesh(x_degree = -2 * cam[5][0][0], z_degree = -2 * cam[5][0][2],)
512 # meshes["Cube_2"].get_normal()
513
514 key = None
515 elif key == "2":
516 cam[4] -= 2
517 cam[4] = max(-90, min(90, cam[4]))
518 cam[5] = calculate_camera_matrix(cam)
519 # meshes["Cube_2"].move_mesh((cam[0] + cam[5][2][0], cam[1] + cam[5][2][1], cam[2] + cam[5][2][2]))
520 # meshes["Cube_2"].rotate_mesh(x_degree = 2 * cam[5][0][0], z_degree = 2 * cam[5][0][2],)
521 # meshes["Cube_2"].get_normal()
522 key = None
523 elif key == "4":
524 cam[3] += 4

Callers

nothing calls this directly

Calls 2

calculate_camera_matrixFunction · 0.70
refreshMethod · 0.45

Tested by

no test coverage detected