Ejemplo n.º 1
0
def onKeyPress(key, x, y):
    global eyeX, eyeY, eyeZ, upX, upY, upZ, cam_theta, cam_phi, cam_r, tool
    if key == chr(27):
        sys.exit()
    if key == "0":
        tool = tool_functions.PlaneTool(cube_length * 0.5)
    if key == "1":
        tool = tool_functions.CubeTool(1)
    if key == "2":
        tool = tool_functions.CubeTool(2)
    if key == "3":
        tool = tool_functions.CubeTool(3)
    if key == "4":
        tool = tool_functions.CubeTool(4)
    if key == "5":
        tool = tool_functions.CubeTool(5)
    if key == "6":
        tool = tool_functions.CubeTool(6)
    if key == "7":
        tool = tool_functions.CubeTool(7)
    if key == "8":
        tool = tool_functions.CubeTool(8)
    if key == "9":
        tool = tool_functions.CubeTool(9)
    if key == "z":
        cam_r = max(0, cam_r - 10)
    if key == "Z":
        cam_r += 10
    newValues = lookInSphere(cam_r, cam_phi, cam_theta)
    eyeX = newValues[0]
    eyeY = newValues[1]
    eyeZ = newValues[2]
    upX = newValues[3]
    upY = newValues[4]
    upZ = newValues[5]
Ejemplo n.º 2
0
def onMouseMove(x, y):
    global mouseDrag, mouseDragX, mouseDragY, mouseDragMove
    global eyeX, eyeY, eyeZ, upX, upY, upZ, cam_theta, cam_phi, cam_r
    if not mouseDrag:
        return
    mouseDragMove = True
    # Mouse point to angle conversion
    # cam_theta = (360.0/winHeight)*y*3.0#3.0 rotations possible
    # cam_phi = (360.0/winWidth)*x*3.0
    cam_phi += 360.0 * (mouseDragX - x) / winWidth * 2.0
    cam_theta += 360.0 * (mouseDragY - y) / winHeight * 2.0
    mouseDragX = x
    mouseDragY = y
    # Restrict the angles within 0~360 deg (optional)
    if cam_theta > 360:
        cam_theta = fmod(cam_theta, 360.0)
    if cam_phi > 360:
        cam_phi = fmod(cam_phi, 360.0)
    newValues = lookInSphere(cam_r, cam_phi, cam_theta)
    eyeX = newValues[0]
    eyeY = newValues[1]
    eyeZ = newValues[2]
    upX = newValues[3]
    upY = newValues[4]
    upZ = newValues[5]
    glutPostRedisplay()
Ejemplo n.º 3
0
def onKeySpecialPress(key, x, y):
    global eyeX, eyeY, eyeZ, upX, upY, upZ, cam_theta, cam_phi, cam_r
    if key == GLUT_KEY_LEFT:
        cam_phi = (math.floor(cam_phi / 45.0) + 1.0) * 45.0
    if key == GLUT_KEY_RIGHT:
        cam_phi = (math.ceil(cam_phi / 45.0) - 1.0) * 45.0
    if key == GLUT_KEY_UP:
        cam_theta = (math.floor(cam_theta / 45.0) + 1.0) * 45.0
    if key == GLUT_KEY_DOWN:
        cam_theta = (math.ceil(cam_theta / 45.0) - 1.0) * 45.0
    # Restrict the angles within 0~360 deg (optional)
    if cam_theta > 360:
        cam_theta = fmod(cam_theta, 360.0)
    if cam_phi > 360:
        cam_phi = fmod(cam_phi, 360.0)
    newValues = lookInSphere(cam_r, cam_phi, cam_theta)
    eyeX = newValues[0]
    eyeY = newValues[1]
    eyeZ = newValues[2]
    upX = newValues[3]
    upY = newValues[4]
    upZ = newValues[5]
Ejemplo n.º 4
0
def init():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE)
    glutInitWindowSize(winWidth, winHeight)
    # Open a window
    glutCreateWindow("Glut test window")

    glutReshapeFunc(reshape)
    glutDisplayFunc(display)
    glutMouseFunc(onMousePress)
    glutMotionFunc(onMouseMove)
    glutKeyboardFunc(onKeyPress)
    glutSpecialFunc(onKeySpecialPress)
    glutIdleFunc(my_idle)
    glEnable(GL_DEPTH_TEST)
    glClearColor(1, 1, 1, 0)

    define_shader()

    global POINTS
    global COLORS
    global STATE
    COLORS = numpy.ones(cube_length ** 3 * 3).reshape((-1, 3))
    POINTS = numpy.ones(cube_length ** 3 * 3).reshape((-1, 3))
    STATE = 2 * numpy.ones(cube_length ** 3 * 3).reshape((-1, 3))

    for i in range(cube_length):
        for j in range(cube_length):
            for k in range(cube_length):
                # POINTS[i*cube_length**2+j*cube_length+k] = [i+i*j,j+j*k,k+k*i]
                POINTS[i * cube_length ** 2 + j * cube_length + k] = [
                    i + 0.5 - cube_length / 2,
                    j + 0.5 - cube_length / 2,
                    k + 0.5 - cube_length / 2,
                ]
                COLORS[i * cube_length ** 2 + j * cube_length + k] = [
                    i * 1.0 / cube_length,
                    j * 1.0 / cube_length,
                    k * 1.0 / cube_length,
                ]
                if i == 0 or j == 0 or k == 0 or i == cube_length - 1 or j == cube_length - 1 or k == cube_length - 1:
                    STATE[
                        i * cube_length ** 2 + j * cube_length + k
                    ] = 1  # set as external point, internal are 2, removed are 0

    global eyeX, eyeY, eyeZ, upX, upY, upZ, cam_theta, cam_phi, cam_r
    newValues = lookInSphere(cam_r, cam_phi, cam_theta)
    eyeX = newValues[0]
    eyeY = newValues[1]
    eyeZ = newValues[2]
    upX = newValues[3]
    upY = newValues[4]
    upZ = newValues[5]
    tool_functions.COLORS = COLORS
    tool_functions.POINTS = POINTS
    tool_functions.cube_length = cube_length

    global tool
    tool = tool_functions.CubeTool(3)

    glutMainLoop()