当前位置: 首页>>代码示例>>Python>>正文


Python Vector.normalize方法代码示例

本文整理汇总了Python中Vector.normalize方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.normalize方法的具体用法?Python Vector.normalize怎么用?Python Vector.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector的用法示例。


在下文中一共展示了Vector.normalize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Specular

# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import normalize [as 别名]
def Specular(aNormal,aTrianglePoint):
  eyeVector = [cameraX - aTrianglePoint[X],
               cameraY - aTrianglePoint[Y],
               cameraZ - aTrianglePoint[Z],
               1.0     - aTrianglePoint[3]]

  eyeVector = Vector.normalize(eyeVector)
 
  lightVec = [lightPoint[X] - aTrianglePoint[X],
              lightPoint[Y] - aTrianglePoint[Y],
              lightPoint[Z] - aTrianglePoint[Z],
              lightPoint[W] - aTrianglePoint[W]]
  
  lightVec = Vector.normalize(lightVec)

  #caculate the half vector
  H = [lightVec[X] + eyeVector[X],
       lightVec[Y] + eyeVector[Y],
       lightVec[Z] + eyeVector[Z],
       lightVec[W] + eyeVector[W]]

  #now normalize and dot the half with the normal vec,
  #use the shininess constant defined in IncludesAndConstants.py
  H = Vector.normalize(H)
  d = Vector.dotProduct(aNormal,H)
  return math.pow(max(d,0),shininess)
开发者ID:LloydGhettoWolf,项目名称:Python-Renderer,代码行数:28,代码来源:Lighting.py

示例2: Diffuse

# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import normalize [as 别名]
def Diffuse(aNormal,aTrianglePoint):
  lightVec = [ lightPoint[X] - aTrianglePoint[X],
               lightPoint[Y] - aTrianglePoint[Y],
               lightPoint[Z] - aTrianglePoint[Z],
               lightPoint[W] - aTrianglePoint[W]]

  lightVec = Vector.normalize(lightVec)
  #print(lightVec[X],lightVec[Y],lightVec[Z])
  #print(Vector.length(lightVec))
  aNormal = Vector.normalize(aNormal)

  return max(Vector.dotProduct(lightVec,aNormal),0)  
开发者ID:LloydGhettoWolf,项目名称:Python-Renderer,代码行数:14,代码来源:Lighting.py

示例3: TestForCull

# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import normalize [as 别名]
def TestForCull(aTriangle):
  camVector = [IncludesAndConstants.lookPointX - IncludesAndConstants.cameraX,
               IncludesAndConstants.lookPointY - IncludesAndConstants.cameraY,
               IncludesAndConstants.lookPointZ - IncludesAndConstants.cameraZ,0]

  camVector = Vector.normalize(camVector)

  normal = [aTriangle.normal[X],aTriangle.normal[Y],aTriangle.normal[Z],0]
  normal = Vector.normalize(normal)

  if Vector.dotProduct(camVector,normal) <= 0.0:
    return True
  else:
    return False
开发者ID:LloydGhettoWolf,项目名称:Python-Renderer,代码行数:16,代码来源:Triangle.py

示例4:

# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import normalize [as 别名]
identityMatrix = Matrix.MatrixMatrixMult(xRotateMatrix,identityMatrix)

identityMatrix = Matrix.MatrixMatrixMult(yRotateMatrix,identityMatrix)

identityMatrix = Matrix.MatrixMatrixMult(zRotateMatrix,identityMatrix)

worldMatrix = Matrix.MatrixMatrixMult(worldMatrix,identityMatrix)


#VIEW MATRIX
#creating a view matrix involves look,up and right vectors, and depending on the orientation and components of the look
#vector 

lookVector = [lookPointX - cameraX,lookPointY - cameraY,lookPointZ - cameraZ,0.0]
lookVector = Vector.normalize(lookVector)

rightVector = Vector.crossProduct([0,1,0,0],lookVector)
rightVector = Vector.normalize(rightVector)

upVector = Vector.crossProduct(lookVector,rightVector)
upVector = Vector.normalize(upVector)


CameraPos = [cameraX,cameraY,cameraZ,1]


