source: golgotha/src/i4/lisp/li_vect.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: 2.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 "lisp/li_vect.hh"
10#include "lisp/lisp.hh"
11#include "file/file.hh"
12#include "loaders/dir_save.hh"
13#include "loaders/dir_load.hh"
14#include "lisp/li_init.hh"
15
16li_type_number li_vect_type;
17class li_vect_type_function_table : public li_type_function_table
18{
19public:
20  // free data associated with an instance of this type
21  virtual void free(li_object   *o)
22  {
23    delete li_vect::get(o,0)->v;
24  }
25
26  virtual int equal(li_object  *o1, li_object *o2)
27  {
28    i4_3d_vector v1=li_vect::get(o1,0)->value(), v2=li_vect::get(o2,0)->value();
29    return v1.x==v2.x && v1.y==v2.y && v1.z==v1.z;
30  }
31
32  virtual void print(li_object  *o, i4_file_class *stream)
33  {
34    i4_3d_vector v=li_vect::get(o,0)->value();
35    stream->printf("(vector %f %f %f)",v.x, v.y, v.z);
36  }
37
38  virtual char *name() { return "vector"; }
39
40  virtual li_object *create(li_object *params, li_environment *env)
41  {
42    i4_3d_vector v;
43    if (params)
44    {
45      v.x=li_get_float(li_eval(li_car(params,env), env),env); params=li_cdr(params,env);
46      v.y=li_get_float(li_eval(li_car(params,env), env),env); params=li_cdr(params,env);
47      v.z=li_get_float(li_eval(li_car(params,env), env),env); params=li_cdr(params,env);
48    }
49     
50    return new li_vect(v);
51  }
52
53
54  virtual void save_object(i4_saver_class *fp, li_object *o, li_environment *env)
55  {
56    i4_3d_vector v=li_vect::get(o,env)->value();
57    fp->write_float(v.x);
58    fp->write_float(v.y);
59    fp->write_float(v.z);
60
61  }
62
63  virtual li_object *load_object(i4_loader_class *fp, li_type_number *type_remap,
64                                 li_environment *env)
65  {
66    i4_3d_vector v;
67    v.x=fp->read_float();
68    v.y=fp->read_float();
69    v.z=fp->read_float();
70    return new li_vect(v);
71  }
72};
73
74li_automatic_add_type(li_vect_type_function_table, li_vect_type);
Note: See TracBrowser for help on using the repository browser.