def _TransformContext(self, q): scenarioSvc = sm.StartService('scenario') originalToolRotation = self.GetRotation() orgX, orgY, orgZ = scenarioSvc.GetDungeonOrigin() toolPositionX, toolPositionY, toolPositionZ = sm.GetService('scenario').GetSelectionCenter() toolOffset = geo2.Vector(toolPositionX - orgX, toolPositionY - orgY, toolPositionZ - orgZ) qout = geo2.QuaternionMultiply(originalToolRotation, q) qout = geo2.QuaternionNormalize(qout) inverse = geo2.QuaternionInverse(originalToolRotation) diff = geo2.QuaternionMultiply(qout, inverse) diff = geo2.QuaternionNormalize(diff) slimItems = scenarioSvc.GetSelObjects() for slimItem in slimItems: if slimItem.dunObjectID in scenarioSvc.GetLockedObjects(): if uicore.uilib.Key(uiconst.VK_CONTROL): scenarioSvc.UnlockObject(slimItem.itemID, slimItem.dunObjectID, force=True) else: continue targetBall = sm.StartService('michelle').GetBall(slimItem.itemID) targetModel = getattr(targetBall, 'model', None) if targetModel and slimItem.categoryID != const.categoryAsteroid and slimItem.groupID != const.groupHarvestableCloud: qout = geo2.QuaternionMultiply(targetModel.rotationCurve.value, diff) qout = geo2.QuaternionNormalize(qout) targetModel.rotationCurve.value = qout slimItem.dunDirection = geo2.QuaternionTransformVector(qout, geo2.Vector(0.0, 0.0, 1.0)) scenarioSvc.UpdateUnsavedObjectChanges(slimItem.itemID, CHANGE_ROTATION) if len(slimItems) > 1 and not uicore.uilib.Key(uiconst.VK_SHIFT): relativeObjectPosition = geo2.Vector(slimItem.dunX - toolOffset.x, slimItem.dunY - toolOffset.y, slimItem.dunZ - toolOffset.z) rotatedDirectionVector = geo2.QuaternionTransformVector(diff, relativeObjectPosition) if targetModel: targetModel.translationCurve.x = rotatedDirectionVector[0] + toolPositionX targetModel.translationCurve.y = rotatedDirectionVector[1] + toolPositionY targetModel.translationCurve.z = rotatedDirectionVector[2] + toolPositionZ elif slimItem.groupID in scenarioSvc.groupsWithNoModel: try: targetTransform = scenarioSvc.fakeTransforms[slimItem.itemID] targetTransform.translationCurve.x = rotatedDirectionVector[0] + toolPositionX targetTransform.translationCurve.y = rotatedDirectionVector[1] + toolPositionY targetTransform.translationCurve.z = rotatedDirectionVector[2] + toolPositionZ except KeyError: scenarioSvc.LogError('Unable to rotate any ball for dungeon object:', slimItem.dunObjectID) slimItem.dunX = rotatedDirectionVector[0] + toolOffset.x slimItem.dunY = rotatedDirectionVector[1] + toolOffset.y slimItem.dunZ = rotatedDirectionVector[2] + toolOffset.z scenarioSvc.UpdateUnsavedObjectChanges(slimItem.itemID, CHANGE_TRANSLATION) qout = geo2.QuaternionMultiply(q, originalToolRotation) qout = geo2.QuaternionNormalize(qout) self.Rotate(qout)
def ToggleChaseCam(self, lockCurrent=False): if lockCurrent: camera = sm.GetService('sceneManager').GetRegisteredCamera( 'default') self.lockedCamVector = camera.viewVec shipBall = sm.GetService('michelle').GetBall(self.lookingAt) if shipBall is not None and shipBall.model is not None: q = shipBall.model.rotationCurve.GetQuaternionAt( blue.os.GetSimTime()) q = geo2.QuaternionInverse((q.x, q.y, q.z, q.w)) v = self.lockedCamVector self.lockedCamVector = geo2.QuaternionTransformVector(q, v) else: self.lockedCamVector = None self.chaseCam = not self.chaseCam
def PickWrapper(self, x, y): xy = (x, y) dev = trinity.device self.markerCorrection = [0.0, 0.0] mask, pick, uv, xyz, isHead = self.GetMaskAtPixel(x, y) if mask > 0: self.startXY = [x, y] camera = self.camera cPos = camera.GetPosition() cInt = camera.GetPointOfInterest() avatarRotation = self.avatar.rotation vector = [cPos[0] - cInt[0], cPos[1] - cInt[1], cPos[2] - cInt[2]] invRotation = geo2.QuaternionInverse(avatarRotation) vector = geo2.QuaternionTransformVector(invRotation, vector) if abs(vector[0]) > abs(vector[2]): if vector[0] > 0.0: self.direction = 'right' else: self.direction = 'left' else: self.direction = 'front' self.zone = self.ConvertMaskToZone(mask) if self.zone not in self.inactiveZones: if self.pickCallback: self.pickCallback(self.zone) if self.useHighlighting: if self.highlightGhost.IsActive(): self.highlightGhost.Stop() if self.bodyHighlightGhost.IsActive(): self.bodyHighlightGhost.Stop() else: self.zone = -1 self.direction = None self.startXY = None self.rightClick = False return self.zone
def Update(self, controller): if hasattr(controller.entityRef, 'aiming'): debugBoneName = 'fj_eyeballLeft' gazeAtEntityID = self.aimingClient.GetTargetEntityID(controller.entityRef, const.aiming.AIMING_VALID_TARGET_GAZE_ID) if gazeAtEntityID: gazeAtEntity = self.entityService.FindEntityByID(gazeAtEntityID) if gazeAtEntity: sensorPos = geo2.Vector(*controller.entityRef.position.position) sensorPos = sensorPos + self.perceptionClient.GetSensorOffset(controller.entityRef) focusPos = geo2.Vector(*gazeAtEntity.position.position) focusPos = focusPos + self.perceptionClient.GetSensorOffset(gazeAtEntity) headTransform = controller.animationNetwork.GetBoneTransform(debugBoneName) if headTransform is None: return headTranslation, headRotation = headTransform useBlendToHeadBone = False if useBlendToHeadBone: workPos = geo2.Vec3Subtract(focusPos, controller.entPos) entRotInvQuat = geo2.QuaternionInverse(controller.entRot) entRotInvQuat = geo2.QuaternionNormalize(entRotInvQuat) workPos = geo2.QuaternionTransformVector(entRotInvQuat, workPos) workPos = geo2.Vec3Subtract(workPos, headTranslation) headRotInvQuat = geo2.QuaternionInverse(headRotation) headRotInvQuat = geo2.QuaternionNormalize(headRotInvQuat) workPos = geo2.QuaternionTransformVector(headRotInvQuat, workPos) relativeLookAtYaw = mathCommon.GetYawAngleFromDirectionVector(workPos) relativeLookAtPitch = mathCommon.GetPitchAngleFromDirectionVector(workPos) else: sensorToFocusVec = geo2.Vec3Subtract(focusPos, sensorPos) yawToFocus = mathCommon.GetYawAngleFromDirectionVector(sensorToFocusVec) pitchToFocus = mathCommon.GetPitchAngleFromDirectionVector(sensorToFocusVec) entityYaw, trash, trash = geo2.QuaternionRotationGetYawPitchRoll(controller.entRot) relativeLookAtYaw = yawToFocus - entityYaw relativeLookAtPitch = pitchToFocus relativeLookAtYaw = math.fmod(relativeLookAtYaw, 2 * math.pi) relativeLookAtPitch = math.fmod(relativeLookAtPitch, 2 * math.pi) if relativeLookAtYaw < 0: relativeLookAtYaw = relativeLookAtYaw + 2 * math.pi if relativeLookAtPitch < 0: relativeLookAtPitch = relativeLookAtPitch + 2 * math.pi if relativeLookAtYaw > math.pi: relativeLookAtYaw = relativeLookAtYaw - 2 * math.pi if relativeLookAtPitch > math.pi: relativeLookAtPitch = relativeLookAtPitch - 2 * math.pi if geo2.Vec3LengthSq(controller.entityRef.movement.physics.velocity) > 0.0: maxYaw = MAXIMUM_HEAD_LOOK_ANGLE_YAW_MOVING maxPitch = MAXIMUM_HEAD_LOOK_ANGLE_PITCH_MOVING else: maxYaw = MAXIMUM_HEAD_LOOK_ANGLE_YAW maxPitch = MAXIMUM_HEAD_LOOK_ANGLE_PITCH if abs(relativeLookAtYaw) < maxYaw and abs(relativeLookAtPitch) < maxPitch: controller.SetControlParameter('Aim_X', -relativeLookAtYaw) controller.SetControlParameter('Aim_Y', -relativeLookAtPitch) controller.SetControlParameter('HeadLookWeight', 1) aimingManager = self.aimingClient.GetAimingManager(controller.entityRef.scene.sceneID) if aimingManager.IsDebugRendering(): self.aimingClient.GetAimingManager(controller.entityRef.scene.sceneID).SetDebugUsedParams(controller.entityRef.entityID, relativeLookAtYaw, -relativeLookAtPitch, maxYaw, maxPitch, headTranslation, headRotation) return controller.SetControlParameter('HeadLookWeight', 0) aimingManager = self.aimingClient.GetAimingManager(controller.entityRef.scene.sceneID) if aimingManager.IsDebugRendering(): translation, orientation = controller.entityRef.animation.updater.network.GetBoneTransform(debugBoneName) self.aimingClient.GetAimingManager(controller.entityRef.scene.sceneID).SetDebugUsedParams(controller.entityRef.entityID, -99, -99, MAXIMUM_HEAD_LOOK_ANGLE_YAW, MAXIMUM_HEAD_LOOK_ANGLE_PITCH, translation, orientation)
def GetRotation(self): scale, rotation, translation = geo2.MatrixDecompose( self.worldTranslation) rotation = geo2.QuaternionInverse(rotation) return rotation