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

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 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: 5.3 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
16#ifdef __linux
17
18#include <stdio.h>
19
20li_object *m1_do(li_object *o, li_environment *env)
21{
22  char buff[1024], *p=buff;
23
24  printf("> ");
25  fgets(buff, sizeof(buff), stdin);
26  lip(li_eval(li_get_expression(p,0),0));
27}
28li_automatic_add_function(m1_do, "command");
29
30#endif
31
32li_object *m1_distribute_selected(li_object *o, li_environment *env)
33{
34  int i;
35  int num_sel=0;
36  i4_float x=0,nx;
37
38  for (i=0; i<m1_info.obj->num_quad; i++)
39    if (m1_info.obj->quad[i].get_flags(g1_quad_class::SELECTED))
40      num_sel++;
41
42  for (i=0; i<m1_info.obj->num_quad; i++)
43  {
44    g1_quad_class *q = &m1_info.obj->quad[i];
45    if (q->get_flags(g1_quad_class::SELECTED))
46    {
47      nx = x+1.0/num_sel;
48      q->u[0] = x;
49      q->v[0] = 0;
50      q->u[1] = nx;
51      q->v[1] = 0;
52      q->u[2] = nx;
53      q->v[2] = 1;
54      q->u[3] = x;
55      q->v[3] = 1;
56      x = nx;
57    }
58  }
59  m1_render_window->request_redraw();
60
61  return 0;
62}
63li_automatic_add_function(m1_distribute_selected, "distribute_sel");
64
65li_object *m1_swap_selected(li_object *o, li_environment *env)
66{
67  int i;
68  int num_sel=0;
69  g1_quad_class *first=0;
70
71  i4_float u[4],v[4],t;
72
73  for (i=0; i<m1_info.obj->num_quad; i++)
74  {
75    g1_quad_class *q = &m1_info.obj->quad[i];
76    if (q->get_flags(g1_quad_class::SELECTED))
77    {
78      if (!first)
79        first = q;
80
81      for (int j=0; j<4; j++)
82      {
83        t = q->u[j];
84        q->u[j] = u[j];
85        u[j] = t;
86        t = q->v[j];
87        q->v[j] = v[j];
88        v[j] = t;
89      }
90    }
91  }
92
93  if (first)
94    for (int j=0; j<4; j++)
95    {
96      t = first->u[j];
97      first->u[j] = u[j];
98      u[j] = t;
99      t = first->v[j];
100      first->v[j] = v[j];
101      v[j] = t;
102    }
103
104  m1_render_window->request_redraw();
105
106  return 0;
107}
108li_automatic_add_function(m1_swap_selected, "swap_sel");
109
110li_object *m1_add_pan_selected(li_object *o, li_environment *env)
111{
112  int i,num_sel;
113  m1_poly_object_class *obj = m1_info.obj;
114
115  if (!obj)
116    return 0;
117 
118  for (i=0; i<obj->num_quad; i++)
119  {
120    g1_quad_class *q = &obj->quad[i];
121    if (q->get_flags(g1_quad_class::SELECTED))
122    {
123      int sp = obj->add_special(i);
124      g1_texture_animation *t = &obj->special[sp];
125     
126      t->quad_number = i;
127      t->max_frames = 0;
128      t->speed = 0.01;
129      t->du = 0.0;
130      t->dv = 0.0;
131      for (int n=0; n<q->num_verts(); n++)
132      {
133        t->u[n] = q->u[n];
134        t->v[n] = q->v[n];
135      }
136    }
137  }
138 
139  return 0;
140}
141
142li_automatic_add_function(m1_add_pan_selected, "pan_texture_sel");
143
144li_object *m1_add_anim_selected(li_object *o, li_environment *env)
145{
146  int i,num_sel;
147  m1_poly_object_class *obj = m1_info.obj;
148
149  if (!obj)
150    return 0;
151 
152  for (i=0; i<obj->num_quad; i++)
153  {
154    g1_quad_class *q = &obj->quad[i];
155    if (q->get_flags(g1_quad_class::SELECTED))
156    {
157      int sp = obj->add_special(i);
158      g1_texture_animation *t = &obj->special[sp];
159     
160      t->quad_number = i;
161      t->max_frames = 1;
162      t->frames_x = 1;
163      t->speed = 1;
164      t->du = 1.0;
165      t->dv = 1.0;
166      for (int n=0; n<q->num_verts(); n++)
167      {
168        t->u[n] = q->u[n];
169        t->v[n] = q->v[n];
170      }
171
172      obj->num_special++;
173    }
174  }
175 
176  return 0;
177}
178li_automatic_add_function(m1_add_anim_selected, "animate_texture_sel");
179
180li_object *m1_create_plane(li_object *o, li_environment *env)
181{
182  int i,num_sel;
183  m1_poly_object_class *obj = new m1_poly_object_class;
184
185  if (obj)
186  {
187    obj->init();
188   
189    if (m1_info.obj)
190      delete m1_info.obj;
191
192    m1_info.obj = obj;
193    m1_info.set_current_filename("c:/tmp/fly.gmod");
194  }
195
196  if (!obj)
197    return 0;
198
199  obj->num_vertex = 4;
200  obj->vert_store.add_many(obj->num_vertex);
201  obj->vert_store[0].v.set(0,0,0);
202  obj->vert_store[1].v.set(1,0,0);
203  obj->vert_store[2].v.set(1,1,0);
204  obj->vert_store[3].v.set(0,1,0);
205
206  obj->anim_store.add();
207  obj->anim_store[0].num_frames=1;
208  obj->anim_store[0].vertex = &obj->vert_store[0];
209  obj->animation_names.add(new i4_str("Default"));
210
211  obj->num_animations = obj->anim_store.size();
212  obj->animation = &obj->anim_store[0];
213
214  obj->quad_store.add();
215  obj->quad_store[0].set(0,1,2,3);
216  obj->quad_store[0].flags=0;
217  obj->quad_store[0].set_material(0);
218  obj->quad_store[0].texture_scale = 1.0;
219  obj->quad_store[0].u[0] = 0.0;
220  obj->quad_store[0].v[0] = 0.0;
221  obj->quad_store[0].u[1] = 1.0;
222  obj->quad_store[0].v[1] = 0.0;
223  obj->quad_store[0].u[2] = 1.0;
224  obj->quad_store[0].v[2] = 1.0;
225  obj->quad_store[0].u[3] = 0.0;
226  obj->quad_store[0].v[3] = 1.0;
227  obj->texture_names.add(new i4_str((char*)0));
228
229  obj->num_quad = obj->quad_store.size();
230  obj->quad = &obj->quad_store[0];
231
232  obj->calc_vert_normals();
233  obj->calc_extents();
234
235  m1_info.texture_list_changed();
236 
237  return 0;
238}
239li_automatic_add_function(m1_create_plane, "create_plane");
240
Note: See TracBrowser for help on using the repository browser.