def _calculateBasis(self): e1 = e2 = e3 = None if len(self._xi) > 2: pta = self._xi[0] ptb = self._xi[1] ptc = self._xi[2] e1 = sub(ptb, pta) e2 = sub(ptc, pta) # e2 = cross(e1, self._nor) e3 = cross(e1, e2) e2 = cross(e1, e3) e1 = normalize(e1) e2 = normalize(e2) e3 = normalize(e3) return e1, e2, e3
def mouseMoveEvent(self, event): if self._start_position is not None: # v_rot = v*cos(theta)+(wxv)*sin(theta)+w*(w.v)*(1-cos(theta)) # v is our vector # w is the unit vector to rotate around # theta is the angle to rotate if self._start_position[0] == event.x() and self._start_position[1] == event.y(): return centre_point = calculateCentroid(self._plane.getRotationPoint(), self._plane.getNormal(), self._get_dimension_method()) centre_widget = self._zinc_view.project(centre_point[0], centre_point[1], centre_point[2]) a = sub(centre_widget, [event.x(), -event.y(), centre_widget[2]]) b = sub(centre_widget, [self._start_position[0], -self._start_position[1], centre_widget[2]]) c = dot(a, b) d = magnitude(a) * magnitude(b) theta = acos(min(c / d, 1.0)) if theta != 0.0: g = cross(a, b) lookat, eye, up, angle = self._zinc_view.getViewParameters() w = normalize(sub(lookat, eye)) if copysign(1, dot(g, [0, 0, 1])) < 0: theta = -theta v = up p1 = mult(v, cos(theta)) p2 = mult(cross(w, v), sin(theta)) p3a = mult(w, dot(w, v)) p3 = mult(p3a, 1 - cos(theta)) v_rot = add(p1, add(p2, p3)) self._zinc_view.setViewParameters(lookat, eye, v_rot, angle) self._start_position = [event.x(), event.y()] else: super(Abstract2DHandler, self).mouseMoveEvent(event)
def mouseMoveEvent(self, event): if self._start_position is not None: # v_rot = v*cos(theta)+(wxv)*sin(theta)+w*(w.v)*(1-cos(theta)) # v is our vector # w is the unit vector to rotate around # theta is the angle to rotate if self._start_position[0] == event.x( ) and self._start_position[1] == event.y(): return centre_point = calculateCentroid(self._plane.getRotationPoint(), self._plane.getNormal(), self._get_dimension_method()) centre_widget = self._zinc_view.project(centre_point[0], centre_point[1], centre_point[2]) a = sub(centre_widget, [event.x(), -event.y(), centre_widget[2]]) b = sub(centre_widget, [ self._start_position[0], -self._start_position[1], centre_widget[2] ]) c = dot(a, b) d = magnitude(a) * magnitude(b) theta = acos(min(c / d, 1.0)) if theta != 0.0: g = cross(a, b) lookat, eye, up, angle = self._zinc_view.getViewParameters() w = normalize(sub(lookat, eye)) if copysign(1, dot(g, [0, 0, 1])) < 0: theta = -theta v = up p1 = mult(v, cos(theta)) p2 = mult(cross(w, v), sin(theta)) p3a = mult(w, dot(w, v)) p3 = mult(p3a, 1 - cos(theta)) v_rot = add(p1, add(p2, p3)) self._zinc_view.setViewParameters(lookat, eye, v_rot, angle) self._start_position = [event.x(), event.y()] else: super(Abstract2DHandler, self).mouseMoveEvent(event)
def mouseMoveEvent(self, event): scene = self._glyph.getScene() scene.beginChange() # super(Orientation, self).mouseMoveEvent(event) if self._glyph.getMaterial().getName() == self._selected_material.getName(): x = event.x() y = event.y() far_plane_point = self._zinc_view.unproject(x, -y, -1.0) near_plane_point = self._zinc_view.unproject(x, -y, 1.0) point_on_plane = calculateLinePlaneIntersection(near_plane_point, far_plane_point, self._plane.getRotationPoint(), self._plane.getNormal()) if point_on_plane is not None: dimensions = self._get_dimension_method() centroid = calculateCentroid(self._plane.getRotationPoint(), self._plane.getNormal(), dimensions) point_on_plane = boundCoordinatesToCuboid(point_on_plane, centroid, dimensions) setGlyphPosition(self._glyph, point_on_plane) else: width = self._zinc_view.width() height = self._zinc_view.height() radius = min([width, height]) / 2.0 delta_x = float(event.x() - self._previous_mouse_position[0]) delta_y = float(event.y() - self._previous_mouse_position[1]) tangent_dist = sqrt((delta_x * delta_x + delta_y * delta_y)) if tangent_dist > 0.0: dx = -delta_y / tangent_dist; dy = delta_x / tangent_dist; d = dx * (event.x() - 0.5 * (width - 1)) + dy * ((event.y() - 0.5 * (height - 1))) if d > radius: d = radius if d < -radius: d = -radius phi = acos(d / radius) - 0.5 * pi angle = 1.0 * tangent_dist / radius eye, lookat, up, _ = self._zinc_view.getViewParameters() b = up[:] b = normalize(b) a = sub(lookat, eye) a = normalize(a) c = cross(b, a) c = normalize(c) e = [None, None, None] e[0] = dx * c[0] + dy * b[0] e[1] = dx * c[1] + dy * b[1] e[2] = dx * c[2] + dy * b[2] axis = [None, None, None] axis[0] = sin(phi) * a[0] + cos(phi) * e[0] axis[1] = sin(phi) * a[1] + cos(phi) * e[1] axis[2] = sin(phi) * a[2] + cos(phi) * e[2] plane_normal = self._plane.getNormal() point_on_plane = self._plane.getRotationPoint() plane_normal_prime_1 = mult(plane_normal, cos(angle)) plane_normal_prime_2 = mult(plane_normal, dot(plane_normal, axis) * (1 - cos(angle))) plane_normal_prime_3 = mult(cross(axis, plane_normal), sin(angle)) plane_normal_prime = add(add(plane_normal_prime_1, plane_normal_prime_2), plane_normal_prime_3) self._plane.setPlaneEquation(plane_normal_prime, point_on_plane) self._previous_mouse_position = [event.x(), event.y()] scene.endChange()
def mouseMoveEvent(self, event): scene = self._glyph.getScene() scene.beginChange() # super(Orientation, self).mouseMoveEvent(event) if self._glyph.getMaterial().getName( ) == self._selected_material.getName(): x = event.x() y = event.y() far_plane_point = self._zinc_view.unproject(x, -y, -1.0) near_plane_point = self._zinc_view.unproject(x, -y, 1.0) point_on_plane = calculateLinePlaneIntersection( near_plane_point, far_plane_point, self._plane.getRotationPoint(), self._plane.getNormal()) if point_on_plane is not None: dimensions = self._get_dimension_method() centroid = calculateCentroid(self._plane.getRotationPoint(), self._plane.getNormal(), dimensions) point_on_plane = boundCoordinatesToCuboid( point_on_plane, centroid, dimensions) setGlyphPosition(self._glyph, point_on_plane) else: width = self._zinc_view.width() height = self._zinc_view.height() radius = min([width, height]) / 2.0 delta_x = float(event.x() - self._previous_mouse_position[0]) delta_y = float(event.y() - self._previous_mouse_position[1]) tangent_dist = sqrt((delta_x * delta_x + delta_y * delta_y)) if tangent_dist > 0.0: dx = -delta_y / tangent_dist dy = delta_x / tangent_dist d = dx * (event.x() - 0.5 * (width - 1)) + dy * (event.y() - 0.5 * (height - 1)) if d > radius: d = radius if d < -radius: d = -radius phi = acos(d / radius) - 0.5 * pi angle = 1.0 * tangent_dist / radius eye, lookat, up, _ = self._zinc_view.getViewParameters() b = up[:] b = normalize(b) a = sub(lookat, eye) a = normalize(a) c = cross(b, a) c = normalize(c) e = [None, None, None] e[0] = dx * c[0] + dy * b[0] e[1] = dx * c[1] + dy * b[1] e[2] = dx * c[2] + dy * b[2] axis = [None, None, None] axis[0] = sin(phi) * a[0] + cos(phi) * e[0] axis[1] = sin(phi) * a[1] + cos(phi) * e[1] axis[2] = sin(phi) * a[2] + cos(phi) * e[2] plane_normal = self._plane.getNormal() point_on_plane = self._plane.getRotationPoint() plane_normal_prime_1 = mult(plane_normal, cos(angle)) plane_normal_prime_2 = mult( plane_normal, dot(plane_normal, axis) * (1 - cos(angle))) plane_normal_prime_3 = mult(cross(axis, plane_normal), sin(angle)) plane_normal_prime = add( add(plane_normal_prime_1, plane_normal_prime_2), plane_normal_prime_3) self._plane.setPlaneEquation(plane_normal_prime, point_on_plane) self._previous_mouse_position = [event.x(), event.y()] scene.endChange()