Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2009, 10:38:06 PM (16 years ago)
Author:
scheusso
Message:

first approach of having client-side pong physics
some optimisations in TrafficControl

Location:
code/branches/netp3/src/orxonox/objects/worldentities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp3/src/orxonox/objects/worldentities/PongBall.cc

    r2896 r3043  
    3232#include "core/CoreIncludes.h"
    3333#include "core/GameMode.h"
    34 #include "objects/worldentities/PongBat.h"
    3534#include "objects/gametypes/Gametype.h"
    3635
     
    4746        this->speed_ = 0;
    4847        this->bat_ = 0;
     48        this->batID_ = new unsigned int[2];
     49        this->batID_[0] = OBJECTID_UNKNOWN;
     50        this->batID_[1] = OBJECTID_UNKNOWN;
    4951        this->relMercyOffset_ = 0.05;
     52       
     53        this->registerVariables();
     54    }
     55   
     56    void PongBall::registerVariables()
     57    {
     58        registerVariable( this->batID_[0] );
     59        registerVariable( this->batID_[1], variableDirection::toclient, new NetworkCallback<PongBall>( this, &PongBall::applyBats) );
    5060    }
    5161
     
    119129                this->setPosition(position);
    120130        }
     131        else
     132        {
     133          Vector3 position = this->getPosition();
     134          Vector3 velocity = this->getVelocity();
     135
     136          if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
     137          {
     138            velocity.z = -velocity.z;
     139
     140            if (position.z > this->fieldHeight_ / 2)
     141              position.z = this->fieldHeight_ / 2;
     142            if (position.z < -this->fieldHeight_ / 2)
     143              position.z = -this->fieldHeight_ / 2;
     144          }
     145
     146          if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
     147          {
     148            float distance = 0;
     149
     150            if (this->bat_)
     151            {
     152              if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
     153              {
     154                distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     155                if (fabs(distance) <= 1)
     156                {
     157                  position.x = this->fieldWidth_ / 2;
     158                  velocity.x = -velocity.x;
     159                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     160                }
     161              }
     162              if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
     163              {
     164                distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     165                if (fabs(distance) <= 1)
     166                {
     167                  position.x = -this->fieldWidth_ / 2;
     168                  velocity.x = -velocity.x;
     169                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     170                }
     171              }
     172            }
     173          }
     174
     175          if (velocity != this->getVelocity())
     176            this->setVelocity(velocity);
     177          if (position != this->getPosition())
     178            this->setPosition(position);
     179        }
    121180    }
    122181
  • code/branches/netp3/src/orxonox/objects/worldentities/PongBall.h

    r2885 r3043  
    3333
    3434#include "objects/worldentities/MovableEntity.h"
     35#include "objects/worldentities/PongBat.h"
    3536
    3637namespace orxonox
     
    4344
    4445            virtual void tick(float dt);
     46           
     47            void registerVariables();
    4548
    4649            void setFieldDimension(float width, float height)
     
    6164
    6265            void setBats(PongBat** bats)
    63                 { this->bat_ = bats; }
     66            { this->bat_ = bats; this->batID_[0] = this->bat_[0]->getObjectID(); this->batID_[1] = this->bat_[1]->getObjectID(); }
     67           
     68            void applyBats()
     69            { if(!this->bat_) this->bat_ = new PongBat*[2]; if(this->batID_[0] != OBJECTID_UNKNOWN) this->bat_[0] = dynamic_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[0])); if(this->batID_[1] != OBJECTID_UNKNOWN) this->bat_[1] = dynamic_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[1])); }
    6470
    6571            static const float MAX_REL_Z_VELOCITY;
     
    7177            float batlength_;
    7278            PongBat** bat_;
     79            unsigned int* batID_;
    7380            float relMercyOffset_;
    7481    };
Note: See TracChangeset for help on using the changeset viewer.