00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef ctReferenceFrame_H
00022 #define ctReferenceFrame_H
00023
00024 #include <stdio.h>
00025 #include "csphyzik/ctvector.h"
00026 #include "csphyzik/ctmatrix.h"
00027 #include "csphyzik/math3d.h"
00028
00031
00032
00033
00034 class ctReferenceFrame
00035 {
00036 public:
00037 ctReferenceFrame ( coord px = 0, coord py = 0, coord pz = 0,
00038 ctangle ppitch = 0, ctangle proll = 0, ctangle pyaw = 0,
00039 ctReferenceFrame *ref = NULL );
00040
00041 ~ctReferenceFrame() {}
00042
00043 static ctReferenceFrame& universe ();
00044
00045 bool is_universe ()
00046 { return is_universe_frame; }
00047
00048 bool not_universe ()
00049 { return !is_universe_frame; }
00050
00051 static void add_ref ( ctReferenceFrame &rf )
00052 { rf.reference_count++; }
00053
00054 static void remove_ref ( ctReferenceFrame &rf )
00055 {
00056 if ( --rf.reference_count <= 0 )
00057 if ( rf.not_universe() )
00058 delete &rf;
00059 }
00060
00061 const ctVector3 &get_offset()
00062 { return offset; }
00063
00064 const ctVector3 &get_world_offset()
00065 { return offset; }
00066
00067 void set_offset( const ctVector3 &v )
00068 { offset = v; }
00069
00070 void set_world_offset( ctVector3 &v )
00071 { offset = v; }
00072
00077 const ctMatrix3 &get_R ()
00078 { return fTg; }
00079
00080 const ctMatrix3 &get_this_to_parent ()
00081 { return fTg; }
00082
00083 void set_R ( const ctMatrix3 &M )
00084 { fTg = M; gTf = fTg.get_transpose(); }
00085
00086 void set_this_to_parent ( const ctMatrix3 &M )
00087 { fTg = M; gTf = fTg.get_transpose(); }
00088
00090 const ctMatrix3 &get_T()
00091 { return gTf; }
00092
00093 const ctMatrix3 &get_parent_to_this ()
00094 { return gTf; }
00095
00096 void set_T ( const ctMatrix3 &M )
00097 { gTf = M; fTg = gTf.get_transpose(); }
00098
00099 void set_parent_to_this ( const ctMatrix3 &M )
00100 { gTf = M; fTg = gTf.get_transpose(); }
00101
00103 const ctMatrix3 &get_this_to_world()
00104 { return fTg; }
00105
00106 void this_to_world ( ctVector3 &v )
00107 {
00108 v = get_this_to_world()*v + get_world_offset();
00109
00110
00111
00112 }
00113
00114 void this_to_world ( ctVector3 &v, ctVector3 &src )
00115 {
00116 v = get_this_to_world()*src + get_world_offset();
00117
00118
00119
00120 }
00121
00122 protected:
00124 ctMatrix3 gTf;
00126 ctMatrix3 fTg;
00128 ctVector3 offset;
00129
00130 int reference_count;
00131
00133 bool is_universe_frame;
00134
00135
00136 };
00137
00138 class ctDeltaReferenceFrame
00139 {
00140 public:
00141
00142 static ctDeltaReferenceFrame& universe ();
00143
00144 bool is_universe ()
00145 { return is_universe_frame; }
00146
00147 bool not_universe ()
00148 { return !is_universe_frame; }
00149
00150 static void add_ref ( ctDeltaReferenceFrame &rf )
00151 { rf.reference_count++; }
00152
00153 static void remove_ref ( ctDeltaReferenceFrame &rf )
00154 {
00155 if ( --rf.reference_count <= 0 )
00156 if ( rf.not_universe() )
00157 delete &rf;
00158 }
00159
00160 ctDeltaReferenceFrame ();
00161 ctVector3 v;
00162 ctVector3 w;
00163
00164 protected:
00165 int reference_count;
00166 bool is_universe_frame;
00167 };
00168
00169 #endif