本文整理汇总了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))
示例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()
示例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