def FindDist(currentDist, bookmark, ownBall, bp): dist = currentDist if bookmark and bookmark.locationID and bookmark.locationID == session.solarsystemid: if ownBall: myLoc = (ownBall.x, ownBall.y, ownBall.z) else: myLoc = None if (bookmark.typeID == const.typeSolarSystem or bookmark.itemID == bookmark.locationID) and bookmark.x is not None: location = None if hasattr(bookmark, 'locationType') and bookmark.locationType in ( 'agenthomebase', 'objective'): location = sm.GetService('agents').GetAgentMoniker( bookmark.agentID).GetEntryPoint() if location is None: location = (bookmark.x, bookmark.y, bookmark.z) if myLoc and location: dist = geo2.Vec3DistanceD(myLoc, location) else: dist = 0 else: dist = 0.0 if bookmark.itemID in bp.balls: b = bp.balls[bookmark.itemID] dist = b.surfaceDist return dist
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 = (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 = (furtherPosition.x, furtherPosition.y, furtherPosition.z) length = geo2.Vec3DistanceD(targetPosition, furtherPosition) self.nextPlanetBinding.sourceObject.input2 = length / 2 else: targetPosition = self.nextCollision[0].GetVectorAt(time) targetPosition = (targetPosition.x, targetPosition.y, targetPosition.z) distanceToCollision = self.GetDistanceToTarget(self.normDirection, targetPosition) returnValue = True warpSpeed = self.warpSpeedModifier * const.AU if distanceToCollision > warpSpeed: self.findNext = False returnValue = False self.nextPlanetBinding.sourceObject.input2 = warpSpeed 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 CalcEffectiveRadius(self, direction, planetPosition, planetRadius): distToMiddle = geo2.Vec3DotD(planetPosition, direction) if distToMiddle < 0: return None midPoint = geo2.Vec3ScaleD(direction, distToMiddle) distToCenter = geo2.Vec3DistanceD(planetPosition, midPoint) if distToCenter > planetRadius: return None return sqrt(planetRadius * planetRadius - distToCenter * distToCenter)
def CalcEffectiveRadius(self, direction, planetPosition, planetRadius): """ Effective radius is half the distance through the planet along the ray of intersection(direction). Assumes player ship is at (0,0,0) direction - normalized direction """ distToMiddle = geo2.Vec3DotD(planetPosition, direction) if distToMiddle < 0: return None midPoint = geo2.Vec3ScaleD(direction, distToMiddle) distToCenter = geo2.Vec3DistanceD(planetPosition, midPoint) if distToCenter > planetRadius: return None return sqrt(planetRadius * planetRadius - distToCenter * distToCenter)
def _GetDistance(self, pos): if self.pos is not None: return geo2.Vec3DistanceD(pos, self.pos) else: return