コード例 #1
0
ファイル: canvas3d.py プロジェクト: Cophy08/kivy3dgui
    def update_glsl(self, *largs):
        width = self.width if self.width > 1 else 100
        height = self.height if self.height > 1 else 100
        asp = width / float(height)
        proj = Matrix().view_clip(-asp, asp, -1, 1, 1, 600, 1)
        proj = Matrix()
        proj.perspective(self.perspective_value, asp, 1, 1000)

        matrix_camera = Matrix().identity()
        matrix_camera.look_at(0, 100, 300, 100, 0, -100, 0, 1, 0)
        self.canvas['projection_mat'] = proj
        self.canvas['diffuse_light'] = (0.0, 1.0, 0.0)
        self.canvas['ambient_light'] = (0.1, 0.1, 0.1)
        if self.shadow:
            self.canvas['texture1'] = 1
            self.canvas["enabled_shadow"] = 1.0
        else:

            self.canvas["enabled_shadow"] = 0.0
            self.canvas["texture1"] = 0

        depthProjectionMatrix = Matrix().view_clip(
            -100 * self.shadow_threshold, 100 * self.shadow_threshold,
            -100 * self.shadow_threshold, 100 * self.shadow_threshold,
            -100 * self.shadow_threshold, 200 * self.shadow_threshold * 2, 0)
        depthViewMatrix = Matrix().look_at(-0.5, -50, -100, 0, 0, 0, 0, 1, 0)
        depthModelMatrix = Matrix().identity()
        depthMVP = depthProjectionMatrix.multiply(depthViewMatrix).multiply(
            depthModelMatrix)
        self.canvas['depthMVP'] = depthMVP
        self.canvas['cond'] = (0.0, 0.7)
        self.canvas['val_sin'] = (self.alpha, 0.0)

        if self.shadow:
            self.update_fbo(largs[0])
コード例 #2
0
ファイル: canvas3d.py プロジェクト: Cophy08/kivy3dgui
    def update_glsl(self, *largs):
        width = self.width if self.width > 1 else 100
        height = self.height if self.height > 1 else 100
        asp = width / float(height)
        proj = Matrix().view_clip(-asp, asp, -1, 1, 1, 600, 1)
        proj = Matrix()
        proj.perspective(self.perspective_value, asp, 1, 1000)

        matrix_camera = Matrix().identity()
        matrix_camera.look_at(0, 100, 300, 100, 0, -100, 0, 1, 0)
        self.canvas['projection_mat'] = proj
        self.canvas['diffuse_light'] = (0.0, 1.0, 0.0)
        self.canvas['ambient_light'] = (0.1, 0.1, 0.1)
        if self.shadow:
            self.canvas['texture1'] = 1
            self.canvas["enabled_shadow"] = 1.0
        else:

            self.canvas["enabled_shadow"] = 0.0
            self.canvas["texture1"] = 0

        depthProjectionMatrix = Matrix().view_clip(-100 * self.shadow_threshold, 100 * self.shadow_threshold,
                                                   -100 * self.shadow_threshold, 100 * self.shadow_threshold,
                                                   -100 * self.shadow_threshold, 200 * self.shadow_threshold * 2, 0)
        depthViewMatrix = Matrix().look_at(-0.5, -50, -100, 0, 0, 0, 0, 1, 0)
        depthModelMatrix = Matrix().identity()
        depthMVP = depthProjectionMatrix.multiply(depthViewMatrix).multiply(depthModelMatrix)
        self.canvas['depthMVP'] = depthMVP
        self.canvas['cond'] = (0.0, 0.7)
        self.canvas['val_sin'] = (self.alpha, 0.0)

        if self.shadow:
            self.update_fbo(largs[0])
