Esempio n. 1
0
    def calculateMatrix(self, x, y):
        objectCenterPos = numpy.append(self._renderer._axisInfo.getObject().getPosition(), [self._renderer._axisInfo.getObject().getSize()[2] / 2.0])
        plane = Plane(self._renderer._axisInfo.getAxis(), 0)
        mousePoint0 = plane.intersectRay(self._app.getView().projectScreenPositionToRay(*self._mouse_start))
        mousePoint1 = plane.intersectRay(self._app.getView().projectScreenPositionToRay(x, y))
        centerPoint = plane.pointOnPlane(objectCenterPos)
        mouseVector0 = mousePoint0 - centerPoint
        mouseVector0 /= numpy.linalg.norm(mouseVector0)
        mouseVector1 = mousePoint1 - centerPoint
        mouseVector1 /= numpy.linalg.norm(mouseVector1)
        angle = max(-1.0, min(1.0, numpy.dot(mouseVector0, mouseVector1)))
        angle = math.acos(angle)
        angleStepSize = 15.0
        angle = round(angle / math.pi * 180.0 / angleStepSize) * math.pi / 180.0 * angleStepSize
        if numpy.dot(mouseVector1, numpy.cross(mouseVector0, plane.normal)) > 0:
            angle = -angle

        d = numpy.array(self._renderer._axisInfo.getAxis(), dtype=numpy.float64)
        d /= numpy.linalg.norm(d)

        eye = numpy.eye(3, dtype=numpy.float64)
        ddt = numpy.outer(d, d)
        skew = numpy.array([
            [0, d[2], -d[1]],
            [-d[2], 0, d[0]],
            [d[1], -d[0], 0]],
            numpy.float64)

        matrix = ddt + numpy.cos(angle) * (eye - ddt) + numpy.sin(angle) * skew
        return matrix
Esempio n. 2
0
    def calculateMatrix(self, x, y):
        objectCenterPos = numpy.append(
            self._renderer._axisInfo.getObject().getPosition(),
            [self._renderer._axisInfo.getObject().getSize()[2] / 2.0])
        plane = Plane(self._renderer._axisInfo.getAxis(), 0)
        mousePoint0 = plane.intersectRay(
            self._app.getView().projectScreenPositionToRay(*self._mouse_start))
        mousePoint1 = plane.intersectRay(
            self._app.getView().projectScreenPositionToRay(x, y))
        centerPoint = plane.pointOnPlane(objectCenterPos)
        mouseVector0 = mousePoint0 - centerPoint
        mouseVector0 /= numpy.linalg.norm(mouseVector0)
        mouseVector1 = mousePoint1 - centerPoint
        mouseVector1 /= numpy.linalg.norm(mouseVector1)
        angle = max(-1.0, min(1.0, numpy.dot(mouseVector0, mouseVector1)))
        angle = math.acos(angle)
        angleStepSize = 15.0
        angle = round(angle / math.pi * 180.0 /
                      angleStepSize) * math.pi / 180.0 * angleStepSize
        if numpy.dot(mouseVector1, numpy.cross(mouseVector0,
                                               plane.normal)) > 0:
            angle = -angle

        d = numpy.array(self._renderer._axisInfo.getAxis(),
                        dtype=numpy.float64)
        d /= numpy.linalg.norm(d)

        eye = numpy.eye(3, dtype=numpy.float64)
        ddt = numpy.outer(d, d)
        skew = numpy.array(
            [[0, d[2], -d[1]], [-d[2], 0, d[0]], [d[1], -d[0], 0]],
            numpy.float64)

        matrix = ddt + numpy.cos(angle) * (eye - ddt) + numpy.sin(angle) * skew
        return matrix
Esempio n. 3
0
    def onMouseMove(self, x, y, dx, dy):
        if self._state == 'rotateView':
            self._app.getView().setYaw(self._app.getView().getYaw() + dx)
            self._app.getView().setPitch(self._app.getView().getPitch() - dy)
        if self._state == 'panView':
            mouse_ray0 = self._app.getView().projectScreenPositionToRay(x - dx, y - dy)
            mouse_ray1 = self._app.getView().projectScreenPositionToRay(x, y)
            plane_z = Plane(numpy.array([0, 0, 1], numpy.float32), 0)
            cursor0_on_plane = plane_z.intersectRay(mouse_ray0)
            cursor1_on_plane = plane_z.intersectRay(mouse_ray1)
            pan_amount = cursor0_on_plane - cursor1_on_plane
            pan_amount[2] = 0.0
            self._app.getView().setViewTarget(self._app.getView().getViewTarget() + pan_amount)
        if self._state == 'dragObjectOrSelect':
            obj = self._app.getView().getFocusObject()
            if obj is not None and isinstance(obj, DisplayableObject) and not obj.isSelected():
                if not wx.GetKeyState(wx.WXK_CONTROL):
                    self._app.getScene().deselectAll()
                obj.setSelected(True)
            self._state = 'dragObject'
        if self._state == 'dragObject':
            mouse_ray = self._app.getView().projectScreenPositionToRay(x, y)
            plane_z = Plane(numpy.array([0, 0, 1], numpy.float32), self._dragPos3D[2])

            cursor_on_plane = plane_z.intersectRay(mouse_ray)
            delta = numpy.array(cursor_on_plane[0:2] - self._dragPos3D[0:2], numpy.float32)
            self._dragPos3D[0:2] = cursor_on_plane[0:2]

            for obj in self._app.getScene().getObjects():
                if obj.isSelected():
                    obj.setPosition(obj.getPosition() + delta, False)
Esempio n. 4
0
    def onMouseMove(self, x, y, dx, dy):
        if self._state == 'rotateView':
            self._app.getView().setYaw(self._app.getView().getYaw() + dx)
            self._app.getView().setPitch(self._app.getView().getPitch() - dy)
        if self._state == 'dragObjectOrSelect':
            obj = self._app.getView().getFocusObject()
            if obj is not None and isinstance(
                    obj, DisplayableObject) and not obj.isSelected():
                if not wx.GetKeyState(wx.WXK_CONTROL):
                    self._app.getScene().deselectAll()
                obj.setSelected(True)
            self._state = 'dragObject'
        if self._state == 'dragObject':
            mouse_ray = self._app.getView().projectScreenPositionToRay(x, y)
            plane_z = Plane(numpy.array([0, 0, 1], numpy.float32),
                            self._dragPos3D[2])

            cursor_on_plane = plane_z.intersectRay(mouse_ray)
            delta = numpy.array(cursor_on_plane[0:2] - self._dragPos3D[0:2],
                                numpy.float32)
            self._dragPos3D[0:2] = cursor_on_plane[0:2]

            for obj in self._app.getScene().getObjects():
                if obj.isSelected():
                    obj.setPosition(obj.getPosition() + delta)