viewMatrix = [[rightVector[X],upVector[X],lookVector[X],0],
              [rightVector[Y],upVector[Y],lookVector[Y],0],
              [rightVector[Z],upVector[Z],lookVector[Z],0],
              [-(Vector.dotProduct(CameraPos,rightVector)),-(Vector.dotProduct(CameraPos,upVector)),-(Vector.dotProduct(CameraPos,lookVector)),1]]
开发者ID:LloydGhettoWolf,项目名称:Python-Renderer,代码行数:32,代码来源:AppInfo.py

示例5: Camera

# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import normalize [as 别名]
class Camera(GameObject):
    def __init__(self):
        self.up = Vector([0,1,0])
        self.position = Vector([0,0,-5])
        self.lookat = Vector([0,0,0])
        self.keysDown = {}
        self.keysDownSpecial = {}
        self.debug = None

        
    def strafe(self,speed):
        if self.debug:
            tmpvect = (self.lookat - self.position).normalize()
            strafe = tmpvect.cross( self.up );
            strafe.y = 0
            strafe.normalize();

            self.position.x +=  (strafe.x * speed)
            self.position.z +=  (strafe.z * speed)

            self.lookat.x += (strafe.x*speed)
            self.lookat.z += (strafe.z*speed)
        
    def move(self, speed):
        if self.debug:
            move = (self.lookat - self.position)
            #move.y = 0
            move.normalize()

            self.position.x +=  (move.x * speed)
            self.position.z +=  (move.z * speed)
            self.position.y +=  (move.y * speed)        

            self.lookat.x += (move.x*speed)
            self.lookat.z += (move.z*speed)
            self.lookat.y += (move.y*speed)
        
    def yaw(self, angle):
        if self.debug:
            view = self.lookat - self.position
            (sinAngle, cosAngle) = (math.sin(angle), math.cos(angle))
            newView = Vector([ view.x * cosAngle + view.z * sinAngle, 
                               view.y,
                               view.x * -sinAngle + view.z * cosAngle])
        
            self.lookat.x = self.position.x + newView.x
            self.lookat.y = self.position.y + newView.y
            self.lookat.z = self.position.z + newView.z


    def pitch(self, angle):
        if self.debug:
            view = self.lookat - self.position
            view.normalize()
            
            #if( (view.x > 0.99 and angle < 0) or (view.y < -0.99 and angle > 0 ) ):
            #    return 0
                  
            crossViewUp = self.up.cross(view).normalize()
            self.up.normalize()
            (sinAngle, cosAngle) = (math.sin(angle), math.cos(angle))
            
            newView = Vector( [ (view.x * ( cosAngle + ( 1 - cosAngle) * (crossViewUp.x**2) ) ) + \
                                (view.y * (( 1 - cosAngle) * crossViewUp.x * crossViewUp.y - sinAngle*crossViewUp.z)) + \
                                (view.z * (( 1 - cosAngle) * crossViewUp.z * crossViewUp.x + sinAngle*crossViewUp.y) ),
                                
                                (view.x * (( 1 - cosAngle) * crossViewUp.x * crossViewUp.y + sinAngle*crossViewUp.z)) + \
                                (view.y * ( cosAngle + ( 1 - cosAngle) * (crossViewUp.y**2) ) ) + \
                                (view.z * (( 1 - cosAngle) * crossViewUp.z * crossViewUp.y - sinAngle*crossViewUp.x) ),
                                
                                (view.x * (( 1 - cosAngle) * crossViewUp.x * crossViewUp.z - sinAngle*crossViewUp.y) )+ \
                                (view.y * (( 1 - cosAngle) * crossViewUp.z * crossViewUp.y + sinAngle*crossViewUp.x)) + \
                                (view.z * ( cosAngle + ( 1 - cosAngle) * (crossViewUp.z**2) ) ) ])
                                
            self.lookat = (self.position + newView )
    
    def apply(self):
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        gluLookAt( self.position.x, self.position.y, self.position.z,
                   self.lookat.x,   self.lookat.y,   self.lookat.z, 
                   self.up.x,       self.up.y,       self.up.z        )
开发者ID:baldurthoremilsson,项目名称:cubix,代码行数:84,代码来源:Cameras.py


注:本文中的Vector.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。