예제 #1
0
 def _calculatePointOnPlane(self, x, 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())
     return point_on_plane
예제 #2
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()
예제 #3
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()
예제 #4
0
 def _calculatePointOnPlane(self, x, 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())
     return point_on_plane