/// Builds the shape
        public Shape realizeShape()
        {
            Radian alpha = Math.ACos((mLengthB * mLengthB + mLengthC * mLengthC - mLengthA * mLengthA) / (2 * mLengthB * mLengthC));

            Shape s = new Shape();

            s.addPoint(0.0f, 0.0f);
            s.addPoint(Math.Cos(alpha) * mLengthB, Math.Sin(alpha) * mLengthB);
            s.addPoint(mLengthC, 0.0f);
            s.close();
            s.translate((Math.Cos(alpha) * mLengthB + mLengthC) / -3.0f, mLengthB / -3.0f);

            return(s);
        }
Esempio n. 2
0
        public static Radian angleBetween(Vector3 v1, Vector3 dest)
        {
            float lenProduct = v1.Length * dest.Length;

            // Divide by zero check
            if (lenProduct < 1e-6f)
            {
                lenProduct = 1e-6f;
            }

            float f = v1.DotProduct(dest) / lenProduct;

            f = Clamp(f, (float)-1.0f, 1.0f);
            return(Math.ACos(f));
        }
Esempio n. 3
0
        //    *
        //	 * Equivalent of Ogre::Vector3::angleBetween, applied to Ogre::Vector2
        //
        public static Radian angleBetween(Vector2 v1, Vector2 v2)
        {
            float lenProduct = v1.Length * v2.Length;

            // Divide by zero check
            if (lenProduct < 1e-6f)
            {
                lenProduct = 1e-6f;
            }

            float f = v1.DotProduct(v2) / lenProduct;

            f = Math_Clamp(f, -1.0f, 1.0f);
            return(Math.ACos(f));
        }
