Exemple #1
0
 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()
Exemple #2
0
 def UpdateMyLocation(self):
     if not uiutil.IsUnder(self, uicore.desktop):
         return
     bp = sm.GetService('michelle').GetBallpark()
     if bp is None or self is None or self.destroyed:
         self.updatemylocationtimer = None
         return
     myball = bp.GetBall(eve.session.shipid)
     if myball is None:
         self.updatemylocationtimer = None
         return
     size = max(1, self.absoluteRight - self.absoluteLeft)
     if size == 1:
         size = max(1, self.absoluteRight - self.absoluteLeft)
     x = y = None
     if self.allowAbstract and settings.user.ui.Get('solarsystemmapabstract', 0):
         if not len(self.orbs):
             return
         x, y = self.GetAbstractPosition((myball.x, 0.0, myball.z), 1)
     elif self.sr.sizefactor is not None and self.sr.sizefactorsize is not None:
         maxdist = self.GetMaxDist()
         sizefactor = size / 2 / maxdist * self.fillSize
         x = FLIPMAP * myball.x * sizefactor / float(size) + 0.5
         y = -(myball.z * sizefactor) / float(size) + 0.5
     if x is not None and y is not None:
         self.imhere.sr.x = x
         self.imhere.sr.y = y
         self.imhere.state = uiconst.UI_DISABLED
     scene = sm.GetService('sceneManager').GetRegisteredScene('default')
     camera = sm.GetService('sceneManager').GetRegisteredCamera('default')
     if camera is None:
         return
     rot = geo2.QuaternionRotationGetYawPitchRoll(camera.rotationAroundParent)
     look = geo2.QuaternionRotationGetYawPitchRoll(camera.rotationOfInterest)
     if not self.fov:
         self.fov = Fov(parent=self.imhere)
     self.fov.SetRotation(rot[0] + look[0] - pi)
     actualfov = camera.fieldOfView * (uicore.desktop.width / float(uicore.desktop.height))
     degfov = actualfov - pi / 2
     self.fov.SetFovAngle(actualfov)
     if self.showingtempangle:
         if not self.tempAngleFov:
             self.tempAngleFov = Fov(parent=self.imhere, state=uiconst.UI_DISABLED, blendMode=trinity.TR2_SBM_ADDX2)
             self.tempAngleFov.SetColor((0.0, 0.3, 0.0, 1.0))
         self.tempAngleFov.display = True
         self.tempAngleFov.SetRotation(rot[0] + look[0] - pi)
         angle = self.showingtempangle
         self.tempAngleFov.SetFovAngle(angle)
     elif self.tempAngleFov:
         self.tempAngleFov.display = False
     self.RefreshOverlays()
Exemple #3
0
    def _ChooseSpawnLocation(self, worldspaceID, sessionChanges={}):
        searchTerm = None
        if 'charid' in sessionChanges and sessionChanges['charid'][0] == None:
            searchTerm = const.cef.CQ_NEWBIE_SPAWN
        elif 'stationid' in sessionChanges and sessionChanges['stationid'][
                0] == None:
            searchTerm = const.cef.CQ_BALCONY_SPAWN
        else:
            searchTerm = const.cef.CQ_BEDROOM_SPAWN
        if searchTerm is not None:
            spawnLocators = sm.GetService(
                'spawnLocationClient').GetSpawnLocationsBySceneID(worldspaceID)
            for locator in spawnLocators:
                spawnLocationComponent = locator.GetComponent('spawnLocation')
                locationType = spawnLocationComponent.spawnLocationType
                if locationType == searchTerm:
                    self.cameraClient.RegisterCameraStartupInfo(
                        spawnLocationComponent.cameraYaw,
                        spawnLocationComponent.cameraPitch,
                        spawnLocationComponent.cameraZoom)
                    spawnPoint = locator.GetComponent('position').position
                    xyzRot = locator.GetComponent('position').rotation
                    spawnRot = geo2.QuaternionRotationGetYawPitchRoll(xyzRot)
                    return (spawnPoint, spawnRot)

            self.LogWarn('Failed to find the locator:', searchTerm)
        spawnPoint, spawnRot = sm.GetService(
            'worldSpaceClient').GetWorldSpaceSafeSpot(session.worldspaceid)
        self.LogWarn(
            "Spawn point search term was None which means we don't have a defined spawn",
            'location and will revert to the default safe spot')
        return (spawnPoint, spawnRot)
 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
