source: golgotha/src/maxtool/m1_commands.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 12.1 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "m1_info.hh"
10#include "st_edit.hh"
11#include "render.hh"
12#include "lisp/lisp.hh"
13#include "lisp/li_init.hh"
14#include "max_object.hh"
15#include "file/file.hh"
16
17
18li_object *m1_wireframe_toggle(li_object *o, li_environment *env)
19{
20  m1_info.set_flags(M1_WIREFRAME, ~m1_info.get_flags(M1_WIREFRAME));
21  m1_render_window->request_redraw();
22  return 0;
23}
24
25li_object *m1_select_none(li_object *o, li_environment *env)
26{
27  // deselect all the old polys
28  for (int i=0; i<m1_info.obj->num_quad; i++)
29    m1_info.obj->quad[i].set_flags(g1_quad_class::SELECTED,0);
30
31  m1_render_window->request_redraw();
32  m1_st_edit->edit_poly_changed();
33
34  return 0;
35}
36
37li_object *m1_select_similar(li_object *o, li_environment *env)
38{
39  i4_str *texture=0;
40  int i,j;
41
42  for (i=0; i<m1_info.obj->num_quad; i++)
43    if (m1_info.obj->quad[i].get_flags(g1_quad_class::SELECTED))
44    {
45      texture = m1_info.obj->texture_names[i];
46     
47      // non-optimal search (lots of reselection)
48      for (j=0; j<m1_info.obj->num_quad; j++)
49        if (*m1_info.obj->texture_names[j] == *texture)
50          m1_info.obj->quad[j].set_flags(g1_quad_class::SELECTED);
51    }
52 
53  if (!texture)
54    return 0;
55 
56  m1_render_window->request_redraw();
57  m1_st_edit->edit_poly_changed();
58   
59  return 0;
60}
61
62li_object *m1_rotate_texture_selected(li_object *o, li_environment *env)
63{
64  for (int i=0; i<m1_info.obj->num_quad; i++)
65  {
66    g1_quad_class *q = &m1_info.obj->quad[i];
67    if (q->get_flags(g1_quad_class::SELECTED))
68    {
69      i4_float u=q->u[0],v=q->v[0], nu,nv;
70      for (int j=q->num_verts()-1; j>=0; j--)
71      {
72        nu = q->u[j]; nv = q->v[j];
73        q->u[j] = u; q->v[j] = v;
74        u = nu; v = nv;
75      }
76    }
77  }
78  m1_info.obj->calc_texture_scales();
79  m1_render_window->request_redraw();
80
81
82  return 0;
83}
84
85li_object *m1_reverse_texture_selected(li_object *o, li_environment *env)
86{
87  for (int i=0; i<m1_info.obj->num_quad; i++)
88  {
89    g1_quad_class *q = &m1_info.obj->quad[i];
90    if (q->get_flags(g1_quad_class::SELECTED))
91    {
92      int j = q->num_verts()-1;
93      i4_float t;
94
95      // swap uv coords
96      t = q->u[1];
97      q->u[1] = q->u[j];
98      q->u[j] = t;
99      t = q->v[1];
100      q->v[1] = q->v[j];
101      q->v[j] = t;
102    }
103  }
104  m1_render_window->request_redraw();
105  m1_info.obj->calc_texture_scales();
106
107  return 0;
108}
109
110li_object *m1_flip_normal_selected(li_object *o, li_environment *env)
111{
112  for (int i=0; i<m1_info.obj->num_quad; i++)
113  {
114    g1_quad_class *q = &m1_info.obj->quad[i];
115    if (q->get_flags(g1_quad_class::SELECTED))
116    {
117      int j = q->num_verts()-1;
118      i4_float t;
119      w16 ref;
120
121      // swap references
122      ref = q->vertex_ref[1];
123      q->vertex_ref[1] = q->vertex_ref[j];
124      q->vertex_ref[j] = ref;
125
126      // swap uv coords
127      t = q->u[1];
128      q->u[1] = q->u[j];
129      q->u[j] = t;
130      t = q->v[1];
131      q->v[1] = q->v[j];
132      q->v[j] = t;
133    }
134  }
135  m1_info.obj->calc_texture_scales();
136  m1_render_window->request_redraw();
137
138  return 0;
139}
140
141li_object *m1_default_coordinates(li_object *o, li_environment *env)
142{
143  for (int i=0; i<m1_info.obj->num_quad; i++)
144  {
145    g1_quad_class *q = &m1_info.obj->quad[i];
146    if (q->get_flags(g1_quad_class::SELECTED))
147    {
148      q->u[0] = 0;
149      q->v[0] = 0;
150      q->u[1] = 1;
151      q->v[1] = 0;
152      q->u[2] = 1;
153      q->v[2] = 1;
154      q->u[3] = 0;
155      q->v[3] = 1;
156    }
157  }
158  m1_info.obj->calc_texture_scales();
159  m1_render_window->request_redraw();
160
161  return 0;
162}
163
164li_object *m1_tint_selected(li_object *o, li_environment *env)
165{
166  for (int i=0; i<m1_info.obj->num_quad; i++)
167  {
168    if (m1_info.obj->quad[i].get_flags(g1_quad_class::SELECTED))
169      m1_info.obj->quad[i].set_flags(g1_quad_class::TINT);
170  }
171  m1_render_window->request_redraw();
172
173  return 0;
174}
175
176li_object *m1_untint_selected(li_object *o, li_environment *env)
177{
178  for (int i=0; i<m1_info.obj->num_quad; i++)
179  {
180    if (m1_info.obj->quad[i].get_flags(g1_quad_class::SELECTED))
181      m1_info.obj->quad[i].set_flags(g1_quad_class::TINT,0);
182  }
183  m1_render_window->request_redraw();
184
185  return 0;
186}
187
188li_object *m1_delete_selected(li_object *o, li_environment *env)
189{
190  m1_poly_object_class *obj=m1_info.obj;
191  if (obj)
192  {
193    int shift=0;
194
195    for (int i=0; i<obj->num_quad; i++)
196    {
197      if (obj->quad[i].get_flags(g1_quad_class::SELECTED))
198        shift++;
199      else
200        if (shift>0)
201        {
202          obj->quad[i-shift]=obj->quad[i];
203          obj->texture_names[i-shift]=obj->texture_names[i];
204        }
205    }
206    obj->num_quad-=shift;
207
208    m1_render_window->request_redraw();
209  }
210  return 0;
211}
212
213li_object *m1_join_coords(li_object *o, li_environment *env)
214{
215  m1_poly_object_class *obj=m1_info.obj;
216
217  i4_float u,v;
218  int set=0;
219
220  if (obj)
221  {
222    for (int j=0; j<obj->num_quad; j++)
223    {
224      g1_quad_class *q=obj->quad+j;
225      if (q->get_flags(g1_quad_class::SELECTED))
226        for (int i=0; i<q->num_verts(); i++)
227          if (obj->get_poly_vert_flag(j, 1<<i))
228            if (set)
229            {
230              q->u[i] = u;
231              q->v[i] = v;
232            }
233            else
234            {
235              set = 1;
236              u = q->u[i];
237              v = q->v[i];
238            }
239    }
240
241    m1_render_window->request_redraw();
242  }
243  return 0;
244}
245
246
247li_object *m1_team1(li_object *o, li_environment *env)
248{
249  m1_info.current_team=1;
250  m1_render_window->request_redraw();
251  return 0;
252}
253
254
255li_object *m1_team2(li_object *o, li_environment *env)
256{
257  m1_info.current_team=2;
258  m1_render_window->request_redraw();
259  return 0;
260}
261
262
263
264li_object *m1_team3(li_object *o, li_environment *env)
265{
266  m1_info.current_team=3;
267  m1_render_window->request_redraw();
268  return 0;
269}
270
271
272
273li_object *m1_team4(li_object *o, li_environment *env)
274{
275  m1_info.current_team=4;
276  m1_render_window->request_redraw();
277  return 0;
278}
279
280
281li_object *m1_team_default(li_object *o, li_environment *env)
282{
283  m1_info.current_team=0;
284  m1_render_window->request_redraw();
285  return 0;
286}
287
288li_object *m1_back_black(li_object *o, li_environment *env)
289{
290  m1_info.bg_color=0;
291  m1_render_window->request_redraw();
292  return 0;
293}
294
295li_object *m1_back_red(li_object *o, li_environment *env)
296{
297  m1_info.bg_color=0xff0000;
298  m1_render_window->request_redraw();
299  return 0;
300}
301
302li_object *m1_back_white(li_object *o, li_environment *env)
303{
304  m1_info.bg_color=0xffffff;
305  m1_render_window->request_redraw();
306  return 0;
307}
308
309li_object *m1_back_blue(li_object *o, li_environment *env)
310{
311  m1_info.bg_color=0xff;
312  m1_render_window->request_redraw();
313  return 0;
314}
315
316li_object *m1_back_darkblue(li_object *o, li_environment *env)
317{
318  m1_info.bg_color=0x2f;
319  m1_render_window->request_redraw();
320  return 0;
321}
322
323li_object *m1_back_green(li_object *o, li_environment *env)
324{
325  m1_info.bg_color=0xff00;
326  m1_render_window->request_redraw();
327  return 0;
328}
329
330
331li_object *m1_recenter(li_object *o, li_environment *env)
332{
333  m1_render_window->recenter();
334  return 0;
335}
336
337li_object *m1_axis_toggle(li_object *o, li_environment *env)
338{
339  m1_info.set_flags(M1_SHOW_AXIS, ~m1_info.get_flags(M1_SHOW_AXIS));
340  m1_render_window->request_redraw();
341  return 0;
342}
343
344
345li_object *m1_toggle_shading(li_object *o, li_environment *env)
346{
347  m1_info.set_flags(M1_SHADING, ~m1_info.get_flags(M1_SHADING));
348  m1_render_window->request_redraw();
349  return 0;
350}
351
352li_object *m1_toggle_names(li_object *o, li_environment *env)
353{
354  m1_info.set_flags(M1_SHOW_FACE_NAMES, ~m1_info.get_flags(M1_SHOW_FACE_NAMES));
355  m1_render_window->request_redraw();
356  return 0;
357}
358
359
360
361li_object *m1_toggle_numbers(li_object *o, li_environment *env)
362{
363  m1_info.set_flags(M1_SHOW_FACE_NUMBERS, ~m1_info.get_flags(M1_SHOW_FACE_NUMBERS));
364  m1_render_window->request_redraw();
365  return 0;
366}
367
368
369li_object *m1_toggle_vnumbers(li_object *o, li_environment *env)
370{
371  m1_info.set_flags(M1_SHOW_VERT_NUMBERS, ~m1_info.get_flags(M1_SHOW_VERT_NUMBERS));
372  m1_render_window->request_redraw();
373  return 0;
374}
375
376
377li_object *m1_swap_polynums(li_object *o, li_environment *env)
378{
379  int q1=-1,q2=-1;
380  for (int i=0; i<m1_info.obj->num_quad; i++)
381  {
382    g1_quad_class *q = &m1_info.obj->quad[i];
383    if (q->get_flags(g1_quad_class::SELECTED))
384      if (q1==-1)
385        q1=i;
386      else if (q2==-1)
387        q2=i;
388      else return 0;
389  }
390   
391  if (q1!=-1 && q2!=-1)
392  {
393    m1_poly_object_class *obj=m1_info.obj;
394
395    i4_str *tmp=obj->texture_names[q1];
396    obj->texture_names[q1]=obj->texture_names[q2];
397    obj->texture_names[q2]=tmp;
398
399
400    g1_quad_class tq;
401    tq=obj->quad_store[q1];
402    obj->quad_store[q1]=obj->quad_store[q2];
403    obj->quad_store[q2]=tq;
404
405    obj->quad[q1]=obj->quad_store[q1];
406    obj->quad[q2]=obj->quad_store[q2];
407  }
408  return 0;
409}
410
411
412li_object *m1_dump_polys(li_object *o, li_environment *env)
413{
414  i4_file_class *fp=i4_open("dump.scm", I4_WRITE);
415  if (!fp) return 0;
416
417  for (int i=0; i<m1_info.obj->num_quad; i++)
418  {
419    g1_quad_class *q = &m1_info.obj->quad[i];
420   
421    char tname[256];
422    i4_os_string(*m1_info.obj->texture_names[i], tname,  256);
423
424    int first=1, j;
425    if (q->u[0]>=0.47 &&
426        q->u[1]>=0.47 &&
427        q->u[2]>=0.47 &&
428        q->u[3]>=0.47)
429      first=0;
430
431
432    for (j=0; j<4; j++)
433      if (first)
434      {
435        q->u[j]*=2;
436        m1_info.obj->texture_names[i]=new i4_str("x:\\crack\\golgotha\\textures\\nuk_sky1.tga");
437      }
438      else
439      {
440        q->u[j]=q->u[j]*2-1.0;
441        m1_info.obj->texture_names[i]=new i4_str("x:\\crack\\golgotha\\textures\\nuk_sky1.tga");
442      }
443   
444
445    fp->printf("(setup_quad %d %s %f %f  %f %f  %f %f  %f %f)\n",
446               i, tname,
447               q->u[0], q->v[0],
448               q->u[1], q->v[1],
449               q->u[2], q->v[2],
450               q->u[3], q->v[3]);
451  }
452  delete fp;
453  return 0;
454}
455
456li_automatic_add_function(m1_dump_polys, "dump_polys");
457
458li_automatic_add_function(m1_axis_toggle, "axis_toggle");
459li_automatic_add_function(m1_recenter, "recenter");
460li_automatic_add_function(m1_select_none, "select_none");
461li_automatic_add_function(m1_select_similar, "select_similar");
462li_automatic_add_function(m1_wireframe_toggle, "wireframe");
463li_automatic_add_function(m1_rotate_texture_selected, "rotate_texture_sel");
464li_automatic_add_function(m1_reverse_texture_selected, "reverse_texture_sel");
465li_automatic_add_function(m1_flip_normal_selected, "flip_normal_sel");
466li_automatic_add_function(m1_default_coordinates, "default_coords");
467li_automatic_add_function(m1_tint_selected, "tint_sel");
468li_automatic_add_function(m1_untint_selected, "untint_sel");
469li_automatic_add_function(m1_delete_selected, "delete_sel");
470li_automatic_add_function(m1_join_coords, "join_coords");
471
472li_automatic_add_function(m1_team1, "team_1");
473li_automatic_add_function(m1_team2, "team_2");
474li_automatic_add_function(m1_team3, "team_3");
475li_automatic_add_function(m1_team4, "team_4");
476li_automatic_add_function(m1_team_default, "no_tint");
477li_automatic_add_function(m1_toggle_shading, "toggle_shading");
478
479li_automatic_add_function(m1_back_black, "back_black");
480li_automatic_add_function(m1_back_red, "back_red");
481li_automatic_add_function(m1_back_white, "back_white");
482li_automatic_add_function(m1_back_blue, "back_blue");
483li_automatic_add_function(m1_back_darkblue, "back_darkblue");
484li_automatic_add_function(m1_back_green, "back_green");
485
486
487li_automatic_add_function(m1_toggle_names, "toggle_names");
488li_automatic_add_function(m1_toggle_numbers, "toggle_numbers");
489li_automatic_add_function(m1_toggle_vnumbers, "toggle_vnumbers");
490li_automatic_add_function(m1_swap_polynums, "swap_polynums");
491
Note: See TracBrowser for help on using the repository browser.