Esempio n. 4
0
        public void Update(float frameTime)
        {
            MainState     mainState  = this.mStateMgr.MainState;
            VanillaPlayer mainPlayer = mainState.CharacMgr.MainPlayer;

            if (this.mIsMainGUIOpen && this.mTimeSinceGUIOpen.Milliseconds >= 3500 && this.mStateMgr.GameInfo.IsInEditorMode)
            {
                this.mIsMainGUIOpen = false;
                GUI.Visible         = false;
            }

            if (this.mStateMgr.Controller.HasActionOccured(UserAction.Start))
            {
                if (!GUI.Visible)
                {
                    this.mStateMgr.MainState.OpenMainGUI();
                    this.SwitchGUIVisibility(true);
                    this.mIsMainGUIOpen = true;
                    this.mTimeSinceGUIOpen.Reset();
                }
                else
                {
                    if (this.mIsInventoryOpen)
                    {
                        this.SwitchInventory(false);
                        this.mIsInventoryOpen = false;
                    }
                    else if (this.mIsBuilderOpen)
                    {
                        this.mIsBuilderOpen = false;
                        if (this.BuildingMgr.HasActualBuilding() && !this.BuildingMgr.GetActualBuilding().Built)
                        {
                            this.BuildingMgr.GetActualBuilding().WaitForRessources();
                        }
                    }
                    else
                    {
                        this.mIsMainGUIOpen = false;

                        /*if (this.mStateMgr.GameInfo.IsInEditorMode)
                         *  (this.mStateMgr.MainState as StoryEditorState).OnExit();*/
                    }

                    this.SwitchGUIVisibility(false);
                    GUI.Visible = false;
                }
            }

            if (RequestBuilderClose && this.mIsBuilderOpen)
            {
                RequestBuilderClose = false;
                this.mIsBuilderOpen = false;
                this.SwitchGUIVisibility(false);
                GUI.Visible = false;
            }

            if (!this.mStateMgr.Controller.IsActionOccuring(UserAction.MainAction))
            {
                if (this.mStateMgr.Controller.HasActionOccured(UserAction.Inventory) && (!GUI.Visible || this.mIsInventoryOpen))
                {
                    this.mIsInventoryOpen = !this.mIsInventoryOpen;
                    this.SwitchInventory(this.mIsInventoryOpen);

                    this.SwitchGUIVisibility(this.mIsInventoryOpen);
                }
            }

            if (OpenBuilder)
            {
                Builder.OnOpen = this.OnBuilderOpen;
                new Builder(this.BuildingMgr);
                OpenBuilder         = false;
                this.mIsBuilderOpen = true;
                this.SwitchGUIVisibility(true);
            }

            if (this.mStateMgr.Controller.HasActionOccured(UserAction.CreateUnit))
            {
                this.PlayerRTS.CreateRobot(1);
            }

            if (this.mStateMgr.Controller.HasActionOccured(UserAction.SelectAll))
            {
                this.mAreAllCharacSelected = !this.mAreAllCharacSelected;
                foreach (VanillaNonPlayer charac in this.mStateMgr.MainState.CharacMgr.GetFactionCharacters(Faction.Blue).OfType <VanillaNonPlayer>())
                {
                    if (!charac.IsFriendlySelected() && this.mAreAllCharacSelected)
                    {
                        this.mSelectedAllies.Add(charac);
                    }
                    else if (charac.IsFriendlySelected() && !this.mAreAllCharacSelected)
                    {
                        this.mSelectedAllies.Remove(charac);
                    }

                    charac.SetSelected(this.mAreAllCharacSelected);
                }
            }

            if (this.mStateMgr.Controller.HasActionOccured(UserAction.GoTo))
            {
                int nbAllies = this.mSelectedAllies.Count;
                if (nbAllies <= 0)
                {
                    return;
                }
                VanillaNonPlayer npc = this.GetSelectedNPC();
                if (npc != null && npc.Info.Faction == Faction.Red)
                {
                    foreach (VanillaNonPlayer ally in this.mSelectedAllies)
                    {
                        ally.SetTargetAndFollow(npc);
                    }
                }
                else if (this.SelectedBlockPos != Vector3.ZERO)
                {
                    int     randomMax   = (int)((nbAllies / 4f + 0.5f) * Cst.CUBE_SIDE);
                    Vector3 imprecision = nbAllies == 1 ? Vector3.ZERO : new Vector3(this.mRandom.Next(0, randomMax), 0, this.mRandom.Next(0, randomMax));
                    foreach (VanillaNonPlayer ally in this.mSelectedAllies)
                    {
                        ally.MoveTo((this.SelectedBlockPos + new Vector3(0.5f, 1, -0.5f)) * Cst.CUBE_SIDE + imprecision);
                    }
                }
            }

            if (this.mStateMgr.Controller.HasActionOccured(UserAction.FollowMe))
            {
                foreach (VanillaNonPlayer ally in this.mSelectedAllies)
                {
                    if (ally.IsFollowingCharac(mainPlayer))
                    {
                        ally.StopFollowing();
                    }
                    else
                    {
                        ally.Follow(mainPlayer, Cst.CUBE_SIDE * 2 + this.mRandom.Next(0, 100));
                    }
                }
            }

            /* Move camera */
            if (this.IsAllowedToMoveCam)
            {
                bool secondaryActionHandled = false;
                if (this.IsFreeCamMode)
                {
                    this.mCameraMan.UpdateCamera(frameTime, this.mStateMgr.Controller);
                }
                else if (mainPlayer.MovementInfo.IsAllowedToMove) // Just pitch the camera
                {
                    this.mCamPitchNode.Pitch(new Degree(this.mStateMgr.Controller.Pitch));

                    if (2 * new Degree(Math.ACos(this.mCamPitchNode.Orientation.w)).ValueAngleUnits > 90.0f) // Limit the pitch between -90 degrees and +90 degrees
                    {
                        this.mCamPitchNode.SetOrientation(Math.Sqrt(0.5f), Math.Sqrt(0.5f) * Math.Sign(this.mCamPitchNode.Orientation.x), 0, 0);
                    }

                    if (this.mStateMgr.Controller.HasActionOccured(UserAction.SecondaryAction))
                    {
                        secondaryActionHandled = this.UpdateSelectedNPC();
                    }
                }

                /* Cube addition and suppression */
                float dist = this.UpdateSelectedBlock();
                if (!(this.mStateMgr.GameInfo.IsInEditorMode ^ mainState.User.IsFreeCamMode) && this.SelectedBlock != null)    // Allow world edition
                {
                    if (this.mStateMgr.Controller.HasActionOccured(UserAction.MainAction) && !Selector.IsBullet && this.mWorld.onLeftClick(this.SelectedBlockPos))
                    {
                        this.AddBlock(dist);
                    }
                    if (!secondaryActionHandled && this.mStateMgr.Controller.HasActionOccured(UserAction.SecondaryAction) && this.mWorld.onRightClick(this.SelectedBlockPos))
                    {
                        this.DeleteBlock();
                    }
                }
            }

            /* Move Selector */
            int selectorPos = Selector.SelectorPos;

            if (this.mStateMgr.Controller.HasActionOccured(UserAction.MoveSelectorLeft))
            {
                selectorPos--;
            }
            if (this.mStateMgr.Controller.HasActionOccured(UserAction.MoveSelectorRight))
            {
                selectorPos++;
            }
            for (int i = 0; i < this.mFigures.Length; i++)
            {
                if (this.mStateMgr.Controller.WasKeyPressed(this.mFigures[i]))
                {
                    selectorPos = i;
                    break;
                }
            }
            if (Selector.SelectorPos != selectorPos)
            {
                Selector.SelectorPos = selectorPos;
            }
        }