def ZoomToDistance(self, endCameraDistance, immediate=True): endCameraDistance = min(self.maxDistance, max(self.minDistance, endCameraDistance)) eyePositionNorm = geo2.Vec3NormalizeD(self._eyePosition) self._eyePosition = geo2.Vec3ScaleD(eyePositionNorm, endCameraDistance) if immediate: self._eyePositionCurrent = self._eyePosition
def PanUpdateThread(self): try: while True: if self.panTarget is None: break if self._IsPanTargetOutOfBounds(): return distLeft = geo2.Vec3LengthD(self.panTarget) if distLeft == 0: break if distLeft < self.kPanStopDist: dist = 1.0 else: dist = min(1.0, self._GetPanSpeed() / blue.os.fps) toMove = geo2.Vec3ScaleD(self.panTarget, dist) self.SetEyePosition(geo2.Vec3Add(self._eyePosition, toMove)) self.SetAtPosition(geo2.Vec3Add(self._atPosition, toMove)) self.panTarget = geo2.Vec3SubtractD(self.panTarget, toMove) if dist == 1.0: break blue.synchro.Yield() finally: self.panUpdateThread = None self.panTarget = None
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 Update(self, center, range, closestPoints, width): self.AddLinesToScene() self.ClearLines() d0 = geo2.Vec3SubtractD(center, closestPoints[0]) d1 = geo2.Vec3SubtractD(center, closestPoints[1]) up = geo2.Vec3NormalizeD(geo2.Vec3CrossD(d1, d0)) dir = geo2.Vec3NormalizeD(d0) pFar = geo2.Vec3AddD(center, geo2.Vec3ScaleD(dir, range)) pNear = geo2.Vec3AddD(center, geo2.Vec3ScaleD(dir, -range)) perp = geo2.Vec3NormalizeD(geo2.Vec3CrossD(dir, up)) pRight = geo2.Vec3AddD(center, geo2.Vec3ScaleD(perp, range)) pLeft = geo2.Vec3AddD(center, geo2.Vec3ScaleD(perp, -range)) width *= LINE_WIDTH self.lineSet.AddSpheredLineCrt(pFar, DEFAULT_COLOR, pRight, DEFAULT_COLOR, center, width) self.lineSet.AddSpheredLineCrt(pRight, DEFAULT_COLOR, pNear, DEFAULT_COLOR, center, width) self.lineSet.AddSpheredLineCrt(pNear, DEFAULT_COLOR, pLeft, DEFAULT_COLOR, center, width) self.lineSet.AddSpheredLineCrt(pLeft, DEFAULT_COLOR, pFar, DEFAULT_COLOR, center, width) self.lineSet.SubmitChanges()
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 Update(self): pointOfInterestOverrideValue = self.GetPointOfInterestOverrideValue() if pointOfInterestOverrideValue is not None: self._pointOfInterest = pointOfInterestOverrideValue elif self.followMarker: followMarker = self.followMarker() if followMarker: markerPosition = followMarker.GetDisplayPosition() if markerPosition is not None: self._pointOfInterest = markerPosition speedFactor = 0.4 diff = geo2.Vec3Subtract(self._pointOfInterest, self._pointOfInterestCurrent) diffLength = geo2.Vec3Length(diff) if diffLength > 0.001: addVector = geo2.Vec3ScaleD(diff, speedFactor) newPosition = geo2.Vec3Add(self._pointOfInterestCurrent, addVector) if geo2.Vec3Equal(newPosition, self._pointOfInterestCurrent): newPosition = self._pointOfInterest self._pointOfInterestCurrent = newPosition else: self._pointOfInterestCurrent = self._pointOfInterest if abs(self._yawSpeed) > 0.0001: yawChange = self._yawSpeed * speedFactor rotYaw = geo2.MatrixRotationAxis(self.upVector, yawChange) self._eyePositionCurrent = geo2.Vec3Transform( self._eyePositionCurrent, rotYaw) currentPositionN = geo2.Vec3Normalize(self._eyePositionCurrent) self._eyePosition = geo2.Vec3Scale( currentPositionN, geo2.Vec3Length(self._eyePosition)) self._yawSpeed -= yawChange else: self._yawSpeed = 0.0 if abs(self._pitchSpeed) > 0.0001: pitchChange = self._pitchSpeed * speedFactor viewVectorNormalized = geo2.Vec3Normalize(self._eyePositionCurrent) axis = geo2.Vec3Cross(viewVectorNormalized, self.upVector) rotPitch = geo2.MatrixRotationAxis(axis, pitchChange) self._eyePositionCurrent = geo2.Vec3Transform( self._eyePositionCurrent, rotPitch) currentPositionN = geo2.Vec3NormalizeD(self._eyePositionCurrent) self._eyePosition = geo2.Vec3ScaleD( currentPositionN, geo2.Vec3Length(self._eyePosition)) self._pitchSpeed -= pitchChange else: self._pitchSpeed = 0.0 setCameraDistance = geo2.Vec3Length(self._eyePosition) currentCameraDistance = geo2.Vec3Length(self._eyePositionCurrent) cameraDistanceDiff = setCameraDistance - currentCameraDistance if math.fabs(cameraDistanceDiff) > 0.001: usedDist = cameraDistanceDiff * speedFactor * 0.5 viewVectorNormalized = geo2.Vec3NormalizeD( self._eyePositionCurrent) newDistance = min( self.maxDistance, max(self.minDistance, currentCameraDistance + usedDist)) self._eyePositionCurrent = geo2.Vec3ScaleD(viewVectorNormalized, newDistance) self.UpdateProjection() self.UpdateView() if self.callback: self.callback()