Exemplo n.º 1
0
 def _getModifierAxisScreenDir(self, modifierAxisDir):
     mvp = self._getModifierMVP()
     v0 = cgmath.Vec4(0.0,0.0,0.0,1.0) * mvp
     v1 = cgmath.Vec4(modifierAxisDir[0],modifierAxisDir[1],modifierAxisDir[2],1.0) * mvp
     v0 /= v0[3]
     v1 /= v1[3]
     a = v1 - v0
     return a.normalized()
Exemplo n.º 2
0
    def _projectEdgeVertices(self, mvp, vertexIndex0, vertexIndex1):
        v0 = cgmath.Vec4(self._vertex_data[vertexIndex0 * 3], self._vertex_data[vertexIndex0 * 3 + 1],
                         self._vertex_data[vertexIndex0 * 3 + 2], 1.0)
        v1 = cgmath.Vec4(self._vertex_data[vertexIndex1 * 3 ], self._vertex_data[vertexIndex1 * 3 + 1],
                         self._vertex_data[vertexIndex1 * 3 + 2], 1.0)

        v0 = v0 * mvp
        v1 = v1 * mvp
        v0x = v0[0] / v0[3]
        v0y = v0[1] / v0[3]
        v1x = v1[0] / v1[3]
        v1y = v1[1] / v1[3]

        return mathutil.Vec2(v0x, v0y), mathutil.Vec2(v1x, v1y)
Exemplo n.º 3
0
    def mousePressEvent(self, mouseEvent):
        super(ModelerViewport, self).mousePressEvent(mouseEvent)

        if self._adjustingCamera:
            return

        modifiers = QApplication.keyboardModifiers()

        # Pan/Rotate/Zoom?
        if modifiers == Qt.AltModifier:
            self._adjustingCamera = True
            self._adjustCameraStartMousePos = mathutil.Vec2(mouseEvent.localPos().x(), mouseEvent.localPos().y())
            self._adjustCameraStartCamera = self._cameraTransform
            self._adjustCameraPivot = self._cameraPivot

            # Panning?
            if mouseEvent.buttons() & Qt.MiddleButton:
                self._adjustCameraMode = 0
            # Rotating?
            elif mouseEvent.buttons() & Qt.LeftButton:
                self._adjustCameraMode = 1
            # Zooming?
            elif mouseEvent.buttons() & Qt.RightButton:
                self._adjustCameraMode = 2

        # Simple click?
        else:
            clickHandled = False

            # Did we click on the modifier, if its visible?
            if self._modifierMode != ModifierMode.SELECT and self._isModifierVisible():
                axis = self._getMouseOnModifierAxis(mouseEvent.localPos().x(), mouseEvent.localPos().y())

                if axis != ModifierAxis.NONE:
                    node = self._getCurrentMainModelNode()
                    clickHandled = True
                    self._modifierAxis = axis
                    self._modifyStartMouseScreenPos = self._convertMousePosToScreenPos(mouseEvent.localPos().x(), mouseEvent.localPos().y())

                    self._modifyStartModelTranslation = {}
                    self._modifyStartModelRotationMatrix = {}
                    self._modifyStartModelSize = {}

                    for node in self._currentModelNodes:
                        self._modifyStartModelTranslation[node] = node.translation
                        self._modifyStartModelRotationMatrix[node] = \
                            cgmath.Mat44.rotateZ(node.rotation[2]) * \
                            cgmath.Mat44.rotateY(node.rotation[1]) * \
                            cgmath.Mat44.rotateX(node.rotation[0])
                        self._modifyStartModelSize[node] = node.size

                    self.update()

            # Otherwise update our selection
            if self._currentModel is not None and not clickHandled:
                clickHandled = True
                self._selecting = True
                self._selectStartMouseScreenPos = self._convertMousePosToScreenPos(mouseEvent.localPos().x(), mouseEvent.localPos().y())
                self._selectCurrentMouseScreenPos = cgmath.Vec4(self._selectStartMouseScreenPos)
Exemplo n.º 4
0
 def getBounds(self):
     modelTransform = self.getModelTransform()
     bounds = Bounds()
     for z in range(-1, 2, 2):
         for y in range(-1, 2, 2):
             for x in range(-1, 2, 2):
                 p = cgmath.Vec4(float(x), float(y), float(z), 1.0)
                 p = modelTransform * p
                 bounds.add(cgmath.Vec3(p[0], p[1], p[2]))
     return bounds
Exemplo n.º 5
0
 def _convertMousePosToScreenPos(self, mousePosX, mousePosY):
     screenX = (mousePosX / self.width()) * 2.0 - 1.0
     screenY = ((mousePosY / self.height()) * -2.0 + 1.0)
     return cgmath.Vec4(screenX, screenY, 0.0, 0.0)