本文整理汇总了Python中kivy.graphics.transformation.Matrix类的典型用法代码示例。如果您正苦于以下问题:Python Matrix类的具体用法?Python Matrix怎么用?Python Matrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Matrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply_transform
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: look_at
def look_at(self, v):
m = Matrix()
pos = self._position * -1
m = m.translate(pos[0], pos[1], pos[2])
self.modelview_matrix = m
self._look_at = v
self.update()
示例3: update_viewport
def update_viewport(self):
from kivy.graphics.opengl import glViewport
from kivy.graphics.transformation import Matrix
width, height = self.system_size
w2 = width / 2.
h2 = height / 2.
# prepare the viewport
glViewport(0, 0, width, height)
projection_mat = Matrix()
projection_mat.view_clip(0.0, width, 0.0, height, -1.0, 1.0, 0)
self.render_context['projection_mat'] = projection_mat
# use the rotated size.
# XXX FIXME fix rotation
'''
width, height = self.size
w2 = width / 2.
h2 = height / 2.
glTranslatef(-w2, -h2, -500)
# set the model view
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glTranslatef(w2, h2, 0)
glRotatef(self._rotation, 0, 0, 1)
glTranslatef(-w2, -h2, 0)
'''
self.update_childsize()
示例4: updateScene
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: apply_angle_scale_trans
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)
示例6: look_at
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: update_glsl
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
示例8: update_glsl
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])
示例9: update_glsl
def update_glsl(self, dt):
from kivy.core.window import Window
g = self.params.get
w, h = Window.system_size
projection_mat = Matrix()
#projection_mat.view_clip(0.0, w, 0.0, h, 10.0, 1000.0, 1)
projection_mat.perspective(g('fovy', 45.), g('aspect', 1), g('zNear', 10), g('zFar', 1000))
#projection_mat.view_clip(0.0, w, 0.0, h, -1, 1, 0)
modelview_mat = Matrix().look_at(0, 200, -200, self.targetx, self.targety, 0, 0, 1, 0)
self.canvas['projection_mat'] = projection_mat
self.canvas['modelview_mat'] = modelview_mat
示例10: get_look_at
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
示例11: get_window_matrix
def get_window_matrix(self, x=0, y=0):
'''Calculate the transformation matrix to convert between window and
widget coordinates.
:Parameters:
`x`: float, defaults to 0
Translates the matrix on the x axis.
`y`: float, defaults to 0
Translates the matrix on the y axis.
'''
m = Matrix()
m.translate(x, y, 0)
m = self._apply_transform(m)
return m
示例12: update_camera
def update_camera(self, pos, angle):
self.eye_pos = pos
self.eye_angle = angle
x, y, z = pos
azi, ele = angle
asp = self.width / float(self.height)
mat = self.get_look_at(x, y, z, azi, ele)
proj = Matrix()
proj.perspective(30, asp, 1, 100)
self.canvas['projection_mat'] = proj
self.canvas['modelview_mat'] = mat
self.fixed_x.x = x
self.fixed_y.y = y
self.fixed_z.z = z
self.fixed_azi.angle = azi * 180/np.pi
self.fixed_ele.angle = ele * 180/np.pi
示例13: __init__
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
示例14: update_glsl
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
示例15: update_glsl
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)