本文整理汇总了Python中mat4函数的典型用法代码示例。如果您正苦于以下问题:Python mat4函数的具体用法?Python mat4怎么用?Python mat4使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mat4函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __rmul__
def __rmul__(self, other):
T = type(other)
# scalar*mat4
if T==types.FloatType or T==types.IntType or T==types.LongType:
return mat4(map(lambda x,other=other: other*x, self.mlist))
# vec4*mat4
if isinstance(other, _vec4):
m11,m12,m13,m14,m21,m22,m23,m24,m31,m32,m33,m34,m41,m42,m43,m44 = self.mlist
return _vec4(other.x*m11 + other.y*m21 + other.z*m31 + other.w*m41,
other.x*m12 + other.y*m22 + other.z*m32 + other.w*m42,
other.x*m13 + other.y*m23 + other.z*m33 + other.w*m43,
other.x*m14 + other.y*m24 + other.z*m34 + other.w*m44)
# vec3*mat4
if isinstance(other, _vec3):
m11,m12,m13,m14,m21,m22,m23,m24,m31,m32,m33,m34,m41,m42,m43,m44 = self.mlist
w = float(other.x*m14 + other.y*m24 + other.z*m34 + m44)
return _vec3(other.x*m11 + other.y*m21 + other.z*m31 + m41,
other.x*m12 + other.y*m22 + other.z*m32 + m42,
other.x*m13 + other.y*m23 + other.z*m33 + m43)/w
# mat4*mat4
if isinstance(other, mat4):
return self.__mul__(other)
# unsupported
else:
raise TypeError("unsupported operand type for *")
示例2: scaling
def scaling(s):
"""Return scaling matrix."""
sx,sy,sz = s
return mat4(sx, 0.0, 0.0, 0.0,
0.0, sy, 0.0, 0.0,
0.0, 0.0, sz, 0.0,
0.0, 0.0, 0.0, 1.0)
示例3: lookAt
def lookAt(pos, target, up=_vec3(0,0,1)):
"""Look from pos to target.
The resulting transformation moves the origin to pos and
rotates so that the z-axis points to target. The y-axis is
as close as possible to the up vector.
"""
pos = _vec3(pos)
target = _vec3(target)
up = _vec3(up)
dir = (target - pos).normalize()
up = up.normalize()
up -= (up * dir) * dir
try:
up = up.normalize()
except:
# We're looking along the up direction, so choose
# an arbitrary direction that is perpendicular to dir
# as new up.
up = dir.ortho()
right = up.cross(dir).normalize()
return mat4(right.x, up.x, dir.x, pos.x,
right.y, up.y, dir.y, pos.y,
right.z, up.z, dir.z, pos.z,
0.0, 0.0, 0.0, 1.0)
示例4: rotation
def rotation(angle, axis):
"""Return rotation matrix.
angle must be given in radians. axis should be of type vec3.
"""
axis = _vec3(axis)
sqr_a = axis.x*axis.x
sqr_b = axis.y*axis.y
sqr_c = axis.z*axis.z
len2 = sqr_a+sqr_b+sqr_c
k2 = math.cos(angle)
k1 = (1.0-k2)/len2
k3 = math.sin(angle)/math.sqrt(len2)
k1ab = k1*axis.x*axis.y
k1ac = k1*axis.x*axis.z
k1bc = k1*axis.y*axis.z
k3a = k3*axis.x
k3b = k3*axis.y
k3c = k3*axis.z
return mat4( k1*sqr_a+k2, k1ab-k3c, k1ac+k3b, 0.0,
k1ab+k3c, k1*sqr_b+k2, k1bc-k3a, 0.0,
k1ac-k3b, k1bc+k3a, k1*sqr_c+k2, 0.0,
0.0, 0.0, 0.0, 1.0)
示例5: frustum
def frustum(self, left, right, bottom, top, near, far):
"""equivalent to the OpenGL command glFrustum()"""
return mat4( (2.0*near)/(right-left), 0.0, float(right+left)/(right-left), 0.0,
0.0, (2.0*near)/(top-bottom), float(top+bottom)/(top-bottom), 0.0,
0.0, 0.0, -float(far+near)/(far-near), -(2.0*far*near)/(far-near),
0.0, 0.0, -1.0, 0.0)
示例6: ortho
def ortho(self):
"""Return a matrix with orthogonal base vectors.
Makes the x-, y- and z-axis orthogonal.
The fourth column and row remain untouched.
"""
m11,m12,m13,m14,m21,m22,m23,m24,m31,m32,m33,m34,m41,m42,m43,m44 = self.mlist
x = _vec3(m11, m21, m31)
y = _vec3(m12, m22, m32)
z = _vec3(m13, m23, m33)
xl = x.length()
xl*=xl
y = y - ((x*y)/xl)*x
z = z - ((x*z)/xl)*x
yl = y.length()
yl*=yl
z = z - ((y*z)/yl)*y
return mat4( x.x, y.x, z.x, m14,
x.y, y.y, z.y, m24,
x.z, y.z, z.z, m34,
m41, m42, m43, m44)
示例7: translation
def translation(t):
"""Return translation matrix."""
tx,ty,tz = t
return mat4(1.0, 0.0, 0.0, tx,
0.0, 1.0, 0.0, ty,
0.0, 0.0, 1.0, tz,
0.0, 0.0, 0.0, 1.0)
示例8: frustum
def frustum(left, right, bottom, top, near, far):
"""Set a perspective transformation.
This method is equivalent to the OpenGL command glFrustum().
"""
return mat4( (2.0*near)/(right-left), 0.0, float(right+left)/(right-left), 0.0,
0.0, (2.0*near)/(top-bottom), float(top+bottom)/(top-bottom), 0.0,
0.0, 0.0, -float(far+near)/(far-near), -(2.0*far*near)/(far-near),
0.0, 0.0, -1.0, 0.0)
示例9: __pos__
def __pos__(self):
"""
>>> M=mat4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
>>> print +M
[ 1.0000, 2.0000, 3.0000, 4.0000]
[ 5.0000, 6.0000, 7.0000, 8.0000]
[ 9.0000, 10.0000, 11.0000, 12.0000]
[ 13.0000, 14.0000, 15.0000, 16.0000]
"""
return mat4(map(lambda x: +x, self.mlist))
示例10: __neg__
def __neg__(self):
"""Negation.
>>> M=mat4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
>>> print -M
[ -1.0000, -2.0000, -3.0000, -4.0000]
[ -5.0000, -6.0000, -7.0000, -8.0000]
[ -9.0000, -10.0000, -11.0000, -12.0000]
[ -13.0000, -14.0000, -15.0000, -16.0000]
"""
return mat4(map(lambda x: -x, self.mlist))
示例11: __mod__
def __mod__(self, other):
"""Modulo.
>>> M=mat4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
>>> print M%5.0
[ 1.0000, 2.0000, 3.0000, 4.0000]
[ 0.0000, 1.0000, 2.0000, 3.0000]
[ 4.0000, 0.0000, 1.0000, 2.0000]
[ 3.0000, 4.0000, 0.0000, 1.0000]
"""
T = type(other)
# mat4%scalar
if T==types.FloatType or T==types.IntType or T==types.LongType:
return mat4(map(lambda x,other=other: x%other, self.mlist))
# mat4%mat4
if isinstance(other, mat4):
return mat4(map(lambda a,b: a%b, self.mlist, other.mlist))
# unsupported
else:
raise TypeError("unsupported operand type for %")
示例12: __mod__
def __mod__(self, other):
"""Modulo.
>>> M=mat4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
>>> print M%5.0
[ 1.0000, 2.0000, 3.0000, 4.0000]
[ 0.0000, 1.0000, 2.0000, 3.0000]
[ 4.0000, 0.0000, 1.0000, 2.0000]
[ 3.0000, 4.0000, 0.0000, 1.0000]
"""
T = type(other)
# mat4%scalar
if T==float or T==int or T==int:
return mat4(list(map(lambda x,other=other: x%other, self.mlist)))
# mat4%mat4
if isinstance(other, mat4):
return mat4([a_b1[0]%a_b1[1] for a_b1 in list(zip(self.mlist, other.mlist))])
# unsupported
else:
raise TypeError("unsupported operand type for %")
示例13: identity
def identity():
"""Return identity matrix.
>>> print mat4().identity()
[ 1.0000, 0.0000, 0.0000, 0.0000]
[ 0.0000, 1.0000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 1.0000, 0.0000]
[ 0.0000, 0.0000, 0.0000, 1.0000]
"""
return mat4(1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0)
示例14: __sub__
def __sub__(self, other):
"""Matrix subtraction.
>>> M=mat4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
>>> print M-M
[ 0.0000, 0.0000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 0.0000, 0.0000]
"""
if isinstance(other, mat4):
return mat4(map(lambda x,y: x-y, self.mlist, other.mlist))
else:
raise TypeError("unsupported operand type for -")
示例15: __add__
def __add__(self, other):
"""Matrix addition.
>>> M=mat4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
>>> print M+M
[ 2.0000, 4.0000, 6.0000, 8.0000]
[ 10.0000, 12.0000, 14.0000, 16.0000]
[ 18.0000, 20.0000, 22.0000, 24.0000]
[ 26.0000, 28.0000, 30.0000, 32.0000]
"""
if isinstance(other, mat4):
return mat4(map(lambda x,y: x+y, self.mlist, other.mlist))
else:
raise TypeError("unsupported operand type for +")