How to use the glfw.get_key function in glfw

To help you get started, we’ve selected a few glfw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tangrams / tangram-es / swig / examples / map.py View on Github external
def scroll_callback(self, window, scrollx, scrolly):
        rotating = (glfw.get_key(window, glfw.KEY_LEFT_ALT) == glfw.PRESS or
                    glfw.get_key(window, glfw.KEY_RIGHT_ALT) == glfw.PRESS)
        shoving = (glfw.get_key(window, glfw.KEY_LEFT_CONTROL) == glfw.PRESS or
                   glfw.get_key(window, glfw.KEY_RIGHT_CONTROL) == glfw.PRESS)

        scroll_span_multiplier = 0.05  # scaling for zoom and rotation
        scroll_distance_multiplier = 5.0  # scaling for shove

        x, y = glfw.get_cursor_pos(window)

        if shoving:
            self.m.input_handler.handle_shove_gesture(scroll_distance_multiplier * scrolly)
        elif rotating:
            self.m.input_handler.handle_rotate_gesture(x, y, scroll_span_multiplier * scrolly)
        else:
            self.m.input_handler.handle_pinch_gesture(x, y, 1.0 + scroll_span_multiplier * scrolly, 0)
github 3D-Printing-for-Microfluidics / OpenGL-STL-slicer / pyopengl / app_pyopengl.py View on Github external
def processInput(window):
    if glfw.get_key(window, glfw.KEY_ESCAPE) == glfw.PRESS:
        glfw.set_window_should_close(window, GL_TRUE)
github openai / mujoco-py / mujoco_py / mjviewer.py View on Github external
def _cursor_pos_callback(self, window, xpos, ypos):
        if not (self._button_left_pressed or self._button_right_pressed):
            return

        # Determine whether to move, zoom or rotate view
        mod_shift = (
            glfw.get_key(window, glfw.KEY_LEFT_SHIFT) == glfw.PRESS or
            glfw.get_key(window, glfw.KEY_RIGHT_SHIFT) == glfw.PRESS)
        if self._button_right_pressed:
            action = const.MOUSE_MOVE_H if mod_shift else const.MOUSE_MOVE_V
        elif self._button_left_pressed:
            action = const.MOUSE_ROTATE_H if mod_shift else const.MOUSE_ROTATE_V
        else:
            action = const.MOUSE_ZOOM

        # Determine
        dx = int(self._scale * xpos) - self._last_mouse_x
        dy = int(self._scale * ypos) - self._last_mouse_y
        width, height = glfw.get_framebuffer_size(window)

        with self._gui_lock:
            self.move_camera(action, dx / height, dy / height)

        self._last_mouse_x = int(self._scale * xpos)
github 3D-Printing-for-Microfluidics / OpenGL-STL-slicer / app.py View on Github external
def processInput(window):
    if glfw.get_key(window, glfw.KEY_ESCAPE) == glfw.PRESS:
        glfw.set_window_should_close(window, GL_TRUE)
github tangrams / tangram-es / swig / examples / map.py View on Github external
def scroll_callback(self, window, scrollx, scrolly):
        rotating = (glfw.get_key(window, glfw.KEY_LEFT_ALT) == glfw.PRESS or
                    glfw.get_key(window, glfw.KEY_RIGHT_ALT) == glfw.PRESS)
        shoving = (glfw.get_key(window, glfw.KEY_LEFT_CONTROL) == glfw.PRESS or
                   glfw.get_key(window, glfw.KEY_RIGHT_CONTROL) == glfw.PRESS)

        scroll_span_multiplier = 0.05  # scaling for zoom and rotation
        scroll_distance_multiplier = 5.0  # scaling for shove

        x, y = glfw.get_cursor_pos(window)

        if shoving:
            self.m.input_handler.handle_shove_gesture(scroll_distance_multiplier * scrolly)
        elif rotating:
            self.m.input_handler.handle_rotate_gesture(x, y, scroll_span_multiplier * scrolly)
        else:
            self.m.input_handler.handle_pinch_gesture(x, y, 1.0 + scroll_span_multiplier * scrolly, 0)
github tangrams / tangram-es / swig / examples / demo.py View on Github external
def scroll_callback(self, window, scrollx, scrolly):

        x, y = glfw.get_cursor_pos(window)

        rotating = (glfw.get_key(window, glfw.KEY_LEFT_ALT) == glfw.PRESS or
                    glfw.get_key(window, glfw.KEY_RIGHT_ALT) == glfw.PRESS)
        shoving = (glfw.get_key(window, glfw.KEY_LEFT_CONTROL) == glfw.PRESS or
                   glfw.get_key(window, glfw.KEY_RIGHT_CONTROL) == glfw.PRESS)

        scroll_span_multiplier = 0.05  # scaling for zoom and rotation
        scroll_distance_multiplier = 5.0  # scaling for shove

        if shoving:
            self.m.handle_shove_gesture(scroll_distance_multiplier * scrolly)
        elif rotating:
            self.m.handle_rotate_gesture(x, y, scroll_span_multiplier * scrolly)
        else:
            self.m.handle_pinch_gesture(x, y, 1.0 + scroll_span_multiplier * scrolly, 0)
