Exemple #1
0
        //if running on a fixed timestep, this might be called
        //more often with a smaller delta time than RenderUpdate()
        internal void Update(UpdateTimer time,
                             List <Input.InputAction> actions, PlayerSteering ps)
        {
            //Thread.Sleep(30);

            mZone.ClearPushableVelocities(time.GetUpdateDeltaSeconds());

            Vector3 impactPos = Vector3.Zero;

            if (mbPicking)
            {
                System.Drawing.Point cPos = System.Windows.Forms.Cursor.Position;

                cPos = mGD.RendForm.PointToClient(cPos);

                Vector2 cursVec = Vector2.UnitX * cPos.X;
                cursVec += Vector2.UnitY * cPos.Y;

                int modelOn;
                impactPos = mZone.TraceScreenPointRay(mGD.GCam, mGD.GetScreenViewPort(),
                                                      cursVec, 1000f, out modelOn);

                var clicked = (from act in actions where act.mAction.Equals(Program.MyActions.MouseSelect)
                               select act).FirstOrDefault();
                if (clicked != null)
                {
                    int        node, numCons;
                    List <int> conTo = new List <int>();
                    bool       bInfo = mGraph.GetInfoAboutLocation(impactPos,
                                                                   mZone.FindWorldNodeLandedIn, out numCons, out node, conTo);

                    if (bInfo)
                    {
                        switch (mPickTarget)
                        {
                        case    PickTarget.A:
                            Misc.SafeInvoke(ePickedA, node, new Vector3EventArgs(impactPos));
                            break;

                        case    PickTarget.B:
                            Misc.SafeInvoke(ePickedB, node, new Vector3EventArgs(impactPos));
                            break;

                        case    PickTarget.Blocked:
                            mGraph.SetPathConnectionPassable(impactPos, mZone.FindWorldNodeLandedIn, false);
                            mPathDraw.BuildDrawInfo(mGraph);
                            break;

                        case    PickTarget.UnBlocked:
                            mGraph.SetPathConnectionPassable(impactPos, mZone.FindWorldNodeLandedIn, true);
                            mPathDraw.BuildDrawInfo(mGraph);
                            break;
                        }
                        mbPicking = false;
                        mST.ModifyStringText(mFonts[0], "Picked point: "
                                             + impactPos.IntStr(), "PathStatus");
                    }
                }
                else
                {
                    if (mbPicking)
                    {
                        mST.ModifyStringText(mFonts[0], "Picking point: "
                                             + impactPos.IntStr(), "PathStatus");
                    }
                }
            }

            float yawAmount   = 0f;
            float pitchAmount = 0f;

            foreach (Input.InputAction act in actions)
            {
                if (act.mAction.Equals(Program.MyActions.NextLevel))
                {
                    mCurLevel++;
                    if (mCurLevel >= mLevels.Count)
                    {
                        mCurLevel = 0;
                    }
                    ChangeLevel(mLevels[mCurLevel]);
                    mST.ModifyStringText(mFonts[0], "(L) CurLevel: " + mLevels[mCurLevel], "LevelStatus");
                }
                else if (act.mAction.Equals(Program.MyActions.Turn))
                {
                    yawAmount = act.mMultiplier;
                }
                else if (act.mAction.Equals(Program.MyActions.Pitch))
                {
                    pitchAmount = act.mMultiplier;
                }
            }

            Vector3 startPos = mCamMob.GetGroundPos();
            Vector3 moveVec  = ps.Update(startPos, mGD.GCam.Forward, mGD.GCam.Left, mGD.GCam.Up, actions);

            moveVec *= FlySpeed;

            Vector3 camPos = Vector3.Zero;
            Vector3 endPos = mCamMob.GetGroundPos() + moveVec * 100f;

            mCamMob.Move(endPos, time.GetUpdateDeltaMilliSeconds(),
                         false, mbFly, true, true, out endPos, out camPos);

            mGD.GCam.Update(camPos, ps.Pitch, ps.Yaw, ps.Roll);

            mST.ModifyStringText(mFonts[0], "Position: " + " : "
                                 + mGD.GCam.Position.IntStr(), "PosStatus");

            if (mGraph != null)
            {
                mGraph.Update();
            }
            mST.Update(mGD.DC);
        }