chiark / gitweb /
Attempt at a new model top half.
[moebius.git] / library.hh
1 /*
2  * Points library
3  */
4
5 #ifndef POINTS_HH
6 #define POINTS_HH
7
8 #include <stdlib.h>
9
10 /*
11  * Coordinate system:
12  *
13  *          Y |
14  *            |
15  *            |
16  *            /-------- X
17  *           /
18  *          /
19  *       Z (coming out of the monitor)
20  */
21
22 struct Onscreen {
23   double x, y;
24   Onscreen(){};
25   Onscreen(double ix, double iy) { x=ix; y=iy; }
26 };
27
28 class Point;
29
30 class Transform {
31 public:
32   virtual Point operator()(Point)= 0;
33 };
34
35 class TransformList {
36   Transform **a;
37   int size,used;
38   void clearcontents();
39  public:
40   TransformList() { size=used=0; a=0; }
41   ~TransformList() { clearcontents(); free(a); }
42   void reset() { clearcontents(); used=0; }
43   Point operator()(Point);
44   void append(Transform*);
45 };
46
47 class Point {
48   static TransformList usertransforms;
49   static TransformList povtransform;
50   static double planedistance, eyedistance, cutoffdistance, eyex;
51   double xyz[3];
52 public:
53   Point(){}
54   Point(double x, double y, double z) { xyz[0]=x; xyz[1]=y; xyz[2]=z; }
55   Point operator+(Point r) { return Point(xyz[0]+r[0], xyz[1]+r[1], xyz[2]+r[2]); }
56   Point operator*(double f) { return Point(xyz[0]*f, xyz[1]*f, xyz[2]*f); }
57   double& operator[](int i) { return xyz[i]; }
58
59   operator Onscreen() const;
60   Point transformed() const { return povtransform(usertransforms(*this)); }
61   double index() const { return transformed()[2]; }
62
63   static int indexvisible(double index) { return index < cutoffdistance; }
64   static void appendtransform(Transform *t) { usertransforms.append(t); }
65   static void cleartransform() { usertransforms.reset(); }
66   static void setobserver(double theta, double eta=0.0,
67                           double planedist=1.0, double eyedist=1.0,
68                           double cutoff=10.0);
69   static void seteyex(double n) { eyex=n; }
70 };
71
72 #endif