public void Rotate(float radian, Vec3 axis)
        {
            float sa;
            float ca;

            MBMath.SinCos(radian, out sa, out ca);
            MatrixFrame matrixFrame = new MatrixFrame();

            matrixFrame[0, 0] = (float)((double)axis.x * (double)axis.x * (1.0 - (double)ca)) + ca;
            matrixFrame[1, 0] = (float)((double)axis.x * (double)axis.y * (1.0 - (double)ca) - (double)axis.z * (double)sa);
            matrixFrame[2, 0] = (float)((double)axis.x * (double)axis.z * (1.0 - (double)ca) + (double)axis.y * (double)sa);
            matrixFrame[3, 0] = 0.0f;
            matrixFrame[0, 1] = (float)((double)axis.y * (double)axis.x * (1.0 - (double)ca) + (double)axis.z * (double)sa);
            matrixFrame[1, 1] = (float)((double)axis.y * (double)axis.y * (1.0 - (double)ca)) + ca;
            matrixFrame[2, 1] = (float)((double)axis.y * (double)axis.z * (1.0 - (double)ca) - (double)axis.x * (double)sa);
            matrixFrame[3, 1] = 0.0f;
            matrixFrame[0, 2] = (float)((double)axis.x * (double)axis.z * (1.0 - (double)ca) - (double)axis.y * (double)sa);
            matrixFrame[1, 2] = (float)((double)axis.y * (double)axis.z * (1.0 - (double)ca) + (double)axis.x * (double)sa);
            matrixFrame[2, 2] = (float)((double)axis.z * (double)axis.z * (1.0 - (double)ca)) + ca;
            matrixFrame[3, 2] = 0.0f;
            matrixFrame[0, 3] = 0.0f;
            matrixFrame[1, 3] = 0.0f;
            matrixFrame[2, 3] = 0.0f;
            matrixFrame[3, 3] = 1f;
            this.origin       = this.TransformToParent(matrixFrame.origin);
            this.rotation     = this.rotation.TransformToParent(matrixFrame.rotation);
        }
        public static MatrixFrame Lerp(MatrixFrame m1, MatrixFrame m2, float alpha)
        {
            MatrixFrame matrixFrame;

            matrixFrame.rotation = Mat3.Lerp(m1.rotation, m2.rotation, alpha);
            matrixFrame.origin   = Vec3.Lerp(m1.origin, m2.origin, alpha);
            return(matrixFrame);
        }
        public void RespawnUnits()
        {
            var scene          = this.Mission.Scene;
            var xInterval      = this.CaptureTheBannerLordParams.soldierXInterval;
            var yInterval      = this.CaptureTheBannerLordParams.soldierYInterval;
            var soldiersPerRow = this.CaptureTheBannerLordParams.soldiersPerRow;

            var startPos        = this.CaptureTheBannerLordParams.FormationPosition;
            var xDir            = this.CaptureTheBannerLordParams.formationDirection;
            var yDir            = this.CaptureTheBannerLordParams.formationDirection.LeftVec();
            var agentDefaultDir = new TL.Vec2(0, 1);
            var useFreeCamera   = this.CaptureTheBannerLordParams.useFreeCamera;

            BasicCharacterObject soldierCharacter = this._game.ObjectManager.GetObject <BasicCharacterObject>(this.CaptureTheBannerLordParams.playerSoldierCharacterId);
            var playerSoldierFormationClass       = soldierCharacter.CurrentFormationClass;

            this.playerTeam = this.Mission.Teams.Add(BattleSideEnum.Attacker, 0xff3f51b5);
            var mapHasNavMesh = false;

            {
                var formation = playerTeam.GetFormation(playerSoldierFormationClass);
                var width     = this.getInitialFormationWidth(playerTeam, playerSoldierFormationClass);
                var centerPos = startPos + yDir * (width / 2);
                var wp        = new WorldPosition(scene, centerPos.ToVec3());
                formation.SetPositioning(wp, xDir, null);
                formation.FormOrder = FormOrder.FormOrderCustom(width);
                mapHasNavMesh       = wp.GetNavMesh() != System.UIntPtr.Zero;
            }
            if (this.playerTeamAgents.Count < this.CaptureTheBannerLordParams.playerSoldierCount)
            {
                var formation = playerTeam.GetFormation(playerSoldierFormationClass);

                AgentBuildData soldierBuildData = new AgentBuildData(new BasicBattleAgentOrigin(soldierCharacter))
                                                  .ClothingColor1(playerTeam.Color)
                                                  .ClothingColor2(playerTeam.Color2)
                                                  .Banner(playerTeam.Banner)
                                                  .IsFemale(false)
                                                  .Team(playerTeam)
                                                  .Formation(formation);

                if (!mapHasNavMesh)
                {
                    var x   = this.playerTeamAgents.Count / soldiersPerRow;
                    var y   = this.playerTeamAgents.Count % soldiersPerRow;
                    var mat = TL.Mat3.Identity;
                    var pos = startPos + xDir * (-xInterval * x) + yDir * yInterval * y;
                    mat.RotateAboutUp(agentDefaultDir.AngleBetween(xDir));
                    var agentFrame = new TaleWorlds.Library.MatrixFrame(mat, new TL.Vec3(pos.x, pos.y, 30));
                    soldierBuildData.InitialFrame(agentFrame);
                }

                var agent = this.Mission.SpawnAgent(soldierBuildData);
                agent.SetWatchState(AgentAIStateFlagComponent.WatchState.Alarmed);
                this.playerTeamAgents.Add(agent);
            }
        }
        public static MatrixFrame Slerp(MatrixFrame m1, MatrixFrame m2, float alpha)
        {
            MatrixFrame matrixFrame;

            matrixFrame.origin = Vec3.Lerp(m1.origin, m2.origin, alpha);
            Quaternion quaternion = Quaternion.Slerp(Quaternion.QuaternionFromMat3(m1.rotation), Quaternion.QuaternionFromMat3(m2.rotation), alpha);

            matrixFrame.rotation = quaternion.ToMat3;
            return(matrixFrame);
        }
        public void Scale(Vec3 scalingVector)
        {
            MatrixFrame identity = MatrixFrame.Identity;

            identity.rotation.s.x = scalingVector.x;
            identity.rotation.f.y = scalingVector.y;
            identity.rotation.u.z = scalingVector.z;
            this.origin           = this.TransformToParent(identity.origin);
            this.rotation         = this.rotation.TransformToParent(identity.rotation);
        }
        private static void DivideWith(ref MatrixFrame matrix, float w)
        {
            float num = 1f / w;

            for (int i = 0; i < 4; ++i)
            {
                for (int j = 0; j < 4; ++j)
                {
                    matrix[i, j] *= num;
                }
            }
        }
        public MatrixFrame Inverse()
        {
            this.AssertFilled();
            MatrixFrame matrix = new MatrixFrame();
            float       num1   = (float)((double)this[2, 2] * (double)this[3, 3] - (double)this[2, 3] * (double)this[3, 2]);
            float       num2   = (float)((double)this[1, 2] * (double)this[3, 3] - (double)this[1, 3] * (double)this[3, 2]);
            float       num3   = (float)((double)this[1, 2] * (double)this[2, 3] - (double)this[1, 3] * (double)this[2, 2]);
            float       num4   = (float)((double)this[0, 2] * (double)this[3, 3] - (double)this[0, 3] * (double)this[3, 2]);
            float       num5   = (float)((double)this[0, 2] * (double)this[2, 3] - (double)this[0, 3] * (double)this[2, 2]);
            float       num6   = (float)((double)this[0, 2] * (double)this[1, 3] - (double)this[0, 3] * (double)this[1, 2]);
            float       num7   = (float)((double)this[2, 1] * (double)this[3, 3] - (double)this[2, 3] * (double)this[3, 1]);
            float       num8   = (float)((double)this[1, 1] * (double)this[3, 3] - (double)this[1, 3] * (double)this[3, 1]);
            float       num9   = (float)((double)this[1, 1] * (double)this[2, 3] - (double)this[1, 3] * (double)this[2, 1]);
            float       num10  = (float)((double)this[0, 1] * (double)this[3, 3] - (double)this[0, 3] * (double)this[3, 1]);
            float       num11  = (float)((double)this[0, 1] * (double)this[2, 3] - (double)this[0, 3] * (double)this[2, 1]);
            float       num12  = (float)((double)this[1, 1] * (double)this[3, 3] - (double)this[1, 3] * (double)this[3, 1]);
            float       num13  = (float)((double)this[0, 1] * (double)this[1, 3] - (double)this[0, 3] * (double)this[1, 1]);
            float       num14  = (float)((double)this[2, 1] * (double)this[3, 2] - (double)this[2, 2] * (double)this[3, 1]);
            float       num15  = (float)((double)this[1, 1] * (double)this[3, 2] - (double)this[1, 2] * (double)this[3, 1]);
            float       num16  = (float)((double)this[1, 1] * (double)this[2, 2] - (double)this[1, 2] * (double)this[2, 1]);
            float       num17  = (float)((double)this[0, 1] * (double)this[3, 2] - (double)this[0, 2] * (double)this[3, 1]);
            float       num18  = (float)((double)this[0, 1] * (double)this[2, 2] - (double)this[0, 2] * (double)this[2, 1]);
            float       num19  = (float)((double)this[0, 1] * (double)this[1, 2] - (double)this[0, 2] * (double)this[1, 1]);

            matrix[0, 0] = (float)((double)this[1, 1] * (double)num1 - (double)this[2, 1] * (double)num2 + (double)this[3, 1] * (double)num3);
            matrix[0, 1] = (float)(-(double)this[0, 1] * (double)num1 + (double)this[2, 1] * (double)num4 - (double)this[3, 1] * (double)num5);
            matrix[0, 2] = (float)((double)this[0, 1] * (double)num2 - (double)this[1, 1] * (double)num4 + (double)this[3, 1] * (double)num6);
            matrix[0, 3] = (float)(-(double)this[0, 1] * (double)num3 + (double)this[1, 1] * (double)num5 - (double)this[2, 1] * (double)num6);
            matrix[1, 0] = (float)(-(double)this[1, 0] * (double)num1 + (double)this[2, 0] * (double)num2 - (double)this[3, 0] * (double)num3);
            matrix[1, 1] = (float)((double)this[0, 0] * (double)num1 - (double)this[2, 0] * (double)num4 + (double)this[3, 0] * (double)num5);
            matrix[1, 2] = (float)(-(double)this[0, 0] * (double)num2 + (double)this[1, 0] * (double)num4 - (double)this[3, 0] * (double)num6);
            matrix[1, 3] = (float)((double)this[0, 0] * (double)num3 - (double)this[1, 0] * (double)num5 + (double)this[2, 0] * (double)num6);
            matrix[2, 0] = (float)((double)this[1, 0] * (double)num7 - (double)this[2, 0] * (double)num8 + (double)this[3, 0] * (double)num9);
            matrix[2, 1] = (float)(-(double)this[0, 0] * (double)num7 + (double)this[2, 0] * (double)num10 - (double)this[3, 0] * (double)num11);
            matrix[2, 2] = (float)((double)this[0, 0] * (double)num12 - (double)this[1, 0] * (double)num10 + (double)this[3, 0] * (double)num13);
            matrix[2, 3] = (float)(-(double)this[0, 0] * (double)num9 + (double)this[1, 0] * (double)num11 - (double)this[2, 0] * (double)num13);
            matrix[3, 0] = (float)(-(double)this[1, 0] * (double)num14 + (double)this[2, 0] * (double)num15 - (double)this[3, 0] * (double)num16);
            matrix[3, 1] = (float)((double)this[0, 0] * (double)num14 - (double)this[2, 0] * (double)num17 + (double)this[3, 0] * (double)num18);
            matrix[3, 2] = (float)(-(double)this[0, 0] * (double)num15 + (double)this[1, 0] * (double)num17 - (double)this[3, 0] * (double)num19);
            matrix[3, 3] = (float)((double)this[0, 0] * (double)num16 - (double)this[1, 0] * (double)num18 + (double)this[2, 0] * (double)num19);
            float w = (float)((double)this[0, 0] * (double)matrix[0, 0] + (double)this[1, 0] * (double)matrix[0, 1] + (double)this[2, 0] * (double)matrix[0, 2] + (double)this[3, 0] * (double)matrix[0, 3]);

            if ((double)w != 1.0)
            {
                MatrixFrame.DivideWith(ref matrix, w);
            }
            return(matrix);
        }
