dlgcamera.cpp 9.9 KB

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