def _GetLinkWeight(self, link, pinA, pinB): spA = planet.SurfacePoint(radius=1.0, theta=pinA.longitude, phi=pinA.latitude) spB = planet.SurfacePoint(radius=1.0, theta=pinB.longitude, phi=pinB.latitude) return spA.GetDistanceToOther(spB)
def GetDistanceBetweenPins(pinA, pinB, planetRadius): spA = planet.SurfacePoint(radius=planetRadius, theta=pinA.longitude, phi=pinA.latitude) spB = planet.SurfacePoint(radius=planetRadius, theta=pinB.longitude, phi=pinB.latitude) return spA.GetDistanceToOther(spB)
def GetDistance(self): planetRadius = self.eventHandler.GetPlanetRadius() spA = planet.SurfacePoint(radius=planetRadius, theta=self.endpoint1.longitude, phi=self.endpoint1.latitude) spB = planet.SurfacePoint(radius=planetRadius, theta=self.endpoint2.longitude, phi=self.endpoint2.latitude) return spA.GetDistanceToOther(spB)
def _GetLineCenterPoint(self, sp1, sp2): x = sp1.x / 2.0 + sp2.x / 2.0 y = sp1.y / 2.0 + sp2.y / 2.0 z = sp1.z / 2.0 + sp2.z / 2.0 sp = planet.SurfacePoint(x, y, z) sp.SetRadius(1.0) return sp
def _GetTriangleCenterPoint(self, sp1, sp2, sp3): x = sp1.x / 3.0 + sp2.x / 3.0 + sp3.x / 3.0 y = sp1.y / 3.0 + sp2.y / 3.0 + sp3.y / 3.0 z = sp1.z / 3.0 + sp2.z / 3.0 + sp3.z / 3.0 sp = planet.SurfacePoint(x, y, z) sp.SetRadius(1.0) return sp
def RenderPin(self, pin): if pin.id in self.pinsByID: self.pinsByID[pin.id].Remove() surfacePoint = planet.SurfacePoint(phi=pin.latitude, theta=pin.longitude) pinClass = self.GetPinGraphicsClassForType(pin.typeID) UIpin = pinClass(surfacePoint, pin, self.planetUISvc.pinTransform) self.pinsByID[pin.id] = UIpin return UIpin
def PlacePinOnNextClick(self, pinTypeID): self.eventManager.SetStateBuildPin() self._RemoveBuildIndicatorPin() self.newPinType = pinTypeID typeObj = cfg.invtypes.Get(pinTypeID) self.buildIndicatorPin = planet.ui.BuildIndicatorPin(planet.SurfacePoint(), pinTypeID, typeObj.groupID, self.planetUISvc.pinOthersTransform) if typeObj.groupID == const.groupExtractionControlUnitPins: self.DisplayECUExtractionAreas(show=True)
def OnPlanetViewOpened(self): self.planetUISvc = sm.GetService('planetUI') self.eventManager = self.planetUISvc.eventManager sp = planet.SurfacePoint() rubberColor = (1.0, 1.0, 1.0, 1.0) self.rubberLink = self.planetUISvc.curveLineDrawer.DrawArc('rubberLink', sp, sp, 2.0, rubberColor, rubberColor) self.InitRubberLinkLabels() self.ReRender() self.depletionPoints = [] self.bracketCurveSet.Play()
def AddLink(self, parentID, childID, linkTypeID): colony = self.planetUISvc.planet.GetColony(session.charid) if colony is None: log.LogError('Unable to render link for planet without a colony') return par = colony.GetPin(parentID) child = colony.GetPin(childID) if par is None or child is None: log.LogWarn('Trying to render link for non-existing pin', parentID, childID) return p1 = planet.SurfacePoint(theta=par.longitude, phi=par.latitude) p2 = planet.SurfacePoint(theta=child.longitude, phi=child.latitude) planetLink = colony.colonyData.GetLink(parentID, childID) link = planet.ui.Link(p1, p2, parentID, childID, linkTypeID, planetLink) self.linksByPinIDs[parentID, childID] = link self.linksByPinIDs[childID, parentID] = link self.links.append(link) linkGraphicID1, linkGraphicID2 = link.GetGraphicIDs() self.linksByGraphicID[linkGraphicID1] = link self.linksByGraphicID[linkGraphicID2] = link
def RenderPins(self): planetBases = sm.GetService('planetBaseSvc').GetPlanetBases( self.planetUISvc.planetID) for item, customInfo in planetBases: surfacePoint = planet.SurfacePoint(phi=customInfo.latitude, theta=customInfo.longitude) pinKv = util.KeyVal() pinKv.typeID = item.typeID pinKv.id = item.itemID pinKv.ownerID = item.ownerID pinKv.conflicts = customInfo.conflicts pinKv.surfacePoint = surfacePoint self.RenderPin(pinKv, surfacePoint)
def _AddDistrictsToPlanets(self): ballpark = self.michelle.GetBallpark() if ballpark is None: return for district in self.districts.itervalues(): if district.get('planet'): continue district['planet'] = ballpark.GetBall(district.get('planetID')) if district.get('planet'): direction = geo2.Vec3Normalize(planet.SurfacePoint(phi=district['latitude'], theta=district['longitude']).GetAsXYZTuple()) district['uniqueName'] = 'district-%s' % district['districtID'] district['planet'].AddDistrict(district['uniqueName'], direction, 0.1, False) self._DisplayDistrictBattles(district)
def RenderCommandCentersOfOtherCharacters(self): if not settings.user.ui.Get('planetShowOtherCharactersPins', True): return commandCenters = self.GetCommandCentersOfOtherCharacters() for charid, cc in commandCenters.iteritems(): if charid == session.charid: continue sp = planet.SurfacePoint(theta=cc.longitude, phi=cc.latitude) pin = planet.ui.OtherPlayersPin( sp, cc.pinID, cc.typeID, cc.ownerID, self.planetUISvc.pinOthersTransform) self.otherPlayerPinsByPinID[cc.pinID] = pin self.planetUISvc.curveLineDrawer.SubmitLineset('otherLinks')
def _CreateTargetBall(self, district, itemID): if itemID not in self.balls: ballpark = self.michelle.GetBallpark() if district and ballpark and district['planet']: direction = geo2.Vec3Normalize(planet.SurfacePoint(phi=district['latitude'], theta=district['longitude']).GetAsXYZTuple()) translation = geo2.Vec3Scale(direction, district['planet'].radius) position = (district['planet'].x + translation[0], district['planet'].y + translation[1], district['planet'].z + translation[2]) ball = DistrictTargetBall(ballpark.AddClientSideBall(position, True)) ball.model.name = 'DistrictBall_%s' % itemID ball.model.translationCurve = ball ball.model.rotationCurve = ball scene = sm.GetService('sceneManager').GetRegisteredScene('default') scene.objects.append(ball.model) self.balls[itemID] = ball return self.balls.get(itemID)
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
def PlaceProbeAtDefaultPosition(self, headID): OFFSET = 0.08 VEC_X = (-1, 0, 0) rotAngle = float(headID) / planetCommon.ECU_MAX_HEADS * 2 * math.pi ecuVector = self.planetUISvc.myPinManager.pinsByID[ self.pin.id].surfacePoint.GetAsXYZTuple() normal = geo2.Vec3Cross(ecuVector, VEC_X) normal = geo2.Vector(*normal) * OFFSET posVec = geo2.Vec3Subtract(ecuVector, normal) posVec = geo2.Vec3Normalize(posVec) rotMat = geo2.MatrixRotationAxis(ecuVector, rotAngle) posVec = geo2.Multiply(rotMat, posVec) surfacePoint = planet.SurfacePoint(*posVec) self.planetUISvc.myPinManager.PlaceExtractionHead( self.pin.id, headID, surfacePoint, self.currentRadius) self.UpdateHeadPosition(headID, surfacePoint)
def RenderOtherPlayersExtractors(self, resourceTypeID): self.HideOtherPlayersExtractors() extractorData = self.GetExtractorsOfOtherCharacters(resourceTypeID) if not extractorData: return for pinData in extractorData: sp = planet.SurfacePoint(theta=pinData.longitude, phi=pinData.latitude) pin = planet.ui.OtherPlayersPin( sp, pinData.pinID, pinData.typeID, pinData.ownerID, self.planetUISvc.pinOthersTransform, isActive=True) self.otherPlayerExtractors.append(pin) self.otherPlayerPinsByPinID[pinData.pinID] = pin
def _AddDistrictsToPlanets(self): """ Make sure that each district has been added to a planet ball so they display. Also update the state of any ongoing district battles. """ ballpark = self.michelle.GetBallpark() if ballpark is None: return for district in self.districts.itervalues(): if district.get('planet'): continue district['planet'] = ballpark.GetBall(district.get('planetID')) if district.get('planet'): direction = geo2.Vec3Normalize(planet.SurfacePoint(phi=district['latitude'], theta=district['longitude']).GetAsXYZTuple()) district['uniqueName'] = 'district-%s' % district['districtID'] district['planet'].AddDistrict(district['uniqueName'], direction, 0.1, False) self._DisplayDistrictBattles(district)
def _SplitTriangle(self, v0, v1, v2, lines, cLines, hLines, sps, level): level -= 1 lc0 = self._GetLineCenterPoint(v0, v1) lc1 = self._GetLineCenterPoint(v1, v2) lc2 = self._GetLineCenterPoint(v2, v0) tc = self._GetTriangleCenterPoint(v0, v1, v2) if level > 0: self._SplitTriangle(v0, lc0, lc2, lines, cLines, hLines, sps, level) self._SplitTriangle(v1, lc1, lc0, lines, cLines, hLines, sps, level) self._SplitTriangle(v2, lc2, lc1, lines, cLines, hLines, sps, level) self._SplitTriangle(lc0, lc1, lc2, lines, cLines, hLines, sps, level) else: v = geo2.Vector vecC = v(*tc.GetAsXYZTuple()) vec0 = v(*v0.GetAsXYZTuple()) vec1 = v(*v0.GetAsXYZTuple()) vec2 = v(*v0.GetAsXYZTuple()) vec01 = v(*(v1.x - v0.x, v1.y - v0.y, v1.z - v0.z)) n0 = v(*geo2.Vec3Cross(vecC, vec01)) vec12 = v(*(v2.x - v1.x, v2.y - v1.y, v2.z - v1.z)) n1 = v(*geo2.Vec3Cross(vecC, vec12)) vec20 = v(*(v0.x - v2.x, v0.y - v2.y, v0.z - v2.z)) n2 = v(*geo2.Vec3Cross(vecC, vec20)) s = 0.16 sGap = 0.1 n0 = v(*(s * n0)) n1 = v(*(s * n1)) n2 = v(*(s * n2)) lp0 = planet.SurfacePoint(*(vecC - n0)) lp1 = planet.SurfacePoint(*(vecC - n1)) lp2 = planet.SurfacePoint(*(vecC - n2)) lr0 = planet.SurfacePoint(*(vecC - v(*(sGap * n0)))) lr1 = planet.SurfacePoint(*(vecC - v(*(sGap * n1)))) lr2 = planet.SurfacePoint(*(vecC - v(*(sGap * n2)))) lp0.SetRadius(1.0) lp1.SetRadius(1.0) lp2.SetRadius(1.0) lr0.SetRadius(1.0) lr1.SetRadius(1.0) lr2.SetRadius(1.0) lines.add((lr0, lp0)) lines.add((lr1, lp1)) lines.add((lr2, lp2))
def RenderOtherCharactersNetwork(self, charid): linkColor = (0.0, 1.0, 1.0, 1.0) linkBgColor = (0.0, 0.0, 0.0, 0.3) pins, links = self.GetOtherCharactersNetwork(charid) self.HideOtherCharactersNetwork() for pinData in pins: groupID = cfg.invtypes.Get(pinData.typeID).groupID if groupID == const.groupCommandPins: self.currentOtherExpandedCommandPin = self.otherPlayerPinsByPinID[ pinData.pinID] self.currentOtherExpandedCommandPin.RenderAsActive() continue sp = planet.SurfacePoint(theta=pinData.longitude, phi=pinData.latitude) pin = planet.ui.OtherPlayersPin( sp, pinData.pinID, pinData.typeID, pinData.ownerID, self.planetUISvc.pinOthersTransform, isActive=True) self.otherPlayerVisiblePins.append(pin) self.otherPlayerPinsByPinID[pinData.pinID] = pin for link in links: sp1 = self.otherPlayerPinsByPinID[link[0]].surfacePoint sp2 = self.otherPlayerPinsByPinID[link[1]].surfacePoint length = sp1.GetDistanceToOther(sp2) texWidth = 600.0 * length lineID = self.planetUISvc.curveLineDrawer.DrawArc( 'otherLinks', sp1, sp2, 5.0, linkBgColor, linkBgColor) numSegments = max(1, int(length * 25.0)) self.planetUISvc.curveLineDrawer.SetLineSetNumSegments( 'otherLinks', lineID, numSegments) self.planetUISvc.curveLineDrawer.ChangeLineAnimation( 'otherLinks', lineID, linkColor, 0.0, texWidth) self.planetUISvc.curveLineDrawer.SubmitLineset('otherLinks')
def _DrawMesh(self, lsName, numPhi=30, numTheta=60, phiSkip=0, lineWidth=2.0, col=(1.0, 1.0, 1.0, 0.01)): col = (0.8, 0.8, 1.0, 0.3) colAnim = (1.0, 1.0, 1.0, 1.0) speedAnim = 0.06 scaleAnim = 2.0 phi0 = math.pi / 90 phiStep = (math.pi - 2 * phi0) / numPhi phiInit = phi0 + phiStep * phiSkip ls = self.GetLineSet(lsName) for p in xrange(numPhi + 1): if p <= phiSkip - 1 or p > numPhi - phiSkip: continue phi = phi0 + float(p) * phiStep for quarter in xrange(0, 4): th0 = math.pi / 2 * quarter p1 = planet.SurfacePoint(theta=th0, phi=phi) p2 = planet.SurfacePoint(theta=th0 + math.pi / 2, phi=phi) pC = planet.SurfacePoint(0.0, p1.y, 0.0) lineID = ls.AddSpheredLineCrt(p1.GetAsXYZTuple(), col, p2.GetAsXYZTuple(), col, pC.GetAsXYZTuple(), lineWidth) ls.ChangeLineAnimation(lineID, colAnim, speedAnim, scaleAnim) for t in xrange(numTheta): th = float(t) / numTheta * math.pi * 2 p1 = planet.SurfacePoint(theta=th, phi=math.pi / 2.0) p2 = planet.SurfacePoint(theta=th, phi=phiInit) lineID = ls.AddSpheredLineCrt(p1.GetAsXYZTuple(), col, p2.GetAsXYZTuple(), col, self.p0, lineWidth) ls.ChangeLineAnimation(lineID, colAnim, speedAnim, scaleAnim) p2 = planet.SurfacePoint(theta=th, phi=math.pi - phiInit) lineID = ls.AddSpheredLineCrt(p1.GetAsXYZTuple(), col, p2.GetAsXYZTuple(), col, self.p0, lineWidth) ls.ChangeLineAnimation(lineID, colAnim, speedAnim, scaleAnim) ls.SubmitChanges()
def LoadOrbitalObjects(self, scene): orbitalObjects = sm.GetService('planetInfo').GetOrbitalsForPlanet( self.planetID, const.groupPlanetaryCustomsOffices) groupClasses = spaceObject.GetGroupDict() categoryClasses = spaceObject.GetCategoryDict() park = sm.GetService('michelle').GetBallpark() addedObjects = [] for orbitalObjectID in orbitalObjects: ball = park.GetBall(orbitalObjectID) invItem = park.GetInvItem(orbitalObjectID) fileName = None if cfg.invtypes.Get(invItem.typeID).graphicID is not None: if type(cfg.invtypes.Get(invItem.typeID).graphicID) != type(0): raise RuntimeError('NeedGraphicIDNotMoniker', invItem.itemID) if cfg.invtypes.Get(invItem.typeID).Graphic(): fileName = cfg.invtypes.Get(invItem.typeID).GraphicFile() if not (fileName.lower().endswith('.red') or fileName.lower().endswith('.blue')): filename_and_turret_type = string.split(fileName, ' ') fileName = filename_and_turret_type[0] if fileName is None: self.LogError( 'Error: Object type %s has invalid graphicFile, using graphicID: %s' % (invItem.typeID, cfg.invtypes.Get( invItem.typeID).graphicID)) continue tryFileName = fileName.replace(':/Model', ':/dx9/Model').replace( '.blue', '.red') tryFileName = tryFileName.replace('.red', '_UI.red') model = None if tryFileName is not None: try: model = blue.resMan.LoadObject(tryFileName) except: model = None sys.exc_clear() if model is None: self.LogError('Was looking for:', tryFileName, 'but it does not exist!') if model is None: try: model = blue.resMan.LoadObject(fileName) except: model = None sys.exc_clear() if not model: log.LogError( 'Could not load model for orbital object. FileName:', fileName, ' id:', invItem.itemID, ' typeID:', getattr(invItem, 'typeID', '?unknown?')) if invItem is not None and hasattr(invItem, 'typeID'): log.LogError('Type is:', cfg.invtypes.Get(invItem.typeID).typeName) continue model.name = '%s' % invItem.itemID model.display = 0 model.scaling = (0.002, 0.002, 0.002) addedObjects.append(model) orbitRoot = trinity.EveTransform() orbitRoot.children.append(model) inclinationRoot = trinity.EveTransform() inclinationRoot.children.append(orbitRoot) orbitalInclination = orbitalObjectID / math.pi % ( math.pi / 4.0) - math.pi / 8.0 if orbitalInclination <= 0.0: orbitalInclination -= math.pi / 8.0 else: orbitalInclination += math.pi / 8.0 inclinationRoot.rotation = geo2.QuaternionRotationSetYawPitchRoll( 0.0, orbitalInclination, 0.0) rotationCurveSet = trinity.TriCurveSet() rotationCurveSet.playOnLoad = False rotationCurveSet.Stop() rotationCurveSet.scaledTime = 0.0 rotationCurveSet.scale = 0.25 orbitRoot.curveSets.append(rotationCurveSet) ypr = trinity.TriYPRSequencer() ypr.YawCurve = trinity.TriScalarCurve() ypr.YawCurve.extrapolation = trinity.TRIEXT_CYCLE ypr.YawCurve.AddKey(0.0, 0.0, 0.0, 0.0, trinity.TRIINT_LINEAR) ypr.YawCurve.AddKey(200.0, 360.0, 0.0, 0.0, trinity.TRIINT_LINEAR) ypr.YawCurve.Sort() rotationCurveSet.curves.append(ypr) binding = trinity.TriValueBinding() binding.sourceObject = ypr binding.sourceAttribute = 'value' binding.destinationObject = orbitRoot binding.destinationAttribute = 'rotation' rotationCurveSet.bindings.append(binding) rotationCurveSet.Play() model.translation = (0.0, 0.0, 1500.0) model.rotation = geo2.QuaternionRotationSetYawPitchRoll( math.pi, 0.0, 0.0) scene.objects.append(inclinationRoot) ls = trinity.EveCurveLineSet() ls.scaling = (1.0, 1.0, 1.0) tex2D1 = trinity.TriTexture2DParameter() tex2D1.name = 'TexMap' tex2D1.resourcePath = 'res:/UI/Texture/Planet/link.dds' ls.lineEffect.resources.append(tex2D1) tex2D2 = trinity.TriTexture2DParameter() tex2D2.name = 'OverlayTexMap' tex2D2.resourcePath = 'res:/UI/Texture/Planet/link.dds' ls.lineEffect.resources.append(tex2D2) lineColor = (1.0, 1.0, 1.0, 0.05) p1 = planet.SurfacePoint(0.0, 0.0, -1500.0, 1000.0) p2 = planet.SurfacePoint(5.0, 0.0, 1498.0, 1000.0) l1 = ls.AddSpheredLineCrt(p1.GetAsXYZTuple(), lineColor, p2.GetAsXYZTuple(), lineColor, (0.0, 0.0, 0.0), 3.0) p1 = planet.SurfacePoint(0.0, 0.0, -1500.0, 1000.0) p2 = planet.SurfacePoint(-5.0, 0.0, 1498.0, 1000.0) l2 = ls.AddSpheredLineCrt(p1.GetAsXYZTuple(), lineColor, p2.GetAsXYZTuple(), lineColor, (0.0, 0.0, 0.0), 3.0) animationColor = (0.3, 0.3, 0.3, 0.5) ls.ChangeLineAnimation(l1, animationColor, 0.25, 1.0) ls.ChangeLineAnimation(l2, animationColor, -0.25, 1.0) ls.ChangeLineSegmentation(l1, 100) ls.ChangeLineSegmentation(l2, 100) ls.SubmitChanges() orbitRoot.children.append(ls) trinity.WaitForResourceLoads() for model in addedObjects: model.display = 1
def Load(self): self.districtID = self.district['districtID'] self.planetID = self.district['planetID'] self.latitude = self.district['latitude'] self.longitude = self.district['longitude'] self.planet = sm.GetService('michelle').GetBallpark( session.solarsystemid).balls[self.planetID] self.point = planet.SurfacePoint(phi=self.latitude, theta=self.longitude) self.name = 'DistrictBracket_%d' % self.districtID self.destrictGfxID = self.planet.GetDistrictNum('district-%d' % self.districtID) if self.container: self.container.Close() self.container = InSceneContainer( scene=sm.GetService('sceneManager').GetRegisteredScene('default'), name=self.name, width=512, height=512, clearBackground=True, backgroundColor=(0, 0, 0, 0)) self.container.transform.translationCurve = self.planet.model.translationCurve self.container.transform.translation = geo2.Vec3Scale( geo2.Vec3Normalize(self.point.GetAsXYZTuple()), self.planet.radius) self.container.transform.scaling = (1000000, 1000000, 1000000) self.container.transform.rotation = geo2.QuaternionRotationSetYawPitchRoll( -self.longitude + math.pi / 2, self.latitude - math.pi / 2, 0) self.hover = uiprimitives.Container(parent=self.container, align=uiconst.CENTER, state=uiconst.UI_NORMAL, opacity=1, width=512, height=512) self.hover.OnMouseEnter = self.OnMouseEnter self.hover.OnMouseExit = self.OnMouseExit self.hover.OnClick = self.OnClick self.transform = uiprimitives.Transform(parent=self.hover, align=uiconst.TOALL, rotation=0, scalingCenter=(0.5, 0.5)) uicore.animations.MorphScalar(self.transform, 'rotation', startVal=0, endVal=math.pi / 2, duration=10, loops=uiconst.ANIM_REPEAT, curveType=uiconst.ANIM_LINEAR) self.frame = self.Corners( parent=self.transform, image='res:/UI/Texture/Bombardment/district_bracket_frame.png', boxSize=450, cornerSize=170, opacity=0.0) self.arrows_transform = uiprimitives.Transform(parent=self.transform, align=uiconst.TOALL, rotation=0, scalingCenter=(0.5, 0.5)) self.arrows = self.Corners( parent=self.arrows_transform, image='res:/UI/Texture/Bombardment/target_triangle.png', boxSize=300, cornerSize=30, opacity=0.0) self.Redraw()