本文整理汇总了Python中Vector.normalized方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.normalized方法的具体用法?Python Vector.normalized怎么用?Python Vector.normalized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.normalized方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotTriangle
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import normalized [as 别名]
def plotTriangle(self, triangle):
v0 = self.project(triangle.p1)
v1 = self.project(triangle.p2)
v2 = self.project(triangle.p3)
v0.z = 1.0/v0.z
v1.z = 1.0/v1.z
v2.z = 1.0/v2.z
x_min = int(min(v0.x, v1.x, v2.x))
x_max = int(max(v0.x, v1.x, v2.x) + 1)
y_min = int(min(v0.y, v1.y, v2.y))
y_max = int(max(v0.y, v1.y, v2.y) + 1)
x_min = max(0, x_min)
x_max = min(self.width, x_max)
y_min = max(0, y_min)
y_max = min(self.height, y_max)
area = self.edgeFunction(v0, v1, v2)
for x in range(x_min, x_max):
for y in range(y_min, y_max):
p = Vector(x,y,0)
w0 = self.edgeFunction(v1, v2, p)
w1 = self.edgeFunction(v2, v0, p)
w2 = self.edgeFunction(v0, v1, p)
if w0 >= 0 and w1 >= 0 and w2 >=0:
w0 /= area
w1 /= area
w2 /= area
z = (1.0/(v0.z * w0 + v1.z * w1 + v2.z * w2))
if (z < self.depth_buffer[y][x]):
self.depth_buffer[y][x] = z
v0cam = self.world_matrix.transformPoint(triangle.p1)
v1cam = self.world_matrix.transformPoint(triangle.p2)
v2cam = self.world_matrix.transformPoint(triangle.p3)
px = (v0cam.x/-v0cam.z) * w0 + (v1cam.x/-v1cam.z) * w1 + (v2cam.x/-v2cam.z) * w2
py = (v0cam.y/-v0cam.z) * w0 + (v1cam.y/-v1cam.z) * w1 + (v2cam.y/-v2cam.z) * w2
pt = Vector(px * z, py * z, z)
n = (v1cam - v0cam).cross(v2cam - v0cam).normalized()
view_direction = pt.normalized()
view_direction = Vector(-pt.x, -pt.y, -pt.z).normalized()
cosine = max(0, n.dot(view_direction))
self.plotPoint(x,y, cosine * 255)