Пример #1
0
    def mouseMoveEvent(self, event):
        if self._glyph.getMaterial().getName(
        ) == self._selected_material.getName():
            pos = getGlyphPosition(self._glyph)
            screen_pos = self._zinc_view.project(pos[0], pos[1], pos[2])
            global_cur_pos = self._zinc_view.unproject(event.x(), -event.y(),
                                                       screen_pos[2])
            global_old_pos = self._zinc_view.unproject(
                self._previous_mouse_position[0],
                -self._previous_mouse_position[1], screen_pos[2])
            global_pos_diff = sub(global_cur_pos, global_old_pos)

            n = self._plane.getNormal()
            proj_n = mult(n, dot(global_pos_diff, n))
            new_pos = add(pos, proj_n)
            scene = self._glyph.getScene()
            scene.beginChange()

            plane_centre = calculateCentroid(new_pos, self._plane.getNormal(),
                                             self._get_dimension_method())
            if plane_centre is not None:
                self._plane.setRotationPoint(plane_centre)
                setGlyphPosition(self._glyph, plane_centre)

            scene.endChange()
            self._previous_mouse_position = [event.x(), event.y()]
        else:
            super(Normal, self).mouseMoveEvent(event)
Пример #2
0
 def enter(self):
     scene = self._glyph.getScene()
     scene.beginChange()
     super(Normal, self).enter()
     setGlyphPosition(
         self._glyph,
         calculateCentroid(self._plane.getRotationPoint(),
                           self._plane.getNormal(),
                           self._get_dimension_method()))
     scene.endChange()
Пример #3
0
    def mouseMoveEvent(self, event):
        if self._glyph.getMaterial().getName() == self._selected_material.getName():
            pos = getGlyphPosition(self._glyph)
            screen_pos = self._zinc_view.project(pos[0], pos[1], pos[2])
            global_cur_pos = self._zinc_view.unproject(event.x(), -event.y(), screen_pos[2])
            global_old_pos = self._zinc_view.unproject(self._previous_mouse_position[0], -self._previous_mouse_position[1], screen_pos[2])
            global_pos_diff = sub(global_cur_pos, global_old_pos)

            n = self._plane.getNormal()
            proj_n = mult(n, dot(global_pos_diff, n))
            new_pos = add(pos, proj_n)
            scene = self._glyph.getScene()
            scene.beginChange()

            plane_centre = calculateCentroid(new_pos, self._plane.getNormal(), self._get_dimension_method())
            if plane_centre is not None:
                self._plane.setRotationPoint(plane_centre)
                setGlyphPosition(self._glyph, plane_centre)

            scene.endChange()
            self._previous_mouse_position = [event.x(), event.y()]
        else:
            super(Normal, self).mouseMoveEvent(event)
Пример #4
0
    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()
Пример #5
0
 def enter(self):
     scene = self._glyph.getScene()
     scene.beginChange()
     super(Orientation, self).enter()
     setGlyphPosition(self._glyph, self._plane.getRotationPoint())
     scene.endChange()
Пример #6
0
    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()
Пример #7
0
 def enter(self):
     scene = self._glyph.getScene()
     scene.beginChange()
     super(Orientation, self).enter()
     setGlyphPosition(self._glyph, self._plane.getRotationPoint())
     scene.endChange()
Пример #8
0
 def enter(self):
     scene = self._glyph.getScene()
     scene.beginChange()
     super(Normal, self).enter()
     setGlyphPosition(self._glyph, calculateCentroid(self._plane.getRotationPoint(), self._plane.getNormal(), self._get_dimension_method()))
     scene.endChange()