Exemple #5
0
 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
Exemple #6
0
 def GetYawPitch(self):
     rotMatrix = geo2.MatrixTranspose(self.viewMatrix.transform)
     quat = geo2.QuaternionRotationMatrix(rotMatrix)
     yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(quat)
     yaw = math.pi / 2 - yaw
     pitch = math.pi / 2 - pitch
     return (yaw, pitch)
Exemple #7
0
 def SetIntendedState(self, xInput, zInput, mbMove, runToggle, facingYaw):
     ent = self.entityClient.GetPlayerEntity()
     mode = ent.GetComponent('movement').moveModeManager.GetCurrentMode()
     metaStateIndex = self.movementStates.FindCurrentMetaState(ent)
     if metaStateIndex >= 0:
         self.metaState = self.movementStates.metaStates[metaStateIndex]
     else:
         self.metaState = None
     if self.metaState is not None:
         lastYaw, trash, trash = geo2.QuaternionRotationGetYawPitchRoll(
             ent.GetComponent('position').rotation)
         baseSpeed = self.metaState.get(const.movement.METASTATE_BASE_SPEED,
                                        0.0)
         if not self.metaState.get(
                 const.movement.METASTATE_DISABLE_RUN_TOGGLE, False):
             self.runToggle = runToggle
         if self.runToggle:
             baseSpeed *= self.metaState.get(
                 const.movement.METASTATE_RUNNING_MOD, 1.0)
         animState = self.GetDesiredState(xInput, zInput, mbMove)
         animState = self.CheckStaticStateOK(animState, facingYaw - lastYaw)
         if animState is not None:
             if hasattr(mode, 'CheckNewSetStaticState'):
                 mode.CheckNewSetStaticState(metaStateIndex, animState,
                                             baseSpeed, facingYaw - lastYaw)
                 return
         if hasattr(mode, 'SetMetaState'):
             mode.SetMetaState(metaStateIndex, baseSpeed)
Exemple #8
0
 def _SaveBall(self, ballID, michelle):
     try:
         slimItem = michelle.GetItem(ballID)
         if not slimItem:
             return
         objectID = slimItem.dunObjectID
         if self.unsavedChanges[
                 ballID] & dungeonEditorTools.CHANGE_TRANSLATION:
             dungeonHelper.SaveObjectPosition(objectID, slimItem.dunX,
                                              slimItem.dunY, slimItem.dunZ)
         if self.unsavedChanges[ballID] & dungeonEditorTools.CHANGE_SCALE:
             dungeonHelper.SaveObjectRadius(objectID, slimItem.dunRadius)
         targetBall = michelle.GetBall(slimItem.itemID)
         targetModel = getattr(targetBall, 'model', None)
         if not targetModel and not self.unsavedChanges[
                 ballID] & dungeonEditorTools.CHANGE_TRANSLATION | dungeonEditorTools.CHANGE_SCALE:
             del self.lockedObjects[objectID]
         if targetModel and self.unsavedChanges[
                 ballID] & dungeonEditorTools.CHANGE_ROTATION:
             quat = targetModel.rotationCurve.value
             yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(quat)
             yaw = yaw / math.pi * 180.0
             pitch = pitch / math.pi * 180.0
             roll = roll / math.pi * 180.0
             dungeonHelper.SaveObjectRotation(objectID, yaw, pitch, roll)
     finally:
         del self.unsavedChanges[ballID]
         del self.unsavedTime[ballID]
Exemple #9
0
 def AdjustYaw(self, delta):
     if self.controlStyle == CONTROL_NONE:
         return
     if self._rotateAvatar:
         delta = min(35.0, max(-35.0, delta)) * 0.005
         yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(
             self.avatar.rotation)
         yaw = yaw + delta
         if self.maxRotation is not None and self.minRotation is not None:
             if yaw < math.pi:
                 yaw = min(yaw, self.minRotation)
             else:
                 yaw = max(yaw, self.maxRotation)
         rotation = geo2.QuaternionRotationSetYawPitchRoll(yaw, pitch, roll)
         self.avatar.rotation = rotation
         charSvc = sm.GetService('character')
         if uiutil.GetAttrs(charSvc, 'sculpting', 'highlightGhost',
                            'avatar'):
             charSvc.sculpting.highlightGhost.avatar.rotation = rotation
         if uiutil.GetAttrs(charSvc, 'sculpting', 'bodyHighlightGhost',
                            'avatar'):
             charSvc.sculpting.bodyHighlightGhost.avatar.rotation = rotation
         self.Update()
     else:
         cameras.PolarCamera.AdjustYaw(self, delta * 0.005)