コード例 #3
0
ファイル: canvas3d.py プロジェクト: cchang888/kivy3dgui
    def update_glsl(self, *largs):
        width = self.width if self.width > 1 else 100
        height = self.height if self.height > 1 else 100

        asp = width / float(height)
        proj = Matrix().view_clip(-asp, asp, -1, 1, 1, 600, 1)
        proj = Matrix()
        proj.perspective(self.perspective_value, asp, 1, 1000)

        matrix_camera = Matrix().identity()
        matrix_camera = matrix_camera.look_at(*self.look_at)

        self.canvas['projection_mat'] = proj
        self.canvas['camera'] = matrix_camera

        self.canvas['diffuse_light'] = (0.0, 1.0, 0.0)
        self.canvas['ambient_light'] = (0.1, 0.1, 0.1)
        if self.shadow:
            self.canvas['texture1'] = 1
            self.canvas["enabled_shadow"] = 1.0
        else:

            self.canvas["enabled_shadow"] = 0.0
            self.canvas["texture1"] = 0

        depthProjectionMatrix = Matrix().view_clip(
            -100 * self.shadow_threshold, 100 * self.shadow_threshold,
            -100 * self.shadow_threshold, 100 * self.shadow_threshold,
            -100 * self.shadow_threshold, 200 * self.shadow_threshold * 2, 0)
        _shadow_pos = self._shadow_pos
        _shadow_target = self._shadow_target
        depthViewMatrix = Matrix().look_at(
            _shadow_target[0], _shadow_target[1],
            _shadow_target[2] + self._shadow_offset, _shadow_pos[0],
            _shadow_pos[1], _shadow_pos[2], 0, 1, 0)

        depthModelMatrix = Matrix().identity()
        depthMVP = depthProjectionMatrix.multiply(depthViewMatrix).multiply(
            depthModelMatrix)
        self.canvas['depthMVP'] = depthMVP
        self.canvas['cond'] = (0.0, 0.7)
        self.canvas['val_sin'] = (self.alpha, 0.0)

        if self.shadow:
            self.update_fbo(largs[0])
            # label.text = str(Clock.get_rfps())

        if self.parent.parent is None:
            # del self.parent

            self.parent.canvas3d = None
            self.fbo_list.clear()
            self.fbo = None
            for a in self.nodes:
                a.remove_a()
            self.nodes = []
            self.parent._nodes = []
            self.parent.clear_widgets()
            self.adding_queue = []
            self.nt.cancel()
コード例 #4
0
ファイル: renderer.py プロジェクト: mikepan/kivyBox
	def updateScene(self, fb, *largs):
		# smooth camera
		cam = fb.scene.camera
		cam._rotation = helpers.mix(cam._rotation, cam._rotationTarget, 0.9)
		cam._distance = helpers.mix(cam._distance, cam._distanceTarget, 0.9)

		# compute camera pos
		cam.position[0] = cos(cam._rotation[2])*cos(cam._rotation[1])*cam._distance
		cam.position[2] = sin(cam._rotation[2])*cos(cam._rotation[1])*cam._distance
		cam.position[1] = sin(cam._rotation[1])*cam._distance

		# setup camera
		fov = cam.fov
		pos = cam.position
		target = fb.scene.camera.target
		asp = self.width / float(self.height)
		proj = Matrix()
		proj.perspective(fov, asp, 0.1, 100)
		modelView = Matrix()
		modelView = modelView.look_at(pos[0],pos[2],pos[1], target[0], target[2], target[1], 0,0,1)

		self.canvas['modelview_mat'] = modelView
		self.canvas['projection_mat'] = proj
		self.canvas['diffuse_light'] = (1.0, 1.0, 0.8)
		self.canvas['ambient_light'] = (0.1, 0.1, 0.1)

		self.mesh1['modelview_mat'] = modelView
		self.mesh1['projection_mat'] = proj
		self.mesh1['diffuse_light'] = (1.0, 2.0, 0.8)
		self.mesh1['ambient_light'] = (0.1, 0.1, 0.1)

		self.mesh2['modelview_mat'] = modelView
		self.mesh2['projection_mat'] = proj
		self.mesh2['diffuse_light'] = (2.0, 1.0, 0.8)
		self.mesh2['ambient_light'] = (0.1, 0.1, 0.1)
