FS2_Open
Open source remastering of the Freespace 2 engine
orienteditor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #include "stdafx.h"
13 #include "FRED.h"
14 #include "OrientEditor.h"
15 #include "Management.h"
16 #include "globalincs/linklist.h"
17 #include "FREDView.h"
18 
19 #ifdef _DEBUG
20 #undef THIS_FILE
21 static char THIS_FILE[] = __FILE__;
22 #endif
23 
24 #define PREC 0.0001f
25 
27 // orient_editor dialog
28 
29 orient_editor::orient_editor(CWnd* pParent /*=NULL*/)
30  : CDialog(orient_editor::IDD, pParent)
31 {
32  vec3d pos;
33 
34  //{{AFX_DATA_INIT(orient_editor)
35  m_object_index = 0;
36  m_point_to = FALSE;
37  m_position_z = _T("");
38  m_position_y = _T("");
39  m_position_x = _T("");
40  m_location_x = _T("0.0");
41  m_location_y = _T("0.0");
42  m_location_z = _T("0.0");
43  //}}AFX_DATA_INIT
46  m_position_x.Format("%.1f", pos.xyz.x);
47  m_position_y.Format("%.1f", pos.xyz.y);
48  m_position_z.Format("%.1f", pos.xyz.z);
49 }
50 
51 void orient_editor::DoDataExchange(CDataExchange* pDX)
52 {
53  CDialog::DoDataExchange(pDX);
54  //{{AFX_DATA_MAP(orient_editor)
55  DDX_Control(pDX, IDC_SPIN6, m_spin6);
56  DDX_Control(pDX, IDC_SPIN5, m_spin5);
57  DDX_Control(pDX, IDC_SPIN4, m_spin4);
58  DDX_Control(pDX, IDC_SPIN3, m_spin3);
59  DDX_Control(pDX, IDC_SPIN2, m_spin2);
60  DDX_Control(pDX, IDC_SPIN1, m_spin1);
61  DDX_CBIndex(pDX, IDC_OBJECT_LIST, m_object_index);
62  DDX_Check(pDX, IDC_POINT_TO_CHECKBOX, m_point_to);
63  DDX_Text(pDX, IDC_POSITION_Z, m_position_z);
64  DDX_Text(pDX, IDC_POSITION_Y, m_position_y);
65  DDX_Text(pDX, IDC_POSITION_X, m_position_x);
66  DDX_Text(pDX, IDC_LOCATION_X, m_location_x);
67  DDX_Text(pDX, IDC_LOCATION_Y, m_location_y);
68  DDX_Text(pDX, IDC_LOCATION_Z, m_location_z);
69  //}}AFX_DATA_MAP
70 }
71 
72 BEGIN_MESSAGE_MAP(orient_editor, CDialog)
73  //{{AFX_MSG_MAP(orient_editor)
74  ON_WM_CLOSE()
75  //}}AFX_MSG_MAP
76 END_MESSAGE_MAP()
77 
79 // orient_editor message handlers
80 
81 BOOL orient_editor::OnInitDialog()
82 {
83  char text[80];
84  int type;
85  CComboBox *box;
86  object *ptr;
87 
88  CDialog::OnInitDialog();
90  ((CButton *) GetDlgItem(IDC_POINT_TO_OBJECT))->SetCheck(1);
91  box = (CComboBox *) GetDlgItem(IDC_OBJECT_LIST);
92  box->ResetContent();
93 
94  total = 0;
95  ptr = GET_FIRST(&obj_used_list);
96  while (ptr != END_OF_LIST(&obj_used_list)) {
97  if (Marked != 1 || OBJ_INDEX(ptr) != cur_object_index) {
98  if ((ptr->type == OBJ_START) || (ptr->type == OBJ_SHIP)) {
99  box->AddString(Ships[ptr->instance].ship_name);
100  index[total++] = OBJ_INDEX(ptr);
101 
102  } else if (ptr->type == OBJ_WAYPOINT) {
103  int waypoint_num;
104  waypoint_list *wp_list = find_waypoint_list_with_instance(ptr->instance, &waypoint_num);
105  Assert(wp_list != NULL);
106  sprintf(text, "%s:%d", wp_list->get_name(), waypoint_num + 1);
107 
108  box->AddString(text);
109  index[total++] = OBJ_INDEX(ptr);
110 
111  } else if ((ptr->type == OBJ_POINT) || (ptr->type == OBJ_JUMP_NODE)) {
112  } else
113  Assert(0); // unknown object type.
114  }
115 
116  ptr = GET_NEXT(ptr);
117  }
118 
119  type = Objects[cur_object_index].type;
120  if (Marked == 1 && type == OBJ_WAYPOINT) {
121  GetDlgItem(IDC_POINT_TO_CHECKBOX)->EnableWindow(0);
122  GetDlgItem(IDC_POINT_TO_OBJECT)->EnableWindow(0);
123  GetDlgItem(IDC_POINT_TO_LOCATION)->EnableWindow(0);
124  GetDlgItem(IDC_OBJECT_LIST)->EnableWindow(0);
125  GetDlgItem(IDC_LOCATION_X)->EnableWindow(0);
126  GetDlgItem(IDC_LOCATION_Y)->EnableWindow(0);
127  GetDlgItem(IDC_LOCATION_Z)->EnableWindow(0);
128  m_object_index = -1;
129 
130  } else {
131  m_object_index = 0;
132  }
133 
134  m_spin1.SetRange((short)-9999, (short)9999);
135  m_spin1.SetPos((int) convert(m_position_x));
136  m_spin2.SetRange((short)-9999, (short)9999);
137  m_spin2.SetPos((int) convert(m_position_y));
138  m_spin3.SetRange((short)-9999, (short)9999);
139  m_spin3.SetPos((int) convert(m_position_z));
140  m_spin4.SetRange((short)-9999, (short)9999);
141  m_spin5.SetRange((short)-9999, (short)9999);
142  m_spin6.SetRange((short)-9999, (short)9999);
143  UpdateData(FALSE);
144  return TRUE;
145 }
146 
148 {
149  float dif;
150 
151  dif = Objects[cur_object_index].pos.xyz.x - convert(m_position_x);
152  if ((dif > PREC) || (dif < -PREC))
153  return 1;
154  dif = Objects[cur_object_index].pos.xyz.y - convert(m_position_y);
155  if ((dif > PREC) || (dif < -PREC))
156  return 1;
157  dif = Objects[cur_object_index].pos.xyz.z - convert(m_position_z);
158  if ((dif > PREC) || (dif < -PREC))
159  return 1;
160 
161  if (((CButton *) GetDlgItem(IDC_POINT_TO_CHECKBOX))->GetCheck() == 1)
162  return 1;
163 
164  return 0;
165 }
166 
168 {
169  vec3d delta, pos;
170  object *ptr;
171 
172  UpdateData(TRUE);
173  pos.xyz.x = convert(m_position_x);
174  pos.xyz.y = convert(m_position_y);
175  pos.xyz.z = convert(m_position_z);
176 
177  if ((((CButton *) GetDlgItem(IDC_POINT_TO_OBJECT))->GetCheck() == 1) ||
178  (((CButton *) GetDlgItem(IDC_POINT_TO_LOCATION))->GetCheck() == 1))
179  set_modified();
180 
181  vm_vec_sub(&delta, &pos, &Objects[cur_object_index].pos);
182  if (delta.xyz.x || delta.xyz.y || delta.xyz.z)
183  set_modified();
184 
185  ptr = GET_FIRST(&obj_used_list);
186  while (ptr != END_OF_LIST(&obj_used_list)) {
187  if (ptr->flags & OF_MARKED) {
188  vm_vec_add2(&ptr->pos, &delta);
189  update_object(ptr);
190  }
191 
192  ptr = GET_NEXT(ptr);
193  }
194 
195  ptr = GET_FIRST(&obj_used_list);
196  while (ptr != END_OF_LIST(&obj_used_list)) {
197  if (ptr->flags & OF_MARKED)
198  object_moved(ptr);
199 
200  ptr = GET_NEXT(ptr);
201  }
202 
204  CDialog::OnOK();
205 }
206 
207 void orient_editor::update_object(object *ptr)
208 {
209  if (ptr->type != OBJ_WAYPOINT && m_point_to) {
210  vec3d v, loc;
211  matrix m;
212 
213  memset(&v, 0, sizeof(vec3d));
214  loc.xyz.x = convert(m_location_x);
215  loc.xyz.y = convert(m_location_y);
216  loc.xyz.z = convert(m_location_z);
217  if (((CButton *) GetDlgItem(IDC_POINT_TO_OBJECT))->GetCheck() == 1) {
219  vm_vec_sub2(&v, &ptr->pos);
220 
221  } else if (((CButton *) GetDlgItem(IDC_POINT_TO_LOCATION))->GetCheck() == 1) {
222  vm_vec_sub(&v, &loc, &ptr->pos);
223 
224  } else {
225  Assert(0); // neither radio button is checked.
226  }
227 
228  if (!v.xyz.x && !v.xyz.y && !v.xyz.z){
229  return; // can't point to itself.
230  }
231 
232  vm_vector_2_matrix(&m, &v, NULL, NULL);
233  ptr->orient = m;
234  }
235 }
236 
237 float orient_editor::convert(CString &str)
238 {
239  char buf[256];
240  int i, j, len;
241 
242  string_copy(buf, str, 255);
243  len = strlen(buf);
244  for (i=j=0; i<len; i++)
245  if (buf[i] != ',')
246  buf[j++] = buf[i];
247 
248  buf[j] = 0;
249  return (float) atof(buf);
250 }
251 
253 {
255  CDialog::OnCancel();
256 }
257 
259 {
260  int z;
261 
262  if (query_modified()) {
263  z = MessageBox("Do you want to keep your changes?", "Close", MB_ICONQUESTION | MB_YESNOCANCEL);
264  if (z == IDCANCEL)
265  return;
266 
267  if (z == IDYES) {
268  OnOK();
269  return;
270  }
271  }
272 
273  CDialog::OnClose();
274 }
void record_window_data(window_data *wndd, CWnd *wnd)
Definition: fred.cpp:670
int i
Definition: multi_pxo.cpp:466
CFREDApp theApp
Definition: fred.cpp:115
CSpinButtonCtrl m_spin3
Definition: orienteditor.h:32
CSpinButtonCtrl m_spin2
Definition: orienteditor.h:33
char * get_name()
Definition: waypoint.cpp:84
#define IDC_POSITION_X
Definition: resource.h:629
window_data Object_wnd_data
Definition: fred.cpp:64
GLuint index
Definition: Glext.h:5608
void object_moved(object *objp)
waypoint_list * find_waypoint_list_with_instance(int waypoint_instance, int *waypoint_index)
Definition: waypoint.cpp:254
Assert(pm!=NULL)
Definition: pstypes.h:88
int init_window(window_data *wndd, CWnd *wnd, int adjust=0, int pre=0)
Definition: fred.cpp:639
CSpinButtonCtrl m_spin6
Definition: orienteditor.h:29
#define IDC_OBJECT_LIST
Definition: resource.h:576
#define MB_ICONQUESTION
Definition: config.h:188
struct vec3d::@225::@227 xyz
#define TRUE
Definition: pstypes.h:399
object obj_used_list
Definition: object.cpp:53
#define MB_YESNOCANCEL
Definition: config.h:183
int Marked
Definition: fredview.cpp:101
vec3d pos
Definition: object.h:152
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: Glext.h:7308
CSpinButtonCtrl m_spin5
Definition: orienteditor.h:30
GLenum type
Definition: Gl.h:1492
CString m_position_z
Definition: orienteditor.h:37
int query_valid_object(int index)
CString m_position_y
Definition: orienteditor.h:38
#define OBJ_WAYPOINT
Definition: object.h:36
int instance
Definition: object.h:150
matrix * vm_vector_2_matrix(matrix *m, const vec3d *fvec, const vec3d *uvec, const vec3d *rvec)
Definition: vecmat.cpp:850
#define IDC_SPIN1
Definition: resource.h:404
CSpinButtonCtrl m_spin1
Definition: orienteditor.h:34
void vm_vec_add2(vec3d *dest, const vec3d *src)
Definition: vecmat.cpp:178
#define OBJ_START
Definition: object.h:35
#define IDC_POINT_TO_OBJECT
Definition: resource.h:636
#define IDC_LOCATION_Y
Definition: resource.h:633
void vm_vec_sub2(vec3d *dest, const vec3d *src)
Definition: vecmat.cpp:187
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
GLdouble GLdouble z
Definition: Glext.h:5451
#define IDC_LOCATION_X
Definition: resource.h:632
#define IDC_SPIN3
Definition: resource.h:297
#define delta
Definition: fvi.cpp:418
CString m_location_x
Definition: orienteditor.h:40
object Objects[MAX_OBJECTS]
Definition: object.cpp:62
orient_editor(CWnd *pParent=NULL)
void string_copy(char *dest, const CString &src, int max_len, int modify)
Definition: management.cpp:142
#define OBJ_INDEX(objp)
Definition: object.h:235
#define OF_MARKED
Definition: object.h:125
afx_msg void OnClose()
matrix orient
Definition: object.h:153
#define OBJ_SHIP
Definition: object.h:32
virtual void DoDataExchange(CDataExchange *pDX)
void set_modified(BOOL arg)
Definition: freddoc.cpp:676
#define IDC_SPIN2
Definition: resource.h:270
#define IDC_SPIN5
Definition: resource.h:326
void vm_vec_sub(vec3d *dest, const vec3d *src0, const vec3d *src1)
Definition: vecmat.cpp:168
int BOOL
Definition: config.h:80
#define IDC_LOCATION_Z
Definition: resource.h:634
ship Ships[MAX_SHIPS]
Definition: ship.cpp:122
CString m_position_x
Definition: orienteditor.h:39
#define IDC_SPIN6
Definition: resource.h:351
#define IDC_POSITION_Y
Definition: resource.h:630
#define PREC
CSpinButtonCtrl m_spin4
Definition: orienteditor.h:31
#define IDC_POSITION_Z
Definition: resource.h:631
int MessageBox(HWND h, const char *s1, const char *s2, int i)
hull_check pos
Definition: lua.cpp:5050
CString m_location_y
Definition: orienteditor.h:41
const GLfloat * m
Definition: Glext.h:10319
#define IDC_POINT_TO_CHECKBOX
Definition: resource.h:635
CString m_location_z
Definition: orienteditor.h:42
GLenum GLsizei len
Definition: Glext.h:6283
int cur_object_index
Definition: management.cpp:79
#define IDC_POINT_TO_LOCATION
Definition: resource.h:637
uint flags
Definition: object.h:151
char type
Definition: object.h:146
#define FALSE
Definition: pstypes.h:400
#define OBJ_POINT
Definition: object.h:40
#define IDC_SPIN4
Definition: resource.h:317
#define OBJ_JUMP_NODE
Definition: object.h:45
const GLdouble * v
Definition: Glext.h:5322
char ship_name[NAME_LENGTH]
Definition: ship.h:604