Exemple #10
0
 def _AutoOrbit(self, surfacePoint, newZoom, time):
     cam = self.camera
     self.cameraAuto = True
     tMax = time
     t = 0.0
     zoomInit = self.zoom
     spTheta = -surfacePoint.theta + math.pi / 2.0
     if spTheta < 0.0:
         spTheta += 2 * math.pi
     spPhi = surfacePoint.phi - math.pi / 2
     camTheta, camPhi, roll = geo2.QuaternionRotationGetYawPitchRoll(
         self.camera.rotationAroundParent)
     if math.fabs(camTheta - spTheta) > math.pi:
         if camTheta > spTheta:
             camTheta -= 2 * math.pi
         else:
             spTheta -= 2 * math.pi
     while self.cameraAuto and t < tMax:
         elapsed = 1.0 / blue.os.fps
         t += elapsed
         if newZoom is not None:
             currZoom = self.GetSplineValue(t, tMax, zoomInit, newZoom)
             self.ApplyZoom(currZoom)
         newTh = self.GetSplineValue(t, tMax, camTheta, spTheta)
         newPhi = self.GetSplineValue(t, tMax, camPhi - self.pitchDiff,
                                      spPhi + self.pitchDiff)
         cam.SetOrbit(newTh, newPhi + self.pitchDiff)
         blue.pyos.synchro.Yield()
Exemple #11
0
def DecomposeMatrix(matrix):
    if hasattr(matrix,
               '__bluetype__') and matrix.__bluetype__ == 'trinity.TriMatrix':
        matrix = util.ConvertTriToTupleMatrix(matrix)
    scale, rot, pos = geo2.MatrixDecompose(matrix)
    rot = geo2.QuaternionRotationGetYawPitchRoll(rot)
    return (pos, rot, scale)
Exemple #12
0
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)
Exemple #13
0
 def SetupComponent(self, entity, component):
     positionComponent = entity.GetComponent('position')
     if positionComponent:
         component.renderObject.position = positionComponent.position
         if hasattr(component.renderObject, 'SetRotationYawPitchRoll'):
             component.renderObject.SetRotationYawPitchRoll(geo2.QuaternionRotationGetYawPitchRoll(positionComponent.rotation))
     self.ApplyShadowCasterType(entity)
     self.ApplyPerformanceLevelLightDisable(entity)
def GetMaxLookAtWeight_Facing(ent, targetPos):
    sourcePos = ent.GetComponent('position').position
    sourceRot = ent.GetComponent('position').rotation
    source2Target = geo2.Vec3Subtract(targetPos, sourcePos)
    source2Target = geo2.Vec3Normalize(source2Target)
    facingDir = mathCommon.CreateDirectionVectorFromYawAngle(geo2.QuaternionRotationGetYawPitchRoll(sourceRot)[0])
    dot = geo2.Vec3Dot(source2Target, facingDir)
    return max(dot, 0)
Exemple #15
0
 def SetupComponent(self, entity, component):
     positionComponent = entity.GetComponent('position')
     if positionComponent:
         component.renderObject.SetPosition(positionComponent.position)
         if hasattr(component.renderObject, 'SetRotationYawPitchRoll'):
             component.renderObject.SetRotationYawPitchRoll(
                 geo2.QuaternionRotationGetYawPitchRoll(
                     positionComponent.rotation))
Exemple #16
0
def GetNewQuatToFacePos(sourcePos, sourceRot, targetPos):
    """
    Get the Quaternion needed to face a target position given a source position/rotation.
    """
    deltaAngle = GetDeltaAngleToFaceTarget(sourcePos, sourceRot, targetPos)
    yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(sourceRot)
    yaw += deltaAngle
    return geo2.QuaternionRotationSetYawPitchRoll(yaw, pitch, roll)
