def ProcessCameraUpdate(self, camera, now, frameTime): if not self.smoothBehindEnabled: return self.camera = camera self.frameTime = frameTime if self.entity is None: self.entity = self._GetEntity(self.charEntID) if self.entity is None: raise RuntimeError("Problem retrieving the avatar's entity. cameras.CameraBehavior._GetEntity returned None for entityID", self.charEntID) if self.model is None: self.model = self._GetEntityModel(self.charEntID) if self.model is None: raise RuntimeError("Problem retrieving the avatar's model object. entityClient.FindEntityByID returned None for entityID", self.charEntID) if not camera.mouseLeftButtonDown and not camera.mouseRightButtonDown: avatarHasMoved = geo2.Vec3Distance(self.model.translation, self.lastAvatarPosition) > const.FLOAT_TOLERANCE avatarHasRotated = geo2.Vec3Distance(geo2.QuaternionRotationGetYawPitchRoll(self.model.rotation), self.lastAvatarRotation) > const.FLOAT_TOLERANCE movementDetected = avatarHasMoved or avatarHasRotated self.lastAvatarPosition = self.model.translation self.lastAvatarRotation = geo2.QuaternionRotationGetYawPitchRoll(self.model.rotation) if movementDetected: self.rotationSpeed = cameras.SMOOTH_BEHIND_ANIMATION_SPEED_REALLY_FAST else: self.rotationSpeed = cameras.SMOOTH_BEHIND_ANIMATION_SPEED if self.enableTriggerableSmoothBehind: if movementDetected: self.smoothBehind = True else: self.smoothBehind = True else: self.smoothBehind = False if self.smoothBehind: self.SmoothBehind()
def GetTransitEyeCurve(self, eyePos, atPos, newDir, atCurve): """ Returns control points for the eye transit curve spline. To get a smooth transition, we do a linear interpolation of the rotation around the y-axis, radius and y-value. """ currDir = self.GetLookAtDirection() try: angle = math.acos(geo2.Vec3Dot(currDir, newDir)) except ValueError: angle = 0 th0 = math.atan2(currDir[2], currDir[0]) th0 = self.ClampAngle(th0) th1 = math.atan2(newDir[2], newDir[0]) th1 = self.ClampAngle(th1) if th0 - th1 > math.pi: th0 -= 2 * math.pi elif th1 - th0 > math.pi: th1 -= 2 * math.pi r0 = geo2.Vec3Distance((self.eyePosition[0], 0, self.eyePosition[2]), (self.atPosition[0], 0, self.atPosition[2])) r1 = geo2.Vec3Distance((eyePos[0], 0, eyePos[2]), (atPos[0], 0, atPos[2])) y0 = self.eyePosition[1] - self.atPosition[1] y1 = eyePos[1] - atPos[1] points = [] for i, atPoint in enumerate(atCurve): t = self._GetHermiteValue(float(i) / len(atCurve)) r = r0 + t * (r1 - r0) th = th0 + t * (th1 - th0) y = y0 + t * (y1 - y0) point = (r * math.cos(th), y, r * math.sin(th)) point = geo2.Vec3Add(point, atCurve[i]) points.append(point) return points
def DistanceFromSegment(self, p, p0, p1, v, c2): w = geo2.Vec3Subtract(p, p0) c1 = geo2.Vec3Dot(v, w) if c1 <= 0: return None if c2 <= c1: return geo2.Vec3Distance(p, p1) return geo2.Vec3Distance(p, geo2.Vec3Add(p0, geo2.Vec3Scale(v, c1 / c2)))
def HandlePointOfInterest(self): """ Handles poi calculations. If there is a desired poi, then we lerp to that, making sure to update it if the camera or avatar moves around. Otherwise, if there is no desired poi, we calculate the correct one based on the camera position and avatar position """ if self.desiredPoi is not None: camMoved = geo2.Vec3Distance( self.lerpPoiCamStats, (self.camera.yaw, self.camera.pitch, 0.0)) avatarMoved = geo2.Vec3Distance( self.lerpPoiAvatarStats, self.entity.GetComponent('position').position) if camMoved > const.FLOAT_TOLERANCE or avatarMoved > const.FLOAT_TOLERANCE: self.desiredPoi = self.CalcCorrectCameraPoi( self.camera.yaw, self.camera.pitch) if avatarMoved > const.FLOAT_TOLERANCE: vect = geo2.Vec3Normalize( geo2.Vec3Subtract(self.centerPoint, self.lastCenterPoint)) dist = geo2.Vec3Distance(self.lastCenterPoint, self.centerPoint) self.camera.poi = geo2.Vec3Add(self.camera.poi, (val * dist for val in vect)) self.lerpPoiCamStats = (self.camera.yaw, self.camera.pitch, 0.0) self.lerpPoiAvatarStats = self.entity.GetComponent( 'position').position self.useLerp = True if self.useLerp: newPoi = geo2.Vec3Lerp(self.camera.poi, self.desiredPoi, self.frameTime * LERP_SPEED) zoom = mathUtil.Lerp(self.camera.zoom, self.desiredZoom, self.frameTime * LERP_SPEED) else: newPoi = self.PlerpVec3(self.originalPoi, self.desiredPoi, self.lerpTimeLeft) zoom = self.Plerp(self.startZoom, self.desiredZoom, self.lerpTimeLeft) self.camera.zoom = self.camera.collisionZoom = self.camera.desiredZoom = zoom self.lerpTimeLeft -= self.frameTime * const.SEC if geo2.Vec3Distance( newPoi, self.desiredPoi) < const.FLOAT_TOLERANCE and abs( self.camera.zoom - self.desiredZoom) < const.FLOAT_TOLERANCE: self.desiredPoi = None self.camera.zoom = self.camera.collisionZoom = self.camera.desiredZoom = self.desiredZoom else: newPoi = self.CalcCorrectCameraPoi(self.camera.yaw, self.camera.pitch) self.camera.SetPointOfInterest(newPoi)
def GetDynamicFov(self): if self._atTransitOffset: atPos = geo2.Vec3Subtract(self.atPosition, self._atTransitOffset) else: atPos = self.atPosition dist = geo2.Vec3Distance(self.eyePosition, atPos) return self.GetDynamicFovByDistance(dist)
def PanTo(self, panLeft, panTop, animate=True, duration=None, timeOffset=0.0, sleep=False): """ Pan to panLeft, panTop (0.0 - 1.0) """ if animate: if not duration: length = geo2.Vec3Distance((panLeft, panTop, 0), (self.panLeft, self.panTop, 0)) duration = max(0.1, length * self.scale) uicore.animations.MorphScalar(self, 'panLeft', self.panLeft, panLeft, duration=duration, timeOffset=timeOffset) uicore.animations.MorphScalar(self, 'panTop', self.panTop, panTop, duration=duration, timeOffset=timeOffset, sleep=sleep) else: self.panLeft = panLeft self.panTop = panTop
def HandlePointOfInterest(self): if self.desiredPoi is not None: camMoved = geo2.Vec3Distance( self.lerpPoiCamStats, (self.camera.yaw, self.camera.pitch, 0.0)) avatarMoved = geo2.Vec3Distance( self.lerpPoiAvatarStats, self.entity.GetComponent('position').position) if camMoved > const.FLOAT_TOLERANCE or avatarMoved > const.FLOAT_TOLERANCE: self.desiredPoi = self.CalcCorrectCameraPoi( self.camera.yaw, self.camera.pitch) if avatarMoved > const.FLOAT_TOLERANCE: vect = geo2.Vec3Normalize( geo2.Vec3Subtract(self.centerPoint, self.lastCenterPoint)) dist = geo2.Vec3Distance(self.lastCenterPoint, self.centerPoint) self.camera.poi = geo2.Vec3Add(self.camera.poi, (val * dist for val in vect)) self.lerpPoiCamStats = (self.camera.yaw, self.camera.pitch, 0.0) self.lerpPoiAvatarStats = self.entity.GetComponent( 'position').position self.useLerp = True if self.useLerp: newPoi = geo2.Vec3Lerp(self.camera.poi, self.desiredPoi, self.frameTime * LERP_SPEED) zoom = mathUtil.Lerp(self.camera.zoom, self.desiredZoom, self.frameTime * LERP_SPEED) else: newPoi = self.PlerpVec3(self.originalPoi, self.desiredPoi, self.lerpTimeLeft) zoom = self.Plerp(self.startZoom, self.desiredZoom, self.lerpTimeLeft) self.camera.zoom = self.camera.collisionZoom = self.camera.desiredZoom = zoom self.lerpTimeLeft -= self.frameTime * const.SEC if geo2.Vec3Distance( newPoi, self.desiredPoi) < const.FLOAT_TOLERANCE and abs( self.camera.zoom - self.desiredZoom) < const.FLOAT_TOLERANCE: self.desiredPoi = None self.camera.zoom = self.camera.collisionZoom = self.camera.desiredZoom = self.desiredZoom else: newPoi = self.CalcCorrectCameraPoi(self.camera.yaw, self.camera.pitch) self.camera.SetPointOfInterest(newPoi)
def SetAppropriateAtPositionForRotation(self, atPos): distanceToNewAtPos = geo2.Vec3Distance(self.eyePosition, atPos) distanceToNewAtPos = min(evecamera.LOOKATRANGE_MAX_NEW, distanceToNewAtPos) lookVec = geo2.Vec3Scale(self.GetLookAtDirection(), distanceToNewAtPos) newAtPos = geo2.Vec3Subtract(self.eyePosition, lookVec) if newAtPos != self._eyePosition: self.SetAtPosition(newAtPos)
def GetZoomDistance(self): dist = geo2.Vec3Distance(self._eyePosition, self.GetZoomToPoint()) if math.isinf(dist): LogException('Error: Infinite camera distance:%s, %s' % (repr(dist), self)) self.ResetCameraPosition() return 1.0 return dist
def IsIntersecting(pos1, radius1, pos2, radius2): distance = geo2.Vec3Distance(pos1, pos2) if distance < 0.0: return False if distance > radius1 + radius2: return False if radius1 > distance + radius2 or radius2 > distance + radius1: return False return True
def GetLookAtDistance(self, ball): if self.IsAttached(): distance = self.GetZoomDistance() else: distance = geo2.Vec3Distance(self.eyePosition, GetBallPosition(ball)) maxZoom = GetBallMaxZoom(ball, self.nearClip) minZoom = evecamera.LOOKATRANGE_MAX_NEW distance = max(maxZoom, min(distance, minZoom)) return distance
def HandleModelVisibility(self): avatarPosRelativeToCamera = (self.centerPoint[0], self.camera.cameraPosition[1], self.centerPoint[2]) if geo2.Vec3Distance(avatarPosRelativeToCamera, self.camera.cameraPosition ) < cameras.AVATAR_MIN_DISPLAY_DISTANCE: self.model.display = False else: self.model.display = True
def _UpdateBobbingOffset(self): if not IsBobbingEnabled() or not self.isBobbingCamera: return self._bobbingAngle += 1.0 / blue.os.fps * BOBBING_SPEED if self._bobbingAngle > 2 * math.pi: self._bobbingAngle %= 2 * math.pi distance = geo2.Vec3Distance(self.atPosition, self.eyePosition) idleYaw = distance * math.cos(self._bobbingAngle) / 400.0 idlePitch = 1.2 * idleYaw * math.sin(self._bobbingAngle) bobbingOffset = (idleYaw, idlePitch, 0) self._AddToEyeAndAtOffset(bobbingOffset)
def PointToYawPitchDist(self, pos): upVector = (0, 1, 0) if trinity.IsRightHanded(): rotMatrix = geo2.MatrixLookAtRH(pos, self.poi, upVector) else: rotMatrix = geo2.MatrixLookAtLH(pos, self.poi, upVector) rotMatrix = geo2.MatrixTranspose(rotMatrix) quat = geo2.QuaternionRotationMatrix(rotMatrix) yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(quat) yaw = math.pi / 2 - yaw pitch = math.pi / 2 - pitch return (yaw, pitch, geo2.Vec3Distance(pos, self.poi))
def AvoidCollision(self): criticalFailInfo = self.gameWorld.SweptSphere(self.poi, self.cameraAdvancedPos, cameras.NORMAL_COLLISION_SPHERE) if criticalFailInfo: safeSpot = geo2.Vec3Add(criticalFailInfo[0], (val * cameras.NORMAL_COLLISION_SPHERE for val in criticalFailInfo[1])) if not self.colliding: self.colliding = True newZoom = geo2.Vec3Distance(self.poi, safeSpot) self.collisionZoom = self.zoom = self.desiredZoom = newZoom elif self.colliding: self.desiredZoom = self.setZoom self.collisionZoom = self.zoom self.colliding = False
def GetLodLevel(position, radius): cam = sm.GetService('sceneManager').GetActiveSpaceCamera() if cam is None: return 1 distance = geo2.Vec3Distance(cam.eyePosition, position) vp = trinity.device.viewport aspectRatio = vp.GetAspectRatio() fov = cam.fov / camutils.GetARZoomMultiplier(aspectRatio) lodQuality = gfxsettings.Get(gfxsettings.GFX_LOD_QUALITY) boundingSize = radius / (math.tan(fov / 2) * distance) * vp.height if boundingSize < 192 / lodQuality: return 1 return 0
def HandleModelVisibility(self): """ Checks to see if the camera is too close to the avatar and if so, turn off the avatar model """ avatarPosRelativeToCamera = (self.centerPoint[0], self.camera.cameraPosition[1], self.centerPoint[2]) if geo2.Vec3Distance(avatarPosRelativeToCamera, self.camera.cameraPosition ) < cameras.AVATAR_MIN_DISPLAY_DISTANCE: self.model.display = False else: self.model.display = True
def SetupFakeAudioTransformLocation(self, shipPosition): self.fakeAudioTransform.translationCurve = trinity.TriVectorCurve() viewTransformOffset = geo2.MatrixTransformation( (0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0), (1.0, 1.0, 1.0), (0.0, 0.0, 0.0), self.sceneRotation, self.sceneTranslation) viewTransformInverse = geo2.MatrixInverse(viewTransformOffset) newAudioEmitterPosition = geo2.Vec3TransformCoord( shipPosition, viewTransformInverse) self.fakeAudioTransform.translationCurve.value = newAudioEmitterPosition distance = geo2.Vec3Distance((0, 0, 0), newAudioEmitterPosition) gallenteHangarBaseline = 561.28692627 audioScaleFactor = distance / gallenteHangarBaseline self.generalAudioEntity.SetAttenuationScalingFactor(audioScaleFactor)
def SetUpChildExplosion(explosionModel, spaceObjectModel=None, explosionSorting='random', initialLocatorIdx=-1): explosionChildren = explosionModel.Find('trinity.EveChildExplosion', 2) if spaceObjectModel is not None: explosionLocatorSets = None if hasattr(spaceObjectModel, 'locatorSets'): explosionLocatorSets = spaceObjectModel.locatorSets.FindByName( 'explosions') explosionLocators = explosionLocatorSets.locators if explosionLocatorSets else spaceObjectModel.damageLocators locators = [(each[0], each[1]) for each in explosionLocators] transforms = [] if explosionSorting == FROM_CENTER_SORTING: point = spaceObjectModel.GetBoundingSphereCenter() radius = spaceObjectModel.GetBoundingSphereRadius() * 0.2 locators.sort(key=lambda explosion: geo2.Vec3Distance( point, explosion[0]) + (random.random() - random.random()) * radius) elif explosionSorting == FROM_LOCATOR_SORTING: if initialLocatorIdx < 0 or initialLocatorIdx > len(locators): initialLocatorIdx = random.randint(0, len(locators) - 1) point = locators[initialLocatorIdx][0] locators.sort(key=lambda explosion: geo2.Vec3Distance( point, explosion[0])) else: random.shuffle(locators) for position, direction in locators: rotation = direction transform = geo2.MatrixTransformation( (0, 0, 0), (0, 0, 0, 1), (1, 1, 1), (0, 0, 0), rotation, position) transforms.append(transform) for each in explosionChildren: each.SetLocalExplosionTransforms(transforms)
def CreateResourceInfo(self, resourceTypeID, entry): info = util.KeyVal(resourceTypeID=resourceTypeID, updateTime=entry.updateTime, oldBand=entry.numBands, planetology=0, advancedPlanetology=0, remoteSensing=0) planetInfo = sm.GetService('map').GetPlanetInfo(self.planetID) planetLoc = cfg.evelocations.Get(planetInfo.solarSystemID) planetPos = (planetLoc.x, planetLoc.y, planetLoc.z) playerLoc = cfg.evelocations.Get(session.solarsystemid2) playerPos = (playerLoc.x, playerLoc.y, playerLoc.z) dist = geo2.Vec3Distance(playerPos, planetPos) / const.LIGHTYEAR skills = sm.GetService('skills').MySkillLevelsByID(renew=True) info.remoteSensing = skills.get(const.typeRemoteSensing, 0) if info.remoteSensing == 0: info.skillMissing = True return info if session.solarsystemid2 == planetInfo.solarSystemID or sm.GetService( 'planetSvc').IsPlanetColonizedByMe(self.planetID): info.proximity = const.planetResourceProximityPlanet else: if util.IsWormholeSystem(session.solarsystemid2) or sm.GetService( 'pathfinder').GetJumpCountFromCurrent( planetInfo.solarSystemID) > 1000: info.unreachableSystem = True return info info.proximity = None for i, scanRange in enumerate(const.planetResourceScanningRanges): if scanRange >= dist: info.proximity = i if info.proximity is None or dist > const.planetResourceScanningRanges[ 5 - info.remoteSensing]: info.systemOutOfRange = True info.systemDistance = dist info.maxScanDistance = const.planetResourceScanningRanges[ 5 - info.remoteSensing] return info info.planetology = skills.get(const.typePlanetology, 0) info.advancedPlanetology = skills.get(const.typeAdvancedPlanetology, 0) minBand, maxBand = const.planetResourceProximityLimits[info.proximity] info.newBand = min( maxBand, minBand + info.planetology + info.advancedPlanetology * 2) requiredSkill = 5 - info.proximity if info.remoteSensing < requiredSkill: info.requiredSkill = requiredSkill return info
def distanceBinding(curve1, curve2, min, max, parameters, index, gamma): avatar = weakAvatar.object if avatar is None: return curve1.skinnedObject = avatar curve2.skinnedObject = avatar if curve1.startValue == curve1.currentValue or curve2.startValue == curve2.currentValue: curve1.skinnedObject = None curve2.skinnedObject = None return p1 = curve1.currentValue[3] p2 = curve2.currentValue[3] dist = geo2.Vec3Distance(p1, p2) d = 1.0 - (dist - min) * 1 / (max - min) if d < 0: d = 0 elif d > 1: d = 1 if gamma != 1.0: d = math.pow(d, gamma) if False: trinity.GetDebugRenderer().DrawLine( (p1[0], p1[1], p1[2]), 4294967295L, (p2[0], p2[1], p2[2]), 4294967295L) trinity.GetDebugRenderer().Print3D((p1[0], p1[1], p1[2]), 4294967295L, str(dist)) trinity.GetDebugRenderer().Print3D((p2[0], p2[1], p2[2]), 4294967295L, str(d)) for p_ in parameters: p = p_.object if p is None: continue if index == 1: p.v1 = d if index == 2: p.v2 = d if index == 3: p.v3 = d if index == 4: p.v4 = d curve1.skinnedObject = None curve2.skinnedObject = None
def GetTransitAtCurve(self, posStart, posEnd, newDir, smoothing, numPoints): """ Returns control points for the lookAt transit curve spline. We travel along a straight line offset quadtratically according the the smoothing argument""" currDir = self.GetLookAtDirection() angle = math.acos(geo2.Vec3Dot((currDir[0], 0, currDir[2]), (newDir[1], 0, newDir[2]))) if smoothing and angle: offset = geo2.Vec3Normalize(geo2.Vec3Negate(newDir)) dist = geo2.Vec3Distance(posStart, posEnd) offset = geo2.Vec3Scale(offset, dist * angle * smoothing) else: offset = (0, 0, 0) points = [] for i in xrange(numPoints + 1): t = self._GetHermiteValue(float(i) / numPoints) offsetDist = 2 * (t - t ** 2) point = geo2.Vec3Lerp(posStart, posEnd, t) point = geo2.Add(point, geo2.Vec3Scale(offset, offsetDist)) points.append(point) return points
def _GetMaxPartSize(et): if not et.mesh.geometry.isGood: raise MeshLoadError(et.mesh.geometryResPath) geoSize = et.mesh.geometry.GetBoundingBox(0) gs = geo2.Vec3Distance(geoSize[0], geoSize[1]) for em in et.Find('trinity.Tr2DynamicEmitter'): for each in em.generators: if each.name == 'sizeDynamic' or each.name == 'size': return max(each.minRange + each.maxRange) * gs for em in et.Find('trinity.Tr2StaticEmitter'): for ps in em.Find('trinity.Tr2ParticleSystem'): for each in ps.elements: if each.name == 'size': remotefilecache.prefetch_single_file( em.geometryResourcePath) return grannyutils.GetMaxPartSize( blue.paths.ResolvePath(em.geometryResourcePath), each.usageIndex, em.meshIndex) * gs logger.warning('No Particle Emitters found for %s' % et.name)
def _GetDistanceToCamera(self, ball): bp = sm.GetService('michelle').GetBallpark() ballPos = GetBallPosition(ball) camPos = self.cameraController.GetCamera().eyePosition return geo2.Vec3Distance(ballPos, camPos)
def CreateBoneDriver(set, bone1, bone2, zone, min, max, oldMin, oldMax, curveDictionary, name, tweakData): if bone1 in pdDoll.bindPose and bone1 in pdDoll.boneOffsets and bone2 in pdDoll.bindPose and bone2 in pdDoll.boneOffsets: bindPosePos1 = pdDoll.bindPose[bone1]['translation'] offset1 = pdDoll.boneOffsets[bone1]['translation'] bindPosePos2 = pdDoll.bindPose[bone2]['translation'] offset2 = pdDoll.boneOffsets[bone2]['translation'] realPos1 = (bindPosePos1[0] / 100.0 + offset1[0], bindPosePos1[1] / 100.0 + offset1[1], bindPosePos1[2] / 100.0 + offset1[2]) realPos2 = (bindPosePos2[0] / 100.0 + offset2[0], bindPosePos2[1] / 100.0 + offset2[1], bindPosePos2[2] / 100.0 + offset2[2]) bindPoseDist = geo2.Vec3Distance(bindPosePos1, bindPosePos2) / 100.0 dist = geo2.Vec3Distance(realPos1, realPos2) multiplier = dist / bindPoseDist oldMin = oldMin * multiplier oldMax = oldMax * multiplier def GetOrMakeCurve(bone, set, curveDictionary, name): curve = curveDictionary.get((weakAvatar, bone), None) if curve is not None: return curve curve = trinity.Tr2BoneMatrixCurve() curve.bone = bone curve.name = name curveDictionary[weakAvatar, bone] = curve set.curves.append(curve) return curve curve1 = GetOrMakeCurve(bone1, set, curveDictionary, 'bone1') curve2 = GetOrMakeCurve(bone2, set, curveDictionary, 'bone2') bind = trinity.TriValueBinding() set.bindings.append(bind) def distanceBinding(curve1, curve2, min, max, parameters, index, gamma): avatar = weakAvatar.object if avatar is None: return curve1.skinnedObject = avatar curve2.skinnedObject = avatar if curve1.startValue == curve1.currentValue or curve2.startValue == curve2.currentValue: curve1.skinnedObject = None curve2.skinnedObject = None return p1 = curve1.currentValue[3] p2 = curve2.currentValue[3] dist = geo2.Vec3Distance(p1, p2) d = 1.0 - (dist - min) * 1 / (max - min) if d < 0: d = 0 elif d > 1: d = 1 if gamma != 1.0: d = math.pow(d, gamma) if False: trinity.GetDebugRenderer().DrawLine((p1[0], p1[1], p1[2]), 4294967295L, (p2[0], p2[1], p2[2]), 4294967295L) trinity.GetDebugRenderer().Print3D((p1[0], p1[1], p1[2]), 4294967295L, str(dist)) trinity.GetDebugRenderer().Print3D((p2[0], p2[1], p2[2]), 4294967295L, str(d)) for p_ in parameters: p = p_.object if p is None: continue if index == 1: p.v1 = d if index == 2: p.v2 = d if index == 3: p.v3 = d if index == 4: p.v4 = d curve1.skinnedObject = None curve2.skinnedObject = None zone = zone - 1 paramIndex = zone / 4 + 1 index = zone % 4 + 1 param = 'WrinkleNormalStrength' + str(paramIndex) parameters = [] for fx in effects: for p in fx.parameters: if p.name == param: parameters.append(blue.BluePythonWeakRef(p)) gammaCurves = tweakData.get('gammaCurves', {}) gamma = gammaCurves.get(name, gammaCurves.get('default', 1.0)) bind.copyValueCallable = lambda source, dest: distanceBinding(curve1, curve2, oldMin, oldMax, parameters, index, gamma)
def GetDistanceToCursor(self): return geo2.Vec3Distance(self.eyePosition, self.sceneCursor)
def GetDurationByDistance(pos0, pos1, minTime=0.3, maxTime=1.0): dist = geo2.Vec3Distance(pos0, pos1) duration = max( minTime, min(minTime + (maxTime - minTime) * dist / 100000.0, maxTime)) return duration
def GetShipDiameter(self, typeID): p0, p1 = self.GetShipBoundingBox(typeID) return geo2.Vec3Distance(p0, p1)
def MoveToTitanCameraPosition(self): self.atPosition = self.model.translationCurve.value self.eyePosition = TITAN_CAMERA_POSITION self.SetMinZoom(geo2.Vec3Distance(self.atPosition, self.eyePosition))
def HandleZooming(self): if self.camera.zoomRequest is None: return if abs(self.camera.zoomRequest - self.camera.zoom) < const.FLOAT_TOLERANCE or abs( self.camera.zoomRequest - self.desiredZoom) < const.FLOAT_TOLERANCE: self.camera.zoomRequest = None return self.useLerp = False if self.desiredPoi is not None: self.camera.zoomRequest = self.desiredZoom + self.camera.lastScrollDelta if self.camera.zoomRequest > self.camera.maxZoom: self.camera.zoomRequest = self.camera.maxZoom elif self.camera.zoomRequest < self.camera.minZoom: self.camera.zoomRequest = self.camera.minZoom self.useLerp = True zoomingOut = False if self.camera.zoomRequest > self.camera.zoom: zoomingOut = True futurePoi = self.CalcCorrectCameraPoi( self.camera.yaw, self.camera.pitch, overrideZoom=self.camera.zoomRequest) cameraAdvancedPos = geo2.Vec3Add( futurePoi, self.camera.YawPitchDistToPoint(self.camera.yaw, self.camera.pitch, self.camera.zoomRequest)) futurePoiCollision = self.gameWorld.SweptSphere( self.centerPoint, cameraAdvancedPos, cameras.ZOOM_COLLISION_SPHERE) collAtSource = self.gameWorld.SphereTest(self.centerPoint, cameras.ZOOM_COLLISION_SPHERE) vect = geo2.Vec3Normalize( geo2.Vec3Subtract(self.cameraAdvancedPos, self.centerPoint)) cameraAdvancedPos = geo2.Vec3Add(self.centerPoint, (val * self.camera.zoomRequest for val in vect)) currPosCollision = self.gameWorld.SweptSphere( self.centerPoint, cameraAdvancedPos, cameras.NORMAL_COLLISION_SPHERE) if futurePoiCollision and not currPosCollision and collAtSource: futurePoiCollision = None if not self.colliding: if futurePoiCollision is None: self.desiredPoi = self.CalcCorrectCameraPoi( self.camera.yaw, self.camera.pitch, overrideZoom=self.camera.zoomRequest) cameraAdvancedPos = geo2.Vec3Add( self.desiredPoi, self.camera.YawPitchDistToPoint(self.camera.yaw, self.camera.pitch, self.camera.zoomRequest)) checkColl = self.gameWorld.SweptSphere( self.centerPoint, cameraAdvancedPos, cameras.ZOOM_COLLISION_SPHERE) if checkColl: self.desiredPoi = None else: self.desiredZoom = self.camera.zoomRequest self.camera.userSelectedZoom = self.camera.zoomRequest self.lerpPoiCamStats = (self.camera.yaw, self.camera.pitch, 0.0) self.lerpPoiAvatarStats = self.entity.GetComponent( 'position').position self.CalcCamCurrAndAdvancedPosition() else: safeSpot = geo2.Vec3Add(futurePoiCollision[0], (val * cameras.ZOOM_COLLISION_SPHERE for val in futurePoiCollision[1])) dist = max(self.camera.minZoom, geo2.Vec3Distance(self.centerPoint, safeSpot)) dist = min(self.camera.maxZoom, dist) if abs(dist - self.camera.zoom) > ZOOM_COLLISION_TOLERANCE: oldPoi = self.desiredPoi self.desiredPoi = self.CalcCorrectCameraPoi( self.camera.yaw, self.camera.pitch, overrideZoom=dist) cameraAdvancedPos = geo2.Vec3Add( self.desiredPoi, self.camera.YawPitchDistToPoint( self.camera.yaw, self.camera.pitch, dist)) checkColl = self.gameWorld.SweptSphere( self.centerPoint, cameraAdvancedPos, cameras.ZOOM_COLLISION_SPHERE) if checkColl: self.desiredPoi = oldPoi elif zoomingOut and dist < self.camera.zoom: self.desiredPoi = oldPoi else: self.CalcCamCurrAndAdvancedPosition() self.desiredZoom = dist self.camera.userSelectedZoom = dist self.lerpPoiCamStats = (self.camera.yaw, self.camera.pitch, 0.0) self.lerpPoiAvatarStats = self.entity.GetComponent( 'position').position elif futurePoiCollision is None: self.desiredZoom = self.camera.zoomRequest self.camera.userSelectedZoom = self.camera.zoomRequest self.desiredPoi = self.CalcCorrectCameraPoi( self.camera.yaw, self.camera.pitch, overrideZoom=self.camera.zoomRequest) self.lerpPoiCamStats = (self.camera.yaw, self.camera.pitch, 0.0) self.lerpPoiAvatarStats = self.entity.GetComponent( 'position').position self.CalcCamCurrAndAdvancedPosition() self.lerpTimeLeft = LERP_TIME self.startZoom = self.camera.zoom self.originalPoi = self.camera.poi self.camera.zoomRequest = None