00001 /* Copyright (c) 2005 Arachi, Inc. and Stanford University. 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining 00004 * a copy of this software and associated documentation files (the 00005 * "Software"), to deal in the Software without restriction, including 00006 * without limitation the rights to use, copy, modify, merge, publish, 00007 * distribute, sublicense, and/or sell copies of the Software, and to 00008 * permit persons to whom the Software is furnished to do so, subject 00009 * to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 00018 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 00019 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 00020 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00021 */ 00022 00023 #ifndef _taoNode_h 00024 #define _taoNode_h 00025 00026 #include "taoDNode.h" 00027 #include "deMath.h" 00028 00029 class taoGroup; 00030 class taoControl; 00031 00039 class taoNode : public taoDNode 00040 { 00041 public: 00042 taoNode(); 00043 taoNode(taoDNode* parent, deFrame* home); 00044 virtual ~taoNode(); 00045 00046 virtual void sync(deFrame* local); 00047 00048 virtual taoJoint* getJointList() { return _jointList; } 00049 00053 virtual deVector6* velocity(); 00057 virtual deVector6* acceleration(); 00058 virtual void getFrameGraphics(deFrame* Tog) { *Tog = *frameGlobal(); } 00059 00060 virtual deFrame* frameHome() { return &_frameHome; } 00061 virtual deFrame* frameLocal() { return &_frameLocal; } 00062 virtual deFrame* frameGlobal() { return &_frameGlobal; } 00063 virtual deFloat* mass() { return &_mass; } 00064 virtual deVector3* center() { return &_center; } 00065 virtual deMatrix3* inertia() { return &_inertia; } 00069 virtual deVector6* force() { return &_Fext; } 00070 virtual void zeroForce() { _Fext.zero(); } 00074 virtual void addForce(const deVector6* f) { _Fext += *f; } 00075 00076 virtual void updateFrame(); 00077 virtual void integrate(deFloat dt); 00078 00079 virtual void setDParent(taoDNode* n) { _parent = n; } 00080 virtual taoDNode* getDParent() { return _parent; } 00081 virtual void setDChild(taoDNode* n) { _child = (taoNode*)n; } 00082 virtual taoDNode* getDChild() { return _child; } 00083 virtual void setDSibling(taoDNode* n) { _sibling = (taoNode*)n; } 00084 virtual taoDNode* getDSibling() { return _sibling; } 00085 00086 virtual void addJoint(taoJoint* joint); 00087 virtual void addABNode(); 00088 00089 virtual void unlink(); 00090 virtual void link(taoDNode* parent, deFrame* home); 00091 00092 virtual void deleteJointABNode(); 00093 00098 virtual void linearVelocity(deVector3* Vie, const deVector3* Pie); 00103 virtual void linearAcceleration(deVector3* Aie, const deVector3* Pie); 00104 // XXX 00105 //virtual deFloat effectiveMass(const deVector3* Pie, const deVector3* Ui); 00106 virtual void impulse(const deVector3* Pie, const deVector3* Yie); 00107 virtual void impulseDist(const deVector3* Pie, const deVector3* Yie); 00108 virtual void force(const deVector3* Pie, const deVector3* Fie); 00109 00110 private: 00111 deFrame _frameHome; 00112 deFrame _frameLocal; 00113 deFrame _frameGlobal; 00114 00115 deVector3 _center; 00116 deFloat _mass; 00117 deMatrix3 _inertia; 00118 00119 deVector6 _Fext; 00120 00121 taoDNode* _parent; 00122 taoNode* _child; 00123 taoNode* _sibling; 00124 00125 taoJoint* _jointList; 00126 00127 void _Initialize(); 00128 }; 00129 00137 class taoNodeRoot : public taoDNode 00138 { 00139 public: 00140 taoNodeRoot(deFrame* global); 00141 00142 virtual ~taoNodeRoot(); 00143 00144 virtual void sync(deFrame* local) { _frameGlobal = *local; } 00145 00146 virtual taoJoint* getJointList() { return NULL; } 00147 00148 virtual deVector6* velocity(); 00149 virtual deVector6* acceleration(); 00150 virtual void getFrameGraphics(deFrame* Tog) { *Tog = *frameGlobal(); } 00151 00152 virtual deFrame* frameHome() { return &_frameGlobal; } 00153 virtual deFrame* frameLocal() { return &_frameGlobal; } 00154 virtual deFrame* frameGlobal() { return &_frameGlobal; } 00155 virtual deFloat* mass() { return &_zero; } // YYY 00156 virtual deVector3* center() { return NULL; } 00157 virtual deMatrix3* inertia() { return NULL; } 00158 virtual deVector6* force() { return NULL; } 00159 virtual void zeroForce() {} 00160 virtual void addForce(const deVector6* f) {} 00161 00162 virtual void updateFrame() {} 00163 virtual void integrate(deFloat dt) {} 00164 00165 virtual taoDNode* getDParent() { return NULL; } 00166 virtual void setDChild(taoDNode* n) { _child = (taoNode*)n; } 00167 virtual taoDNode* getDChild() { return _child; } 00168 virtual taoDNode* getDSibling() { return NULL; } 00169 00170 void setNext(taoNodeRoot* r) { _next = r; } 00171 taoNodeRoot* getNext() { return _next; } 00172 00173 void setGroup(taoGroup* g) { _group = g; } 00174 taoGroup* getGroup() { return _group; } 00175 00176 void setController(taoControl* c) { _controller = c; } 00177 taoControl* getController() { return _controller; } 00178 00182 virtual void sync(); 00183 00184 private: 00185 deFloat _zero; // YYY 00186 deFrame _frameGlobal; 00187 00188 taoGroup* _group; 00189 taoControl* _controller; 00190 00191 taoNode* _child; 00192 00193 taoNodeRoot* _next; 00194 00195 void _DeleteNodeTree(taoDNode* r); 00196 void _SyncNodeTree(taoDNode* r); 00197 }; 00198 00199 #endif // _taoNode_h