/[gzz]/gzz/gfx/libcoords/Coords.hxx
ViewVC logotype

Diff of /gzz/gfx/libcoords/Coords.hxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15 by tjl, Tue Oct 8 18:23:43 2002 UTC revision 1.16 by tjl, Thu Oct 10 05:10:21 2002 UTC
# Line 1  Line 1 
1  #include <GL/gl.h>  #include <GL/gl.h>
2    
3  // XXX homogeneous coordinates for helping texture coordinates  /** Coordinate systems.
4     */
5  namespace Coords {  namespace Coords {
6      PREDBGVAR(dbg);      PREDBGVAR(dbg);
7      using std::vector;      using std::vector;
8      using std::cout;      using std::cout;
9      using namespace Vec23;      using namespace Vec23;
10    
11        /** A single coordinate system, possibly defined
12         * hierarchically through others.
13         * <p>
14         * If you get a CoordSys from somewhere, the only methods
15         * you should need to call are vertex(), transform(),
16         * getInverse(), nonlinearity(), canPerformGL(), performGL()
17         * and dump(). All other methods are for use by CoordSet or
18         * other classes constructing coordinate systems.
19         */
20      class CoordSys {      class CoordSys {
21      protected:      protected:
22          CoordSys *super;          CoordSys *super;
23          CoordSys *inverse;          CoordSys *inverse;
24            /** True if this object owns the object pointed to
25             * by the inverse pointer.
26             */
27          bool ownInverse;          bool ownInverse;
28    
29            /** Don't use; use getInverse instead!
30             * This is the internal
31             */
32            virtual CoordSys *createInverse() ;
33      public:      public:
34          CoordSys() : super(0), inverse(0), ownInverse(1) {          CoordSys() : super(0), inverse(0), ownInverse(1) {
35          }          }
# Line 22  namespace Coords { Line 39  namespace Coords {
39                  super(super), inverse(inverse), ownInverse(ownInverse) {                  super(super), inverse(inverse), ownInverse(ownInverse) {
40          }          }
41    
42            /** Set the parent(s) and determining coordinate systems
43             * of this coordsys.
44             * The number of pointers pointed to by super depends
45             * on the type of this CoordSys.
46             */
47          virtual void setSuper(CoordSys **super) {          virtual void setSuper(CoordSys **super) {
48              this->super = super[0];              this->super = super[0];
49          }          }
50          /** Always call setSuper first!          /** Set the parameters of this coordsys from the given
51             * float array.
52             * The number of parameters read from nparams
53             * depends on the type of this CoordSys.
54             * <p>
55             * <b>Always call setSuper first!</b>
56           */           */
57          virtual void setParams(float *params) = 0;          virtual void setParams(float *params) = 0;
58    
59          /** Get the inverse of this coordinate system.          /** Get the inverse of this coordinate system.
60           * Always returns non-null but it is not guaranteed           * Always returns non-null but it is not guaranteed
61           * that this will work properly. (XXX canInvert())           * that this will work properly. (XXX canInvert() ?)
62           * The returned inverse is owned by this object and           * The returned inverse is owned by this object and
63           * mustn't be deleted by the caller.           * mustn't be deleted by the caller.
64           */           */
# Line 41  namespace Coords { Line 68  namespace Coords {
68              return inverse;              return inverse;
69          }          }
70    
         /** Don't use; use getInverse instead!  
          */  
         virtual CoordSys *createInverse() ;  
71    
72          // For Pt as well?          // For Pt as well?
73                    
# Line 51  namespace Coords { Line 75  namespace Coords {
75           * into this coordinate system.           * into this coordinate system.
76           */           */
77          virtual void vertex(const ZPt &p) const = 0;          virtual void vertex(const ZPt &p) const = 0;
78    
79          /** Return the given ZPt transformed          /** Return the given ZPt transformed
80           * into this coordinate system.           * into this coordinate system.
81           * Note that some "coordinate systems" may overload           * Note that some "coordinate systems" may overload
# Line 60  namespace Coords { Line 85  namespace Coords {
85          virtual ZPt transform(const ZPt &p) const = 0;          virtual ZPt transform(const ZPt &p) const = 0;
86    
87          /** How nonlinear is the coordinate system at the given point.          /** How nonlinear is the coordinate system at the given point.
88           * The return value is 1/l where l would be a reasonable length for dicing.           * The return value is 1/l where l would be a reasonable length
89             * for dicing.
90           * Returns 0 if dicing is required.           * Returns 0 if dicing is required.
91             * XXX This needs more thought.
92           */           */
93          virtual float nonlinearity(const ZPt &p, float radius) {          virtual float nonlinearity(const ZPt &p, float radius) {
94              return 0;              return 0;
# Line 71  namespace Coords { Line 98  namespace Coords {
98           * alone.           * alone.
99           */           */
100          virtual bool canPerformGL() { return false; }          virtual bool canPerformGL() { return false; }
101    
102          /** Try to perform the GL operations to set this          /** Try to perform the GL operations to set this
103           * coordinate system in the modelview matrix.           * coordinate system in the modelview matrix.
104           * Only the topmost modelview matrix may be altered by           * Only the topmost modelview matrix may be altered by
# Line 86  namespace Coords { Line 114  namespace Coords {
114              if(inverse && ownInverse) delete inverse;              if(inverse && ownInverse) delete inverse;
115          }          }
116    
117          virtual void dump() {          /** Print this coordinate system into the given
118              cout << "Unknown coordsys\n";           * ostream.
119             */
120            virtual void dump(ostream &out) {
121                out << "Unknown coordsys\n";
122          }          }
123    
124            /** Check whether this coordinate system should be drawn with
125             * the current parameters.
126             * This method should not recurse; the parents will already
127             * have been asked. It should only consider the parameters
128             * of the current coordinate system.
129             */
130          virtual bool shouldBeDrawn() {          virtual bool shouldBeDrawn() {
131              return super->shouldBeDrawn();              return true;
132          }          }
133    
134          /** Get the parameters of a compatible type.          /** Get the parameters of a compatible type.
135           * Does not find mutual ancestor etc; simply           * Does not find mutual ancestor etc; simply
136           * converts if it can and if not, fails.           * converts if it can and if not, fails.
137             * @param type The internal type code to transform into.
138             * @param into The vector into which the resulting floats
139             *              should be written.
140           * @return true if successful, and into is filled, or false           * @return true if successful, and into is filled, or false
141           *      if conversion cannot be performed.           *      if conversion cannot be performed.
142           */           */

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26