Example #1
0
    def render(self, time, frame_time):
        proj = Matrix44.perspective_projection(90.0, 1.0, 0.1, 1000.0)
        x, y, z = 0.0, 0.0, 1.0
        lookats = [
            Matrix44.look_at((x, y, z), (x - 1.0, y, z), (0.0, 1.0, 0.0)),
            Matrix44.look_at((x, y, z), (x + 1.0, y, z), (0.0, 1.0, 0.0)),
            Matrix44.look_at((x, y, z), (x, y - 1.0, z), (0.0, 0.0, 1.0)),
            Matrix44.look_at((x, y, z), (x, y + 1.0, z), (0.0, 0.0, -1.0)),
            Matrix44.look_at((x, y, z), (x, y, z + 1.0), (0.0, 1.0, 0.0)),
            Matrix44.look_at((x, y, z), (x, y, z - 1.0), (0.0, 1.0, 0.0)),
        ]

        self.prog2['Mvp'] = b''.join((proj * lookat).astype('f4').tobytes() for lookat in lookats)
        self.prog2['Light'] = (0.0, 0.0, 1.0)
        self.fbo1.clear(0, (1.0, 1.0, 1.0))
        self.fbo1.clear(-1, 1.0)
        self.vao2.render()

        camera_pos = (np.cos(time) * 5.0, np.sin(time) * 5.0, 2.0)
        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.0),
            (0.0, 0.0, 1.0),
        )

        self.prog1['Mvp'] = (proj * lookat).astype('f4').tobytes()
        self.prog1['Light'] = camera_pos

        self.ctx.screen.use()
        self.ctx.screen.clear(0, (1.0, 1.0, 1.0))
        self.ctx.screen.clear(-1, 1.0)
        self.vao1.render()
Example #2
0
def generate_lines(obj: Object, camera: Camera, viewport: Polygon, front_brightness: float, back_brightness: float) -> List[Line]:
    # Create transformation matrix
    translation = Matrix44.from_translation(obj.translation)
    rotation = Matrix44.from_eulers(obj.rotation)
    projection = Matrix44.perspective_projection(
        camera.fovy, camera.aspect, camera.near, camera.far)
    cam = matrix44.create_look_at(camera.eye, camera.target, [0, 1.0, 0])
    matrix = projection * cam * translation * rotation

    # Transform vertices, remove hidden faces and get edges for faces
    # TODO: Make the rendering pipeline more generic
    vertices = [matrix * vertex for vertex in obj.mesh.vertices]
    front_faces = [face for face in obj.mesh.faces
                   if cull_face(vertices, face, 'front')]
    back_faces = [face for face in obj.mesh.faces
                  if cull_face(vertices, face, 'back')]
    front_edges = find_edges(front_faces, obj.mesh.edges)
    back_edges = find_edges(back_faces, obj.mesh.edges)

    # Clip lines
    lines = edges_to_lines(front_edges, vertices, front_brightness) + \
        edges_to_lines(back_edges, vertices, back_brightness)
    return [clipped
            for clipped in [clip_line(line, viewport) for line in lines]
            if clipped is not None]
    def render(self, time: float, frame_time: float):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (47.697, -8.147, 24.498),
            (0.0, 0.0, 8.0),
            (0.0, 0.0, 1.0),
        )

        rotate = Matrix44.from_z_rotation(np.sin(time) * 0.5 + 0.2)

        self.use_texture.value = False

        self.light.value = (67.69, -8.14, 52.49)
        self.mvp.write((proj * lookat * rotate).astype('f4').tobytes())

        self.color.value = (0.67, 0.49, 0.29)
        self.objects['ground'].render()

        self.color.value = (0.46, 0.67, 0.29)
        self.objects['grass'].render()

        self.color.value = (1.0, 1.0, 1.0)
        self.objects['billboard'].render()

        self.color.value = (0.2, 0.2, 0.2)
        self.objects['billboard-holder'].render()

        self.use_texture.value = True
        self.texture.use()

        self.objects['billboard-image'].render()
Example #4
0
 def adjust_angle_of_view(self, angle_of_view):
     self.angle_of_view = angle_of_view
     self.TAN_ANGLE = np.tan(np.radians(self.angle_of_view / 2))
     perspective = Matrix44.perspective_projection(
         self.angle_of_view, RATIO, 0.1, 1000.0
     )
     self.PROG["VP"].write((perspective * LOOK_AT).astype("f4").tobytes())
 def on_resize(self, width, height):
     """Set up viewport and projection"""
     ratio = arcade.get_scaling_factor(self)
     self.ctx.viewport = 0, 0, int(width * ratio), int(height * ratio)
     aspect_ratio = width / height
     self.program['projection'] = Matrix44.perspective_projection(
         60, aspect_ratio, 0.1, 100).flatten()
Example #6
0
    def render(self, batch_size):
        warp = np.empty(
            (batch_size, self.height, self.width, 2), dtype=np.float32)
        for i in range(batch_size):
            translation = Matrix44.from_translation((
                np.random.uniform(self.x_low, self.x_high),
                np.random.uniform(self.y_low, self.y_high),
                0.0
            ))
            rotation = Matrix44.from_matrix33(
                self.rand_rotation_matrix(self.deflection)
            )
            view = Matrix44.look_at(
                (0.0, 0.0, np.random.uniform(self.close, self.far)),
                (0.0, 0.0, 0.0),
                (0.0, 1.0, 0.0),
            )
            projection = Matrix44.perspective_projection(
                45.0, self.width / self.height, 0.1, 1000.0
            )

            # TODO: translation or rotation first?
            transform = projection * view * translation * rotation

            self.fbo.use()
            self.fbo.clear()

            self.mvp.write(transform.astype('f4').tobytes())
            self.vao.render()

            framebuffer = self.fbo.read(components=2, floats=True)
            warp[i] = np.frombuffer(framebuffer, dtype=np.float32).reshape(
                (self.height, self.width, 2))[::-1]

        return warp
