本文整理汇总了Python中kivy.graphics.transformation.Matrix.multiply方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.multiply方法的具体用法?Python Matrix.multiply怎么用?Python Matrix.multiply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.graphics.transformation.Matrix
的用法示例。
在下文中一共展示了Matrix.multiply方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply_transform
# 需要导入模块: from kivy.graphics.transformation import Matrix [as 别名]
# 或者: from kivy.graphics.transformation.Matrix import multiply [as 别名]
def apply_transform(self, trans, post_multiply=False, anchor=(0, 0)):
'''
Transforms the scatter by applying the "trans" transformation
matrix (on top of its current transformation state). The resultant
matrix can be found in the :attr:`~Scatter.transform` property.
:Parameters:
`trans`: :class:`~kivy.graphics.transformation.Matrix`.
Transformation matix to be applied to the scatter widget.
`anchor`: tuple, defaults to (0, 0).
The point to use as the origin of the transformation
(uses local widget space).
`post_multiply`: bool, defaults to False.
If True, the transform matrix is post multiplied
(as if applied before the current transform).
Usage example::
from kivy.graphics.transformation import Matrix
mat = Matrix().scale(3, 3, 3)
scatter_instance.apply_transform(mat)
'''
t = Matrix().translate(anchor[0], anchor[1], 0)
t = t.multiply(trans)
t = t.multiply(Matrix().translate(-anchor[0], -anchor[1], 0))
if post_multiply:
self.transform = self.transform.multiply(t)
else:
self.transform = t.multiply(self.transform)
示例2: apply_angle_scale_trans
# 需要导入模块: from kivy.graphics.transformation import Matrix [as 别名]
# 或者: from kivy.graphics.transformation.Matrix import multiply [as 别名]
def apply_angle_scale_trans(self, angle, scale, trans, point=Vector(0, 0)):
'''Update matrix transformation by adding new angle,
scale and translate.
:Parameters:
`angle` : float
Rotation angle to add
`scale` : float
Scaling value to add
`trans` : Vector
Vector translation to add
`point` : Vector, default to (0, 0)
Point to apply transformation
'''
old_scale = self.scale
new_scale = old_scale * scale
if new_scale < self.scale_min or old_scale > self.scale_max:
scale = 1.
t = Matrix().translate(
trans[0] * self.do_translation_x,
trans[1] * self.do_translation_y,
0)
t = t.multiply(Matrix().translate(point[0], point[1], 0))
t = t.multiply(Matrix().rotate(angle, 0, 0, 1))
t = t.multiply(Matrix().scale(scale, scale, scale))
t = t.multiply(Matrix().translate(-point[0], -point[1], 0))
self.apply_transform(t)
示例3: update_viewport
# 需要导入模块: from kivy.graphics.transformation import Matrix [as 别名]
# 或者: from kivy.graphics.transformation.Matrix import multiply [as 别名]
def update_viewport(self):
from kivy.graphics.opengl import glViewport
from kivy.graphics.transformation import Matrix
from math import radians
w, h = self.system_size
w2, h2 = w / 2., h / 2.
r = radians(self.rotation)
# prepare the viewport
glViewport(0, 0, w, h)
# do projection matrix
projection_mat = Matrix()
projection_mat.view_clip(0.0, w, 0.0, h, -1.0, 1.0, 0)
self.render_context['projection_mat'] = projection_mat
# do modelview matrix
modelview_mat = Matrix().translate(w2, h2, 0)
modelview_mat = modelview_mat.multiply(Matrix().rotate(r, 0, 0, 1))
w, h = self.size
w2, h2 = w / 2., h / 2.
modelview_mat = modelview_mat.multiply(Matrix().translate(-w2, -h2, 0))
self.render_context['modelview_mat'] = modelview_mat
# redraw canvas
self.canvas.ask_update()
# and update childs
self.update_childsize()
示例4: update_viewport
# 需要导入模块: from kivy.graphics.transformation import Matrix [as 别名]
# 或者: from kivy.graphics.transformation.Matrix import multiply [as 别名]
def update_viewport(self):
from kivy.graphics.opengl import glViewport
from kivy.graphics.transformation import Matrix
from math import radians
w, h = self.system_size
if self._density != 1:
w, h = self.size
smode = self.softinput_mode
target = self._system_keyboard.target
targettop = target.to_window(0, target.y)[1] if target else 0
kheight = self.keyboard_height
w2, h2 = w / 2., h / 2.
r = radians(self.rotation)
x, y = 0, 0
_h = h
if smode == 'pan':
y = kheight
elif smode == 'below_target':
y = 0 if kheight < targettop else (kheight - targettop) + dp(9)
if smode == 'scale':
_h -= kheight
# prepare the viewport
glViewport(x, y, w, _h)
# do projection matrix
projection_mat = Matrix()
projection_mat.view_clip(0.0, w, 0.0, h, -1.0, 1.0, 0)
self.render_context['projection_mat'] = projection_mat
# do modelview matrix
modelview_mat = Matrix().translate(w2, h2, 0)
modelview_mat = modelview_mat.multiply(Matrix().rotate(r, 0, 0, 1))
w, h = self.size
w2, h2 = w / 2., h / 2.
modelview_mat = modelview_mat.multiply(Matrix().translate(-w2, -h2, 0))
self.render_context['modelview_mat'] = modelview_mat
# redraw canvas
self.canvas.ask_update()
# and update childs
self.update_childsize()
示例5: update_glsl
# 需要导入模块: from kivy.graphics.transformation import Matrix [as 别名]
# 或者: from kivy.graphics.transformation.Matrix import multiply [as 别名]
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])
示例6: update_viewport
# 需要导入模块: from kivy.graphics.transformation import Matrix [as 别名]
# 或者: from kivy.graphics.transformation.Matrix import multiply [as 别名]
def update_viewport(self):
from kivy.graphics.opengl import glViewport
from kivy.graphics.transformation import Matrix
from math import radians
w, h = self.system_size
if self._density != 1:
w, h = self.size
smode = self.softinput_mode
kheight = self.keyboard_height
w2, h2 = w / 2.0, h / 2.0
r = radians(self.rotation)
x, y = 0, 0
_h = h
if smode:
y = kheight
if smode == "scale":
_h -= kheight
# prepare the viewport
glViewport(x, y, w, _h)
# do projection matrix
projection_mat = Matrix()
projection_mat.view_clip(0.0, w, 0.0, h, -1.0, 1.0, 0)
self.render_context["projection_mat"] = projection_mat
# do modelview matrix
modelview_mat = Matrix().translate(w2, h2, 0)
modelview_mat = modelview_mat.multiply(Matrix().rotate(r, 0, 0, 1))
w, h = self.size
w2, h2 = w / 2.0, h / 2.0
modelview_mat = modelview_mat.multiply(Matrix().translate(-w2, -h2, 0))
self.render_context["modelview_mat"] = modelview_mat
# redraw canvas
self.canvas.ask_update()
# and update childs
self.update_childsize()
示例7: update_fbo
# 需要导入模块: from kivy.graphics.transformation import Matrix [as 别名]
# 或者: from kivy.graphics.transformation.Matrix import multiply [as 别名]
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, 600, 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)
depthViewMatrix = Matrix().look_at(-0.5, -50, -100, 0, 0, 0, 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'] = (0.1, 0.1, 0.1)
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
if self.picking_fbo:
self.picking_fbo['projection_mat'] = proj
self.alpha += 10 * time
self.fbo['cond'] = (0.0, 0.7)
self.fbo['val_sin'] = (self.alpha, 0.0)
示例8: SingleRotate
# 需要导入模块: from kivy.graphics.transformation import Matrix [as 别名]
# 或者: from kivy.graphics.transformation.Matrix import multiply [as 别名]
class SingleRotate(object):
def __init__(self, angle, axis, render_context):
# It shold be way to get current context
# but in simple case we may just pass it to constructor
self.context = render_context
self._axis = axis
self._angle = angle
self.renderer = render_context
self.prev_mvm = Matrix()
self.matrix = Matrix()
Callback(self._rotate) # here we perform rotation
def radians(self, degrees):
""" Calculate radians from angle here """
return degrees * (3.14159265 / 180.)
@property
def angle(self):
return self._angle
@angle.setter
def angle(self, v):
self._angle = v
angle = self.radians(self._angle)
ax, ay, az = self._axis
# calculate rotated matrix and store it
self.matrix = Matrix().rotate(angle, ax, ay, az)
def clear(self):
Callback(self._clear)
def _rotate(self, *args):
" This sets rotation in callback "
# get previous matrix and save it
self.prev_mvm = self.renderer['modelview_mat']
# do multiply for rotation
self.context['modelview_mat'] = self.prev_mvm.multiply(self.matrix)
def _clear(self, *args):
self.renderer['modelview_mat'] = self.prev_mvm
示例9: _update_labels
# 需要导入模块: from kivy.graphics.transformation import Matrix [as 别名]
# 或者: from kivy.graphics.transformation.Matrix import multiply [as 别名]
#.........这里部分代码省略.........
yextent = y + height
ymin = self.ymin
ymax = self.ymax
xmin = self.xmin
precision = self.precision
x_overlap = False
y_overlap = False
# set up x and y axis labels
if xlabel:
xlabel.text = self.xlabel
xlabel.texture_update()
xlabel.size = xlabel.texture_size
xlabel.pos = (x + width / 2. - xlabel.width / 2., padding + y)
y_next += padding + xlabel.height
if ylabel:
ylabel.text = self.ylabel
ylabel.texture_update()
ylabel.size = ylabel.texture_size
ylabel.x = padding + x - (ylabel.width / 2. - ylabel.height / 2.)
x_next += padding + ylabel.height
xpoints = self._ticks_majorx
xlabels = self._x_grid_label
xlabel_grid = self.x_grid_label
ylabel_grid = self.y_grid_label
ypoints = self._ticks_majory
ylabels = self._y_grid_label
# now x and y tick mark labels
if len(ylabels) and ylabel_grid:
# horizontal size of the largest tick label, to have enough room
ylabels[0].text = precision % ypoints[0]
ylabels[0].texture_update()
y1 = ylabels[0].texture_size
y_start = y_next + (
padding + y1[1]
if len(xlabels) and xlabel_grid else 0
) + (padding + y1[1] if not y_next else 0)
yextent = y + height - padding - y1[1] / 2.
if self.ylog:
ymax = log10(ymax)
ymin = log10(ymin)
ratio = (yextent - y_start) / float(ymax - ymin)
y_start -= y1[1] / 2.
func = (lambda x: 10 ** x) if self.ylog else lambda x: x
y1 = y1[0]
for k in xrange(len(ylabels)):
ylabels[k].text = precision % func(ypoints[k])
ylabels[k].texture_update()
ylabels[k].size = ylabels[k].texture_size
y1 = max(y1, ylabels[k].texture_size[0])
ylabels[k].pos = (x_next, y_start + (ypoints[k] - ymin) *
ratio)
if len(ylabels) > 1 and ylabels[0].top > ylabels[1].y:
y_overlap = True
else:
x_next += y1 + padding
if len(xlabels) and xlabel_grid:
func = log10 if self.xlog else lambda x: x
# find the distance from the end that'll fit the last tick label
xlabels[0].text = precision % func(xpoints[-1])
xlabels[0].texture_update()
xextent = x + width - xlabels[0].texture_size[0] / 2. - padding
# find the distance from the start that'll fit the first tick label
if not x_next:
xlabels[0].text = precision % func(xpoints[0])
xlabels[0].texture_update()
x_next = padding + xlabels[0].texture_size[0] / 2.
xmin = func(xmin)
ratio = (xextent - x_next) / float(func(self.xmax) - xmin)
func = (lambda x: 10 ** x) if self.xlog else lambda x: x
right = -1
for k in xrange(len(xlabels)):
xlabels[k].text = precision % func(xpoints[k])
# update the size so we can center the labels on ticks
xlabels[k].texture_update()
xlabels[k].size = xlabels[k].texture_size
xlabels[k].pos = (x_next + (xpoints[k] - xmin) * ratio -
xlabels[k].texture_size[0] / 2., y_next)
if xlabels[k].x < right:
x_overlap = True
break
right = xlabels[k].right
if not x_overlap:
y_next += padding + xlabels[0].texture_size[1]
# now re-center the x and y axis labels
if xlabel:
xlabel.x = x_next + (xextent - x_next) / 2. - xlabel.width / 2.
if ylabel:
ylabel.y = y_next + (yextent - y_next) / 2. - ylabel.height / 2.
t = Matrix().translate(ylabel.center[0], ylabel.center[1], 0)
t = t.multiply(Matrix().rotate(-radians(270), 0, 0, 1))
ylabel.transform = t.multiply(Matrix().translate(-ylabel.center[0],
-ylabel.center[1],
0))
if x_overlap:
for k in xrange(len(xlabels)):
xlabels[k].text = ''
if y_overlap:
for k in xrange(len(ylabels)):
ylabels[k].text = ''
return x_next, y_next, xextent, yextent
示例10: apply_transform
# 需要导入模块: from kivy.graphics.transformation import Matrix [as 别名]
# 或者: from kivy.graphics.transformation.Matrix import multiply [as 别名]
def apply_transform(self, rescale, anchor=(0, 0)):
trans = Matrix().scale(rescale, rescale, rescale)
t = Matrix().translate(anchor[0], anchor[1], 0)
t = t.multiply(trans)
t = t.multiply(Matrix().translate(-anchor[0], -anchor[1], 0))
self.transform.matrix = t