Exemple #1
0
        public override void KeyDown(object sender, KeyEventArgs e)
        {
            if (esmanager.PanState)
            {
                Vector3 autopanvertor3 = new Vector3();
                //得到当前摄像机的位置,
                Vector3 position = ogreimage.Camera.Position;
                Vector3 lockat   = ogreimage.LockAt;

                switch (e.Key)
                {
                case Key.W:
                {
                    autopanvertor3 = lockat - position;
                }
                break;

                case Key.A:
                {
                    autopanvertor3 = lockat - position;
                    float      xx = 90 * (float)(System.Math.PI / 180);
                    Quaternion q  = new Quaternion(new Radian(xx), Vector3.UNIT_Z);
                    autopanvertor3.z = 0;
                    autopanvertor3   = q * autopanvertor3;
                }
                break;

                case Key.S:
                {
                    autopanvertor3 = position - lockat;
                }
                break;

                case Key.D:
                {
                    autopanvertor3 = lockat - position;
                    float      xx = -90 * (float)(System.Math.PI / 180);
                    Quaternion q  = new Quaternion(new Radian(xx), Vector3.UNIT_Z);
                    autopanvertor3.z = 0;
                    autopanvertor3   = q * autopanvertor3;
                }
                break;

                default:
                    return;
                }

                esmanager.animFlag          = true;
                esmanager.animState.Enabled = true;
                Vector3 v1 = esmanager.GetPointOnLine(lockat, autopanvertor3.x, autopanvertor3.y, 0, 0.5f);
                Vector3 v2 = esmanager.GetPointOnLine(position, autopanvertor3.x, autopanvertor3.y, 0, 0.5f);

                Vector3 tempv = new Vector3((float)esmanager.manlocate.X, (float)esmanager.manlocate.Y, 0);

                Vector3 v3 = esmanager.GetPointOnLine(tempv, autopanvertor3.x, autopanvertor3.y, 0, 0.5f);

                //更新人物模型位置
                double dis = System.Math.Sqrt((esmanager.manlocate.X - v3.x) * (esmanager.manlocate.X - v3.x) + (esmanager.manlocate.Y - v3.y) * (esmanager.manlocate.Y - v3.y));

                float angle = esmanager.GetManAngle(new Point(v3.x, v3.y), esmanager.manlocate, 0.5f);

                Quaternion y   = new Quaternion(new Radian(-(float)ogreimage.CamerRoateDegree), Vector3.UNIT_Z);
                float      xxx = 90 * (float)(System.Math.PI / 180);
                Quaternion x   = new Quaternion(new Radian(xxx), Vector3.UNIT_X);

                esmanager.animNode.Orientation = y * x;
                esmanager.animNode.Position    = v1;
                esmanager.manlocate.X          = v1.x;
                esmanager.manlocate.Y          = v1.y;
                esmanager.dpt = new Point(v1.x, v1.y);
                //更新摄像机的位置
                ogreimage.Camera.Position = v2;
                ogreimage.LockAt          = v1;
                //OgreView.Singleton.animNode.Position = new Vector3(v1.x, v1.y, 0);
                //OgreView.Singleton.deslocate = new PointF(v1.x, v1.y);
                //更新摄像机
                ogreimage.UpdataCamera();
            }
        }