當前位置: 首頁>>代碼示例>>Python>>正文


Python Vector.normalized方法代碼示例

本文整理匯總了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)
開發者ID:drewying,項目名稱:PySoft3D,代碼行數:49,代碼來源:TriangleRasterizer.py


注:本文中的Vector.normalized方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。