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 TransformAccumulatedAnimFromPos(curPos, curRot, offsetTranslation, offsetYaw): offsetYaw = offsetYaw * math.pi / 180.0 trajRot = geo2.QuaternionRotationSetYawPitchRoll(offsetYaw, 0.0, 0.0) offsetPosRotated = geo2.QuaternionTransformVector(curRot, offsetTranslation) newPos = geo2.Vec3Add(curPos, offsetPosRotated) newRot = geo2.QuaternionMultiply(trajRot, curRot) return (newPos, newRot)
def TryPickSphereBorder(self): matches = [] scannerWnd = Scanner.GetIfOpen() if scannerWnd: x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y) ray, start = GetRayAndPointFromScreen(x, y) pickRadiusRay, pickRadiusStart = GetRayAndPointFromScreen(x - 30, y) camera = sm.GetService('sceneManager').GetRegisteredCamera('systemmap') if camera is None: return viewDir = geo2.QuaternionTransformVector(camera.rotationAroundParent, (0.0, 0.0, 1.0)) viewDir = geo2.Vec3Normalize(viewDir) targetPlaneNormal = geo2.Vector(*viewDir) scanSvc = sm.StartService('scanSvc') probeData = scanSvc.GetProbeData() probes = scannerWnd.GetProbeSpheres() for probeID, probeControl in probes.iteritems(): if probeID not in probeData or probeData[probeID].state != const.probeStateIdle: continue targetPlanePos = geo2.Vector(probeControl.locator.worldTransform[3][0], probeControl.locator.worldTransform[3][1], probeControl.locator.worldTransform[3][2]) rad = list(probeControl.sphere.scaling)[0] * SYSTEMMAP_SCALE pos = RayToPlaneIntersection(start, ray, targetPlanePos, targetPlaneNormal) picRadiusPos = RayToPlaneIntersection(pickRadiusStart, pickRadiusRay, targetPlanePos, targetPlaneNormal) pickRad = (trinity.TriVector(*picRadiusPos) - trinity.TriVector(*pos)).Length() diffFromPickToSphereBorder = (trinity.TriVector(*targetPlanePos) - trinity.TriVector(*pos)).Length() if rad + pickRad > diffFromPickToSphereBorder > rad - pickRad: matches.append((abs(rad - diffFromPickToSphereBorder), probeControl)) if matches: matches = uiutil.SortListOfTuples(matches) return matches[0]
def NewDirectionObstacleCheck(self, destYaw, heading): """ Calculates the direction we want to move in, performs a raycast to a specified length. The compares the collision normal if there is one with the direction vector to determine if angle between them is such where we will allow the character to walk and graze the wall. """ entity = self.entityClient.GetPlayerEntity() gw = GameWorld.Manager.GetGameWorld(long(entity.scene.sceneID)) posComp = entity.GetComponent('position') movComp = entity.GetComponent('movement') start = posComp.position start = geo2.Vec3Add( start, (0.0, self.AVATAR_COLLISION_DETECTION_CAPSULE_HEIGHT_MOD * movComp.characterController.height, 0.0)) yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll( posComp.rotation) direction = geo2.QuaternionRotationSetYawPitchRoll(yaw + destYaw, 0, 0) end = heading end = geo2.QuaternionTransformVector(direction, end) direction = end = geo2.Vec3Scale( end, self.AVATAR_COLLISION_DETECTION_FEELER_LENGTH) end = geo2.Vec3Add(end, start) hitResult = gw.SweptSphere( start, end, self.AVATAR_COLLISION_DETECTION_FEELER_RADIUS) result = False if hitResult: dotProduct = geo2.Vec3Dot(direction, hitResult[1]) if abs(dotProduct) > self.AVATAR_COLLISION_RESTRICTION_ANGLE_DP: result = True return result
def _GetBonePosRot(self, ENTID, boneName, posProp, rotProp): entity = self.entityService.FindEntityByID(ENTID) if entity is None: self.LogError('GetBonePosRot: Entity with ID ', ENTID, ' not found!') return False animClient = entity.GetComponent('animation') posComp = entity.GetComponent('position') if animClient is not None and posComp is not None: if animClient.controller is not None: boneTransform = animClient.controller.animationNetwork.GetBoneTransform( boneName) if boneTransform: translation, orientation = boneTransform translation = geo2.QuaternionTransformVector( posComp.rotation, translation) translation = geo2.Vec3Add(posComp.position, translation) orientation = geo2.QuaternionMultiply( posComp.rotation, orientation) translation = list(translation) orientation = list(orientation) GameWorld.AddPropertyForCurrentPythonProc( {posProp: translation}) GameWorld.AddPropertyForCurrentPythonProc( {rotProp: orientation}) return True self.LogError('GetBonePosRot: Missing critical data in entity!') return False
def NewDirectionObstacleCheck(self, destYaw, heading): entity = self.entityClient.GetPlayerEntity() gw = GameWorld.Manager.GetGameWorld(long(entity.scene.sceneID)) posComp = entity.GetComponent('position') movComp = entity.GetComponent('movement') start = posComp.position start = geo2.Vec3Add( start, (0.0, self.AVATAR_COLLISION_DETECTION_CAPSULE_HEIGHT_MOD * movComp.characterController.height, 0.0)) yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll( posComp.rotation) direction = geo2.QuaternionRotationSetYawPitchRoll(yaw + destYaw, 0, 0) end = heading end = geo2.QuaternionTransformVector(direction, end) direction = end = geo2.Vec3Scale( end, self.AVATAR_COLLISION_DETECTION_FEELER_LENGTH) end = geo2.Vec3Add(end, start) hitResult = gw.SweptSphere( start, end, self.AVATAR_COLLISION_DETECTION_FEELER_RADIUS) result = False if hitResult: dotProduct = geo2.Vec3Dot(direction, hitResult[1]) if abs(dotProduct) > self.AVATAR_COLLISION_RESTRICTION_ANGLE_DP: result = True return result
def GetSpeedDirection(ball): if getattr(ball, 'model', None) and hasattr(ball.model.rotationCurve, 'value'): quat = ball.model.rotationCurve.value else: quat = ball.GetQuaternionAt(blue.os.GetSimTime()) quat = (quat.x, quat.y, quat.z, quat.w) return geo2.QuaternionTransformVector(quat, (0, 0, 1))
def GetUprightCapsulePosAndRot(curPos, curRot, floorHeight): yaw, trash, trash = geo2.QuaternionRotationGetYawPitchRoll(curRot) rot = geo2.QuaternionRotationSetYawPitchRoll(yaw, 0, 0) pos = geo2.Vector(*curPos) adjustment = geo2.QuaternionTransformVector(curRot, adjustment) pos = pos + adjustment pos.y = floorHeight return (pos, rot)
def GetDotInCameraAlignedPlaneFromPosition(self, targetPlanePos): x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y) ray, start = GetRayAndPointFromScreen(x, y) camera = sm.GetService('sceneManager').GetRegisteredCamera('systemmap') viewDir = geo2.QuaternionTransformVector(camera.rotationAroundParent, (0.0, 0.0, 1.0)) viewDir = geo2.Vec3Normalize(viewDir) targetPlaneNormal = geo2.Vector(*viewDir) pos = RayToPlaneIntersection(start, ray, targetPlanePos, targetPlaneNormal) return pos
def _DoCameraLookAnimation_Thread_New(self): if self.startTranslation: targetTranslation = self.startTranslation else: targetTranslation = self.camera.GetZoomDistance() direction = geo2.Vec3Scale(geo2.QuaternionTransformVector(self.rotation, (0, 0, 1)), -targetTranslation) atPosition = self._GetFocusPosition() eyePosition = geo2.Vec3Add(atPosition, direction) self.camera.TransitTo(atPosition, eyePosition, smoothing=0.0)
def _DoCameraLookAnimation_Thread(self): self.camera.Track(None) lookDir = geo2.QuaternionTransformVector(self.rotation, (0, 0, 1)) lookDir = trinity.TriVector(lookDir[0], lookDir[1], lookDir[2]) initialTranslation = self.camera.translationFromParent targetTranslation = initialTranslation if self.startTranslation is not None: targetTranslation = self.startTranslation startTime = blue.os.GetSimTime() endedTime = None maxPanSpeed = math.pi / 500 panCurve = uicore.animations.GetScalar(0, maxPanSpeed, self.cameraIntroTime * 0.9) posLerpCurve = uicore.animations.GetScalar(0.0, 1.0, self.cameraIntroTime * 0.9) dir = geo2.Vec3Scale(geo2.QuaternionTransformVector(self.rotation, (0, 0, 1)), -targetTranslation) self.lookAtAnim = AnimateGateLookAt(self._GetFocusPosition, dir, posLerpCurve) self.camera.animationController.Schedule(self.lookAtAnim) self.panAnim = AnimateGatePan(initialTranslation, posLerpCurve) self.camera.animationController.Schedule(self.panAnim) self.panAnimEnd = camutils.PanCamera(targetTranslation, initialTranslation, self.cameraOutroDelay * 0.9) while True: blue.synchro.Yield() curTime = blue.os.GetSimTime() if not getattr(self, 'lastTime', None): self.lastTime = curTime continue timeDelta = blue.os.TimeDiffInMs(self.lastTime, curTime) self.lastTime = curTime t = blue.os.TimeDiffInMs(startTime, curTime) / 1000.0 panSpeed = maxPanSpeed if t < self.cameraIntroTime: panSpeed = panCurve.GetValueAt(t) if self.ending and endedTime is None: self.lookAtAnim.Stop() self.panAnim.Stop() self.camera.animationController.Schedule(self.panAnimEnd) endedTime = curTime elif endedTime is not None: if self.endFocusID is None: break timeSinceEnd = blue.os.TimeDiffInMs(endedTime, curTime) / 1000.0 if timeSinceEnd >= self.cameraOutroDelay: self.OnJumpDone() break
def MoveTF(self, tf, dx, dy): camera = sm.GetService('sceneManager').GetRegisteredCamera('starmap') X = float(dx) / float(trinity.device.width) Y = -float(dy) / float(trinity.device.height) viewVec = camera.viewVec upVec = geo2.Vec3Scale(camera.upVec, Y) rightVec = geo2.Vec3Scale(camera.rightVec, X) pos = geo2.Vec3Add(rightVec, upVec) pos = geo2.Vec3Scale(pos, pow(tf.cameraDistSq, 0.5) * 1.5) pos = geo2.QuaternionTransformVector(camera.rotationAroundParent, pos) tf.translation = geo2.Vec3Add(tf.translation, pos)
def ApplyTorqueAtDamageLocator(self, damageLocatorID, impactVelocity, impactObjectMass): if not self.model: return damageLocatorPosition = self.model.GetDamageLocator(damageLocatorID) bsCenter = geo2.Vector(*self.model.GetBoundingSphereCenter()) damageLocatorPosition -= bsCenter q = self.GetQuaternionAt(blue.os.GetSimTime()) damageLocatorPosition = geo2.QuaternionTransformVector((q.x, q.y, q.z, q.w), damageLocatorPosition) self.ApplyTorqueAtPosition(damageLocatorPosition, impactVelocity, impactObjectMass)
def ProcessInput(self): if self.CanControl(): yaw, pitch = self.controls() else: yaw, pitch = (0, 0) currentYaw, currentPitch, _ = self.curve.GetQuaternionAt(blue.os.GetSimTime()).GetYawPitchRoll() currentPitch = max(-math.pi / 2.0, min(math.pi / 2.0, currentPitch + pitch)) current = geo2.QuaternionRotationSetYawPitchRoll(currentYaw, currentPitch, 0) rotation = geo2.QuaternionRotationSetYawPitchRoll(yaw, 0, 0) result = geo2.QuaternionMultiply(rotation, current) self.direction = geo2.QuaternionTransformVector(result, (0, 0, 1)) if not self.controlling: self.controlling = bool(yaw or pitch)
def DirectionSearch(self, *args): if self.destroyed or self.busy: return self.busy = True self.ShowLoad() self.scanresult = [] if self.sr.useoverview.checked: selectedValue = self.presetsCombo.GetValue() if selectedValue is None: selectedValue = sm.GetService( 'overviewPresetSvc').GetActiveOverviewPresetName() filters = sm.GetService('overviewPresetSvc').GetValidGroups( presetName=selectedValue) if sm.GetService('viewState').IsViewActive(ViewState.SystemMap): cameraID = 'systemmap' else: cameraID = 'default' camera = sm.GetService('sceneManager').GetRegisteredCamera(cameraID) if not camera: self.busy = False self.HideLoad() raise RuntimeError('No camera found?!') vec = geo2.QuaternionTransformVector(camera.rotationAroundParent, (0, 0, -1)) vec = geo2.Vec3Normalize(vec) rnge = self.dir_rangeinput.GetValue() try: result = self.scanSvc.ConeScan(self.scanangle, rnge * 1000, vec[0], vec[1], vec[2]) except (UserError, RuntimeError) as err: result = None self.busy = False self.HideLoad() raise err settings.user.ui.Set('dir_scanrange', rnge) if result: bp = sm.GetService('michelle').GetBallpark() if bp: for rec in result: if self.sr.useoverview.checked: if rec.groupID not in filters: continue if rec.id in bp.balls: self.scanresult.append([None, bp.balls[rec.id], rec]) else: self.scanresult.append([None, None, rec]) self.ShowDirectionalSearchResult() self.busy = False self.HideLoad()
def GetSynchedAnimStartLocation(sourcePos, sourceRot, targetPos, targetRot, animInfo): relVec = geo2.Vec3Subtract(sourcePos, targetPos) curDist = geo2.Vec3Length(relVec) if curDist <= 0.01: sourcePos = geo2.Vec3Add(targetPos, (0, 0, -1)) relVec = geo2.Vec3Subtract(sourcePos, targetPos) entName = const.animation.ATTACKER_NAME if entName in animInfo and const.animation.METADATA_TURN_TO_FACE in animInfo[entName] and animInfo[entName][const.animation.METADATA_TURN_TO_FACE] == False: newSourceRot = sourceRot else: newSourceRot = GetQuatFromDirection(sourcePos, targetPos) entName = const.animation.VICTIM_NAME if entName in animInfo and const.animation.METADATA_TURN_TO_FACE in animInfo[entName] and animInfo[entName][const.animation.METADATA_TURN_TO_FACE] == False: newTargetRot = targetRot newTargetYaw, trash, trash = geo2.QuaternionRotationGetYawPitchRoll(targetRot) else: newTargetRot = GetQuatFromDirection(targetPos, sourcePos) if entName in animInfo and const.animation.METADATA_START_OFFSET_YAW in animInfo[entName]: degrees = animInfo[entName][const.animation.METADATA_START_OFFSET_YAW] offsetYaw = math.pi * -degrees / 180.0 offsetRot = geo2.QuaternionRotationSetYawPitchRoll(offsetYaw, 0.0, 0.0) newTargetRot = geo2.QuaternionMultiply(newTargetRot, offsetRot) distance = 0.5 if const.animation.METADATA_START_DISTANCE in animInfo: distance = animInfo[const.animation.METADATA_START_DISTANCE] entName = const.animation.VICTIM_NAME if entName in animInfo and const.animation.METADATA_START_OFFSET_YAW in animInfo[entName]: if '/righthanded' in blue.pyos.GetArg(): front = (0, 0, distance) else: front = (0, 0, -distance) degrees = animInfo[entName][const.animation.METADATA_START_OFFSET_YAW] radians = math.pi * degrees / 180.0 offsetRot = geo2.QuaternionRotationSetYawPitchRoll(radians, 0.0, 0.0) yawOffsetQuat = geo2.QuaternionMultiply(newTargetRot, offsetRot) radOffset = geo2.QuaternionTransformVector(yawOffsetQuat, front) newSourcePos = geo2.Vec3Add(targetPos, radOffset) newSourceRot = GetQuatFromDirection(newSourcePos, targetPos) else: direction = geo2.Vec3Normalize(relVec) newSourcePos = geo2.Vec3Add(targetPos, (distance * direction[0], distance * direction[1], distance * direction[2])) entName = const.animation.ATTACKER_NAME if entName in animInfo and const.animation.METADATA_START_OFFSET_YAW in animInfo[entName]: degrees = animInfo[entName][const.animation.METADATA_START_OFFSET_YAW] radians = math.pi * -degrees / 180.0 offsetRot = geo2.QuaternionRotationSetYawPitchRoll(radians, 0.0, 0.0) newSourceRot = geo2.QuaternionMultiply(newSourceRot, offsetRot) return (newSourcePos, newSourceRot, targetPos, newTargetRot)
def GetTargetPlaneNormal(self, ray): if self.activeManipAxis in ('y', ): camera = sm.GetService('sceneManager').GetRegisteredCamera( 'systemmap') y, p, r = geo2.QuaternionRotationGetYawPitchRoll( camera.rotationAroundParent) q = geo2.QuaternionRotationSetYawPitchRoll(y, 0.0, 0.0) return geo2.QuaternionTransformVector(q, (0.0, 0.0, 1.0)) elif self.activeManipAxis in ('x', 'z', 'xz'): return Y_AXIS elif self.activeManipAxis in ('y', 'xy'): return Z_AXIS else: return X_AXIS
def OnMouseMove(self, *args): self.sr.hint = '' lib = uicore.uilib alt = lib.Key(uiconst.VK_MENU) camera = sm.GetService('sceneManager').GetRegisteredCamera( evecamera.CAM_SYSTEMMAP) dx = lib.dx dy = lib.dy if not lib.leftbtn and not lib.rightbtn and not self.sr.rangeProbe: uthread.new(self.TryToHilight) if not self._isPicked: return if lib.leftbtn: if self.sr.movingProbe: if alt: self.ScaleProbesAroundCenter() else: x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi( uicore.uilib.y) self.MoveActiveProbe(x, y) self.ShowGrid() return if self.sr.rangeProbe: self.ScaleActiveProbe() uicore.uilib.SetCursor(uiconst.UICURSOR_DRAGGABLE) return if lib.leftbtn and not lib.rightbtn: fov = camera.fieldOfView camera.OrbitParent(-dx * fov * 0.1, dy * fov * 0.1) sm.GetService('systemmap').SortBubbles() elif lib.rightbtn and not lib.leftbtn: cameraParent = self.GetCameraParent() if cameraParent.translationCurve: pos = cameraParent.translationCurve.GetVectorAt( blue.os.GetSimTime()) cameraParent.translationCurve = None cameraParent.translation = (pos.x, pos.y, pos.z) scalefactor = camera.translationFromParent * (camera.fieldOfView * 0.001) offset = (dx * scalefactor, -dy * scalefactor, 0.0) offset = geo2.QuaternionTransformVector( camera.rotationAroundParent, offset) cameraParent.translation = geo2.Vec3Subtract( cameraParent.translation, offset) elif lib.leftbtn and lib.rightbtn: modifier = uicore.mouseInputHandler.GetCameraZoomModifier() camera.Dolly(modifier * -(dy * 0.01) * abs(camera.translationFromParent)) camera.translationFromParent = camera.CheckTranslationFromParent( camera.translationFromParent)
def OnSetDamageLocator(self, *args): self.damageLocatorID = int(self.damageLocatorInput.GetValue()) self.arrowPositionUpdater.SetDamageLocator(self.damageLocatorID) if not self.lockVelocity: _, rotation = self.GetBall().model.damageLocators[ self.damageLocatorID] self.impactVelocity = geo2.QuaternionTransformVector( rotation, (0.0, geo2.Vec3Length(self.impactVelocity), 0.0)) self.impactVelocity = (-self.impactVelocity[0], -self.impactVelocity[1], -self.impactVelocity[2]) self.impactVelocityXInput.SetValue(str(self.impactVelocity[0])) self.impactVelocityYInput.SetValue(str(self.impactVelocity[1])) self.impactVelocityZInput.SetValue(str(self.impactVelocity[2])) self.arrowPositionUpdater.SetArrowDirection(self.impactVelocity)
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 GetSynchedAnimEndingDeltas(animInfo): atkPos = (0.0, 0.0, 0.0) atkRot = geo2.QuaternionIdentity() vicPos = (0.0, 0.0, -1.0) vicRot = geo2.QuaternionIdentity() atkPos, atkRot, vicPos, vicRot = GetSynchedAnimStartLocation(atkPos, atkRot, vicPos, vicRot, animInfo) offsetXZ = animInfo[const.animation.ATTACKER_NAME][const.animation.METADATA_END_OFFSET] offsetPos = (0.01 * offsetXZ[0], 0.0, 0.01 * offsetXZ[1]) atkPos, atkRot = TransformAccumulatedAnimFromPos(atkPos, atkRot, offsetPos, animInfo[const.animation.ATTACKER_NAME][const.animation.METADATA_YAW]) offsetXZ = animInfo[const.animation.VICTIM_NAME][const.animation.METADATA_END_OFFSET] offsetPos = (0.01 * offsetXZ[0], 0.0, 0.01 * offsetXZ[1]) vicPos, vicRot = TransformAccumulatedAnimFromPos(vicPos, vicRot, offsetPos, animInfo[const.animation.VICTIM_NAME][const.animation.METADATA_YAW]) deltaPos = geo2.Vec3Subtract(vicPos, atkPos) deltaPos = geo2.QuaternionTransformVector(atkRot, deltaPos) deltaRot = geo2.QuaternionMultiply(vicRot, atkRot) return (deltaPos, deltaRot)
def Update(self): print 'starting update thread' while not self.stop: if self.ball: arrowCenter = geo2.QuaternionTransformVector( self.arrowRotation, (self.arrowPoint[0] * self.arrowScale, self.arrowPoint[1] * self.arrowScale, self.arrowPoint[2] * self.arrowScale)) dl = self.ball.GetModel().GetTransformedDamageLocator( self.damageLocator) self.arrowObject.rotation = self.arrowRotation self.arrowObject.translation = (dl[0] - arrowCenter[0], dl[1] - arrowCenter[1], dl[2] - arrowCenter[2]) print 'stopping update thread'
def _PlayTunnelSequence(self): if self.ending: log.LogWarn('Jump Transition: Trying to play tunnel start sequence while ending.') return normDir = geo2.QuaternionTransformVector(self.effectRoot.rotation, (0, 0, 1)) self.normDir = normDir cameraSvc = sm.GetService('camera') cameraSvc.shakeController.DoCameraShake(self.shakeJumpOut) if self.initCS is not None: self.initCS.Stop() if self.startCS is not None: self.startCS.Play() offset = geo2.Vec3Scale(normDir, self.camOffsetStart) cameraSvc.animationController.Schedule(transitioncam.OutExtraTransl(self.startCamDurationS, offset)) cameraSvc.animationController.Schedule(transitioncam.OutFOV(self.startCamDurationS)) blue.synchro.SleepSim(500)
def LimitPanning(self): xLimits, yLimits = self.GetPanLimitsBasedOnDistance() if self.controlStyle == CONTROL_BOTH: xAxis = geo2.Vector(self.viewMatrix.transform[0][0], self.viewMatrix.transform[1][0], self.viewMatrix.transform[2][0]) yAxis = geo2.Vector(self.viewMatrix.transform[0][1], self.viewMatrix.transform[1][1], self.viewMatrix.transform[2][1]) else: xAxis = geo2.Vector(1.0, 0.0, 0.0) yAxis = geo2.Vector(0.0, 1.0, 0.0) self.xFactor = min(xLimits[1], max(xLimits[0], self.xFactor)) self.yFactor = min(yLimits[1], max(yLimits[0], self.yFactor)) horizontal = xAxis * self.xFactor vertical = yAxis * self.yFactor offset = horizontal + vertical rotatedFocus = geo2.QuaternionTransformVector(self.avatar.rotation, self.focus) newPoi = rotatedFocus + offset self.SetPointOfInterest(newPoi)
def _PlayTunnelSequence(self): if self.ending: self.fxSequencer.LogWarn( 'Jump Transition: Trying to play tunnel start sequence while ending.' ) return normDir = geo2.QuaternionTransformVector(self.effectRoot.rotation, (0, 0, 1)) self.normDir = normDir camera = self.GetCamera() camera.shakeController.DoCameraShake(self.shakeJumpOut) if self.initCS is not None: self.initCS.Stop() if self.startCS is not None: self.startCS.Play() camera.animationController.Schedule( transitioncam.OutFOV(self.startCamDurationS)) blue.synchro.SleepSim(500)
def GetTargetPlaneNormal(self, ray): """ We need to pick a plane for ray intersection for translation and scaling because the camera might end up in the plane that the selected axis is fixed to. In 3-Dimensions we have 3 perpendicular planes and each axis can be mapped to two of them, so we need to pick the one that we are further away from. """ if self.activeManipAxis in ('y',): camera = sm.GetService('sceneManager').GetRegisteredCamera('systemmap') y, p, r = geo2.QuaternionRotationGetYawPitchRoll(camera.rotationAroundParent) q = geo2.QuaternionRotationSetYawPitchRoll(y, 0.0, 0.0) return geo2.QuaternionTransformVector(q, (0.0, 0.0, 1.0)) elif self.activeManipAxis in ('x', 'z', 'xz'): return Y_AXIS elif self.activeManipAxis in ('y', 'xy'): return Z_AXIS else: return X_AXIS
def __UpdateCompass(self): bp = self.michelle.GetBallpark() if bp is None: return camera = self.GetCamera() camRotation = geo2.QuaternionRotationGetYawPitchRoll( camera.rotationAroundParent) yaw, pitch, roll = camRotation cx, cy, cz = geo2.QuaternionTransformVector( camera.rotationAroundParent, (0, 0, -1.0)) camLengthInPlane = geo2.Vec2Length((cx, cz)) camAngle = math.atan2(cy, camLengthInPlane) self.compassTransform.rotation = -yaw + math.pi myPos = bp.GetCurrentEgoPos() if self.lastPose: lastCamRot, lastPos = self.lastPose isNewCamRotation = not AreVectorsEqual(lastCamRot, camRotation, 0.05) isNewPosition = not AreVectorsEqual(lastPos, myPos, 0.5) isNewPose = isNewPosition or isNewCamRotation else: isNewPosition = True isNewPose = True for siteID, indicator in self.siteIndicatorsBySiteID.iteritems(): if indicator.isNew or isNewPose: toSiteVec = geo2.Vec3SubtractD(indicator.data.position, myPos) toSiteVec = geo2.Vec3NormalizeD(toSiteVec) if indicator.isNew or isNewPosition: angle = math.atan2(-toSiteVec[2], toSiteVec[0]) indicator.SetRotation(angle + MATH_PI_2) sx, sy, sz = toSiteVec siteLengthInPlane = geo2.Vec2Length((sx, sz)) siteAngle = math.atan2(sy, siteLengthInPlane) inclinationAngle = siteAngle - camAngle verticalAngle = min(inclinationAngle, MATH_PI_2) indicator.SetInclination(verticalAngle) indicator.isNew = False self.lastPose = (camRotation, myPos)
def RotateSelected(self, yaw, pitch, roll): slimItems = self.GetSelObjects() if len(slimItems) == 0: return yawRad = yaw / 180.0 * math.pi pitchRad = pitch / 180.0 * math.pi rollRad = roll / 180.0 * math.pi rotationToAdd = geo2.QuaternionRotationSetYawPitchRoll( yawRad, pitchRad, rollRad) posCtr = geo2.VectorD(0, 0, 0) for slimItem in slimItems: posCtr += geo2.VectorD(slimItem.dunX, slimItem.dunY, slimItem.dunZ) geo2.Scale(posCtr, 1.0 / len(slimItems)) for slimItem in slimItems: rot = getattr(slimItem, 'dunRotation', None) slimItemRotation = geo2.QuaternionIdentity() if rot is not None: yaw, pitch, roll = rot slimItemRotation = geo2.QuaternionRotationSetYawPitchRoll( yaw / 180.0 * math.pi, pitch / 180.0 * math.pi, roll / 180.0 * math.pi) y, p, r = geo2.QuaternionRotationGetYawPitchRoll(slimItemRotation) slimItemRotation = geo2.QuaternionMultiply(rotationToAdd, slimItemRotation) y, p, r = geo2.QuaternionRotationGetYawPitchRoll(slimItemRotation) y = y / math.pi * 180.0 p = p / math.pi * 180.0 r = r / math.pi * 180.0 translation = geo2.VectorD(slimItem.dunX, slimItem.dunY, slimItem.dunZ) translation -= posCtr geo2.QuaternionTransformVector(rotationToAdd, translation) translation += posCtr dungeonHelper.SetObjectPosition(slimItem.dunObjectID, translation.x, translation.y, translation.z) dungeonHelper.SetObjectRotation(slimItem.dunObjectID, y, p, r)
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)