Changeset 541 for branches/cpp-ode/src/libmmpong/ode_obj.h
- Timestamp:
- 03/01/10 22:54:45 (6 months ago)
- Files:
-
- 1 modified
-
branches/cpp-ode/src/libmmpong/ode_obj.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/cpp-ode/src/libmmpong/ode_obj.h
r540 r541 17 17 boost::shared_ptr<NetGameODE> game; 18 18 public: 19 //TODO: should the GEOM be protected? (andre thinks so...) 19 20 GEOM geom; 20 21 protected: … … 33 34 //we could also use: this->classname="ODEObj"; 34 35 NetEntHelper<CLASSID>::classname="ODEObj"; 36 movable=false; 35 37 }; 36 38 39 bool movable; 40 public: 41 //links geom to body => physics do not influence object 42 //note that the object can still be moved by user input 43 void set_immovable() { 44 movable=false; 45 geom.setBody(0); 46 }; 47 48 //links geom to body => physics influence object 49 void set_movable() { 50 movable=true; 51 const dReal *vals=getPosition(); 52 dBody::setPosition(vals); 53 vals=getRotation(); 54 dBody::setRotation(vals); 55 geom.setBody(*this); 56 }; 57 58 //we need these wrapper functions (do NOT use dBody or dGeom 59 //functions directly for positioning) 60 const dReal* getPosition() { 61 return geom.getPosition(); 62 }; 63 64 const dReal* getRotation() { 65 return geom.getRotation(); 66 }; 67 68 void setPosition(const dReal vals[3]) { 69 geom.setPosition(vals[0], vals[1], vals[2]); 70 if (!movable) 71 dBody::setPosition(vals); 72 }; 73 //convenience wrapper 74 void setPosition(dReal x, dReal y, dReal z) { 75 dReal vals[3]={x,y,z}; 76 setPosition(vals); 77 }; 78 79 80 void setRotation(const dMatrix3 rot) { 81 geom.setRotation(rot); 82 if (!movable) 83 dBody::setRotation(rot); 84 }; 85 protected: 37 86 virtual void update(NetMsg::pointer msg) { 38 87 if (msg->get_state()==NetMsg::StatPacking) { 39 const dReal *vals=geom.getPosition(); 88 msg->pack(movable); 89 const dReal *vals=getPosition(); 40 90 LOGDBG("Position==["<<vals[0]<<","<<vals[1]<<","<<vals[2]<<"]"); 41 91 for(unsigned int i=0; i<3; i++) … … 48 98 49 99 //check ODE alignment in dMatrix3 50 vals=ge om.getRotation();100 vals=getRotation(); 51 101 LOGDBG("Rotation==["<<vals[0]<<","<<vals[1]<<","<<vals[2]<<";"<<vals[4]<<","<<vals[5]<<","<<vals[6]<<";"<<vals[8]<<","<<vals[9]<<","<<vals[10]<<"]"); 52 102 for(unsigned int i=0; i<3; i++) … … 62 112 msg->pack_ode(vals[i]); 63 113 } else if (msg->get_state()==NetMsg::StatUnpacking) { 114 bool _movable; 115 msg->unpack(_movable); 116 if (movable && !_movable) 117 set_immovable(); 118 if (!movable && _movable) 119 set_movable(); 64 120 dReal vals[12]; 65 121 for(unsigned int i=0; i<3; i++) 66 122 msg->unpack_ode(vals[i]); 67 123 LOGDBG("Position==["<<vals[0]<<","<<vals[1]<<","<<vals[2]<<"]"); 68 geom.setPosition(vals[0], vals[1], vals[2]);124 setPosition(vals[0], vals[1], vals[2]); 69 125 70 126 for(unsigned int i=0; i<3; i++) … … 80 136 msg->unpack_ode(vals[i]); 81 137 LOGDBG("Rotation==["<<vals[0]<<","<<vals[1]<<","<<vals[2]<<";"<<vals[4]<<","<<vals[5]<<","<<vals[6]<<";"<<vals[8]<<","<<vals[9]<<","<<vals[10]<<"]"); 82 geom.setRotation(vals);138 setRotation(vals); 83 139 84 140 for(unsigned int i=0; i<3; i++)
