Show
Ignore:
Timestamp:
03/01/10 22:54:45 (6 months ago)
Author:
gaul@…
Message:
  • movable flag synced
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/cpp-ode/src/libmmpong/ode_obj.h

    r540 r541  
    1717                boost::shared_ptr<NetGameODE> game; 
    1818        public: 
     19                //TODO: should the GEOM be protected? (andre thinks so...) 
    1920                GEOM geom; 
    2021        protected: 
     
    3334                        //we could also use: this->classname="ODEObj"; 
    3435                        NetEntHelper<CLASSID>::classname="ODEObj"; 
     36                        movable=false; 
    3537                }; 
    3638 
     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: 
    3786                virtual void update(NetMsg::pointer msg) { 
    3887                        if (msg->get_state()==NetMsg::StatPacking) { 
    39                                 const dReal *vals=geom.getPosition(); 
     88                                msg->pack(movable); 
     89                                const dReal *vals=getPosition(); 
    4090                                LOGDBG("Position==["<<vals[0]<<","<<vals[1]<<","<<vals[2]<<"]"); 
    4191                                for(unsigned int i=0; i<3; i++) 
     
    4898 
    4999                                //check ODE alignment in dMatrix3 
    50                                 vals=geom.getRotation(); 
     100                                vals=getRotation(); 
    51101                                LOGDBG("Rotation==["<<vals[0]<<","<<vals[1]<<","<<vals[2]<<";"<<vals[4]<<","<<vals[5]<<","<<vals[6]<<";"<<vals[8]<<","<<vals[9]<<","<<vals[10]<<"]"); 
    52102                                for(unsigned int i=0; i<3; i++) 
     
    62112                                        msg->pack_ode(vals[i]); 
    63113                        } 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(); 
    64120                                dReal vals[12]; 
    65121                                for(unsigned int i=0; i<3; i++) 
    66122                                        msg->unpack_ode(vals[i]); 
    67123                                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]); 
    69125                                 
    70126                                for(unsigned int i=0; i<3; i++) 
     
    80136                                        msg->unpack_ode(vals[i]); 
    81137                                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); 
    83139 
    84140                                for(unsigned int i=0; i<3; i++)