planetCamera.py (4190B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\camera\planetCamera.py 2 import math 3 import geo2 4 from carbonui.uianimations import animations 5 from eve.client.script.ui.camera.baseCamera import Camera 6 import evecamera 7 OFFSET = 0.05 8 K_FOVOFFSET = 0.25 9 K_YOFFSET = 500 10 K_LOOKATDIROFFSET = 850 11 K_ORBITTO_PITCHOFFSET = 0.12 12 K_ZOOMDIFF_ANIMDURATION = 1.4 13 ANIM_DURATION = 0.5 14 15 class PlanetCamera(Camera): 16 cameraID = evecamera.CAM_PLANET 17 maxZoom = 1100.0 18 minZoom = 4000.0 19 kMinPitch = 0.1 20 kMaxPitch = math.pi - kMinPitch 21 kZoomSpeed = 5.0 22 name = 'PlanetCamera' 23 24 def __init__(self): 25 Camera.__init__(self) 26 self.callback = None 27 28 def SetCallback(self, callback): 29 self.callback = callback 30 31 def Update(self): 32 atOffset = self._GetAtOffset() 33 lookAtOffset = atOffset 34 self._AddToAtOffset(lookAtOffset) 35 self.fovOffset = K_FOVOFFSET * (1.0 - self.zoomLinear) 36 if self.callback: 37 self.callback() 38 Camera.Update(self) 39 40 def _GetAtOffset(self): 41 eaquatorDistProp = self.GetEquatorDistanceProp() 42 zoom = self.GetZoomProportionLinear() 43 zoomProp = (1.0 - zoom) ** 7 44 offsetDir = geo2.Vec3Normalize((-self._eyePosition[0], eaquatorDistProp * K_YOFFSET, -self._eyePosition[2])) 45 offsetAmount = K_LOOKATDIROFFSET * eaquatorDistProp * zoomProp 46 offsetDir = geo2.Vec3Scale(offsetDir, math.fabs(offsetAmount)) 47 return offsetDir 48 49 def GetEquatorDistanceProp(self): 50 equatorDistProp = self.GetEquatorDistancePropLinear(self.pitch) 51 equatorDistProp = math.copysign(math.fabs(equatorDistProp) ** 0.35, equatorDistProp) 52 return equatorDistProp 53 54 def GetOrbitPoint(self): 55 return (0, 0, 0) 56 57 def GetZoomToPoint(self): 58 return (0, 0, 0) 59 60 def GetLookAtDirectionWithOffset(self): 61 return self.GetLookAtDirection() 62 63 def OrbitToSurfacePoint(self, surfacePoint, newZoom = None, initStartPos = False): 64 self.StopUpdateThreads() 65 yaw = self._GetYaw(surfacePoint) 66 pitch = self._GetPitch(surfacePoint) 67 if initStartPos: 68 yaw0, pitch0 = self._InitStartPosition(yaw, pitch) 69 self.yaw = yaw0 70 self.pitch = pitch0 71 self.zoomLinear = newZoom * 1.5 72 duration = 1.2 73 else: 74 yaw0, pitch0, zoomLinear0 = self.yaw, self.pitch, self.zoomLinear 75 duration = self.GetAnimDuration(yaw, pitch, newZoom) 76 animations.MorphScalar(self, 'yaw', yaw0, yaw, duration=duration) 77 animations.MorphScalar(self, 'pitch', pitch0, pitch, duration=duration) 78 animations.MorphScalar(self, 'zoomLinear', self.zoomLinear, newZoom, duration=duration) 79 80 def Orbit(self, dx = 0, dy = 0): 81 Camera.Orbit(self, dx, dy) 82 self.StopAnimations() 83 84 def Zoom(self, dz): 85 Camera.Zoom(self, dz) 86 self.StopAnimations() 87 88 def _InitStartPosition(self, yaw, pitch): 89 yaw += OFFSET 90 if self.pitch > math.pi / 2: 91 pitch -= OFFSET 92 else: 93 pitch += OFFSET 94 return (yaw, pitch) 95 96 def _GetPitch(self, surfacePoint): 97 pitch = surfacePoint.phi 98 equatorDistProp = self.GetEquatorDistancePropLinear(pitch) 99 pitch += K_ORBITTO_PITCHOFFSET * equatorDistProp 100 pitch = max(self.kMinPitch, min(pitch, self.kMaxPitch)) 101 return pitch 102 103 def GetEquatorDistancePropLinear(self, pitch): 104 return 1.0 - pitch / (math.pi / 2) 105 106 def _GetYaw(self, surfacePoint): 107 yaw = -surfacePoint.theta - math.pi / 2.0 108 if math.fabs(self.yaw - yaw) > math.pi: 109 if self.yaw > yaw: 110 yaw += 2 * math.pi 111 else: 112 yaw -= 2 * math.pi 113 return yaw 114 115 def GetAnimDuration(self, yaw, pitch, zoom): 116 yawDiff = math.fabs(self.yaw - yaw) * (1.0 - self.GetEquatorDistancePropLinear(pitch)) 117 pitchDiff = math.fabs(self.pitch - pitch) 118 zoomDiff = K_ZOOMDIFF_ANIMDURATION * math.fabs(self.zoomLinear - zoom) 119 diff = max(yawDiff, pitchDiff, zoomDiff) 120 return ANIM_DURATION * (1.2 + diff)