コード例 #1
0
ファイル: manipulator.py プロジェクト: etradewind/Tundra2
    def _rotateEachEntWithQuaternion(self, q, ents, angle):
        """ Rotate each object along selected axis """
        for ent in ents:
            ort = ent.placeable.Orientation
                        
            v1 = ort.rotatedVector(QVector3D(1,0,0))
            v2 = ort.rotatedVector(QVector3D(0,1,0))
            v3 = ort.rotatedVector(QVector3D(0,0,1))

            # rotated unit vectors are equals of objects unit vectors in objects perspective
            # this gives equation M * x = x' (x=(i,j,k) & x'=(i',j',k'))
            # ( M = conversion matrix, x = world unit vector, x' = object unit vector)
            # multiply each sides of equation with inverted matrix of M^-1 gives us:
            # I * x = M^-1 *x' => x = M^-1 * x' 
            # => we can now express world unit vectors i,j,k with i',j',k' 
            # with help of inverted matrix, and use objects quaternion to rotate
            # along world unit vectors i, j, k
            
            m = ((v1.x(),v1.y(),v1.z()),(v2.x(),v2.y(),v2.z()),(v3.x(),v3.y(),v3.z()))
            inv = mu.invert_3x3_matrix(m)

            if self.grabbed_axis == self.AXIS_RED: #rotate around x-axis
                axis = QVector3D(inv[0][0],inv[0][1],inv[0][2]) 
            elif self.grabbed_axis == self.AXIS_GREEN: #rotate around y-axis
                axis = QVector3D(inv[1][0],inv[1][1],inv[1][2]) 
            elif self.grabbed_axis == self.AXIS_BLUE: #rotate around z-axis
                axis = QVector3D(inv[2][0],inv[2][1],inv[2][2]) 

            q = QQuaternion.fromAxisAndAngle(axis, angle)
            q.normalize()

            ent.placeable.Orientation = ort*q
コード例 #2
0
ファイル: dotscenemanager.py プロジェクト: A-K/naali
 def rotateOgreNode(self, on, axis, angle, axisName):
     ort = on.orientation        
     v1 = ort.rotatedVector(Vec(1,0,0))
     v2 = ort.rotatedVector(Vec(0,1,0))
     v3 = ort.rotatedVector(Vec(0,0,1))
     m = ((v1.x(),v1.y(),v1.z()),(v2.x(),v2.y(),v2.z()),(v3.x(),v3.y(),v3.z()))
     inv = mu.invert_3x3_matrix(m)
     switchAxis={'x':Vec(inv[0][0],inv[0][1],inv[0][2]), 'y':Vec(inv[1][0],inv[1][1],inv[1][2]), 'z':Vec(inv[2][0],inv[2][1],inv[2][2])}
     rotateAxis = switchAxis[axisName]
     # print "rotateAxis: %s"%rotateAxis
     # print "angle: %s"%angle
     q = Quat.fromAxisAndAngle(rotateAxis, angle)
     q.normalize()
     on.orientation = ort*q
     e = on.naali_ent
     o = on.orientation
     p=e.placeable   
     p.Orientation = on.orientation
コード例 #3
0
ファイル: dotscenemanager.py プロジェクト: etradewind/Tundra2
 def rotateOgreNode(self, on, axis, angle, axisName):
     ort = on.orientation
     v1 = ort.rotatedVector(Vec(1, 0, 0))
     v2 = ort.rotatedVector(Vec(0, 1, 0))
     v3 = ort.rotatedVector(Vec(0, 0, 1))
     m = ((v1.x(), v1.y(), v1.z()), (v2.x(), v2.y(), v2.z()),
          (v3.x(), v3.y(), v3.z()))
     inv = mu.invert_3x3_matrix(m)
     switchAxis = {
         'x': Vec(inv[0][0], inv[0][1], inv[0][2]),
         'y': Vec(inv[1][0], inv[1][1], inv[1][2]),
         'z': Vec(inv[2][0], inv[2][1], inv[2][2])
     }
     rotateAxis = switchAxis[axisName]
     # print "rotateAxis: %s"%rotateAxis
     # print "angle: %s"%angle
     q = Quat.fromAxisAndAngle(rotateAxis, angle)
     q.normalize()
     on.orientation = ort * q
     e = on.naali_ent
     o = on.orientation
     p = e.placeable
     p.Orientation = on.orientation