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


Python Vector.cross方法代碼示例

本文整理匯總了Python中Vector.cross方法的典型用法代碼示例。如果您正苦於以下問題:Python Vector.cross方法的具體用法?Python Vector.cross怎麽用?Python Vector.cross使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Vector的用法示例。


在下文中一共展示了Vector.cross方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testVectorOperators

# 需要導入模塊: import Vector [as 別名]
# 或者: from Vector import cross [as 別名]
def testVectorOperators() :
   V = Vector([0.0, 1.0, 2.0])
   W = Vector([3.0, 4.0, 5.0])
   print V.dot(W)
   print V.norm()
   U = V.cross(W)
   U.show()
開發者ID:worldnamer,項目名稱:GeometryEngine,代碼行數:9,代碼來源:testVector.py

示例2: Camera

# 需要導入模塊: import Vector [as 別名]
# 或者: from Vector import cross [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.cross方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。