示例#8
0
 public static void RenderDebugFrame(MatrixFrame frame, float lineLength, float time = 0.0f) => Debug.DebugManager?.RenderDebugFrame(frame, lineLength, time);
        public void AfterStart2()
        {
            this._started = true;
            var scene = this.Mission.Scene;

            if (this.battleTestParams.skyBrightness >= 0)
            {
                scene.SetSkyBrightness(this.battleTestParams.skyBrightness);
            }

            if (this.battleTestParams.rainDensity >= 0)
            {
                scene.SetRainDensity(this.battleTestParams.rainDensity);
            }

            this.Mission.MissionTeamAIType = Mission.MissionTeamAITypeEnum.FieldBattle;
            this.Mission.SetMissionMode(MissionMode.Battle, true);

            var xInterval      = this.battleTestParams.soldierXInterval;
            var yInterval      = this.battleTestParams.soldierYInterval;
            var soldiersPerRow = this.battleTestParams.soldiersPerRow;

            var startPos        = this.battleTestParams.FormationPosition;
            var xDir            = this.battleTestParams.formationDirection;
            var yDir            = this.battleTestParams.formationDirection.LeftVec();
            var agentDefaultDir = new TL.Vec2(0, 1);
            var useFreeCamera   = this.battleTestParams.useFreeCamera;

            BasicCharacterObject soldierCharacter = this._game.ObjectManager.GetObject <BasicCharacterObject>(this.battleTestParams.playerSoldierCharacterId);
            var playerSoldierFormationClass       = soldierCharacter.CurrentFormationClass;
            var playerTeam = this.Mission.Teams.Add(BattleSideEnum.Attacker, 0xff3f51b5);

            playerTeam.AddTeamAI(new TeamAIGeneral(this.Mission, playerTeam));
            playerTeam.AddTacticOption(new TacticCharge(playerTeam));
            // playerTeam.AddTacticOption(new TacticFullScaleAttack(playerTeam));
            playerTeam.ExpireAIQuerySystem();
            playerTeam.ResetTactic();
            this.Mission.PlayerTeam = playerTeam;

            var playerPosVec2 = startPos + xDir * -10 + yDir * -10;
            var playerPos     = new TL.Vec3(playerPosVec2.x, playerPosVec2.y, 30);

            if (!useFreeCamera)
            {
                var playerMat = TL.Mat3.Identity;
                playerMat.RotateAboutUp(agentDefaultDir.AngleBetween(xDir));
                BasicCharacterObject playerCharacter = this._game.ObjectManager.GetObject <BasicCharacterObject>(this.battleTestParams.playerCharacterId);
                AgentBuildData       agentBuildData  = new AgentBuildData(new BasicBattleAgentOrigin(playerCharacter))
                                                       .ClothingColor1(0xff3f51b5)
                                                       .ClothingColor2(0xff3f51b5)
                                                       .Banner(Banner.CreateRandomBanner())
                                                       .IsFemale(false)
                                                       .InitialFrame(new TL.MatrixFrame(playerMat, playerPos));
                Agent player = this.Mission.SpawnAgent(agentBuildData, false, 0);
                player.Controller = Agent.ControllerType.Player;
                player.WieldInitialWeapons();
                player.AllowFirstPersonWideRotation();

                Mission.MainAgent = player;
                player.SetTeam(playerTeam, true);
                playerTeam.GetFormation(playerSoldierFormationClass).PlayerOwner = player;
                playerTeam.PlayerOrderController.Owner = player;
                this._playerAgent = player;
            }
            else
            {
                var c = this.battleTestParams.playerSoldierCount;
                if (c <= 0)
                {
                    this.freeCameraPosition = new TL.Vec3(startPos.x, startPos.y, 30);
                }
                else
                {
                    var rowCount = (c + soldiersPerRow - 1) / soldiersPerRow;
                    var p        = startPos + (System.Math.Min(soldiersPerRow, c) - 1) / 2 * yInterval * yDir - rowCount * xInterval * xDir;
                    this.freeCameraPosition = new TL.Vec3(p.x, p.y, 5);
                }
            }

            var mapHasNavMesh = false;

            {
                var formation = playerTeam.GetFormation(playerSoldierFormationClass);
                var width     = this.getInitialFormationWidth(playerTeam, playerSoldierFormationClass);
                var centerPos = startPos + yDir * (width / 2);
                var wp        = new WorldPosition(scene, centerPos.ToVec3());
                formation.SetPositioning(wp, xDir, null);
                formation.FormOrder = FormOrder.FormOrderCustom(width);
                mapHasNavMesh       = wp.GetNavMesh() != System.UIntPtr.Zero;
            }

            for (var i = 0; i < this.battleTestParams.playerSoldierCount; i += 1)
            {
                var formation = playerTeam.GetFormation(playerSoldierFormationClass);

                AgentBuildData soldierBuildData = new AgentBuildData(new BasicBattleAgentOrigin(soldierCharacter))
                                                  .ClothingColor1(playerTeam.Color)
                                                  .ClothingColor2(playerTeam.Color2)
                                                  .Banner(playerTeam.Banner)
                                                  .IsFemale(false)
                                                  .Team(playerTeam)
                                                  .Formation(formation);

                if (!mapHasNavMesh)
                {
                    var x   = i / soldiersPerRow;
                    var y   = i % soldiersPerRow;
                    var mat = TL.Mat3.Identity;
                    var pos = startPos + xDir * (-xInterval * x) + yDir * yInterval * y;
                    mat.RotateAboutUp(agentDefaultDir.AngleBetween(xDir));
                    var agentFrame = new TaleWorlds.Library.MatrixFrame(mat, new TL.Vec3(pos.x, pos.y, 30));
                    soldierBuildData.InitialFrame(agentFrame);
                }

                var agent = this.Mission.SpawnAgent(soldierBuildData);
                agent.SetWatchState(AgentAIStateFlagComponent.WatchState.Alarmed);
            }

            BasicCharacterObject enemyCharacter = this._game.ObjectManager.GetObject <BasicCharacterObject>(this.battleTestParams.enemySoldierCharacterId);
            var enemyTeam = this.Mission.Teams.Add(BattleSideEnum.Defender, 0xffff6090);

            enemyTeam.AddTeamAI(new TeamAIGeneral(this.Mission, enemyTeam));
            enemyTeam.AddTacticOption(new TacticCharge(enemyTeam));
            // enemyTeam.AddTacticOption(new TacticFullScaleAttack(enemyTeam));
            enemyTeam.SetIsEnemyOf(playerTeam, true);
            playerTeam.SetIsEnemyOf(enemyTeam, true);
            enemyTeam.ExpireAIQuerySystem();
            enemyTeam.ResetTactic();

            var enemyFormationClass = enemyCharacter.CurrentFormationClass;
            var enemyFormation      = enemyTeam.GetFormation(FormationClass.Ranged);

            {
                float width     = this.getInitialFormationWidth(enemyTeam, enemyFormationClass);
                var   centerPos = startPos + yDir * (width / 2) + xDir * this.battleTestParams.distance;
                var   wp        = new WorldPosition(scene, centerPos.ToVec3());
                enemyFormation.SetPositioning(wp, -xDir, null);
                enemyFormation.FormOrder = FormOrder.FormOrderCustom(width);
            }

            for (var i = 0; i < this.battleTestParams.enemySoldierCount; i += 1)
            {
                AgentBuildData enemyBuildData = new AgentBuildData(new BasicBattleAgentOrigin(enemyCharacter))
                                                .ClothingColor1(enemyTeam.Color)
                                                .ClothingColor2(enemyTeam.Color2)
                                                .Banner(enemyTeam.Banner)
                                                .Formation(enemyFormation);

                if (!mapHasNavMesh)
                {
                    var x   = i / soldiersPerRow;
                    var y   = i % soldiersPerRow;
                    var mat = TL.Mat3.Identity;
                    mat.RotateAboutUp(agentDefaultDir.AngleBetween(-xDir));
                    var pos        = startPos + xDir * this.battleTestParams.distance + xDir * xInterval * x + yDir * yInterval * y;
                    var agentFrame = new TaleWorlds.Library.MatrixFrame(TaleWorlds.Library.Mat3.Identity, new TL.Vec3(pos.x, pos.y, 30));
                    enemyBuildData.InitialFrame(agentFrame);
                }
                var agent = this.Mission.SpawnAgent(enemyBuildData);
                agent.SetTeam(enemyTeam, true);
                agent.Formation = enemyFormation;
                agent.SetWatchState(AgentAIStateFlagComponent.WatchState.Alarmed);
            }

            {
                var a = this.Mission.IsOrderShoutingAllowed();
                var b = this.Mission.IsAgentInteractionAllowed();
                var c = GameNetwork.IsClientOrReplay;
                var d = playerTeam.PlayerOrderController.Owner == null;
                ModuleLogger.Log("mission allowed shouting: {0} interaction: {1} {2} {3}", a, b, c, d);
            }
        }
 public MatrixFrame TransformToLocalNonOrthogonal(ref MatrixFrame frame) => new MatrixFrame(this.rotation.s.x, this.rotation.s.y, this.rotation.s.z, 0.0f, this.rotation.f.x, this.rotation.f.y, this.rotation.f.z, 0.0f, this.rotation.u.x, this.rotation.u.y, this.rotation.u.z, 0.0f, this.origin.x, this.origin.y, this.origin.z, 1f).Inverse().TransformToParent(frame);
 public bool NearlyEquals(MatrixFrame rhs, float epsilon = 1E-05f) => this.rotation.NearlyEquals(rhs.rotation, epsilon) && this.origin.NearlyEquals(rhs.origin, epsilon);
 public MatrixFrame TransformToLocal(MatrixFrame m) => new MatrixFrame(this.rotation.TransformToLocal(m.rotation), this.TransformToLocal(m.origin));