github Jerdak / opengl_tutorials_python / controls.py View on Github external
up = vec3.cross( right, direction )

    # Move forward
    if glfw.get_key( window, glfw.KEY_UP ) == glfw.PRESS or glfw.get_key( window, glfw.KEY_W ) == glfw.PRESS:
        position += direction * deltaTime * speed;
    
    # Move backward
    if glfw.get_key( window, glfw.KEY_DOWN ) == glfw.PRESS or glfw.get_key( window, glfw.KEY_S ) == glfw.PRESS:
        position -= direction * deltaTime * speed
    
    # Strafe right
    if glfw.get_key( window, glfw.KEY_RIGHT ) == glfw.PRESS or glfw.get_key( window, glfw.KEY_D ) == glfw.PRESS:
        position += right * deltaTime * speed
    
    # Strafe left
    if glfw.get_key( window, glfw.KEY_LEFT ) == glfw.PRESS or glfw.get_key( window, glfw.KEY_A ) == glfw.PRESS:
        position -= right * deltaTime * speed
    

    FoV = initialFoV# - 5 * glfwGetMouseWheel(); # Now GLFW 3 requires setting up a callback for this. It's a bit too complicated for this beginner's tutorial, so it's disabled instead.

    # Projection matrix : 45 Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
    ProjectionMatrix = mat4.perspective(FoV, 4.0 / 3.0, 0.1, 100.0)
    # Camera matrix
    ViewMatrix       = mat4.lookat(
                                position,           # Camera is here
                                position+direction, # and looks here : at the same position, plus "direction"
                                up                  # Head is up (set to 0,-1,0 to look upside-down)
                           )

    # For the next frame, the "last time" will be "now"
    lastTime = currentTime
github Jerdak / opengl_tutorials_python / tutorial4.py View on Github external
0.820,  0.883,  0.371,
		0.982,  0.099,  0.879]

	vertex_buffer = glGenBuffers(1);
	array_type = GLfloat * len(vertex_data)
	glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer)
	glBufferData(GL_ARRAY_BUFFER, len(vertex_data) * 4, array_type(*vertex_data), GL_STATIC_DRAW)

	color_buffer = glGenBuffers(1);
	array_type = GLfloat * len(color_data)
	glBindBuffer(GL_ARRAY_BUFFER, color_buffer)
	glBufferData(GL_ARRAY_BUFFER, len(color_data) * 4, array_type(*color_data), GL_STATIC_DRAW)



	while glfw.get_key(window,glfw.KEY_ESCAPE) != glfw.PRESS and not glfw.window_should_close(window):
		glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT)

		glUseProgram(program_id)

		# Send our transformation to the currently bound shader, 
		# in the "MVP" uniform
		glUniformMatrix4fv(matrix_id, 1, GL_FALSE,mvp.data)
		# Bind vertex buffer data to the attribute 0 in our shader.
		# Note:  This can also be done in the VAO itself (see vao_test.py)

		# Enable the vertex attribute at element[0], in this case that's the triangle's vertices
		# this could also be color, normals, etc.  It isn't necessary to disable these
		#
		#1rst attribute buffer : vertices
		glEnableVertexAttribArray(0)
		glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
github tangrams / tangram-es / swig / examples / demo.py View on Github external
def scroll_callback(self, window, scrollx, scrolly):

        x, y = glfw.get_cursor_pos(window)

        rotating = (glfw.get_key(window, glfw.KEY_LEFT_ALT) == glfw.PRESS or
                    glfw.get_key(window, glfw.KEY_RIGHT_ALT) == glfw.PRESS)
        shoving = (glfw.get_key(window, glfw.KEY_LEFT_CONTROL) == glfw.PRESS or
                   glfw.get_key(window, glfw.KEY_RIGHT_CONTROL) == glfw.PRESS)

        scroll_span_multiplier = 0.05  # scaling for zoom and rotation
        scroll_distance_multiplier = 5.0  # scaling for shove

        if shoving:
            self.m.handle_shove_gesture(scroll_distance_multiplier * scrolly)
        elif rotating:
            self.m.handle_rotate_gesture(x, y, scroll_span_multiplier * scrolly)
        else:
            self.m.handle_pinch_gesture(x, y, 1.0 + scroll_span_multiplier * scrolly, 0)