Пример #1
0
    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)
Пример #2
0
 def _TransformAxis(self, v):
     viewMat = trinity.GetViewTransform()
     viewVec = geo2.Vector(viewMat[0][2], viewMat[1][2], viewMat[2][2])
     pos = self.GetTranslation()
     start = self.startPlanePos - pos
     start = geo2.Vec3Normalize(start)
     end = self.endPlanePos - pos
     end = geo2.Vec3Normalize(end)
     q = geo2.QuaternionIdentity()
     dot = geo2.Vec3Dot(start, end)
     if 1.0 - dot < 1e-05:
         return q
     dnormal = geo2.Vec3Cross(start, end)
     if self.activeManipAxis == 'w':
         worldInv = geo2.MatrixInverse(self.worldTranslation)
         axis = geo2.Vec3TransformNormal(viewVec, worldInv)
         axis = geo2.Vector(*axis)
         rdot = geo2.Vec3Dot(axis, viewVec)
         ddot = geo2.Vec3Dot(dnormal, axis)
         if ddot < 0.0 and rdot > 0.0:
             axis = -axis
         elif ddot > 0.0 and rdot < 0.0:
             axis = -axis
     elif self.activeManipAxis == 'ww':
         curP = self._Hemisphere(self.curX, self.curY)
         preP = self._Hemisphere(self.preX, self.preY)
         viewInverse = geo2.MatrixInverse(viewMat)
         norm = geo2.Vec3Cross(preP, curP)
         worldInv = geo2.MatrixInverse(self.worldTranslation)
         axis = geo2.Vec3TransformNormal(norm, worldInv)
         axis = geo2.Vec3TransformNormal(axis, viewInverse)
         dot = geo2.Vec3Dot(curP, preP)
     else:
         axis = self.axis[self.activeManipAxis]
         if geo2.Vec3Dot(dnormal, axis) < 0.0:
             axis = -axis
         if self.activeManipAxis == 'x' and self.worldTranslation[0][
                 0] < 0.0 or self.activeManipAxis == 'y' and self.worldTranslation[
                     1][1] < 0.0 or self.activeManipAxis == 'z' and self.worldTranslation[
                         2][2] < 0.0:
             axis = -axis
     self.startPlanePos = self.endPlanePos
     if dot < -1:
         dot = -1
     elif dot > 1:
         dot = 1
     q = geo2.QuaternionRotationAxis(axis, math.acos(dot))
     q = geo2.QuaternionNormalize(q)
     return q
Пример #3
0
 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)
Пример #4
0
def CreateMiniCollisionObject(name, miniballs, minicapsules, miniboxes):
    t = trinity.EveRootTransform()
    sphere = blue.resMan.LoadObject('res:/Model/Global/Miniball.red')
    capsule = blue.resMan.LoadObject('res:/Model/Global/Minicapsule.red')
    box = blue.resMan.LoadObject('res:/Model/Global/Minibox.red')
    if len(miniballs) > 0:
        for miniball in miniballs:
            mball = sphere.CopyTo()
            mball.translation = (miniball.x, miniball.y, miniball.z)
            r = miniball.radius * 2
            mball.scaling = (r, r, r)
            t.children.append(mball)

    for minicapsule in minicapsules:
        mcapsule = capsule.CopyTo()
        pointA = (minicapsule.ax, minicapsule.ay, minicapsule.az)
        pointB = (minicapsule.bx, minicapsule.by, minicapsule.bz)
        dir = geo2.Vec3Subtract(pointA, pointB)
        length = geo2.Vec3Length(dir)
        mcapsule.translation = geo2.Vec3Scale(geo2.Vec3Add(pointA, pointB),
                                              0.5)
        radius = minicapsule.radius
        pitch = math.acos(dir[1] / length)
        yaw = math.atan2(dir[0], dir[2])
        quat = geo2.QuaternionRotationSetYawPitchRoll(yaw, pitch, 0)
        mcapsule.rotation = quat
        for each in mcapsule.children:
            if each.name == 'Cylinder':
                height = length * each.scaling[1]
                rscaling = geo2.Vec3Scale((each.scaling[0], each.scaling[2]),
                                          radius)
                each.scaling = (rscaling[0], height, rscaling[1])
            else:
                each.scaling = geo2.Vec3Scale(each.scaling, radius)
                each.translation = geo2.Vec3Scale(each.translation, length)

        t.children.append(mcapsule)

    for minibox in miniboxes:
        mbox = box.CopyTo()
        corner = (minibox.c0, minibox.c1, minibox.c2)
        xAxis = (minibox.x0, minibox.x1, minibox.x2)
        yAxis = (minibox.y0, minibox.y1, minibox.y2)
        zAxis = (minibox.z0, minibox.z1, minibox.z2)
        xyzAxis = geo2.Vec3Add(xAxis, geo2.Vec3Add(yAxis, zAxis))
        center = geo2.Vec3Add(corner, geo2.Vec3Scale(xyzAxis, 0.5))
        xNormalized = geo2.Vec3Normalize(xAxis)
        yNormalized = geo2.Vec3Normalize(yAxis)
        zNormalized = geo2.Vec3Normalize(zAxis)
        rotationMatrix = ((xNormalized[0], xNormalized[1], xNormalized[2], 0),
                          (yNormalized[0], yNormalized[1], yNormalized[2],
                           0), (zNormalized[0], zNormalized[1], zNormalized[2],
                                0), (0, 0, 0, 1))
        rot = geo2.QuaternionRotationMatrix(rotationMatrix)
        mbox.translation = center
        mbox.scaling = geo2.Vec3Transform(
            (1, 1, 1),
            geo2.MatrixScaling(geo2.Vec3Length(xAxis), geo2.Vec3Length(yAxis),
                               geo2.Vec3Length(zAxis)))
        mbox.rotation = geo2.QuaternionNormalize(rot)
        t.children.append(mbox)

    t.name = name
    return t