Exemple #17
0
def GetDeltaAngleToFaceTarget(sourcePos, sourceRot, targetPos):
    """
    Calculates the change in yaw angle necessary to face the targetPos given your sourcePos and your current rotation (sourceRot)
    """
    targetVec = geo2.Vec3Subtract(targetPos, sourcePos)
    theta = GetYawAngleFromDirectionVector(targetVec)
    yaw, trash, trash = geo2.QuaternionRotationGetYawPitchRoll(sourceRot)
    return GetLesserAngleBetweenYaws(yaw, theta)
Exemple #18
0
def GetObjectRotation(objectID):
    scenario = sm.StartService('scenario')
    targetBall, slimItem = scenario.GetBallAndSlimItemFromObjectID(objectID)
    if slimItem is None:
        raise RuntimeError('No slim item?')
    targetModel = getattr(targetBall, 'model', None)
    if not targetModel or not targetModel.rotationCurve or not hasattr(targetModel.rotationCurve, 'value'):
        return (None, None, None)
    return (x * 180.0 / math.pi for x in geo2.QuaternionRotationGetYawPitchRoll(targetModel.rotationCurve.value))
Exemple #19
0
def GetRelativeLookAtVector(sourcePosition, sourceRotation, targetPosition):
    lookAtVector = geo2.Vec3Subtract(targetPosition, sourcePosition)
    yaw, trash, trash = geo2.QuaternionRotationGetYawPitchRoll(sourceRotation)
    yaw = -yaw
    relativeLookAtVector = (lookAtVector[0] * math.cos(yaw) +
                            lookAtVector[2] * math.sin(yaw), lookAtVector[1],
                            -lookAtVector[0] * math.sin(yaw) +
                            lookAtVector[2] * math.cos(yaw))
    return relativeLookAtVector
Exemple #20
0
 def RecreatePlayerMovement(self):
     """
     Decides local heading values from given input; also switches from pathin to kb
     move mode if needed.
     """
     heading = [0, 0, 0]
     if self.navKeys is None:
         self.PrimeNavKeys()
     if self.inputMap is None:
         self.inputMap = EveInputMap()
     if getattr(self, '_delayedMouseUpStillPending', False):
         return
     player = self.entityClient.GetPlayerEntity()
     if player:
         isPathing = isinstance(player.movement.moveModeManager.GetCurrentMode(), GameWorld.PathToMode)
         if self.HasControl() and trinity.app.IsActive() and player.movement.moveModeManager.allowedToMove:
             curKeyState = self.GetKeyState()
             fwdActive, backActive, moveLActive, moveRActive = curKeyState
             isKeyPressed = fwdActive or backActive or moveLActive or moveRActive
             isMouseDriving = self.leftMouseDown and self.rightMouseDown
             if isKeyPressed or isMouseDriving:
                 if isPathing:
                     player.movement.moveModeManager.PushMoveMode(GameWorld.PlayerInputMode())
                     isPathing = False
                 if self.aoClient.IsEntityUsingActionObject(player.entityID):
                     self.aoClient.ExitActionObject(player.entityID)
                     return
             heading[1] = 0.0
             heading[2] = 0.0
             if backActive and fwdActive and self.lastForwardBackward == const.MOVDIR_BACKWARD or backActive and not fwdActive:
                 heading[2] = -1.0
             elif fwdActive or isMouseDriving:
                 heading[2] = 1.0
             heading[0] = 0.0
             if moveLActive and moveRActive and self.lastLeftRight == const.MOVDIR_LEFT or moveLActive and not moveRActive:
                 heading[0] = 1.0
             elif moveRActive:
                 heading[0] = -1.0
             if not isPathing:
                 heading = self.CheckForStop(heading)
                 mode = player.movement.moveModeManager.GetCurrentMode()
                 cc = sm.GetService('cameraClient')
                 cameraOrbitMode = self.rightMouseDown and not self.leftMouseDown
                 if cameraOrbitMode:
                     yawValue, trash, trash = geo2.QuaternionRotationGetYawPitchRoll(player.GetComponent('position').rotation)
                     moving = 1 if heading[2] == 1 else 0
                     self.inputMap.SetIntendedState(0, moving, 0, False, yawValue)
                 else:
                     yawValue = -math.pi / 2.0 - cc.GetActiveCamera().yaw
                     self.inputMap.SetIntendedState(heading[0], heading[2], int(isMouseDriving), False, yawValue)
                 if hasattr(mode, 'SetDynamicState'):
                     if heading[0] != 0 or heading[2] != 0:
                         mode.SetDynamicState(yawValue)
         elif not isPathing:
             self.inputMap.SetIntendedState(0, 0, 0, 0, 0)
     self.lastHeading = heading
