コード例 #1
0
ファイル: BaseForm.cs プロジェクト: weimingtom/pap2
        /// <summary>
        /// 将摄像机移动到对象所在的位置
        /// </summary>
        /// <param name="objectInfo">对象信息</param>
        private void MoveCameraToObject(_AtlObjInfo objectInfo)
        {
            // 移动镜头
            Hashtable infoTable   = Helper.GetInfoTable(objectInfo);
            string    positionStr = infoTable["vPosition"] as string;

            if (positionStr != null) // 有效的坐标
            {
                string[] positionData = positionStr.Split(new char[] { ',' });
                float    positionX    = float.Parse(positionData[0]);
                float    positionY    = float.Parse(positionData[1]);
                float    positionZ    = float.Parse(positionData[2]);

                _AtlVector3 objPos = new _AtlVector3();
                objPos.x = positionX;
                objPos.y = positionY;
                objPos.z = positionZ;

                _AtlVector3 oldpos = new _AtlVector3(), oldlookat = new _AtlVector3();
                SceneSceneEditor.GetCameraPosLookat(ref oldpos, ref oldlookat);
                _AtlVector3 delta = new _AtlVector3();
                delta.x = oldlookat.x - oldpos.x; delta.y = oldlookat.y - oldpos.y; delta.z = oldlookat.z - oldpos.z;
                _AtlVector3 newpos = new _AtlVector3();
                newpos.x = objPos.x - delta.x; newpos.y = objPos.y - delta.y; newpos.z = objPos.z - delta.z;
                SceneSceneEditor.SetCameraLocation(newpos.x, newpos.y, newpos.z, objPos.x, objPos.y, objPos.z);
            }
        }