Example #7
0
 def resizeGL(self, w, h):
     glViewport(0, 0, w, h)
     self.viewport = (w, h)
     self.projTransform = Matrix44.perspective_projection(
         50, float(w) / h,
         0.01, 100.0,
     )
Example #8
0
def render(ctx, prog, objects, fbo, q, x, img):
    print(q)
    m = q.rotation_matrix
    #q から 回転ベクトルだけ取り出して 変換かければ良さそう
    eye = np.array([47.697, -8.147, 24.498])
    eyedir = np.array([-47.7, 8.15, -16.5])
    up = np.array([0.0, 0.0, 1.0])
    mvp = prog['Mvp']
    proj = Matrix44.perspective_projection(58.0, float(W) / H, 0.1, 1000.0)
    lookat = Matrix44.look_at(
        eye,
        np.dot(m, eyedir) + eye,
        np.dot(m, up),
    )
    print(m)

    mvp.write((proj * lookat).astype('f4').tobytes())

    color = prog['Color']
    fbo.clear(0.0, 0.0, 0.0, 0.0)

    color.value = (0.67, 0.49, 0.29)
    objects['ground'].render()

    color.value = (0.46, 0.67, 0.29)
    objects['grass'].render()

    myimg = np.asarray(
        Image.frombytes('RGBA', fbo.size, fbo.read(components=4)))
    obj_mask = myimg[:, :, 3]
    obj_img = myimg[:, :, 0:3]
    idx = (obj_mask != 0)
    img[idx] = obj_img[idx]
    cv2.imshow('RealSense', img)
Example #9
0
 def resize(self, width, height):
     self.ctx.viewport = 0, 0, width, height
     self.projection = Matrix44.perspective_projection(45,
                                                       width / height,
                                                       1,
                                                       50,
                                                       dtype='f4')
Example #10
0
    def reset(self, width, height, color):

        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LESS)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glClearDepth(1.0)
        glClear(GL_DEPTH_BUFFER_BIT)
        glClearColor(color.r, color.g, color.b, color.a)
        glClear(GL_COLOR_BUFFER_BIT)

        glViewport(0, 0, width, height)

        # Determine current znear, zfar
        bbox = self.scene.bounding_box
        mat = self.matrix
        c = -1 * (mat * bbox.center)
        znear = max(1.0, c.z - bbox.diameter / 2.0)
        zfar = c.z + bbox.diameter

        self.raycaster.near = znear
        self.raycaster.far = zfar

        self.box_select.width = width
        self.box_select.height = height
        self.poly_select.width = width
        self.poly_select.height = height

        self.proj_matrix = Matrix44.perspective_projection(
            80.0, width / height, znear, zfar)
Example #11
0
    def render(self, time, frame_time):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1,
                                               100.0)

        camera_pos = np.array([
            np.cos(self.angleY) * np.cos(self.angleX),
            np.sin(self.angleX),
            np.sin(self.angleY)
        ]) * self.distance

        lookat = Matrix44.look_at(
            tuple(camera_pos + self.origin),  # eye
            tuple(self.origin),  # target
            (0.0, 0.0, 1.0),  # up
        )

        self.light.value = (0, -3, 3)
        self.texture.use()

        for coord in self.coords:
            model = Matrix44.from_translation(coord)
            self.mvp.write((proj * lookat * model).astype('f4'))
            self.vao.render()
Example #12
0
    def __init__(self,
                 width=1280,
                 height=720,
                 name='OpenGL Window',
                 cameraSpeed=0.1,
                 mouseSpeed=0.3,
                 invertMouse=False,
                 resizable=False,
                 vsync=False):
        super().__init__(width, height, name, resizable=resizable, vsync=vsync)
        self.cameraSpeed = cameraSpeed
        self.mouseSpeed = mouseSpeed
        self.invertMouse = invertMouse
        self.cameraPos = Vector3([0.0, 0.0, 0.0])
        self.cameraTarget = Vector3([0.0, 0.0, -1.0])
        self.cameraUp = Vector3([0.0, 1.0, 0.0])
        self.worldUp = Vector3([0.0, 1.0, 0.0])
        self.yaw = -90.0
        self.pitch = 0.0
        self.pressedKeys = []

        self.set_mouse_visible(False)
        self.set_exclusive_mouse(True)

        # Matrices
        self.projection = Matrix44.perspective_projection(
            45.0, width / height, 0.1, 1000.0)
        self.view = Matrix44.look_at(self.cameraPos, self.cameraTarget,
                                     self.cameraUp)
Example #13
0
def onsc(window, yof):
    """Wheels. """
    global whel
    sz = window.get_size()
    whel = clip(whel - yof, 1, 180)
    pm = matrix.perspective_projection(whel, sz[0] / sz[1], 0.01, 100)
    GL.glUniformMatrix4fv(GL.glGetUniformLocation(shaderp, 'projectmatrix'), 1, False, pm)
Example #14
0
    def render(self):
        if self.current_pointcloud < len(self.pointclouds):
            self.handle_mouse()
            self.handle_keys()

            self.ctx.viewport = self.wnd.viewport
            self.ctx.clear(0.0, 0.0, 0.0)
            self.ctx.enable(mgl.BLEND)

            vertices = np.load(file=self.pointclouds[self.current_pointcloud])
            self.vbo.write(vertices.astype('f4').tobytes())

            model = Matrix44.from_scale((self.zoom, self.zoom, self.zoom))
            model *= Matrix44.from_x_rotation(-self.theta[1])
            model *= Matrix44.from_y_rotation(-self.theta[0])
            view = Matrix44.look_at((0.0, 0.0, 1.0), (0.0, 0.0, 0.0),
                                    (0.0, 1.0, 0.0))
            projection = Matrix44.perspective_projection(
                45.0, self.wnd.ratio, 0.1, 100.0)

            self.mvp.write((projection * view * model).astype('f4').tobytes())
            self.vao.render(mode=mgl.POINTS)

            self.sleep_to_target_fps(60)
            self.current_pointcloud += 1
        else:
            if self.out_dir is None:
                self.current_pointcloud = 0
            else:
                QtCore.QCoreApplication.instance().quit()
