Changeset 541

Show
Ignore:
Timestamp:
03/01/10 22:54:45 (5 months ago)
Author:
gaul@…
Message:
  • movable flag synced
Location:
branches/cpp-ode/src
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • branches/cpp-ode/src/libmmpong/netgame_ode.cc

    r540 r541  
    3030        for (unsigned int i=0; i<step_count; i++) { 
    3131                collide(); 
    32                 step(STEPSIZE); 
     32                quickStep(STEPSIZE); 
    3333        } 
    3434        world_time=endtime; 
  • branches/cpp-ode/src/libmmpong/netgame_ode.h

    r540 r541  
    4949                        unsigned int n_collide = dCollide(o1, o2, MAX_CONTACTS, &contact[0].geom, sizeof(dContact)); 
    5050                        for (unsigned int i=0; i< n_collide; i++){ 
    51                                 contact[i].surface.mode = dContactBounce; 
     51                                contact[i].surface.mode = dContactBounce;// | dContactSoftCFM; 
    5252                                contact[i].surface.mu=dInfinity; 
    53                                 contact[i].surface.mu2=0; 
    54                                 contact[i].surface.bounce=0.9; 
    55                                 contact[i].surface.bounce_vel=0.1; 
     53                                contact[i].surface.bounce=1.0; // \in [0,1] 
     54                                contact[i].surface.bounce_vel=0.01; 
     55                                //contact[i].surface.soft_cfm = 0.1; 
    5656                                dBodyID b1 = dGeomGetBody(o1), b2 = dGeomGetBody(o2); 
    5757                                dJointID c = dJointCreateContact(id(), 0, contact+i); 
  • branches/cpp-ode/src/libmmpong/netgame_ode_pong.cc

    r540 r541  
    2323        boost::shared_ptr<ODEBox> playerpad=srv_ent_create<ODEBox>(); 
    2424        playerpad->geom.setLengths(0.05,0.5,0.05); 
     25        playerpad->set_immovable(); 
    2526        double ang=M_PI*(1.0+2.0*newteamid/srv_teamid_cur); 
    26         playerpad->geom.setPosition(cos(ang)*1.05, sin(ang)*1.05, 0.0); 
     27        playerpad->setPosition(cos(ang)*1.05, sin(ang)*1.05, 0.0); 
    2728        uint16_t newpadid=playerpad->get_entid(); 
    2829        player2pad[newplayerid]=newpadid; 
     
    274275                boost::shared_ptr<ODEBox> pad=get_ent<ODEBox>(mypadid); 
    275276                double ang=M_PI*(1.0+2.0*myteamid/srv_teamid_cur); 
    276                 pad->geom.setPosition(cos(ang)*1.05, -1.0 + 2.0 * mypadpos, 0.0); 
     277                pad->setPosition(cos(ang)*1.05, -1.0 + 2.0 * mypadpos, 0.0); 
    277278                NetMsg::pointer msg=NetMsg::create(NetMsg::CmdGameCustom); 
    278279                msg->pack_begin(); 
  • branches/cpp-ode/src/libmmpong/netgame_ode_pong.h

    r540 r541  
    5555                                barbot=srv_ent_create<ODEBox>(); 
    5656                        bartop->geom.setLengths(2.0,0.05,0.05); 
    57                         bartop->geom.setPosition(0.0, 1.05, 0.0); 
     57                        bartop->setPosition(0.0, 1.05, 0.0); 
     58                        bartop->set_immovable(); 
     59 
    5860                        barbot->geom.setLengths(2.0,0.05,0.05); 
    59                         barbot->geom.setPosition(0.0, -1.05, 0.0); 
     61                        barbot->setPosition(0.0, -1.05, 0.0); 
     62                        barbot->set_immovable(); 
    6063                         
    6164                        boost::shared_ptr<ODESphere>  
    6265                                ball=srv_ent_create<ODESphere>(); 
    6366                        ball->geom.setRadius(0.025); 
    64                         ball->setLinearVel(-0.1, 0.0, 0.0); 
     67                        ball->setLinearVel(0.0, 1.0, 0.0); 
    6568                }; 
    6669                virtual void srv_con_start(NetCon::pointer con); 
  • branches/cpp-ode/src/libmmpong/netmsg.h

    r528 r541  
    108108                        pack_raw<uint32_t>(&conv); 
    109109                }; 
     110                 
     111                void pack(bool b) { 
     112                        uint16_t i=b; 
     113                        pack(i); 
     114                }; 
    110115 
    111116                void pack(double f) { 
     
    173178                }; 
    174179 
     180                void unpack(bool &ret) { 
     181                        uint16_t i; 
     182                        unpack(i); 
     183                        ret=(bool)i; 
     184                }; 
     185 
    175186                void unpack(double &f) { 
    176187                        //TODO: assure double has 64 bit 
  • branches/cpp-ode/src/libmmpong/ode_box.cc

    r540 r541  
    33using namespace mmp; 
    44 
    5 ODEBox::ODEBox(NetGame::pointer game, uint16_t entid) :  
     5ODEBox::ODEBox(NetGame::pointer game, uint16_t entid, bool _movable) :  
    66        ODEObj<NetEnt::ODEBox, dBox>(game, entid) 
    77{  
    88        geom.create(get_space(), 1.0, 1.0, 1.0); 
    9         //geom.setBody(*this); 
    109        classname="ODEBox"; 
     10        if (_movable) 
     11                set_movable(); 
    1112} 
    1213 
  • branches/cpp-ode/src/libmmpong/ode_box.h

    r528 r541  
    1010class ODEBox : public ODEObj<NetEnt::ODEBox, dBox>, public NetEntCreator<ODEBox> { 
    1111        public: 
    12                 ODEBox(NetGame::pointer game, uint16_t entid); 
     12                ODEBox(NetGame::pointer game, uint16_t entid, bool _movable=true); 
    1313        private: 
    1414                virtual void update(NetMsg::pointer msg) { 
  • 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++) 
  • branches/cpp-ode/src/libmmpong/ode_sphere.cc

    r532 r541  
    33using namespace mmp; 
    44 
    5 ODESphere::ODESphere(NetGame::pointer game, uint16_t entid, dReal r) :  
     5ODESphere::ODESphere(NetGame::pointer game, uint16_t entid, bool _movable) :  
    66        ODEObj<NetEnt::ODESphere, dSphere>(game, entid)  
    77{  
    8         geom.create(get_space(), r); 
     8        geom.create(get_space(), 1.0); 
    99        geom.setBody(*this); 
    1010        classname="ODESphere"; 
     11        if (_movable) 
     12                set_movable(); 
    1113} 
    1214 
  • branches/cpp-ode/src/libmmpong/ode_sphere.h

    r529 r541  
    99class ODESphere : public ODEObj<NetEnt::ODESphere, dSphere>, public NetEntCreator<ODESphere> { 
    1010        public: 
    11                 ODESphere(NetGame::pointer game, uint16_t entid, dReal r=1.0); 
     11                ODESphere(NetGame::pointer game, uint16_t entid, bool _movable=true); 
    1212        private: 
    1313                virtual void update(NetMsg::pointer msg) { 
  • branches/cpp-ode/src/mmpong-gl/client_gl.cc

    r540 r541  
    120120                boost::posix_time::time_duration renderdur=renderend-renderbegin, waitdur=framedur-renderdur; 
    121121                LOG("Rendering: " << renderdur << " => Waiting " << waitdur); 
    122                 boost::this_thread::sleep(waitdur); 
     122                if (!waitdur.is_negative()) 
     123                        boost::this_thread::sleep(waitdur); 
    123124        }        
    124125}