def move(self, delta_x, delta_y, buttons, modifiers): # user is dragging to = (self.at - self.eye) distance = to.length() if int(buttons) & Qt.LeftButton and not int(modifiers) & Qt.ShiftModifier: right = QVector3D.crossProduct(to, self.up) right = right.normalized() up = QVector3D.crossProduct(right, to).normalized() translation = right*(delta_x*distance)\ + up*(delta_y*distance) self.eye -= translation*5 # correct eye position to maintain distance to = (self.at - self.eye) self.eye = self.at - to.normalized()*distance self.up = QVector3D.crossProduct(right, to).normalized() elif int(buttons) & Qt.MiddleButton or (int(buttons) & Qt.LeftButton and int(modifiers) & Qt.ShiftModifier): right = QVector3D.crossProduct(to, self.up).normalized() up = QVector3D.crossProduct(right, to).normalized() translation = right*(delta_x*distance)\ + up*(delta_y*distance) self.at -= translation self.eye -= translation elif int(buttons) & Qt.RightButton : translation = to*delta_y self.eye -= translation
def intersect (self, orig_v, dir_v, pl): ''' method performing ray-triangle intersection (Moller-Trumbore algorithm) @param orig QVector3D @param dir QVector3D @return isect_t float or None ''' e1 = pl[1] - pl[0] e2 = pl[2] - pl[0] p = QVector3D.crossProduct (dir_v, e2) p_dot_e1 = QVector3D.dotProduct (p, e1) if p_dot_e1 == 0: return None inv_p_dot_e1 = 1.0 / p_dot_e1 t = orig_v - pl[0] isect_u = inv_p_dot_e1 * QVector3D.dotProduct (p, t) if isect_u<0 or isect_u>1: return None q = QVector3D.crossProduct (t, e1) isect_v = inv_p_dot_e1 * QVector3D.dotProduct (q, dir_v) if isect_v<0 or isect_u + isect_v>1: return None isect_t = inv_p_dot_e1 * QVector3D.dotProduct (e2, q) return isect_t
def intersect(self, orig_v, dir_v, pl): ''' method performing ray-triangle intersection (Moller-Trumbore algorithm) @param orig QVector3D @param dir QVector3D @return isect_t float or None ''' e1 = pl[1] - pl[0] e2 = pl[2] - pl[0] p = QVector3D.crossProduct(dir_v, e2) p_dot_e1 = QVector3D.dotProduct(p, e1) if p_dot_e1 == 0: return None inv_p_dot_e1 = 1.0 / p_dot_e1 t = orig_v - pl[0] isect_u = inv_p_dot_e1 * QVector3D.dotProduct(p, t) if isect_u < 0 or isect_u > 1: return None q = QVector3D.crossProduct(t, e1) isect_v = inv_p_dot_e1 * QVector3D.dotProduct(q, dir_v) if isect_v < 0 or isect_u + isect_v > 1: return None isect_t = inv_p_dot_e1 * QVector3D.dotProduct(e2, q) return isect_t