Example #15
0
def rematr(wid, hig):
    """Resets the projection matrix."""
    if hig == 0:
        hig = 1
    # This method has FOV in degrees for some reason???
    pm = matrix.perspective_projection(whel, wid/hig, 0.01, 100)
    GL.glUniformMatrix4fv(GL.glGetUniformLocation(shaderp, 'projectmatrix'), 1, False, pm)
    def update(
        self,
        aspect_ratio: float = None,
        fov: float = None,
        near: float = None,
        far: float = None,
    ) -> None:
        """Update the projection matrix

        Keyword Args:
            aspect_ratio (float): Aspect ratio
            fov (float): Field of view
            near (float): Near plane value
            far (float): Far plane value
        """
        self._aspect_ratio = aspect_ratio or self._aspect_ratio
        self._fov = fov or self._fov
        self._near = near or self._near
        self._far = far or self._far

        self._matrix = Matrix44.perspective_projection(
            self._fov,
            self._aspect_ratio,
            self._near,
            self._far,
            dtype="f4",
        )
        self._matrix_bytes = self._matrix.tobytes()
Example #17
0
    def render(self):
        angle = self.wnd.time * 0.2
        width, height = self.wnd.size
        self.ctx.viewport = self.wnd.viewport
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        camera_pos = (np.cos(angle) * 5.0, np.sin(angle) * 5.0, 2.0)

        proj = Matrix44.perspective_projection(45.0, width / height, 0.1,
                                               1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.5),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.light.value = camera_pos

        crate_z = np.sin(self.crate_a * self.wnd.time + self.crate_b) * 0.2
        coordinates = np.dstack([self.crate_x, self.crate_y, crate_z])

        self.vbo2.write(coordinates.astype('f4').tobytes())
        self.vao.render(instances=1024)
Example #18
0
    def render(self, time, frame_time):
        self.ctx.clear(0.2, 0.2, 0.2)

        self.ctx.enable(moderngl.DEPTH_TEST)

        self.fps = 1 / frame_time
        self.control()

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1,
                                               1000.0)
        lookat = Matrix44.look_at(
            (self.movX, self.movY, self.movZ),
            (200.0, 200.0, 0.0),
            (0.0, 0.0, 1.0),
        )

        self.light.value = (100, 0, 200)

        self.texture.use(0)
        self.mvp_map.write((proj * lookat).astype('f4'))
        self.vao_map.render(moderngl.TRIANGLE_FAN)

        model_rot = Matrix44.from_z_rotation(
            3.14 / 4) * Matrix44.from_x_rotation(-3.14 / 2)

        for x in range(int(self.positions.size / 3)):
            size = 1 + self.production[x] * (2.5 - 1)
            model_size = Matrix44.from_scale(np.array([size, size, size]))
            self.gradient.value = self.production[x]
            model = Matrix44.from_translation(np.array(
                self.positions[x])) * model_rot * model_size
            self.mvp.write((proj * lookat * model).astype('f4'))
            self.vao.render()

        self.render_ui()
    def render(self, time: float, frame_time: float):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST | moderngl.CULL_FACE)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1,
                                               1000.0)
        lookat = Matrix44.look_at(
            (47.697, -8.147, 24.498),
            (0.0, 0.0, 8.0),
            (0.0, 0.0, 1.0),
        )

        rotate = Matrix44.from_z_rotation(np.sin(time) * 0.5 + 0.2)

        self.use_texture.value = False

        self.light.value = (67.69, -8.14, 52.49)
        self.mvp.write((proj * lookat * rotate).astype('f4').tobytes())

        self.color.value = (0.67, 0.49, 0.29)
        self.vao_ground.render()

        self.color.value = (0.46, 0.67, 0.29)
        self.vao_grass.render()

        self.color.value = (1.0, 1.0, 1.0)
        self.vao_billboard.render()

        self.color.value = (0.2, 0.2, 0.2)
        self.vao_holder.render()

        self.use_texture.value = True
        self.texture.use()

        self.vao_image.render()
    def __init__(self, ctx, width, height, Type, id):
        self.ctx = ctx
        self.type = Type
        self.ParentCube = id
        self.color = self.fromTypeToColor(self.type)
        self.width = width
        self.height = height
        self.x_rot = 0
        self.y_rot = 0
        self.x_last = 0
        self.y_last = 0
        self.x_cur = 0
        self.y_cur = 0
        self.isRotating = False
        self.orientation = pyrr.quaternion.create(0.0, 0.0, 0.0, 1.0)
        self.proj = Matrix44.perspective_projection(45.0,
                                                    self.width / self.height,
                                                    0.1, 100.0)
        self.camera_pos = [0, 3, -8.0]
        self.vertexes = VERTICES[self.fromTypeTOIndex(Type)]
        self.rotation = Matrix44.identity()
        self.rotationLayer = Matrix44.identity()
        self.degree = 0
        self.translation = Matrix44.identity()
        self.view = Matrix44.look_at(
            self.camera_pos,  # position of camera in world coordinate
            (0.0, 0.0, 0.0),  # target
            (0.0, 1.0, 0.0),
        )
        self.prog = self.ctx.program(
            vertex_shader='''
                #version 330

                uniform mat4 Mvp;
                in vec3 in_vert;
                in vec3 in_color;
                out vec3 v_color;  
                out vec4 Position;
                void main() {
                    gl_Position = Mvp*vec4(in_vert, 1.0);
                    v_color = in_color;
                    Position=vec4(in_vert,1.0);
                }
            ''',
            fragment_shader='''
                #version 330
                in vec3 v_color;
                in vec4 Position;
                out vec4 f_color;
                
                void main() 
                {
                    f_color=vec4(v_color,1);
                   
                    
                }

            ''',
        )
 def resize(self, width: int, height: int):
     self.prog['m_proj'].write(
         Matrix44.perspective_projection(75,
                                         self.wnd.aspect_ratio,
                                         1,
                                         100,
                                         dtype='f4'))
     self.imgui.resize(width, height)