Exemple #21
0
def GetEntityYaw(entity):
    entityRot = entity.GetComponent('position').rotation
    yaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(entityRot)
    yaw += math.pi / 2
    if yaw > 2.0 * math.pi:
        yaw = yaw - 2.0 * math.pi
    elif yaw < 0.0:
        yaw = yaw + 2.0 * math.pi
    if yaw <= math.pi:
        return math.pi - yaw
    else:
        return -(yaw - math.pi)
 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 AlignSpaceCameraToViewVector(self, viewVector, duration = None, callback = None, sleep = False):
     rotation = geo2.QuaternionRotationArc((0, 0, 1), viewVector)
     y, p, r = geo2.QuaternionRotationGetYawPitchRoll(rotation)
     if duration:
         currentYaw, currentPitch = self.spaceCameraOrbit
         yawDiff = GetLesserAngleBetweenYaws(currentYaw, y)
         pitchDiff = GetLesserAngleBetweenYaws(currentPitch, p)
         endVal = (currentYaw + yawDiff, currentPitch + pitchDiff)
         uicore.animations.MorphVector2(self, 'spaceCameraOrbit', startVal=(currentYaw, currentPitch), endVal=endVal, duration=duration, callback=callback, sleep=sleep)
     else:
         uicore.animations.StopAnimation(self, 'spaceCameraOrbit')
         self.spaceCameraOrbit = (y, p)
Exemple #24
0
 def SetupComponent(self, entity, component):
     """
     Gets called once all components have been prepared.
     Use this to setup stuff which references other components
     """
     positionComponent = entity.GetComponent('position')
     if positionComponent:
         component.renderObject.SetPosition(positionComponent.position)
         if hasattr(component.renderObject, 'SetRotationYawPitchRoll'):
             component.renderObject.SetRotationYawPitchRoll(
                 geo2.QuaternionRotationGetYawPitchRoll(
                     positionComponent.rotation))
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)
Exemple #26
0
    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 CameraMove_thread(self):
        try:
            camera = self.GetCamera()
            lastYawRad, _, _ = geo2.QuaternionRotationGetYawPitchRoll(
                camera.GetRotationQuat())
            radDelta = 0
            while self.cameraStillSpinning:
                blue.pyos.synchro.Yield()
                if self.mouseDownPos is None or camera is None:
                    self.cameraStillSpinning = False
                    return
                curYaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(
                    camera.GetRotationQuat())
                angleBtwYaws = mathCommon.GetLesserAngleBetweenYaws(
                    lastYawRad, curYaw)
                radDelta += angleBtwYaws
                lastYawRad = curYaw
                if abs(radDelta) > math.pi / 2:
                    sm.ScatterEvent('OnClientMouseSpinInSpace')
                    return

        except Exception as e:
            LogException(e)
    def _PollCamera(self):
        cameraStillSpinning = True
        while cameraStillSpinning:
            blue.pyos.synchro.Yield()
            if self.camera is None:
                cameraStillSpinning = False
                break
            curYaw, pitch, roll = geo2.QuaternionRotationGetYawPitchRoll(
                self.camera.rotationAroundParent)
            cameraStillSpinning = self._IsCameraSpinning(curYaw)
            if cameraStillSpinning:
                self._CountRotations(curYaw)

        self.spinThread = None
 def SetupComponent(self, entity, component):
     positionComponent = entity.GetComponent('position')
     if positionComponent:
         component.renderObject.SetPosition(positionComponent.position)
         if hasattr(component.renderObject, 'SetRotationYawPitchRoll'):
             component.renderObject.SetRotationYawPitchRoll(
                 geo2.QuaternionRotationGetYawPitchRoll(
                     positionComponent.rotation))
     scene = self.graphicClient.GetScene(entity.scene.sceneID)
     cells = scene.cells
     if component.cellA and component.cellB:
         cellAObj = scene._GetCell(component.cellA)
         cellBObj = scene._GetCell(component.cellB)
         component.renderObject.ConnectCells(cellAObj, cellBObj)
 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