コード例 #5
0
    def update_fbo(self, time):
        width = self.width if self.width > 1 else 100
        height = self.height if self.height > 1 else 100

        asp = (width / float(height))
        proj = Matrix().view_clip(-asp, asp, -1, 1, 1, 1600, 1)
        proj = Matrix()
        proj.perspective(self.perspective_value, asp, 1, 1000)

        lightInvDir = (0.5, 2, 2)
        depthProjectionMatrix = Matrix().view_clip(
            -100 * self.shadow_threshold, 100 * self.shadow_threshold,
            -100 * self.shadow_threshold, 100 * self.shadow_threshold,
            -100 * self.shadow_threshold, 200 * self.shadow_threshold * 2, 0)
        _shadow_pos = self._shadow_pos
        _shadow_target = self._shadow_target

        depthViewMatrix = Matrix().look_at(
            _shadow_target[0], _shadow_target[1],
            _shadow_target[2] + self._shadow_offset, _shadow_pos[0],
            _shadow_pos[1], _shadow_pos[2], 0, 1, 0)
        depthModelMatrix = Matrix().identity()
        depthMVP = depthProjectionMatrix.multiply(depthViewMatrix).multiply(
            depthModelMatrix)

        self.fbo['projection_mat'] = proj
        self.fbo['depthMVP'] = depthMVP
        self.fbo['diffuse_light'] = (0.0, 1.0, 0.0)
        self.fbo['ambient_light'] = self.ambient_light
        for m_pos in range(len(self.nodes)):
            motion_matrix = Matrix().view_clip(-asp, asp, -1, 1, 1, 600, 1)
            angle = self.nodes[m_pos].rotate[0] * 3.14 / 180
            pos = self.nodes[m_pos].get_pos()

            trans = self.nodes[m_pos].translate[:]

            result = [0, 0, 0]
            result[0] = 0.3 if trans[0] < pos[0] else -0.3
            result[1] = 0.3 if trans[1] < pos[1] else -0.3
            result[2] = 0.3 if trans[2] < pos[2] else -0.3

            motion_matrix = motion_matrix.translate(trans[0] + 0.1,
                                                    trans[1] + 0.1, trans[2])
            self.motion_blur_fbo['oldTransformation{0}'.format(
                str(m_pos))] = motion_matrix

        self.motion_blur_fbo['projection_mat'] = proj
        self.motion_blur_fbo['depthMVP'] = depthMVP

        matrix_camera = Matrix().identity()
        matrix_camera = matrix_camera.look_at(*self.look_at)

        if self.picking_fbo:
            self.picking_fbo['projection_mat'] = proj
            self.picking_fbo['camera'] = matrix_camera

        self.alpha += 10 * time
        self.fbo['cond'] = (0.0, 0.7)
        self.fbo['val_sin'] = (self.alpha, 0.0)
コード例 #6
0
ファイル: camera.py プロジェクト: nskrypnik/kivy3
 def look_at(self, *v):
     if len(v) == 1:
         v = v[0]
     m = Matrix()
     pos = self._position * -1
     m = m.look_at(pos[0], pos[1], pos[2], v[0], v[1], v[2], self.up[0], self.up[1], self.up[2])
     self.modelview_matrix = m
     self._look_at = v
     self.update()
コード例 #7
0
 def look_at(self, *v):
     if len(v) == 1:
         v = v[0]
     m = Matrix()
     pos = self._position * -1
     m = m.look_at(pos[0], pos[1], pos[2], v[0], v[1], v[2], self.up[0],
                   self.up[1], self.up[2])
     self.modelview_matrix = m
     self._look_at = v
     self.update()
コード例 #8
0
ファイル: main.py プロジェクト: nskrypnik/pycon2014demos
 def update_glsl(self, *largs):
     asp = self.width / float(self.height)
     asp = asp*0.3
     proj = Matrix()
     mat = Matrix()
     mat = mat.look_at(0, 0, self.camera_translate[2], 0, 0, -3, 0, 1, 0)
     proj = proj.view_clip(-asp, asp, -.3, .3, 1, 100, 1)
     
     self.canvas['projection_mat'] = proj
     self.canvas['modelview_mat'] = mat
コード例 #9
0
ファイル: display.py プロジェクト: eflynch/ectophylla
    def get_look_at(self, x, y, z, azi, ele):
        dx = -np.sin(azi) * np.cos(ele)
        dy = np.sin(ele)
        dz = -np.cos(azi) * np.cos(ele)

        # Not sure why up has to just be up...
        upx, upy, upz = (0, 1, 0)

        mat = Matrix()
        mat = mat.look_at(x, y, z, x + dx, y + dy, z + dz, upx, upy, upz)
        return mat
コード例 #10
0
    def update_glsl(self, *largs):
        asp = self.width / float(self.height)
        asp = asp * 0.3
        asp = 0.8
        proj = Matrix()
        mat = Matrix()
        mat = mat.look_at(0.0, 0.6, self.camera_translate[2], 0, 0, 0, 0, 1, 0)
        proj = proj.view_clip(-asp, asp, -0.6, .6, 1, 100, 1)

        self.canvas['projection_mat'] = proj
        self.canvas['modelview_mat'] = mat
コード例 #11
0
ファイル: display.py プロジェクト: eflynch/ectophylla
    def get_look_at(self, x, y, z, azi, ele):
        dx = - np.sin(azi) * np.cos(ele)
        dy = np.sin(ele)
        dz = - np.cos(azi) * np.cos(ele)

        # Not sure why up has to just be up...
        upx, upy, upz = (0, 1, 0)

        mat = Matrix()
        mat = mat.look_at(x, y, z,
                          x + dx, y + dy, z + dz,
                          upx, upy, upz)
        return mat
