doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DlgCamera.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 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.
23 
24 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.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "../../sys/win32/rc/common_resource.h"
33 #include "../comafx/DialogName.h"
34 
35 #include "qe3.h"
36 #include "DlgCamera.h"
37 #include "DlgEvent.h"
38 #include "splines.h"
39 #include "CameraTargetDlg.h"
40 
41 #ifdef _DEBUG
42 #define new DEBUG_NEW
43 #undef THIS_FILE
44 static char THIS_FILE[] = __FILE__;
45 #endif
46 
48 
49 
51  if (g_dlgCamera.GetSafeHwnd() == NULL) {
52  g_dlgCamera.Create(IDD_DLG_CAMERA);
53  CRect rct;
54  LONG lSize = sizeof(rct);
55  if (LoadRegistryInfo("Radiant::CameraInspector", &rct, &lSize)) {
56  g_dlgCamera.SetWindowPos(NULL, rct.left, rct.top, 0,0, SWP_NOSIZE | SWP_SHOWWINDOW);
57  }
58  Sys_UpdateWindows(W_ALL);
59  }
60  g_dlgCamera.ShowWindow(SW_SHOW);
61  g_dlgCamera.setupFromCamera();
62 }
64 // CDlgCamera dialog
65 
66 
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;
74  m_numSegments = 0;
75  m_currentSegment = 0;
76  m_strType = _T("");
77  m_editPoints = 0;
78  //}}AFX_DATA_INIT
79 }
80 
81 
82 void CDlgCamera::DoDataExchange(CDataExchange* pDX)
83 {
84  CDialog::DoDataExchange(pDX);
85  //{{AFX_DATA_MAP(CDlgCamera)
86  DDX_Control(pDX, IDC_SCROLLBAR_SEGMENT, m_wndSegments);
87  DDX_Control(pDX, IDC_LIST_EVENTS, m_wndEvents);
88  DDX_Control(pDX, IDC_COMBO_SPLINES, m_wndSplines);
89  DDX_Text(pDX, IDC_EDIT_CAM_NAME, m_strName);
90  DDX_Text(pDX, IDC_EDIT_LENGTH, m_fSeconds);
91  DDX_Check(pDX, IDC_CHECK_TRACKCAMERA, m_trackCamera);
92  DDX_Text(pDX, IDC_EDIT_TOTALSEGMENTS, m_numSegments);
93  DDX_Text(pDX, IDC_EDIT_SEGMENT, m_currentSegment);
94  DDX_Text(pDX, IDC_EDIT_TYPE, m_strType);
95  DDX_Radio(pDX, IDC_RADIO_EDITPOINTS, m_editPoints);
96  //}}AFX_DATA_MAP
97 }
98 
99 
100 BEGIN_MESSAGE_MAP(CDlgCamera, CDialog)
101  //{{AFX_MSG_MAP(CDlgCamera)
102  ON_BN_CLICKED(IDC_BTN_ADDEVENT, OnBtnAddevent)
103  ON_BN_CLICKED(IDC_BTN_ADDTARGET, OnBtnAddtarget)
104  ON_BN_CLICKED(IDC_BTN_DELEVENT, OnBtnDelevent)
105  ON_CBN_DBLCLK(IDC_COMBO_SPLINES, OnDblclkComboSplines)
106  ON_CBN_SELCHANGE(IDC_COMBO_SPLINES, OnSelchangeComboSplines)
107  ON_LBN_SELCHANGE(IDC_LIST_EVENTS, OnSelchangeListEvents)
108  ON_LBN_DBLCLK(IDC_LIST_EVENTS, OnDblclkListEvents)
109  ON_WM_DESTROY()
110  ON_BN_CLICKED(IDC_APPLY, OnApply)
111  ON_WM_HSCROLL()
112  ON_BN_CLICKED(ID_FILE_NEW, OnFileNew)
113  ON_BN_CLICKED(ID_FILE_OPEN, OnFileOpen)
114  ON_BN_CLICKED(ID_FILE_SAVE, OnFileSave)
115  ON_BN_CLICKED(IDC_TESTCAMERA, OnTestcamera)
116  ON_BN_CLICKED(IDC_BTN_DELETEPOINTS, OnBtnDeletepoints)
117  ON_BN_CLICKED(IDC_BTN_SELECTALL, OnBtnSelectall)
118  ON_BN_CLICKED(IDC_RADIO_EDITPOINTS, OnRadioEditpoints)
119  ON_BN_CLICKED(IDC_RADIO_EDITPOINTS2, OnRadioAddPoints)
120  //}}AFX_MSG_MAP
121 END_MESSAGE_MAP()
122 
124 // CDlgCamera message handlers
125 
126 void CDlgCamera::OnBtnAddevent()
127 {
128  CDlgEvent dlg;
129  if (dlg.DoModal() == IDOK) {
130  long n = m_wndSegments.GetScrollPos() / 4 * 1000;
131  g_splineList->addEvent(static_cast<idCameraEvent::eventType>(dlg.m_event+1), dlg.m_strParm, n);
132  setupFromCamera();
133  }
134 }
135 
137 {
138  CCameraTargetDlg dlg;
139  if (dlg.DoModal() == IDOK) {
140  g_splineList->addTarget(dlg.m_strName, static_cast<idCameraPosition::positionType>(dlg.m_nType));
141  setupFromCamera();
142  m_wndSplines.SetCurSel(g_splineList->numTargets());
144  }
145 }
146 
148 {
149  // TODO: Add your control notification handler code here
150 
151 }
152 
154 {
155  // TODO: Add your control notification handler code here
156 
157 }
158 
160 {
161  // TODO: Add your control notification handler code here
162 
163 }
164 
166 {
167  UpdateData(TRUE);
168  g_qeglobals.d_select_mode = (m_editPoints == 0) ? sel_editpoint : sel_addpoint;
169  g_qeglobals.d_numpoints = 0;
170  g_qeglobals.d_num_move_points = 0;
171  int i = m_wndSplines.GetCurSel();
172  if (i > 0) {
174  g_qeglobals.selectObject = g_splineList->getActiveTarget(i-1);
175  g_splineList->startEdit(false);
176  } else {
177  g_splineList->startEdit(true);
178  g_qeglobals.selectObject = g_splineList->getPositionObj();
179  }
180 
181  // * 4.0 to set increments in quarter seconds
182  m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
183 
184  Sys_UpdateWindows(W_ALL);
185 }
186 
188 {
189  int sel = m_wndEvents.GetCurSel();
190  //g_splineList->setActiveSegment(sel >= 0 ? sel : 0);
191 }
192 
194 {
195  // TODO: Add your control notification handler code here
196 
197 }
198 
200 {
201  if (m_wndSplines.GetSafeHwnd()) {
202  int i;
203  idStr str;
206  m_wndSplines.ResetContent();
207  m_wndSplines.AddString("Path");
208  for (i = 0; i < g_splineList->numTargets(); i++) {
210  }
211  m_wndSplines.SetCurSel(0);
213  m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
214 
215  m_wndEvents.ResetContent();
216  for (i = 0; i < g_splineList->numEvents(); i++) {
217  str = va("%s\t%s", g_splineList->getEvent(i)->typeStr(), g_splineList->getEvent(i)->getParam());
218  m_wndEvents.AddString(str);
219  }
220  //m_currentSegment = g_splineList->getActiveSegment();
221  //m_numSegments = g_splineList->numSegments();
222  }
223  g_splineList->startEdit(true);
224  UpdateData(FALSE);
225 }
226 
228 {
229  CDialog::OnInitDialog();
230  setupFromCamera();
231  return TRUE; // return TRUE unless you set the focus to a control
232  // EXCEPTION: OCX Property Pages should return FALSE
233 }
234 
236 {
237  g_dlgCamera.ShowWindow(SW_HIDE);
238  g_qeglobals.d_select_mode = sel_brush;
240  Sys_UpdateWindows(W_ALL);
241 }
242 
244 {
245  if (GetSafeHwnd()) {
246  CRect rct;
247  GetWindowRect(rct);
248  SaveRegistryInfo("Radiant::CameraInspector", &rct, sizeof(rct));
249  }
250  CDialog::OnDestroy();
251  Sys_UpdateWindows(W_ALL);
252 }
253 
254 
256 {
257  UpdateData(TRUE);
261  m_wndSegments.SetScrollRange(0, g_splineList->getTotalTime() * 4.0);
262 }
263 
264 void CDlgCamera::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
265 {
266  CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
267  int max = g_splineList->getTotalTime() * 4;
268  if (max == 0) {
269  max = 1;
270  }
271  int n = pScrollBar->GetScrollPos();
272  switch (nSBCode) {
273  case SB_LINEUP : {
274  n--;
275  }
276  break;
277  case SB_LINEDOWN : {
278  n++;
279  }
280  break;
281  case SB_PAGEUP : {
282  n -= (float)max * 0.10;
283  }
284  break;
285  case SB_PAGEDOWN : {
286  n += (float)max * 0.10;
287  }
288  break;
289  case SB_THUMBPOSITION : {
290  n = nPos;
291  }
292  break;
293  case SB_THUMBTRACK : {
294  n = nPos;
295  }
296  }
297 // if (n < 0) {
298 // n = 0;
299 // } else if (n >= g_splineList->numSegments()) {
300 // if (g_splineList->numSegments() == 0) {
301 // g_splineList->buildCamera();
302 // }
303 // n = g_splineList->numSegments() - 1;
304 // }
305  pScrollBar->SetScrollPos(n);
306  if (m_trackCamera) {
307  float p = (float)n / max;
308  p *= g_splineList->getTotalTime() * 1000;
311  idVec3 dir;
312  float fov;
314  g_pParentWnd->GetCamera()->Camera().angles[1] = atan2 (dir[1], dir[0])*180/3.14159;
315  g_pParentWnd->GetCamera()->Camera().angles[0] = asin (dir[2])*180/3.14159;
316 
317  }
318  UpdateData(FALSE);
319  Sys_UpdateWindows(W_XY | W_CAMERA);
320 }
321 
323 {
324  g_splineList->clear();
325  setupFromCamera();
326 }
327 
329 {
330  DialogName dlg("Open Camera File");
331  if (dlg.DoModal() == IDOK) {
332  g_splineList->clear();
333  g_splineList->load(va("cameras/%s.camera", dlg.m_strName));
334  }
335 }
336 
338 {
339  DialogName dlg("Save Camera File");
340  if (dlg.DoModal() == IDOK) {
341  g_splineList->save(va("cameras/%s.camera", dlg.m_strName));
342  }
343 }
344 
346 {
347  // TODO: Add your control notification handler code here
348 
349 }
350 
352 {
353  // TODO: Add your control notification handler code here
354 
355 }
356 
358 {
359  // TODO: Add your control notification handler code here
360 
361 }
362 
364 {
365  UpdateData(TRUE);
366  g_qeglobals.d_select_mode = sel_editpoint;
367 }
368 
370 {
371  UpdateData(TRUE);
372  g_qeglobals.d_select_mode = sel_addpoint;
373 }
CMainFrame * g_pParentWnd
Definition: MainFrm.cpp:73
#define IDC_EDIT_TYPE
afx_msg void OnApply()
Definition: DlgCamera.cpp:255
float getTotalTime()
Definition: splines.h:360
void WINAPI Sys_UpdateWindows(int nBits)
Definition: MainFrm.cpp:3974
afx_msg void OnRadioAddPoints()
Definition: DlgCamera.cpp:369
void showCameraInspector()
Definition: DlgCamera.cpp:50
const char * typeStr()
Definition: splines.h:314
#define IDC_BTN_ADDEVENT
virtual void OnOK()
Definition: DlgCamera.cpp:235
afx_msg void OnSelchangeComboSplines()
Definition: DlgCamera.cpp:165
CScrollBar m_wndSegments
Definition: DlgCamera.h:52
int numTargets()
Definition: splines.h:354
afx_msg void OnFileOpen()
Definition: DlgCamera.cpp:328
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
void stopEdit()
Definition: splines.cpp:903
#define IDC_RADIO_EDITPOINTS2
BOOL m_trackCamera
Definition: DlgCamera.h:57
afx_msg void OnFileNew()
Definition: DlgCamera.cpp:322
#define IDC_BTN_DELETEPOINTS
#define IDC_EDIT_TOTALSEGMENTS
GLenum GLsizei n
Definition: glext.h:3705
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
Definition: DlgCamera.cpp:264
const char * getName()
Definition: splines.h:371
CString m_strName
Definition: DialogName.h:51
camera_t & Camera()
Definition: CamWnd.h:90
#define IDC_CHECK_TRACKCAMERA
Definition: Vector.h:316
case const float
Definition: Callbacks.cpp:62
int m_currentSegment
Definition: DlgCamera.h:59
void addTarget(const char *name, idCameraPosition::positionType type)
Definition: splines.cpp:794
#define IDC_LIST_EVENTS
#define IDC_TESTCAMERA
idAngles angles
Definition: CamWnd.h:49
afx_msg void OnFileSave()
Definition: DlgCamera.cpp:337
bool LoadRegistryInfo(const char *pszName, void *pvBuf, long *plSize)
Definition: Radiant.cpp:405
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
afx_msg void OnDblclkComboSplines()
Definition: DlgCamera.cpp:159
void addEvent(idCameraEvent::eventType t, const char *param, long time)
Definition: splines.cpp:1388
void setActiveTarget(int index)
Definition: splines.cpp:852
#define IDC_COMBO_SPLINES
afx_msg void OnBtnDeletepoints()
Definition: DlgCamera.cpp:351
#define IDC_EDIT_SEGMENT
CString m_strName
Definition: DlgCamera.h:55
afx_msg void OnRadioEditpoints()
Definition: DlgCamera.cpp:363
CCamWnd * GetCamera()
Definition: MainFrm.h:123
CDlgCamera g_dlgCamera
Definition: DlgCamera.cpp:47
void save(const char *filename)
Definition: splines.cpp:1330
void startCamera(long t)
Definition: splines.cpp:1223
int m_numSegments
Definition: DlgCamera.h:58
void clear()
Definition: splines.cpp:751
#define NULL
Definition: Lib.h:88
#define IDC_BTN_DELEVENT
CComboBox m_wndSplines
Definition: DlgCamera.h:54
afx_msg void OnSelchangeListEvents()
Definition: DlgCamera.cpp:187
afx_msg void OnDestroy()
Definition: DlgCamera.cpp:243
afx_msg void OnBtnDeltarget()
Definition: DlgCamera.cpp:153
#define IDC_EDIT_CAM_NAME
virtual BOOL OnInitDialog()
Definition: DlgCamera.cpp:227
CString m_strParm
Definition: DlgEvent.h:50
void setBaseTime(float f)
Definition: splines.h:358
#define IDC_BTN_SELECTALL
#define IDC_RADIO_EDITPOINTS
#define IDC_BTN_ADDTARGET
bool load(const char *filename)
Definition: splines.cpp:1307
bool SaveRegistryInfo(const char *pszName, void *pvBuf, long lSize)
Definition: Radiant.cpp:398
idVec3 origin
Definition: CamWnd.h:48
void startEdit(bool camera)
Definition: splines.cpp:917
int m_editPoints
Definition: DlgCamera.h:61
const char * getName()
Definition: splines.h:174
int numEvents()
Definition: splines.h:343
#define IDC_APPLY
idCameraPosition * getActiveTarget()
Definition: splines.cpp:813
void buildCamera()
Definition: splines.cpp:1081
idCameraEvent * getEvent(int index)
Definition: splines.h:344
CDlgCamera(CWnd *pParent=NULL)
Definition: DlgCamera.cpp:67
long LONG
int m_event
Definition: DlgEvent.h:51
void setupFromCamera()
Definition: DlgCamera.cpp:199
void setName(const char *p)
Definition: splines.h:372
#define IDC_SCROLLBAR_SEGMENT
#define IDD_DLG_CAMERA
const char * getParam()
Definition: splines.h:315
Definition: Str.h:116
afx_msg void OnDblclkListEvents()
Definition: DlgCamera.cpp:193
float m_fSeconds
Definition: DlgCamera.h:56
bool getCameraInfo(long time, idVec3 &origin, idVec3 &direction, float *fv)
Definition: splines.cpp:989
#define FALSE
Definition: mprintf.c:70
#define IDC_EDIT_LENGTH
idCameraDef * g_splineList
Definition: splines.cpp:35
afx_msg void OnBtnDelevent()
Definition: DlgCamera.cpp:147
#define TRUE
Definition: mprintf.c:69
virtual void DoDataExchange(CDataExchange *pDX)
Definition: DlgCamera.cpp:82
char * va(const char *fmt,...)
Definition: Str.cpp:1568
afx_msg void OnTestcamera()
Definition: DlgCamera.cpp:345
#define max(x, y)
Definition: os.h:70
GLfloat GLfloat p
Definition: glext.h:4674
const char * typeStr()
Definition: splines.h:179
CListBox m_wndEvents
Definition: DlgCamera.h:53
afx_msg void OnBtnSelectall()
Definition: DlgCamera.cpp:357
afx_msg void OnBtnAddtarget()
Definition: DlgCamera.cpp:136
CString m_strType
Definition: DlgCamera.h:60
idCameraPosition * getPositionObj()
Definition: splines.cpp:936