|
refframe.h00001 /* 00002 Dynamics/Kinematics modeling and simulation library. 00003 Copyright (C) 1999 by Michael Alexander Ewert 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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 // frame of reference. position and orientation data are stored here. 00033 // uses refrence counting scheme. 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 // if( !T_world_calced() ) 00110 // calc_T_world(); 00111 // return T_world.This2Other( v ); 00112 } 00113 00114 void this_to_world ( ctVector3 &v, ctVector3 &src ) 00115 { 00116 v = get_this_to_world()*src + get_world_offset(); 00117 // if( !T_world_calced() ) 00118 // calc_T_world(); 00119 // return T_world.This2Other( v ); 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 // bool is_T_world_calced; // true if T_world is currently valid 00135 // ctReferenceFrame *parent_frame; 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; // true if this is the top-most reference frame 00167 }; 00168 00169 #endif Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |