当前位置: 首页>>代码示例>>Python>>正文


Python Vector.normalized方法代码示例

本文整理汇总了Python中UM.Math.Vector.Vector.normalized方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.normalized方法的具体用法?Python Vector.normalized怎么用?Python Vector.normalized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UM.Math.Vector.Vector的用法示例。


在下文中一共展示了Vector.normalized方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: lookAt

# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import normalized [as 别名]
    def lookAt(self, target: Vector, up: Vector = Vector.Unit_Y):
        if not self._enabled:
            return

        eye = self.getWorldPosition()
        f = (target - eye).normalized()
        up = up.normalized()
        s = f.cross(up).normalized()
        u = s.cross(f).normalized()

        m = Matrix([
            [ s.x,  u.x,  -f.x, 0.0],
            [ s.y,  u.y,  -f.y, 0.0],
            [ s.z,  u.z,  -f.z, 0.0],
            [ 0.0,  0.0,  0.0,  1.0]
        ])

        self.setOrientation(Quaternion.fromMatrix(m))
开发者ID:senttech,项目名称:Uranium,代码行数:20,代码来源:SceneNode.py

示例2: _zoomCamera

# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import normalized [as 别名]
    def _zoomCamera(self, zoom_range: float, event: Optional[Event] = None) -> None:
        camera = self._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            return

        self.clipToZoom()

        self._scene.getSceneLock().acquire()

        r = (camera.getWorldPosition() - self._origin).length()
        delta = r * (zoom_range / 128 / 10.0)
        r -= delta

        if self._invert_zoom:
            delta *= -1

        move_vector = Vector(0.0, 0.0, 1.0)

        if event is not None and self._zoom_to_mouse:
            viewport_center_x = QtApplication.getInstance().getRenderer().getViewportWidth() / 2
            viewport_center_y = QtApplication.getInstance().getRenderer().getViewportHeight() / 2
            main_window = cast(MainWindow, QtApplication.getInstance().getMainWindow())
            mouse_diff_center_x = viewport_center_x - main_window.mouseX
            mouse_diff_center_y = viewport_center_y - main_window.mouseY

            x_component = mouse_diff_center_x / QtApplication.getInstance().getRenderer().getViewportWidth()
            y_component = mouse_diff_center_y / QtApplication.getInstance().getRenderer().getViewportHeight()

            move_vector = Vector(x_component, -y_component, 1)
            move_vector = move_vector.normalized()

        move_vector = -delta * move_vector
        if delta != 0:
            if self._min_zoom < r < self._max_zoom:
                camera.translate(move_vector)
                if self._zoom_to_mouse:
                    # Set the origin of the camera to the new distance, right in front of the new camera position.
                    self._origin = (r * Vector(0.0, 0.0, -1.0)).preMultiply(camera.getWorldTransformation())
        self._scene.getSceneLock().release()
开发者ID:Ultimaker,项目名称:Uranium,代码行数:41,代码来源:CameraTool.py

示例3: test_normalize

# 需要导入模块: from UM.Math.Vector import Vector [as 别名]
# 或者: from UM.Math.Vector.Vector import normalized [as 别名]
 def test_normalize(self):
     vector = Vector(10, 10, 10)
     assert vector.normalized().length() == 1
开发者ID:Ultimaker,项目名称:Uranium,代码行数:5,代码来源:TestVector.py


注:本文中的UM.Math.Vector.Vector.normalized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。