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


Python Quaternion.reset方法代码示例

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


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

示例1: ArcBall

# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import reset [as 别名]
class ArcBall(object):
    """
    Class contains ArcBall logic see test_arcball.py for usage
    """
    def __init__(self, cx, cy, radius):
        """
        Initialize instance of ArcBall with no constraint on axis of rotation
        """
        self.center_x = cx
        self.center_y = cy
        self.radius = radius
        self.v_down = PVector()
        self.v_drag = PVector()
        self.q_now = Quaternion()
        self.q_down = Quaternion()
        self.q_drag = Quaternion() 
        self.axis_set = [PVector(1.0, 0.0, 0.0), PVector(0.0, 1.0, 0.0), PVector(0.0, 0.0, 1.0)]
        self.axis = -1  
        
    def selectAxis(self, axis):
        """
        call this from sketch (typically in keyPressed() to constrain rotation to one axis)
        valid input 0, 1, 2 or -1
        """
        if ((axis == -1) or (axis == 0) or (axis == 1) or (axis == 2)):
          self.axis = axis
        
    def __mouse2sphere(self, x, y):
        """
        private map mouse to ArcBall (sphere)
        """
        v = PVector()
        v.x = (x - self.center_x) / self.radius
        v.y = (y - self.center_y) / self.radius
        mag = v.x * v.x + v.y * v.y
        if (mag > 1.0) :
            v.normalize()
        else:
            v.z = sqrt(1.0 - mag)
        if (self.axis != -1):
            v = self.__constrain(v, self.axis_set[self.axis])
        return  v  
    
    def mousePressed(self, x, y):
        """
        pass in mouse.x and mouse.y parameters from sketch
        """
        self.v_down = self.__mouse2sphere(x, y)
        self.q_down.copy(self.q_now)
        self.q_drag.reset()

    def mouseDragged(self, x, y):
        """
        pass in mouse.x and mouse.y parameters from sketch
        """
        self.v_drag = self.__mouse2sphere(x, y)
        self.q_drag.set(PVector.dot(self.v_down, self.v_drag), self.v_down.cross(self.v_drag))
        
    def __constrain(self, vector, axis):
        """
        private constrain (used to constrain axis)
        """
        vector.sub(axis.mult(axis, PVector.dot(axis, vector)))
        vector.normalize()
        return vector
        
    def update(self):
        """
        Call this function in the sketch draw loop to get rotation matrix as an array 
        """
        self.q_now = Quaternion.mult(self.q_drag, self.q_down)
        return self.__quat2matrix(self.q_now)

    def __quat2matrix(self,  q) :
        """
        private return matrix as array
        """
        rot = q.getValue()
        return rot
开发者ID:monkstone,项目名称:processing.py-examples,代码行数:81,代码来源:arcball.py

示例2: ArcBall

# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import reset [as 别名]
class ArcBall(object):
    """
    Class for provides intuitive 3d manipulation of sketch object in pyprocessing.
    ArcBall class uses Quaternions class for efficient calculation of rotation. Hold down x, y or z
    keys to constrain rotation to that plane; otherwise drag mouse for smooth rotation
    Written by Martin Prout - see https://github.com/monkstone/pyprocessing-experiments
    """
    def __init__(self, cx, cy, radius):
        """
        Initialize instance of ArcBall with no constraint on axis of rotation
        """
        self.center_x = cx
        self.center_y = cy
        self.radius = radius
        self.v_down = PVector()
        self.v_drag = PVector()
        self.q_now = Quaternion()
        self.q_down = Quaternion()
        self.q_drag = Quaternion() 
        self.axis_set = [PVector(1.0, 0.0, 0.0), PVector(0.0, 1.0, 0.0), PVector(0.0, 0.0, 1.0)]
        self.axis = -1  
        
    def selectAxis(self,  axis):
        """
        call this from sketch (typically in keyPressed() to constrain rotation to one axis)
        valid input 0, 1, 2 or -1
        """
        self.axis = axis
        
    def __mouse2sphere(self, x, y):
        """
        private map mouse to ArcBall (sphere)
        """
        v = PVector()
        v.x = (x - self.center_x) / self.radius
        v.y = (y - self.center_y) / self.radius
        mag = v.x * v.x + v.y * v.y
        if (mag > 1.0) :
            v.normalize()
        else:
            v.z = sqrt(1.0 - mag)
        if (self.axis != -1):
            v = self.__constrain(v, self.axis_set[self.axis])
        return  v  
    
    def mousePressed(self, x, y):
        """
        pass in mouse.x and mouse.y parameters from sketch
        """
        self.v_down = self.__mouse2sphere(x, y)
        self.q_down.copy(self.q_now)
        self.q_drag.reset()

    def mouseDragged(self, x, y):
        """
        pass in mouse.x and mouse.y parameters from sketch
        """
        self.v_drag = self.__mouse2sphere(x, y)
        self.q_drag.set(PVector.dot(self.v_down, self.v_drag), self.v_down.cross(self.v_drag))
        
    def __constrain(self, vector, axis):
        """
        private constrain (used to constrain axis)
        """
        res = PVector.sub(vector, PVector.mult(axis, PVector.dot(axis, vector)))
        res.normalize()
        return res
        
    def update(self):
        """
        Call this function in the sketch draw loop to get rotation matrix as an array 
        """
        self.q_now = Quaternion.mult(self.q_drag, self.q_down)
        return self.__quat2matrix(self.q_now)

    def __quat2matrix(self,  q) :
        """
        private return matrix as array
        """
        rot = q.getValue()
        return rot
开发者ID:mens-amplio,项目名称:pyprocessing-test,代码行数:83,代码来源:arcball.py


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