DlgCamera.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "../../sys/win32/rc/common_resource.h"
  23. #include "../comafx/DialogName.h"
  24. #include "qe3.h"
  25. #include "DlgCamera.h"
  26. #include "DlgEvent.h"
  27. #include "splines.h"
  28. #include "CameraTargetDlg.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. CDlgCamera g_dlgCamera;
  35. void showCameraInspector() {
  36. if (g_dlgCamera.GetSafeHwnd() == NULL) {
  37. g_dlgCamera.Create(IDD_DLG_CAMERA);
  38. CRect rct;
  39. LONG lSize = sizeof(rct);
  40. if (LoadRegistryInfo("Radiant::CameraInspector", &rct, &lSize)) {
  41. g_dlgCamera.SetWindowPos(NULL, rct.left, rct.top, 0,0, SWP_NOSIZE | SWP_SHOWWINDOW);
  42. }
  43. Sys_UpdateWindows(W_ALL);
  44. }
  45. g_dlgCamera.ShowWindow(SW_SHOW);
  46. g_dlgCamera.setupFromCamera();
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CDlgCamera dialog
  50. CDlgCamera::CDlgCamera(CWnd* pParent /*=NULL*/)
  51. : CDialog(CDlgCamera::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CDlgCamera)
  54. m_strName = _T("");
  55. m_fSeconds = 0.0f;
  56. m_trackCamera = TRUE;
  57. m_numSegments = 0;
  58. m_currentSegment = 0;
  59. m_strType = _T("");
  60. m_editPoints = 0;
  61. //}}AFX_DATA_INIT
  62. }
  63. void CDlgCamera::DoDataExchange(CDataExchange* pDX)
  64. {
  65. CDialog::DoDataExchange(pDX);
  66. //{{AFX_DATA_MAP(CDlgCamera)
  67. DDX_Control(pDX, IDC_SCROLLBAR_SEGMENT, m_wndSegments);
  68. DDX_Control(pDX, IDC_LIST_EVENTS, m_wndEvents);
  69. DDX_Control(pDX, IDC_COMBO_SPLINES, m_wndSplines);
  70. DDX_Text(pDX, IDC_EDIT_CAM_NAME, m_strName);
  71. DDX_Text(pDX, IDC_EDIT_LENGTH, m_fSeconds);
  72. DDX_Check(pDX, IDC_CHECK_TRACKCAMERA, m_trackCamera);
  73. DDX_Text(pDX, IDC_EDIT_TOTALSEGMENTS, m_numSegments);
  74. DDX_Text(pDX, IDC_EDIT_SEGMENT, m_currentSegment);
  75. DDX_Text(pDX, IDC_EDIT_TYPE, m_strType);
  76. DDX_Radio(pDX, IDC_RADIO_EDITPOINTS, m_editPoints);
  77. //}}AFX_DATA_MAP
  78. }
  79. BEGIN_MESSAGE_MAP(CDlgCamera, CDialog)
  80. //{{AFX_MSG_MAP(CDlgCamera)
  81. ON_BN_CLICKED(IDC_BTN_ADDEVENT, OnBtnAddevent)
  82. ON_BN_CLICKED(IDC_BTN_ADDTARGET, OnBtnAddtarget)
  83. ON_BN_CLICKED(IDC_BTN_DELEVENT, OnBtnDelevent)
  84. ON_CBN_DBLCLK(IDC_COMBO_SPLINES, OnDblclkComboSplines)
  85. ON_CBN_SELCHANGE(IDC_COMBO_SPLINES, OnSelchangeComboSplines)
  86. ON_LBN_SELCHANGE(IDC_LIST_EVENTS, OnSelchangeListEvents)
  87. ON_LBN_DBLCLK(IDC_LIST_EVENTS, OnDblclkListEvents)
  88. ON_WM_DESTROY()
  89. ON_BN_CLICKED(IDC_APPLY, OnApply)
  90. ON_WM_HSCROLL()
  91. ON_BN_CLICKED(ID_FILE_NEW, OnFileNew)
  92. ON_BN_CLICKED(ID_FILE_OPEN, OnFileOpen)
  93. ON_BN_CLICKED(ID_FILE_SAVE, OnFileSave)
  94. ON_BN_CLICKED(IDC_TESTCAMERA, OnTestcamera)
  95. ON_BN_CLICKED(IDC_BTN_DELETEPOINTS, OnBtnDeletepoints)
  96. ON_BN_CLICKED(IDC_BTN_SELECTALL, OnBtnSelectall)
  97. ON_BN_CLICKED(IDC_RADIO_EDITPOINTS, OnRadioEditpoints)
  98. ON_BN_CLICKED(IDC_RADIO_EDITPOINTS2, OnRadioAddPoints)
  99. //}}AFX_MSG_MAP
  100. END_MESSAGE_MAP()
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CDlgCamera message handlers
  103. void CDlgCamera::OnBtnAddevent()
  104. {
  105. CDlgEvent dlg;
  106. if (dlg.DoModal() == IDOK) {
  107. long n = m_wndSegments.GetScrollPos() / 4 * 1000;
  108. g_splineList->addEvent(static_cast<idCameraEvent::eventType>(dlg.m_event+1), dlg.m_strParm, n);
  109. setupFromCamera();
  110. }
  111. }
  112. void CDlgCamera::OnBtnAddtarget()
  113. {
  114. CCameraTargetDlg dlg;
  115. if (dlg.DoModal() == IDOK) {
  116. g_splineList->addTarget(dlg.m_strName, static_cast<idCameraPosition::positionType>(dlg.m_nType));
  117. setupFromCamera();
  118. m_wndSplines.SetCurSel(g_splineList->numTargets());
  119. OnSelchangeComboSplines();
  120. }
  121. }
  122. void CDlgCamera::OnBtnDelevent()
  123. {
  124. // TODO: Add your control notification handler code here
  125. }
  126. void CDlgCamera::OnBtnDeltarget()
  127. {
  128. // TODO: Add your control notification handler code here
  129. }
  130. void CDlgCamera::OnDblclkComboSplines()
  131. {
  132. // TODO: Add your control notification handler code here
  133. }
  134. void CDlgCamera::OnSelchangeComboSplines()
  135. {
  136. UpdateData(TRUE);
  137. g_qeglobals.d_select_mode = (m_editPoints == 0) ? sel_editpoint : sel_addpoint;
  138. g_qeglobals.d_numpoints = 0;
  139. g_qeglobals.d_num_move_points = 0;
  140. int i = m_wndSplines.GetCurSel();
  141. if (i > 0) {
  142. g_splineList->setActiveTarget(i-1);
  143. g_qeglobals.selectObject = g_splineList->getActiveTarget(i-1);
  144. g_splineList->startEdit(false);
  145. } else {
  146. g_splineList->startEdit(true);
  147. g_qeglobals.selectObject = g_splineList->getPositionObj();
  148. }
  149. // * 4.0 to set increments in quarter seconds
  150. m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
  151. Sys_UpdateWindows(W_ALL);
  152. }
  153. void CDlgCamera::OnSelchangeListEvents()
  154. {
  155. int sel = m_wndEvents.GetCurSel();
  156. //g_splineList->setActiveSegment(sel >= 0 ? sel : 0);
  157. }
  158. void CDlgCamera::OnDblclkListEvents()
  159. {
  160. // TODO: Add your control notification handler code here
  161. }
  162. void CDlgCamera::setupFromCamera()
  163. {
  164. if (m_wndSplines.GetSafeHwnd()) {
  165. int i;
  166. idStr str;
  167. m_strName = g_splineList->getName();
  168. m_strType = g_splineList->getPositionObj()->typeStr();
  169. m_wndSplines.ResetContent();
  170. m_wndSplines.AddString("Path");
  171. for (i = 0; i < g_splineList->numTargets(); i++) {
  172. m_wndSplines.AddString(g_splineList->getActiveTarget(i)->getName());
  173. }
  174. m_wndSplines.SetCurSel(0);
  175. m_fSeconds = g_splineList->getTotalTime();
  176. m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
  177. m_wndEvents.ResetContent();
  178. for (i = 0; i < g_splineList->numEvents(); i++) {
  179. str = va("%s\t%s", g_splineList->getEvent(i)->typeStr(), g_splineList->getEvent(i)->getParam());
  180. m_wndEvents.AddString(str);
  181. }
  182. //m_currentSegment = g_splineList->getActiveSegment();
  183. //m_numSegments = g_splineList->numSegments();
  184. }
  185. g_splineList->startEdit(true);
  186. UpdateData(FALSE);
  187. }
  188. BOOL CDlgCamera::OnInitDialog()
  189. {
  190. CDialog::OnInitDialog();
  191. setupFromCamera();
  192. return TRUE; // return TRUE unless you set the focus to a control
  193. // EXCEPTION: OCX Property Pages should return FALSE
  194. }
  195. void CDlgCamera::OnOK()
  196. {
  197. g_dlgCamera.ShowWindow(SW_HIDE);
  198. g_qeglobals.d_select_mode = sel_brush;
  199. g_splineList->stopEdit();
  200. Sys_UpdateWindows(W_ALL);
  201. }
  202. void CDlgCamera::OnDestroy()
  203. {
  204. if (GetSafeHwnd()) {
  205. CRect rct;
  206. GetWindowRect(rct);
  207. SaveRegistryInfo("Radiant::CameraInspector", &rct, sizeof(rct));
  208. }
  209. CDialog::OnDestroy();
  210. Sys_UpdateWindows(W_ALL);
  211. }
  212. void CDlgCamera::OnApply()
  213. {
  214. UpdateData(TRUE);
  215. g_splineList->setBaseTime(m_fSeconds);
  216. g_splineList->setName(m_strName);
  217. g_splineList->buildCamera();
  218. m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
  219. }
  220. void CDlgCamera::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  221. {
  222. CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  223. int max = g_splineList->getTotalTime() * 4;
  224. if (max == 0) {
  225. max = 1;
  226. }
  227. int n = pScrollBar->GetScrollPos();
  228. switch (nSBCode) {
  229. case SB_LINEUP : {
  230. n--;
  231. }
  232. break;
  233. case SB_LINEDOWN : {
  234. n++;
  235. }
  236. break;
  237. case SB_PAGEUP : {
  238. n -= (float)max * 0.10;
  239. }
  240. break;
  241. case SB_PAGEDOWN : {
  242. n += (float)max * 0.10;
  243. }
  244. break;
  245. case SB_THUMBPOSITION : {
  246. n = nPos;
  247. }
  248. break;
  249. case SB_THUMBTRACK : {
  250. n = nPos;
  251. }
  252. }
  253. // if (n < 0) {
  254. // n = 0;
  255. // } else if (n >= g_splineList->numSegments()) {
  256. // if (g_splineList->numSegments() == 0) {
  257. // g_splineList->buildCamera();
  258. // }
  259. // n = g_splineList->numSegments() - 1;
  260. // }
  261. pScrollBar->SetScrollPos(n);
  262. if (m_trackCamera) {
  263. float p = (float)n / max;
  264. p *= g_splineList->getTotalTime() * 1000;
  265. g_splineList->startCamera(0);
  266. g_splineList->buildCamera();
  267. idVec3 dir;
  268. float fov;
  269. g_splineList->getCameraInfo(p, g_pParentWnd->GetCamera()->Camera().origin, dir, &fov);
  270. g_pParentWnd->GetCamera()->Camera().angles[1] = atan2 (dir[1], dir[0])*180/3.14159;
  271. g_pParentWnd->GetCamera()->Camera().angles[0] = asin (dir[2])*180/3.14159;
  272. }
  273. UpdateData(FALSE);
  274. Sys_UpdateWindows(W_XY | W_CAMERA);
  275. }
  276. void CDlgCamera::OnFileNew()
  277. {
  278. g_splineList->clear();
  279. setupFromCamera();
  280. }
  281. void CDlgCamera::OnFileOpen()
  282. {
  283. DialogName dlg("Open Camera File");
  284. if (dlg.DoModal() == IDOK) {
  285. g_splineList->clear();
  286. g_splineList->load(va("cameras/%s.camera", dlg.m_strName));
  287. }
  288. }
  289. void CDlgCamera::OnFileSave()
  290. {
  291. DialogName dlg("Save Camera File");
  292. if (dlg.DoModal() == IDOK) {
  293. g_splineList->save(va("cameras/%s.camera", dlg.m_strName));
  294. }
  295. }
  296. void CDlgCamera::OnTestcamera()
  297. {
  298. // TODO: Add your control notification handler code here
  299. }
  300. void CDlgCamera::OnBtnDeletepoints()
  301. {
  302. // TODO: Add your control notification handler code here
  303. }
  304. void CDlgCamera::OnBtnSelectall()
  305. {
  306. // TODO: Add your control notification handler code here
  307. }
  308. void CDlgCamera::OnRadioEditpoints()
  309. {
  310. UpdateData(TRUE);
  311. g_qeglobals.d_select_mode = sel_editpoint;
  312. }
  313. void CDlgCamera::OnRadioAddPoints()
  314. {
  315. UpdateData(TRUE);
  316. g_qeglobals.d_select_mode = sel_addpoint;
  317. }