Example #22
0
    def __init__(self, keys, radius=None, target=None, **kws):
        self.default_radius = 10 if radius is None else radius
        self.default_target = vec3.O() if target is None else target
        self.keys = keys
        self.reset_view()

        self.projection = Matrix44.perspective_projection(
                        45.0, self.aspect_ratio, 0.1, 100.0)
    def build_proj_matrix(self):
        """Builds and stores the perspective matrix internally
        Automatically builds the MVP matrix as well"""
        self.p = Matrix44.perspective_projection(self.fov,
                                                 self.width / self.height,
                                                 self.near_plane,
                                                 self.far_plane)

        self.mvp = numpy.array(self.p * self.m).astype("f4")
	def __init__(self, boundlesspath, basedir, ctx, args):
		# Path to a boundless installation
		self.boundlesspath = boundlesspath
		self.basedir = basedir
		self.args = args

		with open(self.boundlesspath + '/assets/archetypes/compiledcolorpalettelists.msgpack', 'rb') as palettefile:
			self.palette_json = utils.convert_msgpackfile(palettefile)

		self.lookat = Matrix44.look_at((10, 10, 0.0), (10, 10, -5), (0, 1, 0))
		self.perspective = Matrix44.perspective_projection(FOV, 1.0, 0.01, 1000.0)

		self.projection_mat = self.perspective * self.lookat
		self.model_mat = Matrix44.identity()

		# Parsed shaders
		self.shaders = parse_shaders.get_shaders()

		with open(self.boundlesspath + "/assets/archetypes/compiledspecialmaterials.msgpack", 'rb') as specialsfile:
			self.specials_json = utils.convert_msgpackfile(specialsfile)

		self.specials_names = list(map(lambda a: a["name"], self.specials_json))

		# A map of all the textures we use which are constant
		# Key is the uniform name, value is the texture object
		self.local_tex_path = os.path.join(self.basedir, 'assets/textures')
		self.const_tex = {}
		# Dynamic textures
		self.dyn_tex = {}

		self.ctx = ctx
		# Necessary to stop memory leaks
		self.ctx.gc_mode = "auto"
		# Note: this is the dimensions of the image. Certain items/blocks/props won't fill
		# 	this canvas.
		self.target_size = (int(args["resolution"]), int(args["resolution"]))
		self.render_size = (
			int(self.target_size[0] // 0.9),
			int(self.target_size[1] // 0.9)
		) if args["anti_alias"] else self.target_size
		# Initialise properly later, just allocating the field
		self.prog = {}
		self.cbo = self.ctx.renderbuffer(self.render_size)
		self.dbo = self.ctx.depth_texture(self.render_size, alignment=1)
		self.fbo = self.ctx.framebuffer(color_attachments=(self.cbo), depth_attachment=self.dbo)
		self.fbo.use()

		# Initialise all of the constant textures
		self.init_constant_tex2ds()
		self.init_constant_texcubes()

		self.buffer_cache = []

		# Grab uniforms
		with open(os.path.join(self.basedir, 'assets/shader_dump.json')) as uniformsfile:
			self.uniforms_json = json.load(uniformsfile)
Example #25
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        # Create a custom attribute name spec
        # so attribute names are not forced to follow gltf standard
        attr_names = AttributeNames(position='in_vert', texcoord_0='in_tex', normal='in_norm')

        # Programs
        self.canvas_prog = self.load_program('mug_mockup/programs/canvas.glsl')
        self.sticker_prog = self.load_program('mug_mockup/programs/sticker.glsl')
        self.mug_prog = self.load_program('mug_mockup/programs/mug.glsl')

        # textures
        self.bg_texture = self.load_texture_2d('mug_mockup/textures/mug-background.jpg')
        self.sticker_texture = self.load_texture_2d('mug_mockup/textures/mug-pymet-logo.png')

        self.canvas_vao = geometry.quad_fs(attr_names=attr_names).instance(self.canvas_prog)

        obj = self.load_scene('mug_mockup/scenes/mug.obj', attr_names=attr_names)
        self.mug_vao = obj.root_nodes[0].mesh.vao.instance(self.mug_prog)

        # Create sticker geometry
        segs = 32
        radius = 29.94
        bottom = 6.601
        top = 57.856
        left = -163.12 * np.pi / 180.0
        right = 11.25 * np.pi / 180.0

        lin = np.linspace(left, right, segs)
        sticker_vertices = np.array([
            np.repeat(np.cos(lin) * radius, 2),
            np.repeat(np.sin(lin) * radius, 2),
            np.tile([bottom, top], segs),
            np.repeat(np.cos(lin), 2),
            np.repeat(np.sin(lin), 2),
            np.tile([0.0, 0.0], segs),
            np.repeat(np.linspace(0.0, 1.0, segs), 2),
            np.tile([0.0, 1.0], segs),
        ])
        self.sticker_vbo = self.ctx.buffer(sticker_vertices.T.astype('f4').tobytes())
        self.sticker_vao = self.ctx.simple_vertex_array(self.sticker_prog, self.sticker_vbo, 'in_vert', 'in_norm', 'in_text')

        # Pre-fill uniforms. These currently do not change during rendering
        proj = Matrix44.perspective_projection(30.0, self.aspect_ratio, 1.0, 1000.0)
        lookat = Matrix44.look_at(
            (46.748, -280.619, 154.391),
            (-23.844, 2.698, 44.493),
            (0.0, 0.0, 1.0),
        )
        mvp = (proj * lookat).astype('f4')
        light = (-143.438, -159.072, 213.268)
        self.mug_prog['Mvp'].write(mvp)
        self.mug_prog['Light'].value = light
        self.sticker_prog['Mvp'].write(mvp)
        self.sticker_prog['Light'].value = light
Example #26
0
 def get_view_model(self):
     proj = Matrix44.perspective_projection(self.fov,
                                            self.width / self.height,
                                            self.near, self.far)
     lookat = Matrix44.look_at(
         self.eye,  # eye / camera position
         self.lookat,  # lookat
         self.up,  # camera up vector
     )
     return proj, lookat
def project_and_render(view, zoom, resolution):
    fovy, aspect, near, far = 60.0, resolution[0] / resolution[1], 0.001, 1000
    projection = Matrix44.perspective_projection(fovy, aspect, near, far)
    view = Matrix44(view)
    scale = Matrix44.from_scale([zoom, zoom, zoom])
    MVP = projection * view * scale

    MVP = cuda.to_device(MVP)
    apply_projection[bpg, maxThreadsPerBlock](MVP, embedding, result)
    return render(result, resolution)
def update(dt):
    ctx.viewport = (0, 0, wnd.width, wnd.height)
    ctx.clear(0.9, 0.9, 0.9)
    ctx.enable(ModernGL.DEPTH_TEST)

    proj = Matrix44.perspective_projection(45.0, wnd.width / wnd.height, 0.1, 1000.0)
    lookat = Matrix44.look_at(
        (40.0, 30.0, 20.0),
        (0.0, 0.0, 0.0),
        (0.0, 0.0, 1.0),
def display():
    ctx.viewport = (0, 0, width, height)
    ctx.clear(0.9, 0.9, 0.9)
    ctx.enable(ModernGL.DEPTH_TEST)

    proj = Matrix44.perspective_projection(45.0, width / height, 0.1, 1000.0)
    lookat = Matrix44.look_at(
        (40.0, 30.0, 20.0),
        (0.0, 0.0, 0.0),
        (0.0, 0.0, 1.0),
Example #30
0
    def render(self):
        angle = self.wnd.time
        width, height = self.wnd.size
        self.ctx.viewport = self.wnd.viewport
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(ModernGL.DEPTH_TEST)

        camera_pos = (np.cos(angle) * 20.0, np.sin(angle) * 20.0, 5.0)

        proj = Matrix44.perspective_projection(45.0, width / height, 0.1,
                                               1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.5),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.light.value = camera_pos

        # self.vbo2.write(Matrix33.from_z_rotation(self.wnd.time).astype('f4').tobytes(), offset=24)
        self.vbo2.write(b''.join(
            struct.pack(
                '15f',
                *car['color'],
                *car['pos'],
                1.0,
                0.0,
                0.0,
                0.0,
                1.0,
                0.0,
                0.0,
                0.0,
                1.0,
            ) for car in cars))
        self.vao.render(instances=len(cars))
        self.vbo2.write(b''.join(
            struct.pack(
                '15f',
                0.0,
                0.0,
                0.0,
                *car['pos'],
                1.0,
                0.0,
                0.0,
                0.0,
                1.0,
                0.0,
                0.3,
                0.6,
                0.0,
            ) for car in cars))
        self.vao.render(instances=len(cars))
    def paintGL(self):
        width, height = self.width(), self.height()
        self.ctx.viewport = (0, 0, width, height)
        self.ctx.clear(0.9, 0.9, 0.9)
        self.ctx.enable(ModernGL.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, width / height, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (40.0, 30.0, 20.0),
            (0.0, 0.0, 0.0),
            (0.0, 0.0, 1.0),
Example #32
0
    def draw(self, *args):
        width, height = Window.size
        self.ctx.viewport = (0, 0, width, height)
        self.ctx.clear(0.9, 0.9, 0.9)
        self.ctx.enable(ModernGL.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, width / height, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (40.0, 30.0, 20.0),
            (0.0, 0.0, 0.0),
            (0.0, 0.0, 1.0),
Example #33
0
    def render(self):
        angle = self.wnd.time
        self.ctx.screen.viewport = self.wnd.viewport
        self.ctx.clear(1.0, 1.0, 1.0)

        with self.ctx.scope(mgl.DEPTH_TEST):
            camera_pos = (np.cos(angle) * 20.0, np.sin(angle) * 20.0, 5.0)

            proj = Matrix44.perspective_projection(45.0, self.wnd.ratio, 0.1,
                                                   1000.0)
            lookat = Matrix44.look_at(
                camera_pos,
                (0.0, 0.0, 0.5),
                (0.0, 0.0, 1.0),
            )

            self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
            self.prog['Light'] = camera_pos

            # self.vbo2.write(Matrix33.from_z_rotation(self.wnd.time).astype('f4').tobytes(), offset=24)
            self.vbo2.write(b''.join(
                struct.pack(
                    '15f',
                    *car['color'],
                    *car['pos'],
                    1.0,
                    0.0,
                    0.0,
                    0.0,
                    1.0,
                    0.0,
                    0.0,
                    0.0,
                    1.0,
                ) for car in cars))
            self.vao.render(instances=len(cars))
            self.vbo2.write(b''.join(
                struct.pack(
                    '15f',
                    0.0,
                    0.0,
                    0.0,
                    *car['pos'],
                    1.0,
                    0.0,
                    0.0,
                    0.0,
                    1.0,
                    0.0,
                    0.3,
                    0.6,
                    0.0,
                ) for car in cars))
            self.vao.render(instances=len(cars))
Example #34
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        imgui.create_context()
        self.wnd.ctx.error
        self.imgui = ModernglWindowRenderer(self.wnd)

        self.cube = geometry.cube(size=(2, 2, 2))
        self.prog = self.load_program('programs/cube_simple.glsl')
        self.prog['color'].value = (1.0, 1.0, 1.0, 1.0)
        self.prog['m_camera'].write(Matrix44.identity(dtype='f4'))
        self.prog['m_proj'].write(Matrix44.perspective_projection(75, self.wnd.aspect_ratio, 1, 100, dtype='f4'))
        self.slider_value = 88
Example #35
0
    def render(self, time, frame_time):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (40.0, 30.0, 30.0),
            (0.0, 0.0, 0.0),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.vao.render(moderngl.LINES)
Example #36
0
    def render(self):
        self.ctx.screen.viewport = self.wnd.viewport
        self.ctx.clear(1.0, 1.0, 1.0)
        with self.ctx.scope(mgl.DEPTH_TEST):
            proj = Matrix44.perspective_projection(45.0, self.wnd.ratio, 0.1, 1000.0)
            lookat = Matrix44.look_at(
                (40.0, 30.0, 30.0),
                (0.0, 0.0, 0.0),
                (0.0, 0.0, 1.0),
            )

            self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
            self.vao.render(mgl.LINES)
Example #37
0
def main():
    window = initWindow()
    classicProgram, normalMapProgram, skyboxProgram, asteroidProgram = initShaders()
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LESS)

    # Initialize objects
    planets, spaceship, skybox, belt = initObjects(classicProgram, normalMapProgram,
                                             skyboxProgram, asteroidProgram)

    projMatrix = mat4.perspective_projection(60,
                                             float(WIDTH/HEIGHT),
                                             0.1,
                                             10000.0,
                                             dtype='f')
    eye, viewMatrix = initCamera()

    dt, oldTime = 0.0, glfw.GetTime()
    animation_speed = 800
    while not glfw.WindowShouldClose(window):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        currentTime = glfw.GetTime()
        dt = currentTime - oldTime
        oldTime = currentTime

        hAngle, vAngle, eye, direction, right, up, viewMatrix, animation_speed = getNewViewMatrixAndEye(window,
                                                                  animation_speed,
                                                                  dt,
                                                                  eye,
                                                                  WIDTH,
                                                                  HEIGHT)

        for planet in planets:
            planet.update(animation_speed)
            planet.draw(eye, viewMatrix, projMatrix)

        spaceship.update(eye, direction, right, up, hAngle, vAngle)
        spaceship.draw(eye, viewMatrix, projMatrix)

        belt.update(0.1)
        belt.draw(eye, viewMatrix, projMatrix)

        skybox.draw(viewMatrix, projMatrix)
        # Swap front and back buffers
        glfw.SwapBuffers(window)

        # Poll for and process events
        glfw.PollEvents()

    glfw.Terminate()
Example #38
0
    def render(self, time: float, frame_time: float):
        camera_pos = (np.cos(time) * 300.0, np.sin(time) * 300.0, 120.0)
        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 50.0),
            (0.0, 0.0, 1.0),
        )

        with self.scope:
            self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
            self.prog['Eye'] = camera_pos
            self.ctx.clear(1.0, 1.0, 1.0)
            self.vao.render()
    def render(self, time, frame_time):
        angle = time * 0.2
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (np.cos(angle), np.sin(angle), 0.8),
            (0.0, 0.0, 0.1),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.vao.render(moderngl.TRIANGLE_STRIP)
Example #40
0
def init():
    """Initialises the display."""
    global projectmatrix, modelmatrix, chaem
    GL.glClearColor(0.0, 0.2, 0.15, 0.0)
    GL.glClearDepth(1.0)
    GL.glDepthFunc(GL.GL_LESS)
    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glShadeModel(GL.GL_SMOOTH)
    shades()
    chaem = Fremv((), deltam)
    GL.glUniform3f(GL.glGetUniformLocation(shaderp, 'lightColour'), *[1.0, 1.0, 1.0])
    modelmatrix = matrix.from_scale([2, 2, 2]) * matrix.from_translation([0, 0, -1])
    wid, hig = window.get_size()
    hig = hig or 1
    projectmatrix = matrix.perspective_projection(whel, wid/hig, 0.01, 100)
    rematr()
    def render(self, time, frame_time):
        angle = time
        self.ctx.clear(1.0, 1.0, 1.0)

        camera_pos = (np.cos(angle) * 5.0, np.sin(angle) * 5.0, 2.0)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.0),
            (0.0, 0.0, 1.0),
        )

        self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
        self.prog['Light'] = camera_pos
        self.vao.render()
    def render(self, time, frame_time):
        self.ctx.clear(1.0, 1.0, 1.0)
        # self.ctx.enable(mgl.DEPTH_TEST)
        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (47.697, -8.147, 24.498),
            (0.0, 0.0, 8.0),
            (0.0, 0.0, 1.0),
        )

        rotate = Matrix44.from_z_rotation(np.sin(time) * 0.5 + 0.2)

        w, h = self.texture.size
        gw, gh = 16, 16
        nx, ny, nz = int(w/gw), int(h/gh), 1

        print('=' * 50)

        self.compute['time'] = time
        GL_WRITE_ONLY = 0x88B9
        GL_R32F = 0x822E
        self.texture.bind_to_image(0,GL_WRITE_ONLY, GL_R32F)
        self.compute.run(nx, ny, nz)
        print('-' * 50)

        with self.scope:
            self.prog['UseTexture'] = False

            self.prog['Light'] = (67.69, -8.14, 52.49)
            self.prog['Mvp'] = (proj * lookat * rotate).astype('f4').tobytes()

            self.prog['Color'] = (0.67, 0.49, 0.29)
            self.objects['ground'].render()

            self.prog['Color'] = (0.46, 0.67, 0.29)
            self.objects['grass'].render()

            self.prog['Color'] = (1.0, 1.0, 1.0)
            self.objects['billboard'].render()

            self.prog['Color'] = (0.2, 0.2, 0.2)
            self.objects['billboard-holder'].render()

            self.prog['UseTexture'] = True

            self.objects['billboard-image'].render()
    def render(self):
        angle = self.wnd.time
        self.ctx.screen.viewport = self.wnd.viewport

        camera_pos = (np.cos(angle) * 5.0, np.sin(angle) * 5.0, 2.0)

        proj = Matrix44.perspective_projection(45.0, self.wnd.ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.5),
            (0.0, 0.0, 1.0),
        )

        self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
        self.prog['Light'] = camera_pos

        self.ctx.replay(self.bytecode)
    def render(self, time, frame_time):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (-85, -180, 140),
            (0.0, 0.0, 65.0),
            (0.0, 0.0, 1.0),
        )

        self.light.value = (-140.0, -300.0, 350.0)
        self.color.value = (1.0, 1.0, 1.0, 0.25)
        self.mvp.write((proj * lookat).astype('f4').tobytes())

        self.texture.use()
        self.vao.render()
