def ApplyZoom(self, newZoom): """ Apply the requested zoom level and rotate/offset the camera according the the new zoom level. """ projection, view, viewport = uix.GetFullscreenProjectionViewAndViewport( ) aspectRatioAdjustment = camutils.GetARZoomMultiplier( viewport.GetAspectRatio()) if newZoom == self.zoom and not self.zoom > aspectRatioAdjustment: return zoom = max(0.05, min(aspectRatioAdjustment, newZoom)) translationAdjustment = 1 if zoom > 1: translationAdjustment = zoom self.zoom = zoom self.camera.translationFromParent = planetCommon.PLANET_ZOOM_MIN + translationAdjustment * ( min(1.0, zoom) * self.zoomScale)**2 yaw = self.camera.yaw pitch = self.camera.pitch criticalZoom = 0.5 kOrbit = 1.1 kPitch = 0.2 if zoom <= criticalZoom: orbitRotation = (criticalZoom - self.zoom)**2 * math.pi * kOrbit self.pitchDiff = (criticalZoom - self.zoom)**2 * math.pi * kPitch newPitch = pitch + self.pitchDiff - self.oldPitchDiff self.camera.SetOrbit(yaw, newPitch) self.oldPitchDiff = self.pitchDiff else: orbitRotation = 0.0 self.camera.SetRotationOnOrbit(0.0, orbitRotation) sm.GetService('planetUI').OnPlanetZoomChanged(min(1.0, self.zoom))
def GetPickIntersectionPoint(x=None, y=None): """ Returns the point on the planet at (x, y) screen coordinates. This is done by casting a ray based on the screen coordinates (x, y) and the viewport and then finally calculating the intersection of that ray and a sphere (the planet). Method defaults to the current mouse coordinates if x and y arguments are None Returns None if the planet was not clicked. Arguments: x - the x coordinates in screen space y - the y coordinares in screen space """ if None in (x, y): x, y = int(uicore.uilib.x * uicore.desktop.dpiScaling), int( uicore.uilib.y * uicore.desktop.dpiScaling) device = trinity.device proj, view, vp = uix.GetFullscreenProjectionViewAndViewport() ray, start = device.GetPickRayFromViewport(x, y, vp, view.transform, proj.transform) lineVec = trinity.TriVector(*ray) lineP0 = trinity.TriVector(*start) sphereP0 = trinity.TriVector(0.0, 0.0, 0.0) sphereRad = 1000.0 pInt = GetSphereLineIntersectionPoint(lineP0, lineVec, sphereP0, sphereRad) if not pInt: return ret = SurfacePoint(pInt.x, pInt.y, pInt.z) ret.SetRadius(1.0) return ret
def GetPick(self): sceneManager = sm.GetService('sceneManager') planetui = sm.GetService('planetUI') scene = sceneManager.GetRegisteredScene('planet') x, y = int(uicore.uilib.x * uicore.desktop.dpiScaling), int( uicore.uilib.y * uicore.desktop.dpiScaling) if scene: projection, view, viewport = uix.GetFullscreenProjectionViewAndViewport( ) result = scene.PickObjectAndAreaID(x, y, projection, view, viewport) if result: pick, areaID = result if pick.__bluetype__ == 'trinity.EveSpherePin' and pick.name: try: pickType, id = self.GetPinTypeAndIDFromPickName( pick.name) except Exception: log.LogException( 'A pin with no ID was picked... this should not be possible:' ) return (None, None) elif pick == sm.GetService( 'planetUI').curveLineDrawer.GetLineSet('links'): pickType = TYPE_LINK id = areaID elif pick.__bluetype__ == 'trinity.EveTransform': pickType = TYPE_PLANET id = None else: pickType = TYPE_OTHER id = None return (pickType, id) return (None, None)
def GetRayAndPointFromScreen(x, y): proj, view, vp = uix.GetFullscreenProjectionViewAndViewport() ray, start = trinity.device.GetPickRayFromViewport(x, y, vp, view.transform, proj.transform) ray = geo2.Vector(*ray) start = geo2.Vector(*start) return (ray, start)
def GetMenu(self): x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y) if self.scene: projection, view, viewport = uix.GetFullscreenProjectionViewAndViewport( ) pick = self.scene.PickObject(x, y, projection, view, viewport) if pick and pick.name == str(util.GetActiveShip()): return self.GetShipMenu()
def GetPick(self): scene = sm.GetService('sceneManager').GetRegisteredScene('systemmap') x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y) if scene: projection, view, viewport = uix.GetFullscreenProjectionViewAndViewport() pick = scene.PickObject(x, y, projection, view, viewport) if pick: return ('scene', pick) return (None, None)
def GetMenu(self): x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y) scene = sm.StartService('sceneManager').GetRegisteredScene('hangar') if scene: projection, view, viewport = uix.GetFullscreenProjectionViewAndViewport( ) pick = scene.PickObject(x, y, projection, view, viewport) if pick and pick.name == str(util.GetActiveShip()): return self.GetShipMenu()
def OnMouseDown(self, button): self._isPicked = True scene = sm.GetService('sceneManager').GetRegisteredScene('starmap') self.pickedTF = None if scene is not None: projection, view, viewport = uix.GetFullscreenProjectionViewAndViewport( ) self.pickedTF = scene.PickObject(uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y), projection, view, viewport) self.mouseDownRegionID = self.PickRegionID()
def PickRegionID(self): scene = sm.GetService('sceneManager').GetRegisteredScene('starmap') if scene is None: return x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y) projection, view, viewport = uix.GetFullscreenProjectionViewAndViewport( ) pick = scene.PickObject(x, y, projection, view, viewport) if pick is not None: if hasattr(pick, 'regionID'): return pick.regionID if pick.name[:11] == '__regionDot': return int(pick.name[11:])
def GetPickIntersectionPoint(x = None, y = None): if None in (x, y): x, y = int(uicore.uilib.x * uicore.desktop.dpiScaling), int(uicore.uilib.y * uicore.desktop.dpiScaling) device = trinity.device proj, view, vp = uix.GetFullscreenProjectionViewAndViewport() ray, start = device.GetPickRayFromViewport(x, y, vp, view.transform, proj.transform) lineVec = trinity.TriVector(*ray) lineP0 = trinity.TriVector(*start) sphereP0 = trinity.TriVector(0.0, 0.0, 0.0) sphereRad = 1000.0 pInt = GetSphereLineIntersectionPoint(lineP0, lineVec, sphereP0, sphereRad) if not pInt: return ret = planet.SurfacePoint(pInt.x, pInt.y, pInt.z) ret.SetRadius(1.0) return ret