def __cameraUpdate(self): currentTime = BigWorld.timeExact() self.__elapsedTime += currentTime - self.__prevTime self.__prevTime = currentTime interpolationCoefficient = self.__easingMethod( self.__elapsedTime, 1.0, self.__totalInterpolationTime) interpolationCoefficient = mathUtils.clamp(0.0, 1.0, interpolationCoefficient) iSource = self.__initialState.source iTarget = self.__initialState.target.b.translation iPivotPosition = self.__initialState.pivotPosition fSource = self.__finalState.source fTarget = self.__finalState.target.b.translation fPivotPosition = self.__finalState.pivotPosition self.__cam.source = Math.slerp(iSource, fSource, interpolationCoefficient) self.__cam.target.b.translation = mathUtils.lerp( iTarget, fTarget, interpolationCoefficient) self.__cam.pivotPosition = mathUtils.lerp(iPivotPosition, fPivotPosition, interpolationCoefficient) BigWorld.projection().fov = mathUtils.lerp(self.__initialFov, self.__finalFov, interpolationCoefficient) if self.__elapsedTime > self.__totalInterpolationTime: self.delayCallback(0.0, self.disable) return 10.0
def __interpolateStates(self, deltaTime, translation, rotation): lerpParam = mathUtils.clamp( 0.0, 1.0, deltaTime * self.__cfg['interpolationSpeed']) self.__sourceMatrix = slerp(self.__sourceMatrix, rotation, lerpParam) self.__targetMatrix.translation = mathUtils.lerp( self.__targetMatrix.translation, translation, lerpParam) return (self.__sourceMatrix, self.__targetMatrix)
def teleport(self, relativeFocusDist, minMaxZoomMultiplier = None): if minMaxZoomMultiplier is not None: self.__minMaxZoomMultiplier = minMaxZoomMultiplier self.__deltaEasing.reset(Vector3(0.0), Vector3(0.0), _InputInertia.__ZOOM_DURATION) fovMultiplier = mathUtils.lerp(self.__minMaxZoomMultiplier.min, self.__minMaxZoomMultiplier.max, relativeFocusDist) self.__zoomMultiplierEasing.reset(fovMultiplier, fovMultiplier, _InputInertia.__ZOOM_DURATION) return
def __updateOscillators(self, deltaTime): if not ArcadeCamera.isCameraDynamic(): self.__impulseOscillator.reset() self.__movementOscillator.reset() self.__noiseOscillator.reset() return (Vector3(0), Vector3(0), 1.0) oscillatorAcceleration = self.__calcCurOscillatorAcceleration( deltaTime) self.__movementOscillator.externalForce += oscillatorAcceleration self.__impulseOscillator.update(deltaTime) self.__movementOscillator.update(deltaTime) self.__noiseOscillator.update(deltaTime) self.__impulseOscillator.externalForce = Vector3(0) self.__movementOscillator.externalForce = Vector3(0) self.__noiseOscillator.externalForce = Vector3(0) relDist = self.__calcRelativeDist() zoomMultiplier = mathUtils.lerp(1.0, self.__dynamicCfg['zoomExposure'], relDist) impulseDeviation = Vector3(self.__impulseOscillator.deviation) impulseDeviation.set(impulseDeviation.x * zoomMultiplier, impulseDeviation.y * zoomMultiplier, impulseDeviation.z * zoomMultiplier) movementDeviation = Vector3(self.__movementOscillator.deviation) movementDeviation.set(movementDeviation.x * zoomMultiplier, movementDeviation.y * zoomMultiplier, movementDeviation.z * zoomMultiplier) return (impulseDeviation, movementDeviation, zoomMultiplier)
def __updateCameraByMouseMove(self, dx, dy, dz): if self.__cam is not BigWorld.camera(): return sourceMat = Math.Matrix(self.__cam.source) yaw = sourceMat.yaw pitch = sourceMat.pitch dist = self.__cam.pivotMaxDist currentMatrix = Math.Matrix(self.__cam.invViewMatrix) currentYaw = currentMatrix.yaw yaw = self.__yawCameraFilter.getNextYaw(currentYaw, yaw, dx) from gui.ClientHangarSpace import hangarCFG cfg = hangarCFG() pitch -= dy * cfg['cam_sens'] dist -= dz * cfg['cam_dist_sens'] camPitchConstr = self.__camConstraints[0] startPitch, endPitch = camPitchConstr pitch = mathUtils.clamp(math.radians(startPitch), math.radians(endPitch), pitch) distConstr = cfg['preview_cam_dist_constr'] if self.__selectedEmblemInfo else self.__camConstraints[2] minDist, maxDist = distConstr dist = mathUtils.clamp(minDist, maxDist, dist) self.__locatedOnEmbelem = False mat = Math.Matrix() mat.setRotateYPR((yaw, pitch, 0.0)) self.__cam.source = mat self.__cam.pivotMaxDist = dist if self.settingsCore.getSetting('dynamicFov') and abs(distConstr[1] - distConstr[0]) > 0.001: relativeDist = (dist - distConstr[0]) / (distConstr[1] - distConstr[0]) _, minFov, maxFov = self.settingsCore.getSetting('fov') fov = mathUtils.lerp(minFov, maxFov, relativeDist) BigWorld.callback(0, partial(FovExtended.instance().setFovByAbsoluteValue, math.radians(fov), 0.1))
def __init__(self, minMaxZoomMultiplier, relativeFocusDist): self.__deltaEasing = _INERTIA_EASING(Vector3(0.0), Vector3(0.0), _InputInertia.__ZOOM_DURATION) fovMultiplier = mathUtils.lerp(minMaxZoomMultiplier.min, minMaxZoomMultiplier.max, relativeFocusDist) self.__zoomMultiplierEasing = _INERTIA_EASING( fovMultiplier, fovMultiplier, _InputInertia.__ZOOM_DURATION) self.__minMaxZoomMultiplier = minMaxZoomMultiplier
def __updateDynamicFOV(self, time): if not self.__goalFov or not self.__startFov: return if time > self.__easeInDuration: return time /= self.__easeInDuration fov = mathUtils.lerp(self.__startFov, self.__goalFov, time) BigWorld.callback( 0.0, partial(FovExtended.instance().setFovByAbsoluteValue, fov, 0.1))
def __startFovIfDynamic(self): if not self.settingsCore.getSetting('dynamicFov'): return _, minFov, maxFov = self.settingsCore.getSetting('fov') distConstr = g_hangarSpace.space.getCameraLocation( )['camConstraints'][2] relativeDist = (self.__goalDistance - distConstr[0]) / (distConstr[1] - distConstr[0]) self.__startFov = BigWorld.projection().fov self.__goalFov = mathUtils.lerp(math.radians(minFov), math.radians(maxFov), relativeDist)
def teleport(self, relativeFocusDist, minMaxZoomMultiplier=None): if minMaxZoomMultiplier is not None: self.__minMaxZoomMultiplier = minMaxZoomMultiplier self.__deltaEasing.reset(Vector3(0.0), Vector3(0.0), _InputInertia.__ZOOM_DURATION) fovMultiplier = mathUtils.lerp(self.__minMaxZoomMultiplier.min, self.__minMaxZoomMultiplier.max, relativeFocusDist) self.__zoomMultiplierEasing.reset(fovMultiplier, fovMultiplier, _InputInertia.__ZOOM_DURATION) return
def updateCameraByMouseMove(self, dx, dy, dz): if self.__selectedEmblemInfo is not None: self.__cam.target.setTranslate( _CFG['preview_cam_start_target_pos']) self.__cam.pivotPosition = _CFG['preview_cam_pivot_pos'] if self.__locatedOnEmbelem: self.__cam.maxDistHalfLife = 0.0 else: self.__cam.maxDistHalfLife = _CFG['cam_fluency'] sourceMat = Math.Matrix(self.__cam.source) yaw = sourceMat.yaw pitch = sourceMat.pitch dist = self.__cam.pivotMaxDist currentMatrix = Math.Matrix(self.__cam.invViewMatrix) currentYaw = currentMatrix.yaw yaw = self.__yawCameraFilter.getNextYaw(currentYaw, yaw, dx) pitch -= dy * _CFG['cam_sens'] dist -= dz * _CFG['cam_sens'] pitch = mathUtils.clamp(math.radians(_CFG['cam_pitch_constr'][0]), math.radians(_CFG['cam_pitch_constr'][1]), pitch) prevDist = dist distConstr = self.__camDistConstr[ 1] if self.__selectedEmblemInfo is not None else self.__camDistConstr[ 0] dist = mathUtils.clamp(distConstr[0], distConstr[1], dist) if self.__boundingRadius is not None: boundingRadius = self.__boundingRadius if self.__boundingRadius < distConstr[ 1] else distConstr[1] dist = dist if dist > boundingRadius else boundingRadius if dist > prevDist and dz > 0: if self.__selectedEmblemInfo is not None: self.locateCameraOnEmblem(*self.__selectedEmblemInfo) return self.__locatedOnEmbelem = False mat = Math.Matrix() mat.setRotateYPR((yaw, pitch, 0.0)) self.__cam.source = mat self.__cam.pivotMaxDist = dist if self.settingsCore.getSetting( 'dynamicFov') and abs(distConstr[1] - distConstr[0]) > 0.001: relativeDist = (dist - distConstr[0]) / (distConstr[1] - distConstr[0]) _, minFov, maxFov = self.settingsCore.getSetting('fov') fov = mathUtils.lerp(minFov, maxFov, relativeDist) BigWorld.callback( 0, functools.partial(FovExtended.instance().setFovByAbsoluteValue, math.radians(fov), 0.1)) return
def __interpolateAim(self, worldStartPosition, worldEndPositionGetter, worldStartAim, worldEndAim, t): relativeStartAim = worldStartAim - worldStartPosition relativeEndAim = worldEndAim - worldEndPositionGetter() deltaAngle = self.__lastTransitionEndAimYaw - relativeEndAim.yaw if math.fabs(deltaAngle) > math.pi and not self.__transitionYawDirty: self.__tansitionYawRevolutions += math.copysign(1, deltaAngle) self.__lastTransitionEndAimYaw = self.__lastTransitionEndAimYaw - deltaAngle + math.copysign( math.pi, deltaAngle) else: self.__lastTransitionEndAimYaw = relativeEndAim.yaw self.__transitionYawDirty = False targetYaw = self.__lastTransitionEndAimYaw + self.__tansitionYawRevolutions * 2 * math.pi angles = mathUtils.lerp( Math.Vector2(relativeStartAim.pitch, relativeStartAim.yaw), Math.Vector2(relativeEndAim.pitch, targetYaw), t) result = Math.Vector3() result.setPitchYaw(angles.x, angles.y) result = result.scale(1000) return Math.Vector3( self.__cam.cameraPositionProvider.value[0:3]) + result
def __updateOscillators(self, deltaTime): if not ArcadeCamera.isCameraDynamic(): self.__impulseOscillator.reset() self.__movementOscillator.reset() self.__noiseOscillator.reset() return (Vector3(0), Vector3(0), 1.0) oscillatorAcceleration = self.__calcCurOscillatorAcceleration(deltaTime) self.__movementOscillator.externalForce += oscillatorAcceleration self.__impulseOscillator.update(deltaTime) self.__movementOscillator.update(deltaTime) self.__noiseOscillator.update(deltaTime) self.__impulseOscillator.externalForce.set(0, 0, 0) self.__movementOscillator.externalForce.set(0, 0, 0) self.__noiseOscillator.externalForce.set(0, 0, 0) relDist = self.__calcRelativeDist() zoomMultiplier = mathUtils.lerp(1.0, self.__dynamicCfg['zoomExposure'], relDist) impulseDeviation = Vector3(self.__impulseOscillator.deviation) impulseDeviation.set(impulseDeviation.x * zoomMultiplier, impulseDeviation.y * zoomMultiplier, impulseDeviation.z * zoomMultiplier) movementDeviation = Vector3(self.__movementOscillator.deviation) movementDeviation.set(movementDeviation.x * zoomMultiplier, movementDeviation.y * zoomMultiplier, movementDeviation.z * zoomMultiplier) return (impulseDeviation, movementDeviation, zoomMultiplier)
def updateCameraByMouseMove(self, dx, dy, dz): if self.__selectedEmblemInfo is not None: self.__cam.target.setTranslate(_CFG['preview_cam_start_target_pos']) self.__cam.pivotPosition = _CFG['preview_cam_pivot_pos'] if self.__locatedOnEmbelem: self.__cam.maxDistHalfLife = 0.0 else: self.__cam.maxDistHalfLife = _CFG['cam_fluency'] sourceMat = Math.Matrix(self.__cam.source) yaw = sourceMat.yaw pitch = sourceMat.pitch dist = self.__cam.pivotMaxDist currentMatrix = Math.Matrix(self.__cam.invViewMatrix) currentYaw = currentMatrix.yaw yaw = self.__yawCameraFilter.getNextYaw(currentYaw, yaw, dx) pitch -= dy * _CFG['cam_sens'] dist -= dz * _CFG['cam_sens'] pitch = mathUtils.clamp(math.radians(_CFG['cam_pitch_constr'][0]), math.radians(_CFG['cam_pitch_constr'][1]), pitch) prevDist = dist distConstr = self.__camDistConstr[1] if self.__selectedEmblemInfo is not None else self.__camDistConstr[0] dist = mathUtils.clamp(distConstr[0], distConstr[1], dist) if self.__boundingRadius is not None: boundingRadius = self.__boundingRadius if self.__boundingRadius < distConstr[1] else distConstr[1] dist = dist if dist > boundingRadius else boundingRadius if dist > prevDist and dz > 0: if self.__selectedEmblemInfo is not None: self.locateCameraOnEmblem(*self.__selectedEmblemInfo) return self.__locatedOnEmbelem = False mat = Math.Matrix() mat.setRotateYPR((yaw, pitch, 0.0)) self.__cam.source = mat self.__cam.pivotMaxDist = dist if g_settingsCore.getSetting('dynamicFov') and abs(distConstr[1] - distConstr[0]) > 0.001: relativeDist = (dist - distConstr[0]) / (distConstr[1] - distConstr[0]) _, minFov, maxFov = g_settingsCore.getSetting('fov') fov = mathUtils.lerp(minFov, maxFov, relativeDist) BigWorld.callback(0, functools.partial(FovExtended.instance().setFovByAbsoluteValue, math.radians(fov), 0.1)) return
def __init__(self, minMaxZoomMultiplier, relativeFocusDist): self.__deltaEasing = _INERTIA_EASING(Vector3(0.0), Vector3(0.0), _InputInertia.__ZOOM_DURATION) fovMultiplier = mathUtils.lerp(minMaxZoomMultiplier.min, minMaxZoomMultiplier.max, relativeFocusDist) self.__zoomMultiplierEasing = _INERTIA_EASING(fovMultiplier, fovMultiplier, _InputInertia.__ZOOM_DURATION) self.__minMaxZoomMultiplier = minMaxZoomMultiplier
def glideFov(self, newRelativeFocusDist): minMult, maxMult = self.__minMaxZoomMultiplier endMult = mathUtils.lerp(minMult, maxMult, newRelativeFocusDist) self.__zoomMultiplierEasing.reset(self.__zoomMultiplierEasing.value, endMult, _InputInertia.__ZOOM_DURATION)
def new_SmothCamera_InputInertia_glideFov(self, newRelativeFocusDist): minMult, maxMult = self._InputInertia__minMaxZoomMultiplier endMult = mathUtils.lerp(minMult, maxMult, newRelativeFocusDist) self._InputInertia__zoomMultiplierEasing.reset( self._InputInertia__zoomMultiplierEasing.value, endMult, 0.001)
def __normalizeEnergy(self, energy): minBound, maxBound = _TurretDetachmentEffects._MIN_COLLISION_ENERGY, _TurretDetachmentEffects._MAX_COLLISION_ENERGY clampedEnergy = mathUtils.clamp(minBound, maxBound, energy) t = (clampedEnergy - minBound) / (maxBound - minBound) return mathUtils.lerp(_TurretDetachmentEffects._MIN_NORMALIZED_ENERGY, 1.0, t)
def glideFov(func, newRelativeFocusDist): minMulti, maxMulti = func._InputInertia__minMaxZoomMultiplier endMulti = mathUtils.lerp(minMulti, maxMulti, newRelativeFocusDist) func._InputInertia__zoomMultiplierEasing.reset(func._InputInertia__zoomMultiplierEasing.value, endMulti, 0.001)
def tick(self): dt = self.measureDeltaTime() self.__active = not self.__interpolationState.stopped if self.__active: lerpValue = self.__interpolationState.update(dt) for idx in range(self.__numItems): lerpFunc = self.__customInterpolatorFuncs[idx] start = self.__startValueGetters[idx]() end = self.__endValueGetters[idx]() self.__interpolatedValues[idx] = lerpFunc(start, end, lerpValue) if lerpFunc is not None else mathUtils.lerp(start, end, lerpValue) for idx in range(self.__numItems): self.__setters[idx](self.__interpolatedValues[idx]) self.__active = not self.__interpolationState.stopped return self.__active