debugCamera.py (7406B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\camera\debugCamera.py 2 import geo2 3 import math 4 import blue 5 from carbonui.camera.polarCamera import PolarCamera 6 from eve.common.lib import appConst as const 7 8 class DebugCamera(PolarCamera): 9 10 def __init__(self): 11 self.updatingDebugCamera = True 12 self.showNormalCamera = False 13 self.translationVector = [0.0, 0.0, 0.0] 14 normCam = self._GetNonDebugCamera() 15 self.lastCamPos = normCam.GetPosition() if normCam else (0.0, 0.0, 0.0) 16 self.debugRenderClient = sm.GetService('debugRenderClient') 17 self.debugRenderClient.SetDebugRendering(True) 18 PolarCamera.__init__(self) 19 20 def IsUpdatingDebugCamera(self): 21 return self.updatingDebugCamera 22 23 def ToggleDebugCameraUpdate(self): 24 self.updatingDebugCamera = not self.updatingDebugCamera 25 26 def IsShowingNormalCamera(self): 27 return self.showNormalCamera 28 29 def SetShowNormalCamera(self, showCamera): 30 self.showNormalCamera = showCamera 31 self.lastCamPos = None 32 self.debugRenderClient.ClearAllShapes() 33 34 def AdjustDebugCamYaw(self, delta, maxRotate = None, ignoreUpdate = True): 35 if self.IsUpdatingDebugCamera(): 36 PolarCamera.AdjustYaw(self, delta, maxRotate, ignoreUpdate) 37 38 def AdjustDebugCamPitch(self, delta): 39 if self.IsUpdatingDebugCamera(): 40 PolarCamera.AdjustPitch(self, delta) 41 42 def IsControlEnabled(self): 43 return not self.IsUpdatingDebugCamera() 44 45 def GetTranslationVector(self): 46 return self.translationVector 47 48 def SetTranslationVector(self, translationVector): 49 self.translationVector = translationVector 50 51 def _GetNonDebugCamera(self): 52 return None 53 54 def Update(self): 55 normalCamera = self._GetNonDebugCamera() 56 if not self.IsUpdatingDebugCamera() and normalCamera: 57 if normalCamera: 58 normalCamera.Update() 59 if self.IsShowingNormalCamera() and normalCamera: 60 camPos = normalCamera.GetPosition() 61 poi = normalCamera.GetPointOfInterest() 62 vec = geo2.Vec3Subtract(poi, camPos) 63 vec = geo2.Vec3Normalize(vec) 64 vec = geo2.Vec3Scale(vec, 0.5) 65 self.debugRenderClient.RenderCone(camPos, geo2.Vec3Add(camPos, vec), 0.25, 4278190335L, time=1) 66 if self.lastCamPos is not None and camPos != self.lastCamPos: 67 self.debugRenderClient.RenderRay(self.lastCamPos, camPos, 4278190335L, 4278255360L, time=1000, pulse=True) 68 self.lastCamPos = camPos 69 if self.translationVector != [0.0, 0.0, 0.0]: 70 now = blue.os.GetWallclockTime() 71 frameTime = float(now - self.lastUpdateTime) / const.SEC 72 poi = PolarCamera.GetPointOfInterest(self) 73 rotMatrix = geo2.MatrixRotationYawPitchRoll(math.pi / 2.0 - self.yaw, math.pi / 2.0 - self.pitch, 0.0) 74 scaledVector = geo2.Vec3Scale(self.translationVector, frameTime) 75 relativeVector = geo2.Vec3TransformCoord(scaledVector, rotMatrix) 76 newPos = geo2.Vec3Add(poi, relativeVector) 77 PolarCamera.SetPointOfInterest(self, newPos) 78 PolarCamera.Update(self) 79 80 def SetRotationWithYaw(self, yawValue): 81 if not self.IsUpdatingDebugCamera(): 82 normalCamera = self._GetNonDebugCamera() 83 if normalCamera: 84 normalCamera.SetRotationWithYaw(yawValue) 85 86 def AdjustZoomFactorByZoom(self, delta): 87 if not self.IsUpdatingDebugCamera(): 88 normalCamera = self._GetNonDebugCamera() 89 if normalCamera: 90 normalCamera.AdjustZoomFactorByZoom(delta) 91 92 def SetPointOfInterest(self, poi): 93 if self.IsUpdatingDebugCamera(): 94 PolarCamera.SetPointOfInterest(self, poi) 95 else: 96 normalCamera = self._GetNonDebugCamera() 97 if normalCamera: 98 normalCamera.SetPointOfInterest(poi) 99 100 def AdjustPitch(self, delta): 101 if not self.IsUpdatingDebugCamera(): 102 normalCamera = self._GetNonDebugCamera() 103 if normalCamera: 104 normalCamera.AdjustPitch(delta) 105 106 def SetPitch(self, value): 107 if self.IsUpdatingDebugCamera(): 108 PolarCamera.SetPitch(self, value) 109 else: 110 normalCamera = self._GetNonDebugCamera() 111 if normalCamera: 112 normalCamera.SetPitch(value) 113 114 def SetPosition(self, position): 115 if self.IsUpdatingDebugCamera(): 116 PolarCamera.SetPosition(self, position) 117 else: 118 normalCamera = self._GetNonDebugCamera() 119 if normalCamera: 120 normalCamera.SetPosition(position) 121 122 def SetYawPitchDist(self, yaw, pitch, dist): 123 if self.IsUpdatingDebugCamera(): 124 PolarCamera.SetYawPitchDist(self, yaw, pitch, dist) 125 else: 126 normalCamera = self._GetNonDebugCamera() 127 if normalCamera: 128 normalCamera.SetYawPitchDist(yaw, pitch, dist) 129 130 def SetYaw(self, value, ignoreUpdate = True): 131 if self.IsUpdatingDebugCamera(): 132 PolarCamera.SetYaw(self, value, ignoreUpdate) 133 else: 134 normalCamera = self._GetNonDebugCamera() 135 if normalCamera: 136 normalCamera.SetYaw(value, ignoreUpdate) 137 138 def AdjustYaw(self, delta, maxRotate = None, ignoreUpdate = True): 139 if not self.IsUpdatingDebugCamera(): 140 normalCamera = self._GetNonDebugCamera() 141 if normalCamera: 142 normalCamera.AdjustYaw(delta, maxRotate, ignoreUpdate) 143 144 def AdjustZoom(self, delta): 145 if self.IsUpdatingDebugCamera(): 146 PolarCamera.AdjustZoom(self, delta) 147 else: 148 normalCamera = self._GetNonDebugCamera() 149 if normalCamera: 150 normalCamera.AdjustZoom(delta) 151 152 def SetZoom(self, zoom): 153 if self.IsUpdatingDebugCamera(): 154 PolarCamera.SetZoom(self, zoom) 155 else: 156 normalCamera = self._GetNonDebugCamera() 157 if normalCamera: 158 normalCamera.SetZoom(zoom) 159 160 def SmoothMove(self, targetPosition, targetRotation, targetTilt, targetDist, durationMS, callbackOnEnd = None): 161 if self.IsUpdatingDebugCamera(): 162 PolarCamera.SmoothMove(self, targetPosition, targetRotation, targetTilt, targetDist, durationMS, callbackOnEnd) 163 else: 164 normalCamera = self._GetNonDebugCamera() 165 if normalCamera: 166 normalCamera.SmoothMove(targetPosition, targetRotation, targetTilt, targetDist, durationMS, callbackOnEnd) 167 168 def UpdateSmoothMove(self, *args): 169 if self.IsUpdatingDebugCamera(): 170 PolarCamera.UpdateSmoothMove(self, *args) 171 else: 172 normalCamera = self._GetNonDebugCamera() 173 if normalCamera: 174 normalCamera.UpdateSmoothMove(*args) 175 176 def GetPosition(self): 177 normalCamera = self._GetNonDebugCamera() 178 return normalCamera.GetPosition() 179 180 def GetYaw(self): 181 normalCamera = self._GetNonDebugCamera() 182 return normalCamera.GetYaw() 183 184 def GetPitch(self): 185 normalCamera = self._GetNonDebugCamera() 186 return normalCamera.GetPitch() 187 188 def GetYawPitch(self): 189 normalCamera = self._GetNonDebugCamera() 190 return normalCamera.GetYawPitch()