Ejemplo n.º 1
0
    def setViewDirection(self, direction):
        if direction.normSquared() < 1E-10:
            return

        xAxis = Vec(direction.cross(self.upVec))
        if xAxis.normSquared() < 1E-10:
            xAxis = Vec([1.0, 0.0, 0.0])
        #piet = xAxis.cross(direction)
        #print "xAxis: ", xAxis, " direction: ", direction, " cross: " , piet
        q = Quaternion()
        q.setFromRotatedBasis(xAxis, xAxis.cross(direction), -direction)
        self.setAltOrientation(q)
Ejemplo n.º 2
0
    def setViewDirection(self, direction):
        if direction.normSquared() < 1E-10:
            return

        xAxis = Vec(direction.cross(self.upVec))
        if xAxis.normSquared() < 1E-10:
            xAxis = Vec([1.0, 0.0, 0.0])
        #piet = xAxis.cross(direction)
        #print "xAxis: ", xAxis, " direction: ", direction, " cross: " , piet
        q = Quaternion()
        q.setFromRotatedBasis(xAxis, xAxis.cross(direction), -direction)
        self.setAltOrientation(q)
Ejemplo n.º 3
0
    def fromDirection(self, vFrom, vTo):
        vFrom = Vec(vFrom)
        vTo = Vec(vTo)
        epsilon = 1E-10
        fromLengthSq = vFrom.normSquared()
        toLengthSq = vTo.normSquared()

        if (fromLengthSq < epsilon) or (toLengthSq < epsilon):
            self.quaternion[0] = self.quaternion[1] = self.quaternion[2] = 0.0
            self.quaternion[3] = 1.0
        else:
            axis = vTo.cross(vFrom)
            axisLengthSq = axis.normSquared()

            if axisLengthSq < epsilon:
                if (math.fabs(vFrom[1]) >= math.fabs(vFrom[0])) and (math.fabs(
                        vFrom[2]) >= math.fabs(vFrom[0])):
                    axis[0] = 0.0
                    axis[1] = -vFrom[2]
                    axis[2] = vFrom[0]
                elif (math.fabs(vFrom[0]) >= math.fabs(vFrom[1])) and (
                        math.fabs(vFrom[2]) >= math.fabs(vFrom[1])):
                    axis[0] = -vFrom[2]
                    axis[1] = 0.0
                    axis[2] = vFrom[0]
                else:
                    axis[0] = -vFrom[1]
                    axis[1] = vFrom[0]
                    axis[2] = 0.0

            squareroot = math.sqrt(axisLengthSq / (fromLengthSq * toLengthSq))

            if squareroot > 1.0:
                squareroot = 1.0
            elif squareroot < -1.0:
                squareroot = -1.0

            angle = math.asin(squareroot)

            if vFrom.dot(vTo) < 0.0:
                angle = math.pi - angle

            self.fromAxisAngle(axis, angle)
Ejemplo n.º 4
0
    def fromDirection(self, vFrom, vTo):
        vFrom = Vec(vFrom)
        vTo = Vec(vTo)
        epsilon = 1E-10
        fromLengthSq = vFrom.normSquared()
        toLengthSq = vTo.normSquared()
        
        if (fromLengthSq < epsilon) or (toLengthSq < epsilon):
            self.quaternion[0] = self.quaternion[1] = self.quaternion[2] = 0.0
            self.quaternion[3] = 1.0
        else:
            axis = vTo.cross(vFrom)
            axisLengthSq = axis.normSquared()

            if axisLengthSq < epsilon:
                if (math.fabs(vFrom[1]) >= math.fabs(vFrom[0])) and (math.fabs(vFrom[2]) >= math.fabs(vFrom[0])):
                    axis[0] = 0.0
                    axis[1] = -vFrom[2]
                    axis[2] = vFrom[0]
                elif (math.fabs(vFrom[0]) >= math.fabs(vFrom[1])) and (math.fabs(vFrom[2]) >= math.fabs(vFrom[1])):
                    axis[0] = -vFrom[2]
                    axis[1] = 0.0
                    axis[2] = vFrom[0]
                else:
                    axis[0] = -vFrom[1]
                    axis[1] = vFrom[0]
                    axis[2] = 0.0
            
            squareroot = math.sqrt(axisLengthSq / (fromLengthSq * toLengthSq))

            if squareroot > 1.0:
                squareroot = 1.0
            elif squareroot < -1.0:
                squareroot = -1.0
            
            angle = math.asin(squareroot)

            if vFrom.dot(vTo) < 0.0:
                angle = math.pi - angle

            self.fromAxisAngle(axis, angle)