/// <summary>
        /// Uaktualnia kierunek/predkosc na podstawie danych z myszki
        /// </summary>
        /// <param name="dt">Czas od ostatniej klatki</param>
        /// <param name="dx">obrot w kierunku x</param>
        /// <param name="dy">obrot w kierunku y</param>
        /// <param name="dz">obort w kierunku z</param>
        /// <param name="strafeX">Strafe x</param>
        /// <param name="strafeY">Strade y</param>
        private void Update(float dt, float dx, float dy, float strafeSpeedX, float strafeSpeedY)
        {
            //xDeltaAvg.Add(dx);
            //yDeltaAvg.Add(dy);
            //GM.GeneralLog.Write("xDelta:" + dx.ToString() + " yDelta:" + dy.ToString() + " dt:" + dt.ToString());
            float rotX = dy * dt;

            float rotY = dx * dt;

            angleX += rotX;
            angleY += rotY;

            if (angleX > 0.9 * Math.PI / 2)
            {
                angleX = (float)(0.9 * Math.PI / 2);
            }
            if (angleX < -0.9 * Math.PI / 2)
            {
                angleX = (float)(-0.9 * Math.PI / 2);
            }

            MyQuaternion qY = MyQuaternion.FromAxisAngle(-angleY, initialUp);
            MyQuaternion qX = MyQuaternion.FromAxisAngle(-angleX, initialRight);

            //player.CurrentCharacter.Orientation = initialOrientation * (qY);
            //orientation zostanie zmienione przez fizyke, jeœli ustawie odpowiednie AngularVelocity
            if (dt > 0)
            {
                //float currentRotY = player.CurrentCharacter.Orientation.EulerAngles().Z/2;
                ////currentRotY *= (float)Math.PI / 180f;
                //player.CurrentCharacter.AngularVelocity = upVector * ((currentRotY-angleY) / 0.03f);
                //player.CurrentCharacter.AngularVelocity = upVector * ((-rotY) / 0.03f);

            }
            lookVector = initialLook;
            rightVector = initialRight;
            lookVector.Rotate(qX);
            lookVector.Rotate(qY);
            rightVector.Rotate(qY);
            lookVector.Normalize();
            //            character.LookOrientation = initialOrientation * (qY * qX);
            if (updateDirections)
            {
                character.LookOrientation = initialOrientation * (qY * qX);
                character.WalkOrientation = initialOrientation * qY;
            }

            //MyVector zVelocity = lookVector * (ship.Velocity.Dot(lookVector));
            ////MyVector xVelocity = rightVector * (ship.Velocity.Dot(rightVector));
            ////MyVector yVelocity = upVector * (ship.Velocity.Dot(upVector));
            //MyVector xVelocity = rightVector * strafeSpeedX * dt;
            //MyVector yVelocity = upVector * strafeSpeedY * dt;
            //MyVector tVelocity = ship.Velocity - zVelocity-xVelocity-yVelocity;

            //this.ship.Forces += Drag(tVelocity);
            ////this.ship.Velocity -= tVelocity;

            //if (zVelocity.Length > SetVelocity)
            //{
            //    this.ship.Velocity -= lookVector * Math.Min(zVelocity.Length - SetVelocity, dt * objectParameters.Acceleration);
            //}
            //else if (zVelocity.Length < SetVelocity)
            //{
            //    this.ship.Velocity += lookVector * Math.Min(SetVelocity - zVelocity.Length, dt * objectParameters.Acceleration); ;
            //}
            //if (xVelocity.Length > strafeSpeedX)
            //{

            //}
            if (updateDirections)
            {
                if (Flying)
                {

                    this.character.Velocity = SetVelocity * (lookVector) + strafeSpeedX * rightVector;
                }
                else
                {
                    float yVelocity = character.Velocity.Dot(upVector);

                    this.character.Velocity = yVelocity * upVector + strafeSpeedX * rightVector -
                        SetVelocity * (rightVector ^ upVector);
                }
            }
        }
示例#2
0
        static void Main()
        {
            using (Framework.GM gmanager = new Framework.GM())
            {
                using (Framework.FrameworkWindow form = new Framework.FrameworkWindow(true, AppConfig.WindowWidth, AppConfig.WindowHeight))
                {
                    form.Text = "CastleButcher";

                    ///All resources that are allocated during OnCreate/OnResetDevice should be created
                    ///before InitializeGraphics(), so that when the device is created those resources
                    ///can be properly allocated. Creating resources after InitializeGraphics() can lead to
                    ///crashes because of unallocated resources(After InitializeGraphics() OnCreateDevice may not
                    ///be called).

                    MyVector up = new MyVector(0, 1, 0);
                    MyVector v = new MyVector(-21, -0.3f, 1.2f);
                    MyVector v2 = new MyVector(v.X, 0, v.Z);
                    v.Normalize();
                    v2.Normalize();
                    MyVector right = v ^ up;
                    right.Normalize();

                    Matrix rot=Matrix.LookAtRH(new Vector3(0, 0, 0), new Vector3(v.X,v.Y,v.Z), new Vector3(0, 1, 0));
                    rot.Invert();
                    Matrix rot2=Matrix.LookAtRH(new Vector3(0, 0, 0), new Vector3(v2.X,v2.Y,v2.Z), new Vector3(0, 1, 0));
                    rot2.Invert();
                    Quaternion q = Quaternion.RotationMatrix(rot);
                    MyQuaternion lookOrientation = (MyQuaternion)q;
                    Quaternion q2 = Quaternion.RotationMatrix(rot2);
                    MyQuaternion walkOrientation = (MyQuaternion)q2;

                    MyVector vp = new MyVector(0, 0, -1);
                    vp.Rotate(lookOrientation);
                    MyVector v2p = new MyVector(0, 0, -1);
                    v2p.Rotate(walkOrientation);

                    //add guistyles/fonts
                    GM.GUIStyleManager.AddStyle(DefaultValues.MediaPath + "mystyle.xml");
                    GM.GUIStyleManager.AddStyle(DefaultValues.MediaPath + "PlayerInfoStyle.xml");
                    GM.GUIStyleManager.SetCurrentStyle("mystyle");

                    if (!form.InitializeGraphics())
                    {
                        MessageBox.Show("Unable to initialize DirectX");
                        form.Dispose();
                    }

                    //push some layers to display
                    form.PushLayer(new AppControl(form));

                    SoundSystem.SoundEngine.InitializeEngine(GM.AppWindow, 0, 0.05f, 1);
                    SoundSystem.SoundEngine.NameFinder.MusicDirectoryPath = GameSettings.Default.MusicPath;
                    SoundSystem.SoundEngine.NameFinder.SoundDirectoryPath = GameSettings.Default.SoundPath;

                    //SoundSystem.SoundEngine.ListenerUpVector = new Vector3(0, 1, 0);
                    //SoundSystem.SoundEngine.Update(new Vector3(10, -15, 12), new Vector3(0, 0, -1),new Vector3(0,1,0));
                    //SoundSystem.SoundEngine.PlaySound(SoundSystem.Enums.SoundTypes.fanfare1, new Vector3(10, -15, 12));
                    Application.Idle += new EventHandler(form.OnApplicationIdle);
                    Application.Run(form);
                    Properties.Settings.Default.Save();
                }
            }
        }