Example #45
0
    def render(self, time, frame_time):
        self.ctx.clear(1.0, 1.0, 1.0)
        self.bg_texture.use()
        self.ctx.enable_only(moderngl.BLEND)
        self.canvas_vao.render(moderngl.TRIANGLE_STRIP)
        self.ctx.enable_only(moderngl.DEPTH_TEST)

        proj = Matrix44.perspective_projection(30.0, self.aspect_ratio, 1.0, 1000.0)
        lookat = Matrix44.look_at(
            (46.748, -280.619, 154.391),
            (-23.844, 2.698, 44.493),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.light.value = (-143.438, -159.072, 213.268)
        self.mug_texture.use()
        self.mug_vao.render()
        self.ctx.enable_only(moderngl.DEPTH_TEST | moderngl.BLEND)
        self.sticker_texture.use()
        self.sticker_vao.render(moderngl.TRIANGLE_STRIP)
    def render(self, time, frame_time):
        angle = time * 0.2
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        camera_pos = (np.cos(angle) * 5.0, np.sin(angle) * 5.0, 2.0)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.5),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.light.value = camera_pos

        crate_z = np.sin(self.crate_a * time + self.crate_b) * 0.2
        coordinates = np.dstack([self.crate_x, self.crate_y, crate_z])

        self.vbo2.write(coordinates.astype('f4').tobytes())
        self.vao.render(instances=1024)
    def render(self):
        width, height = self.wnd.size
        self.ctx.screen.viewport = self.wnd.viewport
        self.ctx.clear(1.0, 1.0, 1.0)
        with self.ctx.scope(mgl.DEPTH_TEST):

            proj = Matrix44.perspective_projection(45.0, width / height, 0.1, 1000.0)
            lookat = Matrix44.look_at(
                (47.697, -8.147, 24.498),
                (0.0, 0.0, 8.0),
                (0.0, 0.0, 1.0),
            )

            rotate = Matrix44.from_z_rotation(np.sin(self.wnd.time) * 0.5 + 0.2)

            self.prog['UseTexture'] = False

            self.prog['Light'] = (67.69, -8.14, 52.49)
            self.prog['Mvp'] = (proj * lookat * rotate).astype('f4').tobytes()

            self.prog['Color'] = (0.67, 0.49, 0.29)
            self.objects['ground'].render()

            self.prog['Color'] = (0.46, 0.67, 0.29)
            self.objects['grass'].render()

            self.prog['Color'] = (1.0, 1.0, 1.0)
            self.objects['billboard'].render()

            self.prog['Color'] = (0.2, 0.2, 0.2)
            self.objects['billboard-holder'].render()

            self.prog['UseTexture'] = True
            # self.texture.use()
            self.sampler.use()

            self.objects['billboard-image'].render()
    def render(self):
        angle = self.wnd.time
        self.ctx.screen.viewport = self.wnd.viewport
        self.ctx.clear(1.0, 1.0, 1.0)

        with self.ctx.scope(mgl.DEPTH_TEST):
            camera_pos = (np.cos(angle) * 20.0, np.sin(angle) * 20.0, 5.0)

            proj = Matrix44.perspective_projection(45.0, self.wnd.ratio, 0.1, 1000.0)
            lookat = Matrix44.look_at(
                camera_pos,
                (0.0, 0.0, 0.5),
                (0.0, 0.0, 1.0),
            )

            self.prog['Mvp'] = (proj * lookat).astype('f4').tobytes()
            self.prog['Light'] = camera_pos

            # self.vbo2.write(Matrix33.from_z_rotation(self.wnd.time).astype('f4').tobytes(), offset=24)
            self.vbo2.write(b''.join(struct.pack(
                '15f',
                *car['color'],
                *car['pos'],
                1.0, 0.0, 0.0,
                0.0, 1.0, 0.0,
                0.0, 0.0, 1.0,
            ) for car in cars))
            self.vao.render(instances=len(cars))
            self.vbo2.write(b''.join(struct.pack(
                '15f',
                0.0, 0.0, 0.0,
                *car['pos'],
                1.0, 0.0, 0.0,
                0.0, 1.0, 0.0,
                0.3, 0.6, 0.0,
            ) for car in cars))
            self.vao.render(instances=len(cars))
    def render(self, time, frame_time):
        angle = time
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(moderngl.DEPTH_TEST)

        camera_pos = (np.cos(angle) * 20.0, np.sin(angle) * 20.0, 5.0)

        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.5),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.light.value = camera_pos

        # self.vbo2.write(Matrix33.from_z_rotation(self.wnd.time).astype('f4').tobytes(), offset=24)
        self.vbo2.write(b''.join(struct.pack(
            '15f',
            *car['color'],
            *car['pos'],
            1.0, 0.0, 0.0,
            0.0, 1.0, 0.0,
            0.0, 0.0, 1.0,
        ) for car in cars))
        self.vao.render(instances=len(cars))
        self.vbo2.write(b''.join(struct.pack(
            '15f',
            0.0, 0.0, 0.0,
            *car['pos'],
            1.0, 0.0, 0.0,
            0.0, 1.0, 0.0,
            0.3, 0.6, 0.0,
        ) for car in cars))
        self.vao.render(instances=len(cars))
    def render(self, time, frame_time):
        self.ctx.clear(1.0, 1.0, 1.0)
        # self.ctx.enable(mgl.DEPTH_TEST)
        proj = Matrix44.perspective_projection(45.0, self.aspect_ratio, 0.1, 1000.0)
        lookat = Matrix44.look_at(
            (47.697, -8.147, 24.498),
            (0.0, 0.0, 8.0),
            (0.0, 0.0, 1.0),
        )

        rotate = Matrix44.from_z_rotation(np.sin(time) * 0.5 + 0.2)

        self.fbo.clear(0, (1.0, 1.0, 1.0))
        self.fbo.clear(-1, 1.0)
        for scope in [self.scope1, self.scope2]:
            with scope:
                self.prog['UseTexture'] = False

                self.prog['Light'] = (67.69, -8.14, 52.49)
                self.prog['Mvp'] = (proj * lookat * rotate).astype('f4').tobytes()

                self.prog['Color'] = (0.67, 0.49, 0.29)
                self.objects['ground'].render()

                self.prog['Color'] = (0.46, 0.67, 0.29)
                self.objects['grass'].render()

                self.prog['Color'] = (1.0, 1.0, 1.0)
                self.objects['billboard'].render()

                self.prog['Color'] = (0.2, 0.2, 0.2)
                self.objects['billboard-holder'].render()

                self.prog['UseTexture'] = True

                self.objects['billboard-image'].render()
 def build_projection(self):
     self.mat_projection = Matrix44.perspective_projection(
         self._field_of_view_degrees,
         self._ratio,
         self._z_near,
         self._z_far)
    '''),
])

mvp = prog.uniforms['Mvp']

grid = bytearray()

for i in range(0, 32 + 1):
    grid += struct.pack('6f', i - 16.0, -16.0, 0.0, 0.0, 0.0, 0.0)
    grid += struct.pack('6f', i - 16.0, 16.0, 0.0, 0.0, 0.0, 0.0)
    grid += struct.pack('6f', -16.0, i - 16.0, 0.0, 0.0, 0.0, 0.0)
    grid += struct.pack('6f', 16.0, i - 16.0, 0.0, 0.0, 0.0, 0.0)

vbo = ctx.buffer(grid)
vao = ctx.simple_vertex_array(prog, vbo, ['in_vert', 'in_color'])

while wnd.update():
    ctx.viewport = wnd.viewport
    ctx.clear(0.9, 0.9, 0.9)
    ctx.enable(ModernGL.DEPTH_TEST)

    proj = Matrix44.perspective_projection(45.0, wnd.ratio, 0.1, 1000.0)
    lookat = Matrix44.look_at(
        (40.0, 30.0, 20.0),
        (0.0, 0.0, 0.0),
        (0.0, 0.0, 1.0),
    )

    mvp.write((proj * lookat).astype('float32').tobytes())
    vao.render(ModernGL.LINES)
Example #53
0
 def window_did_resize(self, application, width, height):
     aspect = width / height
     proj_matrix = Matrix44.perspective_projection(
         50.0, aspect, 0.1, 100.0,
         dtype='f4')
     self._uniform_block.proj_matrix[:] = proj_matrix.reshape(16)
Example #54
0
	def SetPerspective(self, width, height):
		screenRatio = (1.0 * width) / (1.0 * height)
		self.perspectiveMatrix = Matrix44.perspective_projection(CAMERA_FOV, screenRatio, CAMERA_NEAR, CAMERA_FAR)
    grid += struct.pack('6f', i - 16.0, -16.0, 0.0, 0.0, 0.0, 0.0)
    grid += struct.pack('6f', i - 16.0, 16.0, 0.0, 0.0, 0.0, 0.0)
    grid += struct.pack('6f', -16.0, i - 16.0, 0.0, 0.0, 0.0, 0.0)
    grid += struct.pack('6f', 16.0, i - 16.0, 0.0, 0.0, 0.0, 0.0)

vbo = ctx.buffer(grid)
vao = ctx.simple_vertex_array(prog, vbo, ['in_vert', 'in_color'])

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    ctx.viewport = (0, 0, width, height)
    ctx.clear(0.9, 0.9, 0.9)
    ctx.enable(ModernGL.DEPTH_TEST)

    proj = Matrix44.perspective_projection(45.0, width / height, 0.1, 1000.0)
    lookat = Matrix44.look_at(
        (40.0, 30.0, 20.0),
        (0.0, 0.0, 0.0),
        (0.0, 0.0, 1.0),
    )

    mvp.write((proj * lookat).astype('float32').tobytes())
    vao.render(ModernGL.LINES)

    pygame.display.flip()
    pygame.time.wait(10)
Example #56
0
def onsc(yof):
    """Wheels. """
    global whel, projectmatrix
    sz = window.get_size()
    whel = clip(whel - yof, 1, 180)
    projectmatrix = matrix.perspective_projection(whel, sz[0] / sz[1], 0.01, 100)