コード例 #12
0
ファイル: camera.py プロジェクト: sulik011/pong
    def look_at(self, *v):
        if len(v) == 1:
            v = v[0]
        m = Matrix()
        pos = self._position
        m = m.look_at(pos[0], pos[1], pos[2], v[0], v[1], v[2], self.up[0],
                      self.up[1], self.up[2])
        m = m.rotate(radians(self.rot.x), 1.0, 0.0, 0.0)
        m = m.rotate(radians(self.rot.y), 0.0, 1.0, 0.0)
        m = m.rotate(radians(self.rot.z), 0.0, 0.0, 1.0)
        self.modelview_matrix = m

        # set camera vectors from view matrix
        self._right = Vector3(m[0], m[1], m[2])
        self._up = Vector3(m[4], m[5], m[6])
        self._back = Vector3(m[8], m[9], m[10])
        self._look_at = v
        self.update()
コード例 #13
0
    def update_glsl(self, *largs):
        global no_width_error_enable
        if self.player_velocity[0] != 0:
            self.camera_translate_instruction.x += self.player_velocity[0]
        if self.player_velocity[1] != 0:
            self.camera_translate_instruction.y += self.player_velocity[1]
        if self.player_velocity[2] != 0:
            self.camera_translate_instruction.z += self.player_velocity[2]
        if self.height > 0:
            asp = self.width / float(self.height)
        else:
            if no_width_error_enable:
                print("[ TestingKivy3D ] ERROR in update_glsl: Failed to get width.")
                no_width_error_enable = False

        clip_top = 0.06  # NOTE: 0.03 is ~1.72 degrees, if that matters
        # formerly field_of_view_factor
        # was changed to .03 when projection_near was changed from 1 to .1
        # was .3 when projection_near was 1

        clip_right = asp*clip_top  # formerly overwrote asp
        self.projection_near = 0.1
        projectionMatrix = Matrix().view_clip(-clip_right, clip_right, -1*clip_top, clip_top, self.projection_near, 100, 1)  # last params: far, perspective
        #projectionMatrix = Matrix().view_clip(-asp, asp, -1, 1, 1, 100, 1)  # last params: far, perspective
        modelViewMatrix = Matrix()
        modelViewMatrix.translate(self.camera_translate_instruction.x, self.camera_translate_instruction.y, self.camera_translate_instruction.z)
        if (self.camera_translate_instruction.x != self.look_point[0] or
            self.camera_translate_instruction.y != self.look_point[1] or
            self.camera_translate_instruction.z != self.look_point[2]):
            try:
                modelViewMatrix = modelViewMatrix.look_at(self.camera_translate_instruction.x, self.camera_translate_instruction.y, self.camera_translate_instruction.z, self.look_point[0], self.look_point[1], self.look_point[2], 0, 1, 0)  # 0,1,0 is y-up orientation
            except:
                print("[ TestingKivy3D ] Could not finish modelViewMatrix.look_at:")
        else:
            print("[ TestingKivy3D ] Can't run modelViewMatrix.look_at since camera is at look_point")

        self.gl_widget.canvas['projection_mat'] = projectionMatrix
        self.gl_widget.canvas['modelview_mat'] = modelViewMatrix
        self.gl_widget.canvas["camera_world_pos"] = [self.camera_translate_instruction.x, self.camera_translate_instruction.y, self.camera_translate_instruction.z]
        self.gl_widget.canvas['ambient_light'] = (0.1, 0.1, 0.1)
コード例 #14
-1
ファイル: main.py プロジェクト: tuanfeng/texture_transfer
    def update_glsl(self, *largs):
        asp = self.width / float(self.height)
        asp = 15 / 6.0
        proj = Matrix()
        mat = Matrix()
        mat = mat.look_at(
            self.camera_loc[0] * self.camera_r,
            self.camera_loc[1] * self.camera_r,
            self.camera_loc[2] * self.camera_r,
            0,
            0,
            0,
            self.camera_up[0],
            self.camera_up[1],
            self.camera_up[2],
        )
        proj = proj.view_clip(-asp * 0.5, asp * 0.5, -0.5, 0.5, 1, 10, 1)

        self.canvas["projection_mat"] = proj
        self.canvas["modelview_mat"] = mat