def GetWarpCollisions(self, ball): space = sm.GetService('space') planets = space.planetManager.planets destination = Vector3(self.destination) source = Vector3(ball.x, ball.y, ball.z) self.direction = destination - source direction = self.direction warpDistance = direction.Length() normDirection = Vector3(direction).Normalize() self.normDirection = normDirection ballpark = sm.GetService('michelle').GetBallpark() collisions = [] for planet in planets: planetBall = ballpark.GetBall(planet.id) if planetBall is None: log.LogWarn('Warping got a None planet ball.') continue planetRadius = planetBall.radius planetPosition = Vector3(planetBall.x, planetBall.y, planetBall.z) planetDir = planetPosition - source if self.direction.Length2() < planetDir.Length2(): continue effectiveRadius = self.CalcEffectiveRadius(normDirection, planetDir, planetRadius) if effectiveRadius is None: continue collisions.append((planetBall, effectiveRadius)) blue.pyos.BeNice() return collisions
def AlignToDirection(self, direction): zaxis = Vector3(direction) if zaxis.Length2() > 0.0: Up = Vector3([0.0, 1.0, 0.0]) zaxis.Normalize() xaxis = zaxis ^ Up if xaxis.Length2() == 0.0: zaxis += Vector3().Randomize(0.0001) zaxis.Normalize() xaxis = zaxis ^ Up xaxis.Normalize() yaxis = xaxis ^ zaxis else: self.LogError('Space object', self.id, 'has zero dunDirection. I cannot rotate it.') return mat = ((xaxis[0], xaxis[1], xaxis[2], 0.0), (yaxis[0], yaxis[1], yaxis[2], 0.0), (-zaxis[0], -zaxis[1], -zaxis[2], 0.0), (0.0, 0.0, 0.0, 1.0)) quat = geo2.QuaternionRotationMatrix(mat) if self.model and self.HasBlueInterface( self.model, 'IEveSpaceObject2') and hasattr( self.model, 'modelRotationCurve'): if not self.model.modelRotationCurve: self.model.modelRotationCurve = trinity.TriRotationCurve( 0.0, 0.0, 0.0, 1.0) self.model.modelRotationCurve.value = quat else: self.model.rotationCurve = None
def SetupNextCollision(self): self.hasMoreCollisions = False self.distanceTracker.direction = self.normDirection time = blue.os.GetSimTime() if self.findNext: lastCollision = self.nextCollision self.nextCollision = self.FindNextCollision(self.destination, self.collisions) if self.nextCollision is None: self.nextCollision = lastCollision if self.nextCollision is None: self.collisionCurve.input1 = 1.0 self.fadeInLength.input1 = 0.0 self.collisionCurve.input3 = 100000000 self.collisionCurve.input3 = 100000000 self.distanceTracker.targetObject = None self.distanceTraveled.input1 = 100000000 self.distanceTracker.targetPosition = (0, 0, 100000000) self.distanceTracker.direction = (0, 0, -1) return True targetPosition = self.nextCollision[0].GetVectorAt(time) targetPosition = Vector3(targetPosition.x, targetPosition.y, targetPosition.z) furtherCollision = self.FindNextCollision(self.destination, self.collisions, False) if furtherCollision is not None: self.hasMoreCollisions = True furtherPosition = furtherCollision[0].GetVectorAt(time) furtherPosition = Vector3(furtherPosition.x, furtherPosition.y, furtherPosition.z) length = Vector3(targetPosition - furtherPosition).Length() self.nextPlanetBinding.sourceObject.input2 = length / 2 else: targetPosition = self.nextCollision[0].GetVectorAt(time) targetPosition = Vector3(targetPosition.x, targetPosition.y, targetPosition.z) distanceToCollision = self.GetDistanceToTarget(self.normDirection, targetPosition) returnValue = True if distanceToCollision > self.warpSpeedModifier * 3 * const.AU: self.findNext = False returnValue = False self.nextPlanetBinding.sourceObject.input2 = self.warpSpeedModifier * 3 * const.AU else: self.findNext = True planetRadius = self.nextCollision[0].radius delta = self.CalcEffectiveRadius(self.normDirection, targetPosition, planetRadius) if delta is None: delta = planetRadius self.nextCollision = (self.nextCollision[0], delta) self.collisionCurve.input1 = 1.1 * delta / 10000.0 self.fadeInLength.input1 = 80000 * self.warpSpeedModifier * 3 self.collisionCurve.input3 = abs(distanceToCollision) / 10000.0 self.distanceTracker.targetObject = self.nextCollision[0] self.distanceTraveled.input1 = abs(distanceToCollision) / 10000.0 return returnValue
def SaveLoadProbePositions(self, *args): probeData = sm.GetService("scanSvc").GetProbeData() if probeData == {}: return avg = Vector3(0, 0, 0) for key in probeData: avg = avg + probeData[key].destination avg = avg / len(probeData) shift = uicore.uilib.Key(uiconst.VK_SHIFT) if (shift): pos = [] for key in probeData: pos.append( [probeData[key].destination - avg, probeData[key].rangeStep]) settings.public.ui.Set('ProbePositions', pos) return pos = settings.public.ui.Get('ProbePositions', []) if (pos == []): return i = 0 for key in probeData: sm.GetService("scanSvc").SetProbeDestination(key, pos[i][0] + avg) sm.GetService("scanSvc").SetProbeRangeStep(key, pos[i][1]) i = i + 1 if (i >= len(pos)): break self.UpdateProbeSpheres()
def SendProbes(self, *args): selected = self.sr.resultscroll.GetSelected() try: data = selected[0].result.data except: return if isinstance(data, float): data = selected[0].result.pos if not isinstance(data, Vector3): data = data.point probeData = sm.GetService("scanSvc").GetProbeData() if probeData == {}: return avg = Vector3(0, 0, 0) for key in probeData: avg = avg + probeData[key].destination avg = avg / len(probeData) for key in probeData: destination = data + probeData[key].destination - avg sm.GetService("scanSvc").SetProbeDestination(key, destination) self.UpdateProbeSpheres()
def sendToResult(self): selected = sm.services.get( 'window', None).GetWindow('scanner').sr.resultscroll.GetNodes() try: data = selected[1]["result"].data except: return if isinstance(data, float): data = selected[1]["result"].pos if not isinstance(data, Vector3): data = data.point probeData = sm.GetService("scanSvc").GetProbeData() if probeData == {}: return avg = Vector3(0, 0, 0) for key in probeData: avg = avg + probeData[key].destination avg = avg / len(probeData) for key in probeData: destination = data + probeData[key].destination - avg sm.GetService("scanSvc").SetProbeDestination(key, destination) sm.services.get('window', None).GetWindow('scanner').UpdateProbeSpheres()
def FindClosestPlanetDir(self): bp = sm.StartService('michelle').GetBallpark() dist = 1e+100 closestPlanetID = None for ballID, slimItem in bp.slimItems.iteritems(): if slimItem.groupID == const.groupPlanet: test = bp.DistanceBetween(self.id, ballID) if test < dist: dist = test closestPlanetID = ballID if closestPlanetID is None: return Vector3([1.0, 0.0, 0.0]) planet = bp.GetBall(closestPlanetID) direction = Vector3( [self.x - planet.x, self.y - planet.y, self.z - planet.z]) return direction
def CalcEffectiveRadius(self, direction, planetPosition, planetRadius): distToMiddle = planetPosition * direction if distToMiddle < 0: return None midPoint = direction * distToMiddle distToCenter = Vector3(planetPosition - midPoint).Length() if distToCenter > planetRadius: return None return sqrt(planetRadius * planetRadius - distToCenter * distToCenter)
def AlignToDirection(self): destination = sm.StartService('space').warpDestinationCache[3] ballPark = sm.StartService('michelle').GetBallpark() egoball = ballPark.GetBall(ballPark.ego) direction = [egoball.x - destination[0], egoball.y - destination[1], egoball.z - destination[2]] zaxis = Vector3(direction) if zaxis.Length2() > 0.0: Up = Vector3([0.0, 1.0, 0.0]) zaxis.Normalize() xaxis = Up ^ zaxis if xaxis.Length2() == 0.0: zaxis += Vector3().Randomize(0.0001) zaxis.Normalize() xaxis = Up ^ zaxis xaxis.Normalize() yaxis = zaxis ^ xaxis else: self.transformFlags = effects.FX_TF_POSITION_BALL | effects.FX_TF_ROTATION_BALL self.Prepare() return mat = ((xaxis[0], xaxis[1], xaxis[2], 0.0), (yaxis[0], yaxis[1], yaxis[2], 0.0), (zaxis[0], zaxis[1], zaxis[2], 0.0), (0.0, 0.0, 0.0, 1.0)) quat = geo2.QuaternionRotationMatrix(mat) self.gfxModel.rotationCurve = None if self.gfxModel and hasattr(self.gfxModel, 'modelRotationCurve'): self.gfxModel.modelRotationCurve = trinity.TriRotationCurve(0.0, 0.0, 0.0, 1.0) self.gfxModel.modelRotationCurve.value = quat self.debugAligned = True
def FindNextCollision(self, destination, candidates, popCollision = True): minDist = None time = blue.os.GetSimTime() position = self.shipBall.GetVectorAt(blue.os.GetSimTime()) position = (position.x, position.y, position.z) nextCollision = None for each in candidates: collisionBall = each[0] collisionCenter = collisionBall.GetVectorAt(time) collisionCenter = Vector3(collisionCenter.x, collisionCenter.y, collisionCenter.z) projection = collisionCenter * self.normDirection if minDist is None or projection < minDist: minDist = projection nextCollision = each if nextCollision is not None and popCollision: candidates.remove(nextCollision) return nextCollision
def ExpandProbes(self, *args): probeData = sm.GetService("scanSvc").GetProbeData() if probeData == {}: return avg = Vector3(0, 0, 0) max_range = 1 for key in probeData: max_range = max(max_range, probeData[key].rangeStep) avg = avg + probeData[key].destination if (max_range >= const.scanProbeNumberOfRangeSteps): return avg = avg / len(probeData) for key in probeData: destination = (2 * probeData[key].destination) - avg sm.GetService("scanSvc").SetProbeDestination(key, destination) sm.GetService("scanSvc").SetProbeRangeStep( key, probeData[key].rangeStep + 1) self.UpdateProbeSpheres()
def ContractProbes(self, *args): probeData = sm.GetService("scanSvc").GetProbeData() if probeData == {}: return avg = Vector3(0, 0, 0) min_range = const.scanProbeNumberOfRangeSteps for key in probeData: min_range = min(min_range, probeData[key].rangeStep) avg = avg + probeData[key].destination if (min_range <= 1): return avg = avg / len(probeData) for key in probeData: destination = (probeData[key].destination + avg) / 2 sm.GetService("scanSvc").SetProbeDestination(key, destination) sm.GetService("scanSvc").SetProbeRangeStep( key, probeData[key].rangeStep - 1) self.UpdateProbeSpheres()
def setupProbes(): probeData = sm.GetService("scanSvc").GetProbeData() if probeData == {}: return maxprobes = getMaxProbes() ideallocs = {} scanstep = {} au = 149598000 * 1000 if maxprobes == 8: ideallocs[0] = Vector3(-13 * au, 0, 0) ideallocs[1] = Vector3(13 * au, 0, 0) ideallocs[2] = Vector3(0, 0, -13 * au) ideallocs[3] = Vector3(0, 0, 13 * au) ideallocs[4] = Vector3(-1.625 * au, 0, 0) ideallocs[5] = Vector3(1.625 * au, 0, 0) ideallocs[6] = Vector3(0, 0, -1.625 * au) ideallocs[7] = Vector3(0, 0, 1.625 * au) scanstep[0] = 8 scanstep[1] = 8 scanstep[2] = 8 scanstep[3] = 8 scanstep[4] = 5 scanstep[5] = 5 scanstep[6] = 5 scanstep[7] = 5 if maxprobes == 7: ideallocs[0] = Vector3(-13 * au, 0, 0) ideallocs[1] = Vector3(13 * au, 0, 0) ideallocs[2] = Vector3(0, -13 * au, 0) ideallocs[3] = Vector3(0, 13 * au, 0) ideallocs[4] = Vector3(0, 0, -13 * au) ideallocs[5] = Vector3(0, 0, 13 * au) ideallocs[6] = Vector3(0, 0, .1 * au) scanstep[0] = 8 scanstep[1] = 8 scanstep[2] = 8 scanstep[3] = 8 scanstep[4] = 8 scanstep[5] = 8 scanstep[6] = 6 if maxprobes == 6: ideallocs[0] = Vector3(-13 * au, 0, 0) ideallocs[1] = Vector3(13 * au, 0, 0) ideallocs[2] = Vector3(0, -13 * au, 0) ideallocs[3] = Vector3(0, 13 * au, 0) ideallocs[4] = Vector3(0, 0, -13 * au) ideallocs[5] = Vector3(0, 0, 13 * au) scanstep[0] = 8 scanstep[1] = 8 scanstep[2] = 8 scanstep[3] = 8 scanstep[4] = 8 scanstep[5] = 8 if maxprobes == 5: ideallocs[0] = Vector3(-13 * au, 0, 0) ideallocs[1] = Vector3(13 * au, 0, 0) ideallocs[2] = Vector3(0, -13 * au, 0) ideallocs[3] = Vector3(0, 13 * au, 0) ideallocs[4] = Vector3(0, 0, .1 * au) scanstep[0] = 8 scanstep[1] = 8 scanstep[2] = 8 scanstep[3] = 8 scanstep[4] = 6 if maxprobes == 4: ideallocs[0] = Vector3(-13 * au, 0, 0) ideallocs[1] = Vector3(13 * au, 0, 0) ideallocs[2] = Vector3(0, -13 * au, 0) ideallocs[3] = Vector3(0, 13 * au, 0) scanstep[0] = 8 scanstep[1] = 8 scanstep[2] = 8 scanstep[3] = 8 i = 0 for key in probeData: sm.GetService("scanSvc").SetProbeDestination(key, ideallocs[i]) sm.GetService("scanSvc").SetProbeRangeStep(key, scanstep[i]) i = i + 1 if (i >= len(ideallocs)): break