def getEditor(self, parent): if not NurbsObjectEditor: return None editor = NurbsObjectEditor(parent, 3) editor.view.camera().setPosition(Vec(1, 0, 0.5)) editor.view.camera().setUpVector(Vec(0, 0, 1)) editor.view.camera().setViewDirection(Vec(-1, 0, 0)) editor.view.camera().fitSphere(Vec(0, 0, 0.5), 0.8) return editor
def __init__(self, parent=None): QGLViewer.__init__(self, parent) self.scene = None self.discretizer = Discretizer() self.glrenderer = GLRenderer(self.discretizer) self.bboxcomputer = BBoxComputer(self.discretizer) self.animationMode = eStatic self.forceclear = True self.camera().setViewDirection(Vec(-1, 0, 0)) self.camera().setUpVector(Vec(0, 0, 1))
def init(self): self.camera().setUpVector(Vec(0, 1, 0)) self.camera().setType(Camera.ORTHOGRAPHIC) self.camConstraint = WorldConstraint() self.camera().frame().setConstraint(self.camConstraint) self.camera().setZClippingCoefficient(4) #arbitrary. self.showEntireScene()
def __init__(self, parent=None, scene=None, statefilename='.temp_scene.xml', shareWidget=None): QGLViewer.__init__(self, parent, shareWidget) self.set_bg_white() # set the scene if scene == None: scene = self.defaultScene() self.scene = scene # set some parameters self.setAxisIsDrawn(False) # show axis self.setGridIsDrawn(True) # show grid orientation = Quaternion(0.475117, 0.472505, 0.524479, 0.525286) position = Vec(2.91287, -0.0109797, 0.659613) self.camera().setPosition(position) self.camera().setOrientation(orientation) self.camera().setSceneRadius(1) # Size of vectors x,y,z # connection self.connect(self, QtCore.SIGNAL("drawNeeded()"), self.draw) self.orientation_initiale = self.camera().orientation() self.position_initiale = self.camera().position() # Block "*.xml" save self.setStateFileName("") # Disable Quit in clicking on 'Escape' # Set "show_axis" instead of "kill_application" self.setShortcut(0, QtCore.Qt.Key_Escape)
def mouseMoveEvent(self, event): if self.__oldY is not None: pos = self.__position #some values that are used a bit everywhere newX, newY = event.x(), event.y() xDiff = float(newX - self.__oldX) yDiff = float(newY - self.__oldY) cartDist = sqrt(yDiff**2 + xDiff**2) mod = event.modifiers() if mod != QtCore.Qt.ControlModifier: delta = newY - self.__oldY if delta > 0: pos += self.increment elif delta < 0: pos -= self.increment self.__oldY = newY self.set_position(pos) elif self.__scalingDirection is None: if cartDist < 50: #pixels return #compute direction coefficient of the mouse pointer to the screen center if xDiff == 0.0: return pA = atan2(yDiff, xDiff) tol = self._axisScaleTolerance #compute projected direction coefficients of axes camera = self.camera() origin = camera.getProjectedCoordinatesOf(Vec(0., 0., 0.)) xProj = camera.getProjectedCoordinatesOf(Vec(1., 0., 0.)) yProj = camera.getProjectedCoordinatesOf(Vec(0., 1., 0.)) zProj = camera.getProjectedCoordinatesOf(Vec(0., 0., 1.)) xVec = (xProj[0] - origin[0]), (xProj[1] - origin[1]) yVec = (yProj[0] - origin[0]), (yProj[1] - origin[1]) zVec = (zProj[0] - origin[0]), (zProj[1] - origin[1]) #angles if xVec[0] == 0.0 or yVec[0] == 0.0 or zVec[0] == 0.0: return xA = atan(xVec[1] / xVec[0]) yA = atan(yVec[1] / yVec[0]) zA = atan(zVec[1] / zVec[0]) dire = min((abs(xA % pi - pA % pi), 0, pA, xVec), (abs(yA % pi - pA % pi), 1, pA, yVec), (abs(zA % pi - pA % pi), 2, pA, zVec)) self.__scalingDirection = dire if (dire[0] <= tol) else None elif self.__scalingDirection is not None: angD, dire, angle, vec = self.__scalingDirection #cartDist is used to obtain a significant difference #or else computations are screwed. if xDiff != 0.0 and yDiff != 0 and cartDist > 5: pA = atan2(yDiff, xDiff) if pA < 0: pA += 2 * pi if angle < 0: angle += 2 * pi angleDiv = int(angle / pi * 2) mouseDiv = int(pA / pi * 2) positive = angleDiv == mouseDiv f = self.factor[dire] f = f * 1.02 if positive else f * 0.98 self.factor[dire] = f self.__oldY = newY self.__oldX = newX self.update() else: QGLViewer.mouseMoveEvent(self, event)